Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / ble / tests / TestBleUUID.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2016-2017 Nest Labs, Inc.
5  *    All rights reserved.
6  *
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
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 /**
21  *    @file
22  *      This file implements a process to effect a functional test for
23  *      the CHIP BLE layer library error string support interfaces.
24  *
25  */
26
27 #include <ble/BleUUID.h>
28 #include <support/UnitTestRegistration.h>
29
30 #include <nlunit-test.h>
31
32 using namespace chip;
33 using namespace chip::Ble;
34
35 namespace {
36
37 void CheckStringToUUID_ChipUUID(nlTestSuite * inSuite, void * inContext)
38 {
39     // Test positive scenario - CHIP Service UUID
40     ChipBleUUID uuid;
41     NL_TEST_ASSERT(inSuite, StringToUUID("0000FEAF-0000-1000-8000-00805F9B34FB", uuid));
42     NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
43 }
44
45 void CheckStringToUUID_ChipUUID_RandomCase(nlTestSuite * inSuite, void * inContext)
46 {
47     // Test that letter case doesn't matter
48     ChipBleUUID uuid;
49     NL_TEST_ASSERT(inSuite, StringToUUID("0000FeAf-0000-1000-8000-00805f9B34Fb", uuid));
50     NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
51 }
52
53 void CheckStringToUUID_ChipUUID_NoSeparators(nlTestSuite * inSuite, void * inContext)
54 {
55     // Test that separators don't matter
56     ChipBleUUID uuid;
57     NL_TEST_ASSERT(inSuite, StringToUUID("0000FEAF00001000800000805F9B34FB", uuid));
58     NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
59 }
60
61 void CheckStringToUUID_TooLong(nlTestSuite * inSuite, void * inContext)
62 {
63     // Test that even one more digit is too much
64     ChipBleUUID uuid;
65     NL_TEST_ASSERT(inSuite, !StringToUUID("0000FEAF00001000800000805F9B34FB0", uuid));
66 }
67
68 void CheckStringToUUID_TooShort(nlTestSuite * inSuite, void * inContext)
69 {
70     // Test that even one less digit is too little
71     ChipBleUUID uuid;
72     NL_TEST_ASSERT(inSuite, !StringToUUID("0000FEAF00001000800000805F9B34F", uuid));
73 }
74
75 void CheckStringToUUID_InvalidChar(nlTestSuite * inSuite, void * inContext)
76 {
77     // Test that non-hex digits don't pass
78     ChipBleUUID uuid;
79     NL_TEST_ASSERT(inSuite, !StringToUUID("0000GEAF-0000-1000-8000-00805F9B34FB0", uuid));
80 }
81
82 // clang-format off
83 const nlTest sTests[] =
84 {
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),
91     NL_TEST_SENTINEL()
92 };
93 // clang-format on
94
95 } // namespace
96
97 int TestBleUUID()
98 {
99     nlTestSuite theSuite = { "BleUUID", &sTests[0], NULL, NULL };
100     nlTestRunner(&theSuite, nullptr);
101     return nlTestRunnerStats(&theSuite);
102 }
103
104 CHIP_REGISTER_TEST_SUITE(TestBleUUID)