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/common/metrics.h"
16
17 #include "pw_bluetooth_sapphire/internal/host/testing/inspect.h"
18 #include "pw_unit_test/framework.h"
19
20 #ifndef NINSPECT
21
22 namespace bt {
23 namespace {
24
25 using namespace inspect::testing;
26
TEST(MetrictsTest,PropertyAddSubInt)27 TEST(MetrictsTest, PropertyAddSubInt) {
28 inspect::Inspector inspector;
29 auto counter = UintMetricCounter();
30 auto child = inspector.GetRoot().CreateChild("child");
31 counter.AttachInspect(child, "value");
32
33 auto node_matcher_0 = AllOf(NodeMatches(
34 AllOf(NameMatches("child"),
35 PropertyList(UnorderedElementsAre(UintIs("value", 0))))));
36
37 auto hierarchy = inspect::ReadFromVmo(inspector.DuplicateVmo()).take_value();
38 EXPECT_THAT(hierarchy,
39 AllOf(ChildrenMatch(UnorderedElementsAre(node_matcher_0))));
40
41 counter.Add(5);
42
43 auto node_matcher_1 = AllOf(NodeMatches(
44 AllOf(NameMatches("child"),
45 PropertyList(UnorderedElementsAre(UintIs("value", 5))))));
46
47 hierarchy = inspect::ReadFromVmo(inspector.DuplicateVmo()).take_value();
48 EXPECT_THAT(hierarchy,
49 AllOf(ChildrenMatch(UnorderedElementsAre(node_matcher_1))));
50
51 counter.Subtract();
52
53 auto node_matcher_2 = AllOf(NodeMatches(
54 AllOf(NameMatches("child"),
55 PropertyList(UnorderedElementsAre(UintIs("value", 4))))));
56
57 hierarchy = inspect::ReadFromVmo(inspector.DuplicateVmo()).take_value();
58 EXPECT_THAT(hierarchy,
59 AllOf(ChildrenMatch(UnorderedElementsAre(node_matcher_2))));
60 }
61
62 } // namespace
63
64 } // namespace bt
65
66 #endif // NINSPECT
67