C/C++ API Reference
Loading...
Searching...
No Matches
responder_test_interface.h
1// Copyright 2025 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 "pw_bytes/span.h"
18#include "pw_function/function.h"
19#include "pw_i2c/address.h"
20#include "pw_i2c/responder.h"
21#include "pw_result/result.h"
22#include "pw_status/status.h"
23#include "pw_unit_test/framework.h"
24
25namespace pw::i2c::test {
26
28
34 public:
35 bool OnStartRead() override { return on_start_read_cb(); }
36
37 bool OnStartWrite() override { return on_start_write_cb(); }
38
39 bool OnWrite(ConstByteSpan data) override { return on_write_cb(data); }
40
41 Result<ConstByteSpan> OnRead() override { return on_read_cb(); }
42
43 bool OnStop() override { return on_stop_cb(); }
44
45 void SetOnStartReadCb(pw::Function<bool()>&& cb) {
46 on_start_read_cb = std::move(cb);
47 }
48
49 void SetOnStartWriteCb(pw::Function<bool()>&& cb) {
50 on_start_write_cb = std::move(cb);
51 }
52
53 void SetOnWriteCb(pw::Function<bool(ConstByteSpan)>&& cb) {
54 on_write_cb = std::move(cb);
55 }
56
57 void SetOnReadCb(pw::Function<Result<ConstByteSpan>()>&& cb) {
58 on_read_cb = std::move(cb);
59 }
60
61 void SetOnStopCb(pw::Function<bool()>&& cb) { on_stop_cb = std::move(cb); }
62
63 private:
65 pw::Function<bool()> on_start_read_cb;
66
68 pw::Function<bool()> on_start_write_cb;
69
71 pw::Function<bool(ConstByteSpan)> on_write_cb;
72
75
77 pw::Function<bool()> on_stop_cb;
78};
79
84 public:
88 virtual Responder& GetResponder() = 0;
89
97 bool send_stop) = 0;
98
105 virtual Status SimulateInitiatorRead(ByteSpan buffer, bool send_stop) = 0;
106};
107
109
110} // namespace pw::i2c::test
Definition: result.h:143
Definition: status.h:120
Definition: responder.h:27
Definition: responder.h:87
Definition: responder_test_interface.h:83
virtual Status SimulateInitiatorWrite(ConstByteSpan write_data, bool send_stop)=0
virtual Status SimulateInitiatorRead(ByteSpan buffer, bool send_stop)=0
Definition: responder_test_interface.h:33
bool OnWrite(ConstByteSpan data) override
Definition: responder_test_interface.h:39
Result< ConstByteSpan > OnRead() override
Definition: responder_test_interface.h:41
bool OnStop() override
Definition: responder_test_interface.h:43
bool OnStartRead() override
Definition: responder_test_interface.h:35
bool OnStartWrite() override
Definition: responder_test_interface.h:37
Definition: framework_backend.h:723
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73