C/C++ API Reference
Loading...
Searching...
No Matches
event_handler.h
1// Copyright 2020 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#pragma once
15
16namespace pw {
18namespace unit_test {
19
20// The result of a complete test run.
21enum class TestResult {
22 kSuccess = 0,
23 kFailure = 1,
24 // Test skipped at runtime. This is neither a success nor a failure.
25 kSkipped = 2,
26};
27
28struct TestCase {
29 // Name of the test suite to which this test case belongs.
30 const char* suite_name;
31
32 // Name of the test case.
33 const char* test_name;
34
35 // Path to the file in which the test case is defined.
36 const char* file_name;
37};
38
40 // The source code for the expression which was run.
41 const char* expression;
42
43 // The expression with arguments evaluated.
44 const char* evaluated_expression;
45
46 // Line number at which the expectation is located.
47 int line_number;
48
49 // Whether the expectation succeeded.
50 bool success;
51};
52
54 // The number of passed tests among the run tests.
55 int passed_tests;
56
57 // The number of passed tests among the run tests.
58 int failed_tests;
59
60 // The number of tests skipped or filtered out.
61 int skipped_tests;
62
63 // The number of disabled tests encountered.
64 int disabled_tests;
65};
66
68 // The total number of tests to run in the program.
69 int tests_to_run;
70
71 // The number of test suites included in the program.
72 int test_suites;
73
74 // Test summary for the program once complete.
75 RunTestsSummary tests_summary;
76};
77
78struct TestSuite {
79 // Name of the test suite.
80 const char* name;
81
82 // Total number of tests in suite to run.
83 int test_to_run_count;
84};
85
117 public:
118 virtual ~EventHandler() = default;
119
121 virtual void TestProgramStart(const ProgramSummary& program_summary) = 0;
122
124 virtual void EnvironmentsSetUpEnd() = 0;
125
127 virtual void TestSuiteStart(const TestSuite& test_suite) = 0;
128
130 virtual void TestSuiteEnd(const TestSuite& test_suite) = 0;
131
133 virtual void EnvironmentsTearDownEnd() = 0;
134
136 virtual void TestProgramEnd(const ProgramSummary& program_summary) = 0;
137
139 virtual void RunAllTestsStart() = 0;
140
142 virtual void RunAllTestsEnd(const RunTestsSummary& run_tests_summary) = 0;
143
145 virtual void TestCaseStart(const TestCase& test_case) = 0;
146
149 virtual void TestCaseEnd(const TestCase& test_case, TestResult result) = 0;
150
152 virtual void TestCaseDisabled(const TestCase&) {}
153
156 virtual void TestCaseExpect(const TestCase& test_case,
157 const TestExpectation& expectation) = 0;
158};
159
166
167} // namespace unit_test
168} // namespace pw
Definition: event_handler.h:116
virtual void EnvironmentsSetUpEnd()=0
Called after environment setup for each iteration of tests ends.
virtual void TestCaseExpect(const TestCase &test_case, const TestExpectation &expectation)=0
virtual void TestCaseDisabled(const TestCase &)
Called when a disabled test case is encountered.
Definition: event_handler.h:152
virtual void TestProgramEnd(const ProgramSummary &program_summary)=0
Called after all test activities have ended.
virtual void TestCaseEnd(const TestCase &test_case, TestResult result)=0
virtual void EnvironmentsTearDownEnd()=0
Called after environment teardown for each iteration of tests ends.
virtual void TestCaseStart(const TestCase &test_case)=0
Called when a new test case is started.
virtual void TestSuiteEnd(const TestSuite &test_suite)=0
Called after the test suite ends.
virtual void RunAllTestsEnd(const RunTestsSummary &run_tests_summary)=0
Called after all tests are run.
virtual void TestProgramStart(const ProgramSummary &program_summary)=0
Called before any test activity starts.
virtual void TestSuiteStart(const TestSuite &test_suite)=0
Called before the test suite starts.
virtual void RunAllTestsStart()=0
Called before all tests are run.
void RegisterEventHandler(EventHandler *event_handler)
The Pigweed namespace.
Definition: alignment.h:27
Definition: event_handler.h:67
Definition: event_handler.h:53
Definition: event_handler.h:28
Definition: event_handler.h:39
Definition: event_handler.h:78