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