Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / lib / support / tests / TestCHIPCounter.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    All rights reserved.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 #include <nlunit-test.h>
20
21 #include <support/CHIPCounter.h>
22 #include <support/UnitTestRegistration.h>
23
24 static void CheckStartWithZero(nlTestSuite * inSuite, void * inContext)
25 {
26     chip::MonotonicallyIncreasingCounter counter;
27     NL_TEST_ASSERT(inSuite, counter.GetValue() == 0);
28 }
29
30 static void CheckInitialize(nlTestSuite * inSuite, void * inContext)
31 {
32     chip::MonotonicallyIncreasingCounter counter;
33
34     NL_TEST_ASSERT(inSuite, counter.Init(4321) == CHIP_NO_ERROR);
35     NL_TEST_ASSERT(inSuite, counter.GetValue() == 4321);
36 }
37
38 static void CheckAdvance(nlTestSuite * inSuite, void * inContext)
39 {
40     chip::MonotonicallyIncreasingCounter counter;
41
42     NL_TEST_ASSERT(inSuite, counter.Init(22) == CHIP_NO_ERROR);
43     NL_TEST_ASSERT(inSuite, counter.GetValue() == 22);
44     NL_TEST_ASSERT(inSuite, counter.Advance() == CHIP_NO_ERROR);
45     NL_TEST_ASSERT(inSuite, counter.GetValue() == 23);
46     NL_TEST_ASSERT(inSuite, counter.Advance() == CHIP_NO_ERROR);
47     NL_TEST_ASSERT(inSuite, counter.GetValue() == 24);
48 }
49
50 /**
51  *   Test Suite. It lists all the test functions.
52  */
53
54 // clang-format off
55 static const nlTest sTests[] =
56 {
57     NL_TEST_DEF("Start with zero", CheckStartWithZero),
58     NL_TEST_DEF("Can initialize",  CheckInitialize),
59     NL_TEST_DEF("Can Advance",     CheckAdvance),
60     NL_TEST_SENTINEL()
61 };
62 // clang-format on
63
64 /**
65  *  Set up the test suite.
66  */
67 static int TestSetup(void * inContext)
68 {
69     return (SUCCESS);
70 }
71
72 /**
73  *  Tear down the test suite.
74  */
75 static int TestTeardown(void * inContext)
76 {
77     return (SUCCESS);
78 }
79
80 int TestCHIPCounter(void)
81 {
82     // clang-format off
83     nlTestSuite theSuite = {
84         "chip-counter",
85         &sTests[0],
86         TestSetup,
87         TestTeardown
88     };
89     // clang-format on
90
91     // Run test suit againt one context.
92     nlTestRunner(&theSuite, nullptr);
93
94     return nlTestRunnerStats(&theSuite);
95 }
96
97 CHIP_REGISTER_TEST_SUITE(TestCHIPCounter)