forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestmod_internalnotification.c
More file actions
782 lines (588 loc) · 23.5 KB
/
Copy pathtestmod_internalnotification.c
File metadata and controls
782 lines (588 loc) · 23.5 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/**
* @file
*
* @brief Tests for internalnotification plugin
*
* @copyright BSD License (see doc/COPYING or http://www.libelektra.org)
*
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <kdbconfig.h>
#include <kdbmacros.h>
#include <kdbnotificationinternal.h>
#include <kdbtypes.h>
#include <tests.h>
#include <tests_plugin.h>
#include "internalnotification.h"
int callback_called;
char * callback_keyValue;
char * callback_keyName;
int doUpdate_callback_called;
#define CALLBACK_CONTEXT_MAGIC_NUMBER ((void *) 1234)
#define TEST_CASE_UPDATE_NAME(TYPE_NAME) test_update##TYPE_NAME
#define TEST_CASE_NO_UPDATE_NAME(TYPE_NAME) test_noUpdate##TYPE_NAME
#define RUN_TYPE_TESTS(TYPE_NAME) \
printf ("\n" #TYPE_NAME "\n----------------\n"); \
TEST_CASE_UPDATE_NAME (TYPE_NAME) (); \
TEST_CASE_NO_UPDATE_NAME (TYPE_NAME) ();
static void test_callback (Key * key, void * context)
{
succeed_if (context == CALLBACK_CONTEXT_MAGIC_NUMBER, "callback context was not passed");
callback_called = 1;
callback_keyValue = (char *) keyValue (key);
callback_keyName = (char *) keyName (key);
}
static int internalnotificationRegisterInt (Plugin * plugin, Key * key, int * variable)
{
size_t address = elektraPluginGetFunction (plugin, "registerInt");
if (!address) yield_error ("function not exported");
// Register key with plugin
ELEKTRA_NOTIFICATION_REGISTERFUNC_TYPEDEF (RegisterFuncType, int)
return ((RegisterFuncType) address) (plugin, key, variable);
}
static int internalnotificationSetConversionErrorCallback (Plugin * plugin, ElektraNotificationConversionErrorCallback callback,
void * context)
{
size_t address = elektraPluginGetFunction (plugin, "setConversionErrorCallback");
if (!address) yield_error ("function not exported");
// Register key with plugin
((ElektraNotificationSetConversionErrorCallback) address) (plugin, callback, context);
return 1;
}
static int internalnotificationRegisterCallback (Plugin * plugin, Key * key, ElektraNotificationChangeCallback callback, void * context)
{
size_t address = elektraPluginGetFunction (plugin, "registerCallback");
if (!address) yield_error ("function not exported");
// Register key with plugin
return ((ElektraNotificationPluginRegisterCallback) address) (plugin, key, callback, context);
}
static int internalnotificationRegisterCallbackSameOrBelow (Plugin * plugin, Key * key, ElektraNotificationChangeCallback callback,
void * context)
{
size_t address = elektraPluginGetFunction (plugin, "registerCallbackSameOrBelow");
if (!address) yield_error ("function not exported");
// Register key with plugin
return ((ElektraNotificationPluginRegisterCallbackSameOrBelow) address) (plugin, key, callback, context);
}
static int digits (long long number)
{
int digits = 0;
while (number)
{
number /= 10;
digits++;
}
return digits;
}
static char * convertLongLongToString (long long number)
{
int correction = 1; // Allocate space for '\0'
int invert = 1;
if (number < 0)
{
invert = -1; // Invert negative numbers
correction += 1; // Allocate extra space for sign ('-')
}
int size = digits (number * invert) + correction;
char * buffer = elektraMalloc (size);
exit_if_fail (buffer != NULL, "elektraMalloc failed!");
sprintf (buffer, "%lli", number);
succeed_if (buffer[0] != '0', "number conversion failed!");
return buffer;
}
static void test_basics (void)
{
printf ("test basics\n");
Key * parentKey = keyNew ("user:/tests/internalnotification", KEY_END);
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
KeySet * ks = ksNew (0, KS_END);
succeed_if (plugin->kdbOpen (plugin, parentKey) == 1, "call to kdbOpen was not successful");
succeed_if (plugin->kdbGet (plugin, ks, parentKey) == 1, "call to kdbGet was not successful");
succeed_if (plugin->kdbSet (plugin, ks, parentKey) == 1, "call to kdbSet was not successful");
succeed_if (plugin->kdbClose (plugin, parentKey) == 1, "call to kdbClose was not successful");
keyDel (parentKey);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_updateOnKdbGet (void)
{
printf ("test update on kdbGet\n");
Key * parentKey = keyNew ("user:/tests/internalnotification", KEY_END);
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_VALUE, "42", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
int value = 0;
succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
plugin->kdbGet (plugin, ks, parentKey);
succeed_if (value == 42, "registered value was not updated");
keyDel (parentKey);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_updateOnKdbSet (void)
{
printf ("test update on kdbSet\n");
Key * parentKey = keyNew ("user:/tests/internalnotification", KEY_END);
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_VALUE, "42", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
int value = 0;
succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
plugin->kdbSet (plugin, ks, parentKey);
succeed_if (value == 42, "registered value was not updated");
keyDel (parentKey);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_intUpdateWithCascadingKey (void)
{
printf ("test update with cascading key registered\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * registeredKey = keyNew ("/test/internalnotification/value", KEY_END);
int value = 0;
succeed_if (internalnotificationRegisterInt (plugin, registeredKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_VALUE, "42", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (value == 42, "registered value was not updated");
keyDel (registeredKey);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_intNoUpdateWithInvalidValue (void)
{
printf ("test no update with invalid value\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
int value = 123;
succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
keySetString (valueKey, "42abcd");
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (value == 123, "registered value was updated");
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_conversionError (void)
{
printf ("test conversion error callback is called on invalid value\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
succeed_if (internalnotificationSetConversionErrorCallback (plugin, test_callback, CALLBACK_CONTEXT_MAGIC_NUMBER) == 1,
"call to elektraInternalnotificationSetConversionErrorCallback was not successful");
int value = 123;
succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
keySetString (valueKey, "42abcd");
callback_called = 0;
callback_keyName = NULL;
callback_keyValue = NULL;
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (value == 123, "registered value was updated");
succeed_if (callback_called, "conversion error callback was not called");
succeed_if_same_string (keyName (valueKey), callback_keyName) succeed_if_same_string (keyString (valueKey), callback_keyValue)
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_intUpdateWithValueNotYetExceedingIntMax (void)
{
printf ("test update with value = INT_MAX\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
int value = 123;
succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
int exceedsInt = INT_MAX;
char * stringValue = convertLongLongToString ((long long) exceedsInt);
keySetString (valueKey, stringValue);
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (value == INT_MAX, "registered value was not updated");
elektraFree (stringValue);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_intNoUpdateWithValueExceedingIntMax (void)
{
printf ("test no update with value that exceeds INT_MAX\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
int value = 123;
succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
long long exceedsInt = (long long) INT_MAX + 1;
char * stringValue = convertLongLongToString (exceedsInt);
keySetString (valueKey, stringValue);
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (value == 123, "registered value was updated");
elektraFree (stringValue);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_intUpdateWithValueNotYetExceedingIntMin (void)
{
printf ("test update with value = INT_MIN\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
int value = 123;
succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
int exceedsInt = INT_MIN;
char * stringValue = convertLongLongToString ((long long) exceedsInt);
keySetString (valueKey, stringValue);
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (value == INT_MIN, "registered value was not updated");
elektraFree (stringValue);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_intNoUpdateWithValueExceedingIntMin (void)
{
printf ("test no update with value that exceeds INT_MIN\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
int value = 123;
succeed_if (internalnotificationRegisterInt (plugin, valueKey, &value) == 1,
"call to elektraInternalnotificationRegisterInt was not successful");
long long exceedsInt = (long long) INT_MIN - 1;
char * stringValue = convertLongLongToString (exceedsInt);
keySetString (valueKey, stringValue);
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (value == 123, "registered value was updated");
elektraFree (stringValue);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_callbackCalledWithKey (void)
{
printf ("test callback is called with changed key\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
char * value = "foobaroo!";
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_VALUE, value, KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
succeed_if (internalnotificationRegisterCallback (plugin, valueKey, test_callback, CALLBACK_CONTEXT_MAGIC_NUMBER) == 1,
"call to elektraInternalnotificationRegisterCallback was not successful");
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (callback_called, "registered value was not updated");
succeed_if_same_string (callback_keyName, keyName (valueKey));
succeed_if_same_string (callback_keyValue, value);
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_callbackCalledWithChangeDetection (void)
{
printf ("test callback is not called when key has not changed\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
char * value = "foobaroo!";
Key * valueKey = keyNew ("user:/test/internalnotification/value", KEY_VALUE, value, KEY_END);
KeySet * ks = ksNew (1, valueKey, KS_END);
succeed_if (internalnotificationRegisterCallback (plugin, valueKey, test_callback, CALLBACK_CONTEXT_MAGIC_NUMBER) == 1,
"call to elektraInternalnotificationRegisterCallback was not successful");
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (callback_called, "registered value was not updated");
callback_called = 0;
elektraInternalnotificationUpdateRegisteredKeys (plugin, ks);
succeed_if (callback_called == 0, "registered value was updated but value has not changed");
ksDel (ks);
PLUGIN_CLOSE ();
}
static void test_doUpdate_callback (KDB * kdb ELEKTRA_UNUSED, Key * changedKey ELEKTRA_UNUSED)
{
doUpdate_callback_called = 1;
}
static void test_doUpdateShouldUpdateKey (void)
{
printf ("test doUpdate should update same key\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * changedKey = keyNew ("user:/test/internalnotification/value", KEY_END);
succeed_if (internalnotificationRegisterCallback (plugin, changedKey, test_callback, NULL) == 1,
"call to elektraInternalnotificationRegisterCallback was not successful");
ElektraNotificationCallbackContext * context = elektraMalloc (sizeof *context);
context->kdbUpdate = NULL;
context->kdbUpdate = test_doUpdate_callback;
context->notificationPlugin = plugin;
doUpdate_callback_called = 0;
elektraInternalnotificationDoUpdate (changedKey, context);
succeed_if (doUpdate_callback_called, "did not call callback for registered key");
elektraFree (context);
PLUGIN_CLOSE ();
}
static void test_doUpdateShouldUpdateKeyBelow (void)
{
printf ("test doUpdate should update key below changed key\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * changedKey = keyNew ("user:/test/internalnotification", KEY_END);
Key * registeredKey = keyNew ("user:/test/internalnotification/value", KEY_END);
succeed_if (internalnotificationRegisterCallback (plugin, registeredKey, test_callback, NULL) == 1,
"call to elektraInternalnotificationRegisterCallback was not successful");
ElektraNotificationCallbackContext * context = elektraMalloc (sizeof *context);
context->kdbUpdate = NULL;
context->kdbUpdate = test_doUpdate_callback;
context->notificationPlugin = plugin;
doUpdate_callback_called = 0;
elektraInternalnotificationDoUpdate (changedKey, context);
succeed_if (doUpdate_callback_called, "did not call callback for registered key");
elektraFree (context);
keyDel (registeredKey);
PLUGIN_CLOSE ();
}
static void test_doUpdateShouldNotUpdateKeyAbove (void)
{
printf ("test doUpdate should not update key above changed key\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * changedKey = keyNew ("user:/test/internalnotification/value", KEY_END);
Key * registeredKey = keyNew ("user:/test/internalnotification", KEY_END);
succeed_if (internalnotificationRegisterCallback (plugin, registeredKey, test_callback, NULL) == 1,
"call to elektraInternalnotificationRegisterCallback was not successful");
ElektraNotificationCallbackContext * context = elektraMalloc (sizeof *context);
context->kdbUpdate = NULL;
context->kdbUpdate = test_doUpdate_callback;
context->notificationPlugin = plugin;
doUpdate_callback_called = 0;
elektraInternalnotificationDoUpdate (changedKey, context);
succeed_if (doUpdate_callback_called == 0, "did call callback for key above");
elektraFree (context);
keyDel (registeredKey);
PLUGIN_CLOSE ();
}
static void test_doUpdateShouldUpdateKeyAbove (void)
{
printf ("test doUpdate should update key above changed key for sameOrBelow callbacks\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * changedKey = keyNew ("user:/test/internalnotification/value", KEY_END);
Key * registeredKey = keyNew ("user:/test/internalnotification", KEY_END);
succeed_if (internalnotificationRegisterCallbackSameOrBelow (plugin, registeredKey, test_callback, NULL) == 1,
"call to internalnotificationRegisterCallbackSameOrBelow was not successful");
ElektraNotificationCallbackContext * context = elektraMalloc (sizeof *context);
context->kdbUpdate = NULL;
context->kdbUpdate = test_doUpdate_callback;
context->notificationPlugin = plugin;
doUpdate_callback_called = 0;
elektraInternalnotificationDoUpdate (changedKey, context);
succeed_if (doUpdate_callback_called, "did not call callback for key above");
elektraFree (context);
keyDel (registeredKey);
PLUGIN_CLOSE ();
}
static void test_doUpdateShouldNotUpdateUnregisteredKey (void)
{
printf ("test doUpdate should not update unregistered key\n");
KeySet * conf = ksNew (0, KS_END);
PLUGIN_OPEN ("internalnotification");
Key * changedKey = keyNew ("user:/test/internalnotification/value", KEY_END);
// No key registration made
ElektraNotificationCallbackContext * context = elektraMalloc (sizeof *context);
context->kdbUpdate = NULL;
context->kdbUpdate = test_doUpdate_callback;
context->notificationPlugin = plugin;
doUpdate_callback_called = 0;
elektraInternalnotificationDoUpdate (changedKey, context);
succeed_if (doUpdate_callback_called == 0, "did call callback for unregistered key");
elektraFree (context);
PLUGIN_CLOSE ();
}
// Generate test cases for C built-in types
#define TYPE unsigned int
#define TYPE_NAME UnsignedInt
#define FORMAT_STRING "%u"
#define TEST_VALUE UINT_MAX
#define INVALID_VALUE "-1"
#include "macros/create_type_tests.h"
#define TYPE long
#define TYPE_NAME Long
#define FORMAT_STRING "%ld"
#define TEST_VALUE LONG_MAX
#define INVALID_VALUE "5000abc000"
#include "macros/create_type_tests.h"
#define TYPE unsigned long
#define TYPE_NAME UnsignedLong
#define FORMAT_STRING "%lu"
#define TEST_VALUE ULONG_MAX
#define INVALID_VALUE "-446744073715"
#include "macros/create_type_tests.h"
#define TYPE long long
#define TYPE_NAME LongLong
#define FORMAT_STRING "%lld"
#define TEST_VALUE LLONG_MAX
#define INVALID_VALUE "322337abc6854775807"
#include "macros/create_type_tests.h"
#define TYPE unsigned long long
#define TYPE_NAME UnsignedLongLong
#define FORMAT_STRING "%llu"
#define TEST_VALUE ULLONG_MAX
#define INVALID_VALUE "-3223372036854775807"
#include "macros/create_type_tests.h"
#define TYPE float
#define TYPE_NAME Float
#define FORMAT_STRING "%f"
#define TEST_VALUE 2.3
#define CHECK_VALUE (value >= 2.295 && value <= 2.305)
#define INVALID_VALUE "4.a"
#define CHECK_INVALID ((int) value == 0)
#include "macros/create_type_tests.h"
#define TYPE double
#define TYPE_NAME Double
#define FORMAT_STRING "%1.8f"
#define TEST_VALUE 1.00000001
#define CHECK_VALUE (value >= 1 + 1e-9 && value <= 1 + 1e-7)
#define INVALID_VALUE "4.a"
#define CHECK_INVALID ((int) value == 0)
#include "macros/create_type_tests.h"
// for kdb_*_t types
#define TYPE kdb_boolean_t
#define TYPE_NAME KdbBoolean
#define FORMAT_STRING "%d"
#define TEST_VALUE 1
#define CHECK_VALUE (value)
#include "macros/create_type_tests.h"
#define TYPE kdb_char_t
#define TYPE_NAME KdbChar
#define FORMAT_STRING "abc%d"
#define TEST_VALUE 1
#define CHECK_VALUE (value == 'a')
#include "macros/create_type_tests.h"
#define TYPE kdb_octet_t
#define TYPE_NAME KdbOctet
#define FORMAT_STRING "%d"
#define TEST_VALUE 255
#define INVALID_VALUE "4a"
#include "macros/create_type_tests.h"
#define TYPE kdb_short_t
#define TYPE_NAME KdbShort
#define FORMAT_STRING "%d"
#define TEST_VALUE SHRT_MIN
#define INVALID_VALUE "-55ABC"
#include "macros/create_type_tests.h"
#define TYPE kdb_unsigned_short_t
#define TYPE_NAME KdbUnsignedShort
#define FORMAT_STRING "%d"
#define TEST_VALUE USHRT_MAX
#define INVALID_VALUE "-55"
#include "macros/create_type_tests.h"
#define TYPE kdb_long_t
#define TYPE_NAME KdbLong
#define FORMAT_STRING "%d"
#define TEST_VALUE INT_MIN
#define INVALID_VALUE "B5C"
#include "macros/create_type_tests.h"
#define TYPE kdb_unsigned_long_t
#define TYPE_NAME KdbUnsignedLong
#define FORMAT_STRING "%u"
#define TEST_VALUE UINT_MAX
#define INVALID_VALUE "-523255"
#include "macros/create_type_tests.h"
#define TYPE kdb_long_long_t
#define TYPE_NAME KdbLongLong
#define FORMAT_STRING ELEKTRA_LONG_LONG_F
#define TEST_VALUE (kdb_long_long_t) LONG_MAX
#define INVALID_VALUE "50000asasd"
#include "macros/create_type_tests.h"
#define TYPE kdb_unsigned_long_long_t
#define TYPE_NAME KdbUnsignedLongLong
#define FORMAT_STRING ELEKTRA_UNSIGNED_LONG_LONG_F
#define TEST_VALUE (kdb_unsigned_long_long_t) ULONG_MAX
#define INVALID_VALUE "-5326523652"
#include "macros/create_type_tests.h"
#define TYPE kdb_float_t
#define TYPE_NAME KdbFloat
#define FORMAT_STRING "%f"
#define TEST_VALUE 2.3
#define CHECK_VALUE (value >= 2.295 && value <= 2.305)
#define INVALID_VALUE "4.a"
#define CHECK_INVALID ((int) value == 0)
#include "macros/create_type_tests.h"
#define TYPE kdb_double_t
#define TYPE_NAME KdbDouble
#define FORMAT_STRING "%1.8f"
#define TEST_VALUE 1.00000001
#define CHECK_VALUE (value >= 1 + 1e-9 && value <= 1 + 1e-7)
#define INVALID_VALUE "4.a"
#define CHECK_INVALID ((int) value == 0)
#include "macros/create_type_tests.h"
#ifdef ELEKTRA_HAVE_KDB_LONG_DOUBLE
#define TYPE kdb_long_double_t
#define TYPE_NAME KdbLongDouble
#define FORMAT_STRING "%1.8f"
#define TEST_VALUE 1.00000001
#define CHECK_VALUE (value >= 1 + 1e-9 && value <= 1 + 1e-7)
#define INVALID_VALUE "4.a"
#define CHECK_INVALID ((int) value == 0)
#include "macros/create_type_tests.h"
#endif // ELEKTRA_HAVE_KDB_LONG_DOUBLE
int main (int argc, char ** argv)
{
printf ("INTERNALNOTIFICATION TESTS\n");
printf ("==============================\n\n");
init (argc, argv);
test_basics ();
test_updateOnKdbGet ();
test_updateOnKdbSet ();
test_conversionError ();
printf ("\nregisterInt\n-----------\n");
test_intUpdateWithCascadingKey ();
test_intNoUpdateWithInvalidValue ();
test_intUpdateWithValueNotYetExceedingIntMax ();
test_intNoUpdateWithValueExceedingIntMax ();
test_intUpdateWithValueNotYetExceedingIntMin ();
test_intNoUpdateWithValueExceedingIntMin ();
printf ("\nregisterCallback\n----------------\n");
test_callbackCalledWithKey ();
test_callbackCalledWithChangeDetection ();
RUN_TYPE_TESTS (UnsignedInt)
RUN_TYPE_TESTS (Long)
RUN_TYPE_TESTS (UnsignedLong)
RUN_TYPE_TESTS (LongLong)
RUN_TYPE_TESTS (UnsignedLongLong)
RUN_TYPE_TESTS (Float)
RUN_TYPE_TESTS (Double)
printf ("\nKdbBoolean\n----------------\n");
TEST_CASE_UPDATE_NAME (KdbBoolean) ();
printf ("\nKdbChar\n----------------\n");
TEST_CASE_UPDATE_NAME (KdbChar) ();
RUN_TYPE_TESTS (KdbOctet)
RUN_TYPE_TESTS (KdbShort)
RUN_TYPE_TESTS (KdbUnsignedShort)
RUN_TYPE_TESTS (KdbLong)
RUN_TYPE_TESTS (KdbUnsignedLong)
RUN_TYPE_TESTS (KdbLongLong)
RUN_TYPE_TESTS (KdbUnsignedLongLong)
RUN_TYPE_TESTS (KdbFloat)
RUN_TYPE_TESTS (KdbDouble)
#ifdef ELEKTRA_HAVE_KDB_LONG_DOUBLE
RUN_TYPE_TESTS (KdbLongDouble)
#endif // ELEKTRA_HAVE_KDB_LONG_DOUBLE
printf ("\nelektraInternalnotificationDoUpdate\n-----------------------------------\n");
test_doUpdateShouldUpdateKey ();
test_doUpdateShouldUpdateKeyBelow ();
test_doUpdateShouldNotUpdateKeyAbove ();
test_doUpdateShouldNotUpdateUnregisteredKey ();
test_doUpdateShouldUpdateKeyAbove ();
print_result ("testmod_internalnotification");
return nbError;
}