Yufeng Wang | 551e53f | 2021-10-26 13:41:18 -0700 | [diff] [blame] | 1 | /* |
| 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 Wang | c1b032a | 2021-11-23 12:24:40 -0800 | [diff] [blame] | 37 | #include <platform/DiagnosticDataProvider.h> |
Yufeng Wang | 551e53f | 2021-10-26 13:41:18 -0700 | [diff] [blame] | 38 | |
| 39 | using namespace chip; |
| 40 | using namespace chip::Logging; |
| 41 | using namespace chip::Inet; |
| 42 | using namespace chip::DeviceLayer; |
| 43 | |
| 44 | // ================================= |
| 45 | // Unit tests |
| 46 | // ================================= |
| 47 | |
| 48 | static 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 | |
| 55 | static void TestConnectivityMgr_GetNetworkInterfaces(nlTestSuite * inSuite, void * inContext) |
| 56 | { |
| 57 | CHIP_ERROR err = CHIP_NO_ERROR; |
| 58 | |
| 59 | NetworkInterface * netifs = nullptr; |
| 60 | |
Yufeng Wang | c1b032a | 2021-11-23 12:24:40 -0800 | [diff] [blame] | 61 | err = GetDiagnosticDataProvider().GetNetworkInterfaces(&netifs); |
Yufeng Wang | 551e53f | 2021-10-26 13:41:18 -0700 | [diff] [blame] | 62 | NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); |
| 63 | NL_TEST_ASSERT(inSuite, netifs != nullptr); |
| 64 | |
Yufeng Wang | c1b032a | 2021-11-23 12:24:40 -0800 | [diff] [blame] | 65 | GetDiagnosticDataProvider().ReleaseNetworkInterfaces(netifs); |
Yufeng Wang | 551e53f | 2021-10-26 13:41:18 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Test Suite. It lists all the test functions. |
| 70 | */ |
| 71 | static 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 | */ |
| 80 | int 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 | */ |
| 91 | int TestConnectivityMgr_Teardown(void * inContext) |
| 92 | { |
| 93 | PlatformMgr().Shutdown(); |
| 94 | chip::Platform::MemoryShutdown(); |
| 95 | return SUCCESS; |
| 96 | } |
| 97 | |
| 98 | int TestConnectivityMgr() |
| 99 | { |
| 100 | nlTestSuite theSuite = { "ConfigurationMgr tests", &sTests[0], TestConnectivityMgr_Setup, TestConnectivityMgr_Teardown }; |
| 101 | |
Arkadiusz Bokowy | 6ec5f81 | 2023-04-28 10:56:51 +0200 | [diff] [blame^] | 102 | // Run test suite against one context. |
Yufeng Wang | 551e53f | 2021-10-26 13:41:18 -0700 | [diff] [blame] | 103 | nlTestRunner(&theSuite, nullptr); |
| 104 | return nlTestRunnerStats(&theSuite); |
| 105 | } |
| 106 | |
| 107 | CHIP_REGISTER_TEST_SUITE(TestConnectivityMgr) |