Problem/Opportunity
ut-core wraps the gtest backend (include/ut_gtest.h, src/cpp_source/ut_gtest.cpp) with UT_ASSERT_* / UT_ADD_TEST macros, but it does not wrap GoogleMock (gmock). There is currently no supported way to author mocks for a C++ interface under test, which is the core need when unit-testing abstract HAL/AIDL C++ interfaces.
The pinned googletest release (1.15.2, fetched by build.sh into framework/gtest/<target>/googletest-1.15.2) is the combined distribution — it already contains googlemock/ alongside googletest/. So gmock source is present; it is simply not built, linked, initialised, or wrapped.
Proposed Solution
Wrap gmock in ut-core, mirroring the existing gtest wrap:
- Build — build the gmock libraries from the already-fetched googletest tree (
build.sh): produce libgmock.a / libgmock_main.a into build/<target>/cpp_libs alongside the gtest libs (gmock's CMake builds both).
- Link + include — in the
Makefile GTEST case, add googlemock/include to INC_DIRS and -lgmock to the link line (before -lgtest).
- Initialise — call
::testing::InitGoogleMock(&argc, argv) in the UTTestRunner constructor (instead of / in addition to InitGoogleTest), so gmock installs its verification listener and unmet EXPECT_CALLs fail the run.
- Wrapper header — add
include/ut_gmock.h exposing ut-core-styled macros over gmock: UT_MOCK_METHOD, UT_EXPECT_CALL, and thin aliases for the common matchers/actions (UT_ANY/_, UT_RETURN, UT_RETURN_REF, UT_INVOKE, UT_TIMES, UT_AT_LEAST, ...). Pull it in from ut_gtest.h (or ut.h) for the CPP variant.
- Examples — add mocking example tests under
tests/src/cpp_source/ (e.g. ut_test_gmock.cpp): a small abstract interface, a UT_MOCK_METHOD mock, and tests demonstrating expectation setting, matchers, actions (Return/Invoke), cardinality, and a deliberately-unmet expectation (documented/negative case).
- Docs — update
AGENTS.md (§ gtest wrap → add gmock), README.md, and the template/ test example to show mock usage.
Acceptance Criteria
- A user can define a mock of a C++ interface using
UT_MOCK_METHOD, set expectations with UT_EXPECT_CALL, and use common matchers/actions — all via UT_-prefixed macros, no direct gmock/gmock.h include required in the test.
- Unmet expectations fail the test run (gmock verification is active).
- The mocking example suite builds and runs under the CPP/gtest variant (
./build.sh TARGET=linux VARIANT=CPP or equivalent) and is registered like other suites.
- No regression to the existing gtest wrap or the C/CUnit variant.
Additional Notes
Problem/Opportunity
ut-core wraps the gtest backend (
include/ut_gtest.h,src/cpp_source/ut_gtest.cpp) withUT_ASSERT_*/UT_ADD_TESTmacros, but it does not wrap GoogleMock (gmock). There is currently no supported way to author mocks for a C++ interface under test, which is the core need when unit-testing abstract HAL/AIDL C++ interfaces.The pinned googletest release (
1.15.2, fetched bybuild.shintoframework/gtest/<target>/googletest-1.15.2) is the combined distribution — it already containsgooglemock/alongsidegoogletest/. So gmock source is present; it is simply not built, linked, initialised, or wrapped.Proposed Solution
Wrap gmock in ut-core, mirroring the existing gtest wrap:
build.sh): producelibgmock.a/libgmock_main.aintobuild/<target>/cpp_libsalongside the gtest libs (gmock's CMake builds both).MakefileGTEST case, addgooglemock/includetoINC_DIRSand-lgmockto the link line (before-lgtest).::testing::InitGoogleMock(&argc, argv)in theUTTestRunnerconstructor (instead of / in addition toInitGoogleTest), so gmock installs its verification listener and unmetEXPECT_CALLs fail the run.include/ut_gmock.hexposing ut-core-styled macros over gmock:UT_MOCK_METHOD,UT_EXPECT_CALL, and thin aliases for the common matchers/actions (UT_ANY/_,UT_RETURN,UT_RETURN_REF,UT_INVOKE,UT_TIMES,UT_AT_LEAST, ...). Pull it in fromut_gtest.h(orut.h) for the CPP variant.tests/src/cpp_source/(e.g.ut_test_gmock.cpp): a small abstract interface, aUT_MOCK_METHODmock, and tests demonstrating expectation setting, matchers, actions (Return/Invoke), cardinality, and a deliberately-unmet expectation (documented/negative case).AGENTS.md(§ gtest wrap → add gmock),README.md, and thetemplate/test example to show mock usage.Acceptance Criteria
UT_MOCK_METHOD, set expectations withUT_EXPECT_CALL, and use common matchers/actions — all viaUT_-prefixed macros, no directgmock/gmock.hinclude required in the test../build.sh TARGET=linux VARIANT=CPPor equivalent) and is registered like other suites.Additional Notes
gmock_gen.pygenerator was removed from googletest by 1.15.2 (present up to ~1.10), so mock generation is handled in Feature: Autogenerate gmock mocks + CPP/gtest test skeletons from interface headers #254 via ut-core's own autogenerate scripts, not the upstream script.