blob: 3a4548c43ef2a7b7971f2857a6a80f125ee6f76f [file] [log] [blame]
Yufeng Wang551e53f2021-10-26 13:41:18 -07001/*
2 *
3 * Copyright (c) 2021 Project CHIP Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file
20 * This file implements a unit test suite for the Connectivity Manager
21 * code functionality.
22 *
23 */
24
25#include <inttypes.h>
26#include <stdarg.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30
31#include <lib/support/CHIPMem.h>
32#include <lib/support/CodeUtils.h>
33#include <lib/support/UnitTestRegistration.h>
34#include <nlunit-test.h>
35
36#include <platform/CHIPDeviceLayer.h>
Yufeng Wangc1b032a2021-11-23 12:24:40 -080037#include <platform/DiagnosticDataProvider.h>
Yufeng Wang551e53f2021-10-26 13:41:18 -070038
39using namespace chip;
40using namespace chip::Logging;
41using namespace chip::Inet;
42using namespace chip::DeviceLayer;
43
44// =================================
45// Unit tests
46// =================================
47
48static void TestPlatformMgr_Init(nlTestSuite * inSuite, void * inContext)
49{
50 // ConfigurationManager is initialized from PlatformManager indirectly
51 CHIP_ERROR err = PlatformMgr().InitChipStack();
52 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
53}
54
55static void TestConnectivityMgr_GetNetworkInterfaces(nlTestSuite * inSuite, void * inContext)
56{
57 CHIP_ERROR err = CHIP_NO_ERROR;
58
59 NetworkInterface * netifs = nullptr;
60
Yufeng Wangc1b032a2021-11-23 12:24:40 -080061 err = GetDiagnosticDataProvider().GetNetworkInterfaces(&netifs);
Yufeng Wang551e53f2021-10-26 13:41:18 -070062 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
63 NL_TEST_ASSERT(inSuite, netifs != nullptr);
64
Yufeng Wangc1b032a2021-11-23 12:24:40 -080065 GetDiagnosticDataProvider().ReleaseNetworkInterfaces(netifs);
Yufeng Wang551e53f2021-10-26 13:41:18 -070066}
67
68/**
69 * Test Suite. It lists all the test functions.
70 */
71static const nlTest sTests[] = {
72
73 NL_TEST_DEF("Test PlatformMgr::Init", TestPlatformMgr_Init),
74 NL_TEST_DEF("Test ConfigurationMgr::GetNetworkInterfaces", TestConnectivityMgr_GetNetworkInterfaces), NL_TEST_SENTINEL()
75};
76
77/**
78 * Set up the test suite.
79 */
80int TestConnectivityMgr_Setup(void * inContext)
81{
82 CHIP_ERROR error = chip::Platform::MemoryInit();
83 if (error != CHIP_NO_ERROR)
84 return FAILURE;
85 return SUCCESS;
86}
87
88/**
89 * Tear down the test suite.
90 */
91int TestConnectivityMgr_Teardown(void * inContext)
92{
93 PlatformMgr().Shutdown();
94 chip::Platform::MemoryShutdown();
95 return SUCCESS;
96}
97
98int TestConnectivityMgr()
99{
100 nlTestSuite theSuite = { "ConfigurationMgr tests", &sTests[0], TestConnectivityMgr_Setup, TestConnectivityMgr_Teardown };
101
Arkadiusz Bokowy6ec5f812023-04-28 10:56:51 +0200102 // Run test suite against one context.
Yufeng Wang551e53f2021-10-26 13:41:18 -0700103 nlTestRunner(&theSuite, nullptr);
104 return nlTestRunnerStats(&theSuite);
105}
106
107CHIP_REGISTER_TEST_SUITE(TestConnectivityMgr)