1 // Copyright 2023 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 #include "pw_i2c_linux/initiator.h"
16
17 #include <type_traits>
18
19 #include "pw_i2c/initiator.h"
20 #include "pw_unit_test/framework.h"
21
22 namespace pw::i2c {
23 namespace {
24
25 // A bus path that doesn't exist. Linux only supports 255 minor numbers.
26 constexpr auto kBusPathMissing = "/dev/i2c-256";
27 // A bus path that points at something that is not an I2C bus.
28 constexpr auto kBusPathInvalid = "/dev/null";
29
TEST(LinuxInitiatorTest,TestOpenMissingFileFails)30 TEST(LinuxInitiatorTest, TestOpenMissingFileFails) {
31 EXPECT_EQ(LinuxInitiator::OpenI2cBus(kBusPathMissing).status(),
32 Status::InvalidArgument());
33 }
34
TEST(LinuxInitiatorTest,TestOpenInvalidFileFails)35 TEST(LinuxInitiatorTest, TestOpenInvalidFileFails) {
36 EXPECT_EQ(LinuxInitiator::OpenI2cBus(kBusPathInvalid).status(),
37 Status::InvalidArgument());
38 }
39
40 // Check that LinuxInitiator implements Initiator.
41 static_assert(std::is_assignable_v<Initiator&, LinuxInitiator&>);
42
43 } // namespace
44 } // namespace pw::i2c