1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
16 #include "pw_log/log.h"
17 #include "pw_unit_test/internal/rpc_event_handler.h"
18 #include "pw_unit_test_proto/unit_test.pwpb.h"
19 #include "pw_unit_test_proto/unit_test.raw_rpc.pb.h"
21 namespace pw::unit_test {
23 class UnitTestService final : public generated::UnitTest<UnitTestService> {
25 UnitTestService() : handler_(*this), verbose_(false) {}
27 void Run(ServerContext& ctx, ConstByteSpan request, RawServerWriter& writer);
30 friend class internal::RpcEventHandler;
32 // TODO(frolv): This function essentially performs what a pw_protobuf RPC
33 // method would do. Once that API is implemented, this service should be
35 template <typename WriteFunction>
36 void WriteEvent(WriteFunction event_writer) {
37 protobuf::NestedEncoder<2, 3> encoder(writer_.PayloadBuffer());
38 Event::Encoder event(&encoder);
40 if (Result<ConstByteSpan> result = encoder.Encode(); result.ok()) {
41 writer_.Write(result.value());
45 void WriteTestRunStart();
46 void WriteTestRunEnd(const RunTestsSummary& summary);
47 void WriteTestCaseStart(const TestCase& test_case);
48 void WriteTestCaseEnd(TestResult result);
49 void WriteTestCaseDisabled(const TestCase& test_case);
50 void WriteTestCaseExpectation(const TestExpectation& expectation);
52 internal::RpcEventHandler handler_;
53 RawServerWriter writer_;
57 } // namespace pw::unit_test