forked from arduino-libraries/ArduinoBLE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_permissions.cpp
126 lines (115 loc) · 3.98 KB
/
test_permissions.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
This file is part of the ArduinoBLE library.
Copyright (c) 2018 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <catch2/catch_test_macros.hpp>
#define private public
#define protected public
#include "FakeBLELocalDevice.h"
#include "BLEAdvertisingData.h"
#include "BLETypedCharacteristics.h"
#include "BLELocalCharacteristic.h"
#include "BLEStringCharacteristic.h"
#include "BLEProperty.h"
#include <memory>
int property[] = {
BLEBroadcast,
BLERead,
BLEWriteWithoutResponse,
BLEWrite,
BLENotify,
BLEIndicate,
BLEAuthSignedWrite,
BLEExtProp,
BLERead | BLEWrite | BLENotify
};
int permission[] = {
BLEEncryption,
BLEAuthentication,
BLEAuthorization,
BLEEncryption | BLEAuthentication
};
const char uuid[][31] = {
"1 Bool",
"2 Char",
"3 UnsignedChar",
"4 Byte",
"5 Short",
"6 UnsignedShort",
"7 Word",
"8 Int",
"9 UnsignedInt",
"A Long",
"B UnsignedLong",
"C Float",
"D Double",
"E String"
};
std::unique_ptr<BLECharacteristic> createCharacteristic(const char* uuid, unsigned int properties)
{
switch(uuid[0])
{
case '1':
return std::unique_ptr<BLECharacteristic>(new BLEBoolCharacteristic(uuid, properties));
case '2':
return std::unique_ptr<BLECharacteristic>(new BLECharCharacteristic(uuid, properties));
case '3':
return std::unique_ptr<BLECharacteristic>(new BLEUnsignedCharCharacteristic(uuid, properties));
case '4':
return std::unique_ptr<BLECharacteristic>(new BLEByteCharacteristic(uuid, properties));
case '5':
return std::unique_ptr<BLECharacteristic>(new BLEShortCharacteristic(uuid, properties));
case '6':
return std::unique_ptr<BLECharacteristic>(new BLEUnsignedShortCharacteristic(uuid, properties));
case '7':
return std::unique_ptr<BLECharacteristic>(new BLEWordCharacteristic(uuid, properties));
case '8':
return std::unique_ptr<BLECharacteristic>(new BLEIntCharacteristic(uuid, properties));
case '9':
return std::unique_ptr<BLECharacteristic>(new BLEUnsignedIntCharacteristic(uuid, properties));
case 'A':
return std::unique_ptr<BLECharacteristic>(new BLELongCharacteristic(uuid, properties));
case 'B':
return std::unique_ptr<BLECharacteristic>(new BLEUnsignedLongCharacteristic(uuid, properties));
case 'C':
return std::unique_ptr<BLECharacteristic>(new BLEFloatCharacteristic(uuid, properties));
case 'D':
return std::unique_ptr<BLECharacteristic>(new BLEDoubleCharacteristic(uuid, properties));
case 'E':
return std::unique_ptr<BLECharacteristic>(new BLEStringCharacteristic(uuid, properties, 2));
default:
break;
}
return nullptr;
}
TEST_CASE("Test characteristic properties and permissions", "[ArduinoBLE::BLECharacteristic]")
{
WHEN("Create a characteristic")
{
for(int i = 0; i < sizeof(property)/sizeof(int); i++)
{
for(int j = 0; j < sizeof(permission)/sizeof(int); j++)
{
for(int k = 0; k < 14; k++)
{
std::unique_ptr<BLECharacteristic> ptr = createCharacteristic(uuid[k], property[i] | permission[j]);
REQUIRE(ptr != nullptr);
REQUIRE(ptr->properties() == (property[i]));
BLELocalCharacteristic * local = ptr->local();
REQUIRE(local->permissions() == (permission[j] >> 8));
}
}
}
}
}