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