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 {
17
18namespace unit_test {
19
21
23enum class TestResult {
24 kSuccess = 0,
25 kFailure = 1,
26 // Test skipped at runtime. This is neither a success nor a failure.
27 kSkipped = 2,
28};
29
30struct TestCase {
32 const char* suite_name;
33
35 const char* test_name;
36
38 const char* file_name;
39};
40
43 const char* expression;
44
47
50
52 bool success;
53};
54
58
61
64
67};
68
72
75
78};
79
80struct TestSuite {
82 const char* name;
83
86};
87
119 public:
120 virtual ~EventHandler() = default;
121
123 virtual void TestProgramStart(const ProgramSummary& program_summary) = 0;
124
126 virtual void EnvironmentsSetUpEnd() = 0;
127
129 virtual void TestSuiteStart(const TestSuite& test_suite) = 0;
130
132 virtual void TestSuiteEnd(const TestSuite& test_suite) = 0;
133
135 virtual void EnvironmentsTearDownEnd() = 0;
136
138 virtual void TestProgramEnd(const ProgramSummary& program_summary) = 0;
139
141 virtual void RunAllTestsStart() = 0;
142
144 virtual void RunAllTestsEnd(const RunTestsSummary& run_tests_summary) = 0;
145
147 virtual void TestCaseStart(const TestCase& test_case) = 0;
148
151 virtual void TestCaseEnd(const TestCase& test_case, TestResult result) = 0;
152
154 virtual void TestCaseDisabled(const TestCase&) {}
155
158 virtual void TestCaseExpect(const TestCase& test_case,
159 const TestExpectation& expectation) = 0;
160};
161
168
170
171} // namespace unit_test
172
173} // namespace pw
Definition: event_handler.h:118
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:154
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)
TestResult
The result of a complete test run.
Definition: event_handler.h:23
The Pigweed namespace.
Definition: alignment.h:27
Definition: event_handler.h:69
int test_suites
The number of test suites included in the program.
Definition: event_handler.h:74
int tests_to_run
The total number of tests to run in the program.
Definition: event_handler.h:71
RunTestsSummary tests_summary
Test summary for the program once complete.
Definition: event_handler.h:77
Definition: event_handler.h:55
int disabled_tests
The number of disabled tests encountered.
Definition: event_handler.h:66
int failed_tests
The number of passed tests among the run tests.
Definition: event_handler.h:60
int skipped_tests
The number of tests skipped or filtered out.
Definition: event_handler.h:63
int passed_tests
The number of passed tests among the run tests.
Definition: event_handler.h:57
Definition: event_handler.h:30
const char * file_name
Path to the file in which the test case is defined.
Definition: event_handler.h:38
const char * suite_name
Name of the test suite to which this test case belongs.
Definition: event_handler.h:32
const char * test_name
Name of the test case.
Definition: event_handler.h:35
Definition: event_handler.h:41
int line_number
Line number at which the expectation is located.
Definition: event_handler.h:49
bool success
Whether the expectation succeeded.
Definition: event_handler.h:52
const char * evaluated_expression
The expression with arguments evaluated.
Definition: event_handler.h:46
const char * expression
The source code for the expression which was run.
Definition: event_handler.h:43
Definition: event_handler.h:80
int test_to_run_count
Total number of tests in suite to run.
Definition: event_handler.h:85
const char * name
Name of the test suite.
Definition: event_handler.h:82