1 // Copyright 2021 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
15 #include "pw_i2c/address.h"
17 #include "gtest/gtest.h"
21 TEST(Address, SevenBitConstexpr) {
22 constexpr Address kSevenBit =
23 Address::SevenBit<Address::kMaxSevenBitAddress>();
24 EXPECT_EQ(kSevenBit.GetSevenBit(), Address::kMaxSevenBitAddress);
27 TEST(Address, TenBitConstexpr) {
28 constexpr Address kTenBit = Address::TenBit<Address::kMaxTenBitAddress>();
29 EXPECT_EQ(kTenBit.GetTenBit(), Address::kMaxTenBitAddress);
32 TEST(Address, SevenBitRuntimeChecked) {
33 const Address seven_bit(Address::kMaxSevenBitAddress);
34 EXPECT_EQ(seven_bit.GetSevenBit(), Address::kMaxSevenBitAddress);
37 TEST(Address, TenBitRuntimeChecked) {
38 const Address ten_bit(Address::kMaxTenBitAddress);
39 EXPECT_EQ(ten_bit.GetTenBit(), Address::kMaxTenBitAddress);
42 // TODO(pwbug/88): Verify assert behaviour when trying to get a 7bit address out
43 // of a 10bit address.
45 // TODO(pwbug/47): Add tests to ensure the constexpr constructors fail to
46 // compile with invalid addresses once no-copmile tests are set up in Pigweed.
48 } // namespace pw::i2c