Pigweed
 
Loading...
Searching...
No Matches
googletest_style_event_handler.h
1// Copyright 2022 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#pragma once
16
17#include "pw_preprocessor/compiler.h"
18#include "pw_unit_test/event_handler.h"
19
20// Define the test messages and string formats as literal strings so they
21// work with different log databases.
22#define PW_UNIT_TEST_GOOGLETEST_RUN_ALL_TESTS_START \
23 "[==========] Running all tests."
24#define PW_UNIT_TEST_GOOGLETEST_RUN_ALL_TESTS_END \
25 "[==========] Done running all tests."
26
27#define PW_UNIT_TEST_GOOGLETEST_TEST_PROGRAM_START \
28 "[==========] Running %d tests from %d test suite%s."
29
30#define PW_UNIT_TEST_GOOGLETEST_TEST_PROGRAM_END \
31 "[==========] %d / %d tests from %d test suite%s ran."
32
33#define PW_UNIT_TEST_GOOGLETEST_ENVIRONMENTS_SETUP_END \
34 "[----------] Global test environments setup."
35
36#define PW_UNIT_TEST_GOOGLETEST_ENVIRONMENTS_TEAR_DOWN_END \
37 "[----------] Global test environments tear-down."
38
39#define PW_UNIT_TEST_GOOGLETEST_TEST_SUITE_START \
40 "[----------] %d tests from %s."
41
42#define PW_UNIT_TEST_GOOGLETEST_TEST_SUITE_END "[----------] %d tests from %s."
43
44#define PW_UNIT_TEST_GOOGLETEST_PASSED_SUMMARY "[ PASSED ] %d test(s)."
45#define PW_UNIT_TEST_GOOGLETEST_DISABLED_SUMMARY "[ DISABLED ] %d test(s)."
46#define PW_UNIT_TEST_GOOGLETEST_FAILED_SUMMARY "[ FAILED ] %d test(s)."
47
48#define PW_UNIT_TEST_GOOGLETEST_CASE_START "[ RUN ] %s.%s"
49#define PW_UNIT_TEST_GOOGLETEST_CASE_OK "[ OK ] %s.%s"
50#define PW_UNIT_TEST_GOOGLETEST_CASE_FAILED "[ FAILED ] %s.%s"
51#define PW_UNIT_TEST_GOOGLETEST_CASE_DISABLED "[ DISABLED ] %s.%s"
52
53namespace pw {
54namespace unit_test {
55
62 public:
63 void TestProgramStart(const ProgramSummary& program_summary) override;
64 void EnvironmentsSetUpEnd() override;
65 void TestSuiteStart(const TestSuite& test_suite) override;
66 void TestSuiteEnd(const TestSuite& test_suite) override;
67 void EnvironmentsTearDownEnd() override;
68 void TestProgramEnd(const ProgramSummary& program_summary) override;
69
70 void RunAllTestsStart() override;
71 void RunAllTestsEnd(const RunTestsSummary& run_tests_summary) override;
72 void TestCaseStart(const TestCase& test_case) override;
73 void TestCaseEnd(const TestCase& test_case, TestResult result) override;
74 void TestCaseExpect(const TestCase& test_case,
75 const TestExpectation& expectation) override;
76 void TestCaseDisabled(const TestCase& test_case) override;
77
78 protected:
79 constexpr GoogleTestStyleEventHandler(bool verbose) : verbose_(verbose) {}
80
81 bool verbose() const { return verbose_; }
82
83 // Writes the content without a trailing newline.
84 virtual void Write(const char* content) = 0;
85
86 // Writes the formatted content and appends a newline character.
87 virtual void WriteLine(const char* format, ...) PW_PRINTF_FORMAT(2, 3) = 0;
88
89 private:
90 bool verbose_;
91};
92
93} // namespace unit_test
94} // namespace pw
Definition: event_handler.h:115
Definition: googletest_style_event_handler.h:61
void TestProgramEnd(const ProgramSummary &program_summary) override
Called after all test activities have ended.
void RunAllTestsStart() override
Called before all tests are run.
void TestSuiteStart(const TestSuite &test_suite) override
Called before the test suite starts.
void TestSuiteEnd(const TestSuite &test_suite) override
Called after the test suite ends.
void EnvironmentsSetUpEnd() override
Called after environment setup for each iteration of tests ends.
void EnvironmentsTearDownEnd() override
Called after environment teardown for each iteration of tests ends.
void RunAllTestsEnd(const RunTestsSummary &run_tests_summary) override
Called after all tests are run.
void TestCaseExpect(const TestCase &test_case, const TestExpectation &expectation) override
void TestProgramStart(const ProgramSummary &program_summary) override
Called before any test activity starts.
void TestCaseStart(const TestCase &test_case) override
Called when a new test case is started.
void TestCaseEnd(const TestCase &test_case, TestResult result) override
void TestCaseDisabled(const TestCase &test_case) override
Called when a disabled test case is encountered.
#define PW_PRINTF_FORMAT(format_index, parameter_index)
Definition: compiler.h:86
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27
Definition: event_handler.h:66
Definition: event_handler.h:52
Definition: event_handler.h:27
Definition: event_handler.h:38
Definition: event_handler.h:77