forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestBleUUID.cpp
More file actions
104 lines (89 loc) · 3.4 KB
/
Copy pathTestBleUUID.cpp
File metadata and controls
104 lines (89 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2016-2017 Nest Labs, Inc.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* This file implements a process to effect a functional test for
* the CHIP BLE layer library error string support interfaces.
*
*/
#include <ble/BleUUID.h>
#include <support/UnitTestRegistration.h>
#include <nlunit-test.h>
using namespace chip;
using namespace chip::Ble;
namespace {
void CheckStringToUUID_ChipUUID(nlTestSuite * inSuite, void * inContext)
{
// Test positive scenario - CHIP Service UUID
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, StringToUUID("0000FFF6-0000-1000-8000-00805F9B34FB", uuid));
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
}
void CheckStringToUUID_ChipUUID_RandomCase(nlTestSuite * inSuite, void * inContext)
{
// Test that letter case doesn't matter
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, StringToUUID("0000FfF6-0000-1000-8000-00805f9B34Fb", uuid));
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
}
void CheckStringToUUID_ChipUUID_NoSeparators(nlTestSuite * inSuite, void * inContext)
{
// Test that separators don't matter
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, StringToUUID("0000FFF600001000800000805F9B34FB", uuid));
NL_TEST_ASSERT(inSuite, UUIDsMatch(&uuid, &CHIP_BLE_SVC_ID));
}
void CheckStringToUUID_TooLong(nlTestSuite * inSuite, void * inContext)
{
// Test that even one more digit is too much
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, !StringToUUID("0000FFF600001000800000805F9B34FB0", uuid));
}
void CheckStringToUUID_TooShort(nlTestSuite * inSuite, void * inContext)
{
// Test that even one less digit is too little
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, !StringToUUID("0000FFF600001000800000805F9B34F", uuid));
}
void CheckStringToUUID_InvalidChar(nlTestSuite * inSuite, void * inContext)
{
// Test that non-hex digits don't pass
ChipBleUUID uuid;
NL_TEST_ASSERT(inSuite, !StringToUUID("0000GFF6-0000-1000-8000-00805F9B34FB0", uuid));
}
// clang-format off
const nlTest sTests[] =
{
NL_TEST_DEF("CheckStringToUUID_ChipUUID", CheckStringToUUID_ChipUUID),
NL_TEST_DEF("CheckStringToUUID_ChipUUID_RandomCase", CheckStringToUUID_ChipUUID_RandomCase),
NL_TEST_DEF("CheckStringToUUID_ChipUUID_NoSeparators", CheckStringToUUID_ChipUUID_NoSeparators),
NL_TEST_DEF("CheckStringToUUID_TooLong", CheckStringToUUID_TooLong),
NL_TEST_DEF("CheckStringToUUID_TooShort", CheckStringToUUID_TooShort),
NL_TEST_DEF("CheckStringToUUID_InvalidChar", CheckStringToUUID_InvalidChar),
NL_TEST_SENTINEL()
};
// clang-format on
} // namespace
int TestBleUUID()
{
nlTestSuite theSuite = { "BleUUID", &sTests[0], NULL, NULL };
nlTestRunner(&theSuite, nullptr);
return nlTestRunnerStats(&theSuite);
}
CHIP_REGISTER_TEST_SUITE(TestBleUUID)