3 * Copyright (c) 2020 Project CHIP Authors
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <nlunit-test.h>
21 #include <support/CHIPCounter.h>
22 #include <support/UnitTestRegistration.h>
24 static void CheckStartWithZero(nlTestSuite * inSuite, void * inContext)
26 chip::MonotonicallyIncreasingCounter counter;
27 NL_TEST_ASSERT(inSuite, counter.GetValue() == 0);
30 static void CheckInitialize(nlTestSuite * inSuite, void * inContext)
32 chip::MonotonicallyIncreasingCounter counter;
34 NL_TEST_ASSERT(inSuite, counter.Init(4321) == CHIP_NO_ERROR);
35 NL_TEST_ASSERT(inSuite, counter.GetValue() == 4321);
38 static void CheckAdvance(nlTestSuite * inSuite, void * inContext)
40 chip::MonotonicallyIncreasingCounter counter;
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);
51 * Test Suite. It lists all the test functions.
55 static const nlTest sTests[] =
57 NL_TEST_DEF("Start with zero", CheckStartWithZero),
58 NL_TEST_DEF("Can initialize", CheckInitialize),
59 NL_TEST_DEF("Can Advance", CheckAdvance),
65 * Set up the test suite.
67 static int TestSetup(void * inContext)
73 * Tear down the test suite.
75 static int TestTeardown(void * inContext)
80 int TestCHIPCounter(void)
83 nlTestSuite theSuite = {
91 // Run test suit againt one context.
92 nlTestRunner(&theSuite, nullptr);
94 return nlTestRunnerStats(&theSuite);
97 CHIP_REGISTER_TEST_SUITE(TestCHIPCounter)