Skip to content

Feature: Autogenerate gmock mocks + CPP/gtest test skeletons from interface headers #254

Description

@Ulrond

Problem/Opportunity

ut-core's autogenerate scripts (scripts/autogenerate.sh, autogenerate_tests.sh, autogenerate_skeletons.sh, autogenerate_shared.sh) today generate compilable C tests from a provided header, but they cannot generate CPP/gtest tests, and they cannot generate gmock mocks for a C++ interface. Unit-testing an abstract C++ interface needs both: a mock of the interface, and a gtest test skeleton that drives it.

Note: GoogleMock's own mock generator (gmock_gen.py, googlemock/scripts/generator/) that historically produced MOCK_METHOD classes from a header was removed from googletest by the pinned 1.15.2 (it existed up to ~1.10). So autogeneration must be provided by ut-core's own tooling rather than the upstream script.

Proposed Solution

Extend ut-core's autogenerate tooling to, given a C++ interface header:

  1. Generate a gmock mock class — a UT_MOCK_METHOD entry per pure-virtual method (using the wrappers from Feature: Wrap GoogleMock (gmock) in ut-core with UT_ mocking macros + examples #253).
  2. Generate a compilable CPP/gtest test skeleton that instantiates the mock and stubs out UT_ADD_TEST cases — the CPP analogue of today's C-test generation.
  3. Reuse the existing skeleton/shared machinery where possible; add a CPP/gtest code path selected by variant or flag.

This subsumes / directly relates to the existing open issues #174 (Add support in auto-generate script to generate CPP tests for GTEST) and #161 (Autogenerate scripts for generating CPP/gtest tests) — the AIDL team has reportedly already used ut-core to generate CPP tests, so liaise on the expected shape.

Acceptance Criteria

  • Given a user-provided C++ interface header, the autogenerate script emits:
    • a compilable gmock mock class (one UT_MOCK_METHOD per virtual method, correct signatures/const/override), and
    • a compilable gtest test skeleton referencing that mock and the UT_ macros,
      matching the ergonomics of today's C-test generation.
  • Generated output builds under the CPP/gtest variant without hand-editing (skeleton bodies may be TODO stubs).
  • Covered by an entry in scripts/test_autogenerate_script.sh.

Additional Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions