1+ // Copyright 2023 Google LLC
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://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,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ #include < libhal/current_sensor.hpp>
16+
17+ #include < boost/ut.hpp>
18+
19+ namespace hal {
20+ namespace {
21+ class test_current_sensor : public hal ::current_sensor
22+ {
23+ public:
24+ bool m_return_error_status{ false };
25+ ~test_current_sensor () override = default ;
26+
27+ private:
28+ result<read_t > driver_read () override
29+ {
30+ if (m_return_error_status) {
31+ return hal::new_error ();
32+ }
33+ return read_t {};
34+ }
35+ };
36+ } // namespace
37+
38+ void current_sensor_test ()
39+ {
40+ using namespace boost ::ut;
41+ " current sensor interface test" _test = []() {
42+ test_current_sensor test;
43+
44+ auto result = test.read ();
45+
46+ expect (bool { result });
47+ };
48+ " current sensor errors test" _test = []() {
49+ test_current_sensor test;
50+ test.m_return_error_status = true ;
51+
52+ auto result = test.read ();
53+
54+ expect (!bool { result });
55+ };
56+ }
57+
58+ } // namespace hal
0 commit comments