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_bluetooth_sapphire/internal/host/testing/inspect_util.h"
16
17 #ifndef NINSPECT
18
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21
22 namespace bt::testing {
23
24 using ::testing::Optional;
25
TEST(InspectUtil,InspectPropertyValueAtPathSuccess)26 TEST(InspectUtil, InspectPropertyValueAtPathSuccess) {
27 inspect::Inspector inspector_;
28 inspect::Node child = inspector_.GetRoot().CreateChild("child");
29 inspect::IntProperty prop = child.CreateInt("property", 42);
30 EXPECT_THAT(GetInspectValue<inspect::IntPropertyValue>(inspector_,
31 {"child", "property"}),
32 Optional(42));
33 }
34
TEST(InspectUtil,InspectPropertyValueAtPathFailure)35 TEST(InspectUtil, InspectPropertyValueAtPathFailure) {
36 inspect::Inspector inspector_;
37 inspect::Node child = inspector_.GetRoot().CreateChild("child");
38 EXPECT_FALSE(GetInspectValue<inspect::StringPropertyValue>(
39 inspector_, {"child", "property"}));
40 }
41
TEST(InspectUtil,EmptyPath)42 TEST(InspectUtil, EmptyPath) {
43 inspect::Inspector inspector_;
44 EXPECT_FALSE(GetInspectValue<inspect::IntPropertyValue>(inspector_, {}));
45 }
46
TEST(InspectUtil,NodeInPathDoesNotExist)47 TEST(InspectUtil, NodeInPathDoesNotExist) {
48 inspect::Inspector inspector_;
49 EXPECT_FALSE(GetInspectValue<inspect::StringPropertyValue>(
50 inspector_, {"child", "property"}));
51 }
52
53 } // namespace bt::testing
54
55 #endif // NINSPECT
56