Pigweed
 
Loading...
Searching...
No Matches
simple_printing_event_handler.h
1// Copyright 2019 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 <cstddef>
18#include <string_view>
19
20#include "pw_preprocessor/compiler.h"
21#include "pw_unit_test/event_handler.h"
22#include "pw_unit_test/googletest_style_event_handler.h"
23
24namespace pw::unit_test {
25
65 public:
66 // Function for writing output as a string.
67 using WriteFunction = void (*)(std::string_view string, bool append_newline);
68
69 // Instantiates an event handler with a function to which to output results.
70 // If verbose is set, information for successful tests is written as well as
71 // failures.
72 constexpr SimplePrintingEventHandler(WriteFunction write_function,
73 bool verbose = false)
75 write_(write_function),
76 buffer_{} {}
77
78 private:
79 void WriteLine(const char* format, ...) override PW_PRINTF_FORMAT(2, 3);
80
81 void Write(const char* content) override { write_(content, false); }
82
83 WriteFunction write_;
84 char buffer_[512];
85};
86
87} // namespace pw::unit_test
Definition: googletest_style_event_handler.h:61
Definition: simple_printing_event_handler.h:64
#define PW_PRINTF_FORMAT(format_index, parameter_index)
Definition: compiler.h:86