@@ -21,13 +21,13 @@ bool test_preferences(T value,
21
21
// .6 we compare the value with what we inserted at the beginning
22
22
// .7 we remove the value
23
23
24
- Serial.println (" Tesing isKey()" );
24
+ Serial.println (" Testing isKey()" );
25
25
if (preferences->isKey (KEY)) {
26
26
Serial.println (" [Error] kvstore already contains a key" );
27
27
return false ;
28
28
}
29
29
30
- Serial.println (" Tesing put()" );
30
+ Serial.println (" Testing put()" );
31
31
size_t s;
32
32
if ((s=putf (KEY, value)) != sizeof (value)) {
33
33
Serial.println (" [Error] kvstore put returned a size that is different from the expected one: " );
@@ -37,13 +37,13 @@ bool test_preferences(T value,
37
37
return false ;
38
38
}
39
39
40
- Serial.println (" Tesing isKey()" ); // FIXME always failing
40
+ Serial.println (" Testing isKey()" );
41
41
if (!preferences->isKey (KEY)) {
42
42
Serial.println (" [Error] The inserted key is not present in the KVStore" );
43
43
return false ;
44
44
}
45
45
46
- Serial.println (" Tesing getf()" );
46
+ Serial.println (" Testing getf()" );
47
47
T val;
48
48
if ((val = getf (KEY)) != value) {
49
49
Serial.print (" [Error] get of the previously value returned a wrong value: " );
@@ -53,7 +53,7 @@ bool test_preferences(T value,
53
53
return false ;
54
54
}
55
55
56
- Serial.println (" Tesing remove()" );
56
+ Serial.println (" Testing remove()" );
57
57
if (!preferences->remove (KEY)) {
58
58
Serial.println (" [Error] Failed removing the inserted key" );
59
59
return false ;
@@ -62,6 +62,70 @@ bool test_preferences(T value,
62
62
return true ;
63
63
}
64
64
65
+ template <>
66
+ bool test_preferences (String value,
67
+ std::function<size_t (const char *, String)> putf,
68
+ std::function<String(const char *)> getf,
69
+ Preferences *preferences) {
70
+ // we are going now to test all the apis of kvstore:
71
+ // .1 We check that the key do not exist
72
+ // .2 we put a value inside the KVStore
73
+ // .3 we check that the size returned is correct
74
+ // .4 we check again the key exists
75
+ // .5 we get the value contained
76
+ // .6 we compare the value with what we inserted at the beginning
77
+ // .7 we remove the value
78
+
79
+ Serial.println (" Testing isKey()" );
80
+ if (preferences->isKey (KEY)) {
81
+ Serial.println (" [Error] kvstore already contains a key" );
82
+ return false ;
83
+ }
84
+
85
+ Serial.println (" Testing put()" );
86
+ size_t s;
87
+ if ((s=putf (KEY, value)) != value.length ()) {
88
+ Serial.println (" [Error] kvstore put returned a size that is different from the expected one: " );
89
+ Serial.print (s);
90
+ Serial.print (" != " );
91
+ Serial.println (value.length ());
92
+ return false ;
93
+ }
94
+
95
+ Serial.println (" Testing isKey()" );
96
+ if (!preferences->isKey (KEY)) {
97
+ Serial.println (" [Error] The inserted key is not present in the KVStore" );
98
+ return false ;
99
+ }
100
+
101
+ Serial.println (" Testing getBytesLength()" );
102
+ if ((s=preferences->getBytesLength (KEY)) != value.length ()+1 ) {
103
+ Serial.println (" [Error] The length of the value do not match with the expected one" );
104
+ Serial.print (s);
105
+ Serial.print (" != " );
106
+ Serial.println (value.length ()+1 );
107
+ return false ;
108
+ }
109
+
110
+ Serial.println (" Testing getf()" );
111
+ String val;
112
+ if ((val = getf (KEY)) != value) {
113
+ Serial.print (" [Error] get of the previously inserted value returned a wrong value: " );
114
+ Serial.print (val);
115
+ Serial.print (" != " );
116
+ Serial.println (value);
117
+ return false ;
118
+ }
119
+
120
+ Serial.println (" Testing remove()" );
121
+ if (!preferences->remove (KEY)) {
122
+ Serial.println (" [Error] Failed removing the inserted key" );
123
+ return false ;
124
+ }
125
+
126
+ return true ;
127
+ }
128
+
65
129
bool test_preferences (char * value, Preferences *preferences) {
66
130
// we are going now to test all the apis of preferences:
67
131
// .1 We check that the key do not exist
@@ -72,13 +136,13 @@ bool test_preferences(char* value, Preferences *preferences) {
72
136
// .6 we compare the value with what we inserted at the beginning
73
137
// .7 we remove the value
74
138
75
- Serial.println (" Tesing isKey()" );
139
+ Serial.println (" Testing isKey()" );
76
140
if (preferences->isKey (KEY)) {
77
141
Serial.println (" [Error] kvstore already contains a key" );
78
142
return false ;
79
143
}
80
144
81
- Serial.println (" Tesing put()" );
145
+ Serial.println (" Testing put()" );
82
146
size_t s;
83
147
if ((s=preferences->putString (KEY, value)) != strlen (value)) {
84
148
Serial.println (" [Error] kvstore put returned a size that is different from the expected one: " );
@@ -88,13 +152,13 @@ bool test_preferences(char* value, Preferences *preferences) {
88
152
return false ;
89
153
}
90
154
91
- Serial.println (" Tesing isKey()" );
155
+ Serial.println (" Testing isKey()" );
92
156
if (!preferences->isKey (KEY)) {
93
157
Serial.println (" [Error] The inserted key is not present in the KVStore" );
94
158
return false ;
95
159
}
96
160
97
- Serial.println (" Tesing getf()" );
161
+ Serial.println (" Testing getf()" );
98
162
char val[500 ];
99
163
preferences->getString (KEY, val, sizeof (val));
100
164
if (strcmp (val, value) != 0 ) {
@@ -116,7 +180,7 @@ bool test_preferences(char* value, Preferences *preferences) {
116
180
return false ;
117
181
}
118
182
119
- Serial.println (" Tesing remove()" );
183
+ Serial.println (" Testing remove()" );
120
184
if (!preferences->remove (KEY)) {
121
185
Serial.println (" [Error] Failed removing the inserted key" );
122
186
return false ;
@@ -134,14 +198,13 @@ bool test_preferences(uint8_t* value, size_t size, Preferences *preferences) {
134
198
// .5 we get the value contained
135
199
// .6 we compare the value with what we inserted at the beginning
136
200
// .7 we remove the value
137
-
138
- Serial.println (" Tesing isKey()" );
201
+ Serial.println (" Testing isKey()" );
139
202
if (preferences->isKey (KEY)) {
140
203
Serial.println (" [Error] kvstore already contains a key" );
141
204
return false ;
142
205
}
143
206
144
- Serial.println (" Tesing put()" );
207
+ Serial.println (" Testing put()" );
145
208
size_t s;
146
209
if ((s=preferences->putBytes (KEY, value, size)) != size) {
147
210
Serial.println (" [Error] kvstore put returned a size that is different from the expected one: " );
@@ -151,13 +214,13 @@ bool test_preferences(uint8_t* value, size_t size, Preferences *preferences) {
151
214
return false ;
152
215
}
153
216
154
- Serial.println (" Tesing isKey()" );
217
+ Serial.println (" Testing isKey()" );
155
218
if (!preferences->isKey (KEY)) {
156
219
Serial.println (" [Error] The inserted key is not present in the KVStore" );
157
220
return false ;
158
221
}
159
222
160
- Serial.println (" Tesing getBytesLength()" );
223
+ Serial.println (" Testing getBytesLength()" );
161
224
if ((s=preferences->getBytesLength (KEY)) != size) {
162
225
Serial.println (" [Error] The length of the value do not match with the expected one" );
163
226
Serial.print (s);
@@ -166,7 +229,7 @@ bool test_preferences(uint8_t* value, size_t size, Preferences *preferences) {
166
229
return false ;
167
230
}
168
231
169
- Serial.println (" Tesing getf()" );
232
+ Serial.println (" Testing getf()" );
170
233
uint8_t val[500 ];
171
234
s = preferences->getBytes (KEY, val, sizeof (val));
172
235
@@ -183,7 +246,7 @@ bool test_preferences(uint8_t* value, size_t size, Preferences *preferences) {
183
246
return false ;
184
247
}
185
248
186
- Serial.println (" Tesing remove()" );
249
+ Serial.println (" Testing remove()" );
187
250
if (!preferences->remove (KEY)) {
188
251
Serial.println (" [Error] Failed removing the inserted key" );
189
252
return false ;
0 commit comments