1 // Copyright 2021 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/address.h"
16
17 #include "gtest/gtest.h"
18
19 namespace pw::i2c {
20
TEST(Address,SevenBitConstexpr)21 TEST(Address, SevenBitConstexpr) {
22 constexpr Address kSevenBit =
23 Address::SevenBit<Address::kMaxSevenBitAddress>();
24 EXPECT_EQ(kSevenBit.GetSevenBit(), Address::kMaxSevenBitAddress);
25 }
26
TEST(Address,TenBitConstexpr)27 TEST(Address, TenBitConstexpr) {
28 constexpr Address kTenBit = Address::TenBit<Address::kMaxTenBitAddress>();
29 EXPECT_EQ(kTenBit.GetTenBit(), Address::kMaxTenBitAddress);
30 }
31
TEST(Address,SevenBitRuntimeChecked)32 TEST(Address, SevenBitRuntimeChecked) {
33 const Address seven_bit(Address::kMaxSevenBitAddress);
34 EXPECT_EQ(seven_bit.GetSevenBit(), Address::kMaxSevenBitAddress);
35 }
36
TEST(Address,TenBitRuntimeChecked)37 TEST(Address, TenBitRuntimeChecked) {
38 const Address ten_bit(Address::kMaxTenBitAddress);
39 EXPECT_EQ(ten_bit.GetTenBit(), Address::kMaxTenBitAddress);
40 }
41
42 // TODO(b/235289499): Verify assert behaviour when trying to get a 7bit address
43 // out of a 10bit address.
44
45 // TODO(b/234882063): Add tests to ensure the constexpr constructors fail to
46 // compile with invalid addresses once no-copmile tests are set up in Pigweed.
47
48 } // namespace pw::i2c
49