3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2016-2017 Nest Labs, Inc.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 * This file implements a process to effect a functional test for
23 * the CHIP BLE layer library error string support interfaces.
27 #include <ble/BleUUID.h>
28 #include <support/UnitTestRegistration.h>
30 #include <nlunit-test.h>
33 using namespace chip::Ble;
37 void CheckStringToUUID_ChipUUID(nlTestSuite * inSuite, void * inContext)
39 // Test positive scenario - CHIP Service UUID
41 NL_TEST_ASSERT(inSuite, StringToUUID("0000FEAF-0000-1000-8000-00805F9B34FB", uuid));
42 NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
45 void CheckStringToUUID_ChipUUID_RandomCase(nlTestSuite * inSuite, void * inContext)
47 // Test that letter case doesn't matter
49 NL_TEST_ASSERT(inSuite, StringToUUID("0000FeAf-0000-1000-8000-00805f9B34Fb", uuid));
50 NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
53 void CheckStringToUUID_ChipUUID_NoSeparators(nlTestSuite * inSuite, void * inContext)
55 // Test that separators don't matter
57 NL_TEST_ASSERT(inSuite, StringToUUID("0000FEAF00001000800000805F9B34FB", uuid));
58 NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
61 void CheckStringToUUID_TooLong(nlTestSuite * inSuite, void * inContext)
63 // Test that even one more digit is too much
65 NL_TEST_ASSERT(inSuite, !StringToUUID("0000FEAF00001000800000805F9B34FB0", uuid));
68 void CheckStringToUUID_TooShort(nlTestSuite * inSuite, void * inContext)
70 // Test that even one less digit is too little
72 NL_TEST_ASSERT(inSuite, !StringToUUID("0000FEAF00001000800000805F9B34F", uuid));
75 void CheckStringToUUID_InvalidChar(nlTestSuite * inSuite, void * inContext)
77 // Test that non-hex digits don't pass
79 NL_TEST_ASSERT(inSuite, !StringToUUID("0000GEAF-0000-1000-8000-00805F9B34FB0", uuid));
83 const nlTest sTests[] =
85 NL_TEST_DEF("CheckStringToUUID_ChipUUID", CheckStringToUUID_ChipUUID),
86 NL_TEST_DEF("CheckStringToUUID_ChipUUID_RandomCase", CheckStringToUUID_ChipUUID_RandomCase),
87 NL_TEST_DEF("CheckStringToUUID_ChipUUID_NoSeparators", CheckStringToUUID_ChipUUID_NoSeparators),
88 NL_TEST_DEF("CheckStringToUUID_TooLong", CheckStringToUUID_TooLong),
89 NL_TEST_DEF("CheckStringToUUID_TooShort", CheckStringToUUID_TooShort),
90 NL_TEST_DEF("CheckStringToUUID_InvalidChar", CheckStringToUUID_InvalidChar),
99 nlTestSuite theSuite = { "BleUUID", &sTests[0], NULL, NULL };
100 nlTestRunner(&theSuite, nullptr);
101 return nlTestRunnerStats(&theSuite);
104 CHIP_REGISTER_TEST_SUITE(TestBleUUID)