The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
edit_tests.c
Go to the documentation of this file.
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/** Tests for a AVP manipulation and search API.
18 *
19 * @file src/lib/util/test//edit_tests.c
20 * @author Alan DeKok (aland@networkradius.com)
21 * @copyright 2021 Network RADIUS SAS (legal@networkradius.com)
22 */
23
24/**
25 * The 'TEST_INIT' macro provided by 'acutest.h' allowing to register a function to be called
26 * before call the unit tests. Therefore, It calls the function ALL THE TIME causing an overhead.
27 * That is why we are initializing test_init() by "__attribute__((constructor));" reducing the
28 * test execution by 50% of the time.
29 */
30#define USE_CONSTRUCTOR
31
32/*
33 * It should be declared before include the "acutest.h"
34 */
35#ifdef USE_CONSTRUCTOR
36static void test_init(void) __attribute__((constructor));
37#else
38static void test_init(void);
39# define TEST_INIT test_init()
40#endif
41
42#include "acutest.h"
43#include"acutest_helpers.h"
44#include "pair_test_helpers.h"
45
46#include <freeradius-devel/util/conf.h>
47#include <freeradius-devel/util/dict.h>
48#include <freeradius-devel/util/edit.h>
49
50#ifdef HAVE_GPERFTOOLS_PROFILER_H
51# include <gperftools/profiler.h>
52#endif
53
54static TALLOC_CTX *autofree;
56static fr_dict_t *test_dict;
57
58/** Global initialisation
59 */
60static void test_init(void)
61{
63 if (!autofree) {
64 error:
65 fr_perror("edit_tests");
66 fr_exit_now(EXIT_FAILURE);
67 }
68
69 /*
70 * Mismatch between the binary and the libraries it depends on
71 */
72 if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) goto error;
73
74 if (fr_dict_test_init(autofree, &test_dict, NULL) < 0) goto error;
75
76 /* Initialize the "test_pairs" list */
78
79 if (fr_pair_test_list_alloc(autofree, &test_pairs, NULL) < 0) goto error;
80}
81
105
107{
108 int count;
109 fr_pair_t *vp;
110
112 TEST_CASE("Expected (count == 3) after undoing the edits");
113 TEST_CHECK(count == 3);
114
117
120
122}
123
124/*
125 * Tests functions
126 */
127static void test_pair_delete_head(void)
128{
129 fr_pair_t *vp;
131 size_t count;
133 int rcode;
134
135 TEST_CASE("Add 3 pairs and delete the first one");
136
138
140
141 el = fr_edit_list_alloc(NULL, 5, NULL);
142 fr_assert(el != NULL);
143
145 TEST_CHECK(rcode == 0);
146
148
150 TEST_CASE("Expected (count == 2) after deleting the head");
151 TEST_CHECK(count == 2);
152
154 TEST_CASE("head is now what was the second pair");
156
158}
159
161{
162 fr_pair_t *vp;
164 size_t count;
166 int rcode;
167
168 TEST_CASE("Add 3 pairs and delete the first one");
169
171
173
174 el = fr_edit_list_alloc(NULL, 5, NULL);
175 fr_assert(el != NULL);
176
178 TEST_CHECK(rcode == 0);
179
181 TEST_CASE("Expected (count == 2) after deleting the head");
182 TEST_CHECK(count == 2);
183
184 /*
185 * Abort the edit
186 */
188
190}
191
192static void test_pair_delete_middle(void)
193{
194 fr_pair_t *vp;
196 size_t count;
198 int rcode;
199
200 TEST_CASE("Add 3 pairs and delete the middle one");
201
203
206 fr_assert(vp != NULL);
207
208 el = fr_edit_list_alloc(NULL, 5, NULL);
209 fr_assert(el != NULL);
210
212 TEST_CHECK(rcode == 0);
213
215
216 /* let's count */
218 TEST_CASE("Expected (count == 2) after deleting the middle");
219 TEST_CHECK(count == 2);
220
223
226
228}
229
231{
232 fr_pair_t *vp, *middle;
234 size_t count;
236 int rcode;
237
238 TEST_CASE("Add 3 pairs and delete the middle one, then abort");
239
241
243 middle = fr_pair_list_next(&local_pairs, vp);
244 fr_assert(middle != NULL);
246
247 el = fr_edit_list_alloc(NULL, 5, NULL);
248 fr_assert(el != NULL);
249
250 rcode = fr_edit_list_pair_delete(el, &local_pairs, middle);
251 TEST_CHECK(rcode == 0);
252
254 TEST_CASE("Expected (count == 2) after deleting the middle");
255 TEST_CHECK(count == 2);
256
259
262
263 /*
264 * Abort the edit
265 */
267
269}
270
272{
273 fr_pair_t *vp;
275 size_t count;
277 int rcode;
278
279 TEST_CASE("Add 3 pairs and delete the last 2");
280
282
285 fr_assert(vp != NULL);
286
287 el = fr_edit_list_alloc(NULL, 5, NULL);
288 fr_assert(el != NULL);
289
290 rcode = fr_edit_list_pair_delete(el, &local_pairs, vp); /* middle */
291 TEST_CHECK(rcode == 0);
292
294 fr_assert(vp != NULL);
295
296 rcode = fr_edit_list_pair_delete(el, &local_pairs, vp); /* tail */
297 TEST_CHECK(rcode == 0);
298
300
302 TEST_CASE("Expected (count == 1) after deleting the last 2");
303 TEST_CHECK(count == 1);
304
307
309 TEST_CHECK(vp->da == fr_dict_attr_test_uint32); /* head == tail */
310
312}
313
315{
316 fr_pair_t *vp;
318 size_t count;
320 int rcode;
321
322 TEST_CASE("Add 3 pairs and delete the last two, then abort");
323
325
327 fr_assert(vp != NULL);
329 fr_assert(vp != NULL);
331
332 el = fr_edit_list_alloc(NULL, 5, NULL);
333 fr_assert(el != NULL);
334
335 rcode = fr_edit_list_pair_delete(el, &local_pairs, vp); /* middle */
336 TEST_CHECK(rcode == 0);
337
339 fr_assert(vp != NULL);
340
341 rcode = fr_edit_list_pair_delete(el, &local_pairs, vp); /* tail */
342 TEST_CHECK(rcode == 0);
343
345 TEST_CASE("Expected (count == 1) after deleting the last 2");
346 TEST_CHECK(count == 1);
347
350
353
354 /*
355 * Abort the edit
356 */
358
360}
361
362
363static void test_pair_edit_value(void)
364{
365 fr_pair_t *vp;
368 int rcode;
369
370 TEST_CASE("Add 3 pairs and change the value of the first one");
371
373
375 fr_assert(vp != NULL);
376
377 el = fr_edit_list_alloc(NULL, 5, NULL);
378 fr_assert(el != NULL);
379
381 TEST_CHECK(rcode == 0);
382
383 TEST_CHECK(vp->vp_uint32 == 0);
384
385 vp->vp_uint32 = 1;
386 TEST_CHECK(vp->vp_uint32 == 1);
387
389
392 TEST_CHECK(vp->vp_uint32 == 1);
393
395}
396
398{
399 fr_pair_t *vp;
402 int rcode;
403
404 TEST_CASE("Add 3 pairs and change the value of the first one, then abort");
405
407
409 fr_assert(vp != NULL);
410
411 el = fr_edit_list_alloc(NULL, 5, NULL);
412 fr_assert(el != NULL);
413
415 TEST_CHECK(rcode == 0);
416
417 TEST_CHECK(vp->vp_uint32 == 0);
418
419 vp->vp_uint32 = 1;
420 TEST_CHECK(vp->vp_uint32 == 1);
421
422 /*
423 * Abort the edit
424 */
426
429 TEST_CHECK(vp->vp_uint32 == 0);
430
432}
433
435{
436 fr_pair_t *vp;
438 size_t count;
440 int rcode;
441
442 TEST_CASE("Add 3 pairs and insert a new one at the head");
443
445
446 el = fr_edit_list_alloc(NULL, 5, NULL);
447 fr_assert(el != NULL);
448
450 fr_assert(vp != NULL);
452 TEST_CHECK(rcode == 0);
453
455
457 TEST_CASE("Expected (count == 4) after inserting a new one");
458 TEST_CHECK(count == 4);
459
461 TEST_CASE("head is now what was the second pair");
463
465}
466
468{
469 fr_pair_t *vp;
471 size_t count;
473 int rcode;
474
475 TEST_CASE("Add 3 pairs and insert a new one at the head, then abort");
476
478
479 el = fr_edit_list_alloc(NULL, 5, NULL);
480 fr_assert(el != NULL);
481
483 fr_assert(vp != NULL);
485 TEST_CHECK(rcode == 0);
486
488 TEST_CASE("Expected (count == 4) after inserting a new one");
489 TEST_CHECK(count == 4);
490
491 /*
492 * Abort the edit
493 */
495
497}
498
500{
501 fr_pair_t *vp, *middle;
503 size_t count;
505 int rcode;
506
507 TEST_CASE("Add 3 pairs and insert a new one at the head");
508
510
512 middle = fr_pair_list_next(&local_pairs, vp);
513 fr_assert(middle != NULL);
514
515 el = fr_edit_list_alloc(NULL, 5, NULL);
516 fr_assert(el != NULL);
517
519 fr_assert(vp != NULL);
521 TEST_CHECK(rcode == 0);
522
524
526 TEST_CASE("Expected (count == 4) after inserting a new one");
527 TEST_CHECK(count == 4);
528
530}
531
533{
534 fr_pair_t *vp, *middle;
536 size_t count;
538 int rcode;
539
540 TEST_CASE("Add 3 pairs and insert a new one at the head, then abort");
541
543
545 middle = fr_pair_list_next(&local_pairs, vp);
546 fr_assert(middle != NULL);
547
548 el = fr_edit_list_alloc(NULL, 5, NULL);
549 fr_assert(el != NULL);
550
552 fr_assert(vp != NULL);
554 TEST_CHECK(rcode == 0);
555
557 TEST_CASE("Expected (count == 4) after inserting a new one");
558 TEST_CHECK(count == 4);
559
560 /*
561 * Abort the edit
562 */
564
566}
567
569{
570 fr_pair_t *vp;
573 int rcode, count;
574
575 TEST_CASE("Add 3 pairs, change the value of the first one, and delete it");
576
578
580 fr_assert(vp != NULL);
581
582 el = fr_edit_list_alloc(NULL, 5, NULL);
583 fr_assert(el != NULL);
584
586 TEST_CHECK(rcode == 0);
587
588 TEST_CHECK(vp->vp_uint32 == 0);
589
590 vp->vp_uint32 = 1;
591 TEST_CHECK(vp->vp_uint32 == 1);
592
594 TEST_CHECK(rcode == 0);
595
597
600
602 TEST_CASE("Expected (count == 2) after deleting the edited pair");
603 TEST_CHECK(count == 2);
604}
605
607{
608 fr_pair_t *vp;
611 int rcode;
612
613 TEST_CASE("Add 3 pairs, change the value of the first one, and delete it, then abort");
614
616
618 fr_assert(vp != NULL);
619
620 el = fr_edit_list_alloc(NULL, 5, NULL);
621 fr_assert(el != NULL);
622
624 TEST_CHECK(rcode == 0);
625
626 TEST_CHECK(vp->vp_uint32 == 0);
627
628 vp->vp_uint32 = 1;
629 TEST_CHECK(vp->vp_uint32 == 1);
630
632 TEST_CHECK(rcode == 0);
633
634 /*
635 * Abort the edit
636 */
638
641 TEST_CHECK(vp->vp_uint32 == 0);
642
644}
645
647{
648 fr_pair_t *vp;
650 size_t count;
652 int rcode;
653
654 TEST_CASE("Add 3 pairs and insert a new one at the head, and delete it");
655
657
658 el = fr_edit_list_alloc(NULL, 5, NULL);
659 fr_assert(el != NULL);
660
662 fr_assert(vp != NULL);
664 TEST_CHECK(rcode == 0);
665
667 TEST_CASE("Expected (count == 4) after inserting a new one");
668 TEST_CHECK(count == 4);
669
671 TEST_CHECK(rcode == 0);
672
674 TEST_CASE("Expected (count == 3) after deleting the just inserted on");
675 TEST_CHECK(count == 3);
676
678
680}
681
683{
684 fr_pair_t *vp;
686 size_t count;
688 int rcode;
689
690 TEST_CASE("Add 3 pairs and insert a new one at the head and delete it, then abort");
691
693
694 el = fr_edit_list_alloc(NULL, 5, NULL);
695 fr_assert(el != NULL);
696
698 fr_assert(vp != NULL);
700 TEST_CHECK(rcode == 0);
701
703 TEST_CASE("Expected (count == 4) after inserting a new one");
704 TEST_CHECK(count == 4);
705
706 /*
707 * Abort the edit
708 */
710
712}
713
714
716{
717 fr_pair_t *vp;
719 fr_edit_list_t *el, *child;
720 int rcode;
721
722 TEST_CASE("Add 3 pairs and change the value of the first one in a child transaction");
723
725
727 fr_assert(vp != NULL);
728
729 el = fr_edit_list_alloc(NULL, 5, NULL);
730 fr_assert(el != NULL);
731
733 TEST_CHECK(rcode == 0);
734
735 TEST_CHECK(vp->vp_uint32 == 0);
736
737 vp->vp_uint32 = 1;
738 TEST_CHECK(vp->vp_uint32 == 1);
739
740 child = fr_edit_list_alloc(NULL, 5, el);
741 fr_assert(child != NULL);
742
743 rcode = fr_edit_list_save_pair_value(child, vp); /* CHILD */
744 TEST_CHECK(rcode == 0);
745
746 TEST_CHECK(vp->vp_uint32 == 1);
747
748 vp->vp_uint32 = 2;
749 TEST_CHECK(vp->vp_uint32 == 2);
750
751 fr_edit_list_commit(child); /* should do nothing */
752
753 TEST_CHECK(vp->vp_uint32 == 2);
754
756
759 TEST_CHECK(vp->vp_uint32 == 2);
760
762}
763
765{
766 fr_pair_t *vp;
768 fr_edit_list_t *el, *child;
769 int rcode;
770
771 TEST_CASE("Add 3 pairs and change the value of the first one, then abort");
772
774
776 fr_assert(vp != NULL);
777
778 el = fr_edit_list_alloc(NULL, 5, NULL);
779 fr_assert(el != NULL);
780
782 TEST_CHECK(rcode == 0);
783
784 TEST_CHECK(vp->vp_uint32 == 0);
785
786 vp->vp_uint32 = 1;
787 TEST_CHECK(vp->vp_uint32 == 1);
788
789 child = fr_edit_list_alloc(NULL, 5, el);
790 fr_assert(child != NULL);
791
792 rcode = fr_edit_list_save_pair_value(child, vp); /* CHILD */
793 TEST_CHECK(rcode == 0);
794
795 TEST_CHECK(vp->vp_uint32 == 1);
796
797 vp->vp_uint32 = 2;
798 TEST_CHECK(vp->vp_uint32 == 2);
799
800 fr_edit_list_abort(child); /* CHILD */
801
802 TEST_CHECK(vp->vp_uint32 == 1);
803
805
808 TEST_CHECK(vp->vp_uint32 == 1);
809
811}
812
813static void test_pair_delete_tail(void)
814{
815 fr_pair_t *vp;
817 size_t count;
819 int rcode;
820
821 TEST_CASE("Add 3 pairs and delete the tail");
822
824
826 fr_assert(vp != NULL);
828
829 el = fr_edit_list_alloc(NULL, 5, NULL);
830 fr_assert(el != NULL);
831
833 TEST_CHECK(rcode == 0);
834
836
838 TEST_CASE("Expected (count == 2) after deleting the tail");
839 TEST_CHECK(count == 2);
840
843
845}
846
848{
849 fr_pair_t *vp;
851 size_t count;
853 int rcode;
854
855 TEST_CASE("Add 3 pairs and delete the tail, then abort");
856
858
860 fr_assert(vp != NULL);
862
863 el = fr_edit_list_alloc(NULL, 5, NULL);
864 fr_assert(el != NULL);
865
867 TEST_CHECK(rcode == 0);
868
870 TEST_CHECK(count == 2);
871
873
875}
876
877static void test_pair_delete_by_da(void)
878{
879 fr_pair_t *vp;
881 size_t count;
883 int rcode;
884
885 TEST_CASE("Add pairs and delete all with a matching da");
886
888
889 /* Add another uint32 at the tail */
891 fr_assert(vp != NULL);
892 vp->vp_uint32 = 42;
894
896 TEST_CHECK(count == 4);
897
898 el = fr_edit_list_alloc(NULL, 5, NULL);
899 fr_assert(el != NULL);
900
902 TEST_CHECK(rcode == 0);
903
905
907 TEST_CASE("Expected (count == 2) after deleting all uint32 pairs");
908 TEST_CHECK(count == 2);
909
912
915
917}
918
920{
921 fr_pair_t *vp;
923 size_t count;
925 int rcode;
926
927 TEST_CASE("Add pairs and delete all with a matching da, then abort");
928
930
932 fr_assert(vp != NULL);
933 vp->vp_uint32 = 42;
935
937 TEST_CHECK(count == 4);
938
939 el = fr_edit_list_alloc(NULL, 5, NULL);
940 fr_assert(el != NULL);
941
943 TEST_CHECK(rcode == 0);
944
946 TEST_CHECK(count == 2);
947
949
951 TEST_CASE("Expected (count == 4) after aborting the delete");
952 TEST_CHECK(count == 4);
953
956 TEST_CHECK(vp->vp_uint32 == 0);
957
960 TEST_CHECK(vp->vp_uint32 == 42);
961
963}
964
965static void test_pair_replace_value(void)
966{
967 fr_pair_t *vp;
970 int rcode;
971 fr_value_box_t box;
972
973 TEST_CASE("Add 3 pairs and replace the value of the first one");
974
976
978 fr_assert(vp != NULL);
979
980 el = fr_edit_list_alloc(NULL, 5, NULL);
981 fr_assert(el != NULL);
982
983 TEST_CHECK(vp->vp_uint32 == 0);
984
985 fr_value_box_init(&box, FR_TYPE_UINT32, NULL, false);
986 box.vb_uint32 = 42;
987
988 rcode = fr_edit_list_replace_pair_value(el, vp, &box);
989 TEST_CHECK(rcode == 0);
990 TEST_CHECK(vp->vp_uint32 == 42);
991
993
996 TEST_CHECK(vp->vp_uint32 == 42);
997
999}
1000
1002{
1003 fr_pair_t *vp;
1006 int rcode;
1007 fr_value_box_t box;
1008
1009 TEST_CASE("Add 3 pairs and replace the value of the first one, then abort");
1010
1012
1014 fr_assert(vp != NULL);
1015
1016 el = fr_edit_list_alloc(NULL, 5, NULL);
1017 fr_assert(el != NULL);
1018
1019 TEST_CHECK(vp->vp_uint32 == 0);
1020
1021 fr_value_box_init(&box, FR_TYPE_UINT32, NULL, false);
1022 box.vb_uint32 = 42;
1023
1024 rcode = fr_edit_list_replace_pair_value(el, vp, &box);
1025 TEST_CHECK(rcode == 0);
1026 TEST_CHECK(vp->vp_uint32 == 42);
1027
1029
1032 TEST_CHECK(vp->vp_uint32 == 0);
1033
1035}
1036
1037static void test_pair_replace_pair(void)
1038{
1039 fr_pair_t *vp, *new_vp;
1041 size_t count;
1043 int rcode;
1044
1045 TEST_CASE("Add 3 pairs and replace the head with a new pair");
1046
1048
1050 fr_assert(vp != NULL);
1051
1052 el = fr_edit_list_alloc(NULL, 5, NULL);
1053 fr_assert(el != NULL);
1054
1056 fr_assert(new_vp != NULL);
1057 new_vp->vp_uint32 = 99;
1058
1059 rcode = fr_edit_list_replace_pair(el, &local_pairs, vp, new_vp);
1060 TEST_CHECK(rcode == 0);
1061
1063
1065 TEST_CASE("Expected (count == 3) after replacing a pair");
1066 TEST_CHECK(count == 3);
1067
1070 TEST_CHECK(vp->vp_uint32 == 99);
1071
1073}
1074
1076{
1077 fr_pair_t *vp, *new_vp;
1080 int rcode;
1081
1082 TEST_CASE("Add 3 pairs and replace the head, then abort");
1083
1085
1087 fr_assert(vp != NULL);
1088
1089 el = fr_edit_list_alloc(NULL, 5, NULL);
1090 fr_assert(el != NULL);
1091
1093 fr_assert(new_vp != NULL);
1094 new_vp->vp_uint32 = 99;
1095
1096 rcode = fr_edit_list_replace_pair(el, &local_pairs, vp, new_vp);
1097 TEST_CHECK(rcode == 0);
1098
1100 TEST_CHECK(vp->vp_uint32 == 99);
1101
1103
1106 TEST_CHECK(vp->vp_uint32 == 0);
1107
1109}
1110
1112{
1113 fr_pair_t *vp;
1115 size_t count;
1117 int rcode;
1118
1119 TEST_CASE("Add 3 pairs and insert a new one at the tail");
1120
1122
1123 el = fr_edit_list_alloc(NULL, 5, NULL);
1124 fr_assert(el != NULL);
1125
1127 fr_assert(vp != NULL);
1129 TEST_CHECK(rcode == 0);
1130
1132
1134 TEST_CASE("Expected (count == 4) after inserting at the tail");
1135 TEST_CHECK(count == 4);
1136
1139
1141}
1142
1144{
1145 fr_pair_t *vp;
1147 size_t count;
1149 int rcode;
1150
1151 TEST_CASE("Add 3 pairs and insert a new one at the tail, then abort");
1152
1154
1155 el = fr_edit_list_alloc(NULL, 5, NULL);
1156 fr_assert(el != NULL);
1157
1159 fr_assert(vp != NULL);
1161 TEST_CHECK(rcode == 0);
1162
1164 TEST_CHECK(count == 4);
1165
1167
1169}
1170
1172{
1173 fr_pair_t *vp, *child;
1175 size_t count;
1177 int rcode;
1178
1179 TEST_CASE("Add children to a TLV pair and free them");
1180
1182
1185
1187 fr_assert(child != NULL);
1188 fr_pair_append(&vp->vp_group, child);
1189 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1190
1191 el = fr_edit_list_alloc(NULL, 5, NULL);
1192 fr_assert(el != NULL);
1193
1195 TEST_CHECK(rcode == 0);
1196 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1197
1199
1200 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1201
1203 TEST_CHECK(count == 3);
1204
1206}
1207
1209{
1210 fr_pair_t *vp, *child;
1213 int rcode;
1214
1215 TEST_CASE("Add children to a TLV pair, free them, then abort");
1216
1218
1221
1223 fr_assert(child != NULL);
1224 fr_pair_append(&vp->vp_group, child);
1225 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1226
1227 el = fr_edit_list_alloc(NULL, 5, NULL);
1228 fr_assert(el != NULL);
1229
1231 TEST_CHECK(rcode == 0);
1232 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1233
1235
1236 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1237
1238 child = fr_pair_list_head(&vp->vp_group);
1240
1242}
1243
1245{
1246 fr_pair_t *vp;
1247 fr_pair_list_t local_pairs, to_insert;
1248 size_t count;
1250 int rcode;
1251
1252 TEST_CASE("Add 3 pairs and insert a list of 2 at the tail");
1253
1255
1256 fr_pair_list_init(&to_insert);
1257
1259 fr_assert(vp != NULL);
1260 fr_pair_append(&to_insert, vp);
1261
1263 fr_assert(vp != NULL);
1264 fr_pair_append(&to_insert, vp);
1265
1266 el = fr_edit_list_alloc(NULL, 5, NULL);
1267 fr_assert(el != NULL);
1268
1269 rcode = fr_edit_list_insert_list_tail(el, &local_pairs, &to_insert);
1270 TEST_CHECK(rcode == 0);
1271
1273
1275 TEST_CASE("Expected (count == 5) after inserting a list of 2");
1276 TEST_CHECK(count == 5);
1277
1280
1282}
1283
1285{
1286 fr_pair_t *vp;
1287 fr_pair_list_t local_pairs, to_insert;
1288 size_t count;
1290 int rcode;
1291
1292 TEST_CASE("Add 3 pairs and insert a list of 2 at the tail, then abort");
1293
1295
1296 fr_pair_list_init(&to_insert);
1297
1299 fr_assert(vp != NULL);
1300 fr_pair_append(&to_insert, vp);
1301
1303 fr_assert(vp != NULL);
1304 fr_pair_append(&to_insert, vp);
1305
1306 el = fr_edit_list_alloc(NULL, 5, NULL);
1307 fr_assert(el != NULL);
1308
1309 rcode = fr_edit_list_insert_list_tail(el, &local_pairs, &to_insert);
1310 TEST_CHECK(rcode == 0);
1311
1313 TEST_CHECK(count == 5);
1314
1316
1318}
1319
1321{
1322 fr_pair_t *vp;
1324 fr_edit_list_t *el, *child;
1325 int rcode;
1326
1327 TEST_CASE("Child commits value change, parent aborts - everything reverted");
1328
1330
1332 fr_assert(vp != NULL);
1333
1334 el = fr_edit_list_alloc(NULL, 5, NULL);
1335 fr_assert(el != NULL);
1336
1338 TEST_CHECK(rcode == 0);
1339
1340 TEST_CHECK(vp->vp_uint32 == 0);
1341
1342 vp->vp_uint32 = 1;
1343 TEST_CHECK(vp->vp_uint32 == 1);
1344
1345 child = fr_edit_list_alloc(NULL, 5, el);
1346 fr_assert(child != NULL);
1347
1348 rcode = fr_edit_list_save_pair_value(child, vp);
1349 TEST_CHECK(rcode == 0);
1350
1351 vp->vp_uint32 = 2;
1352 TEST_CHECK(vp->vp_uint32 == 2);
1353
1354 fr_edit_list_commit(child); /* does nothing, value stays at 2 */
1355 TEST_CHECK(vp->vp_uint32 == 2);
1356
1357 /* Abort parent - everything should revert */
1359
1362 TEST_CHECK(vp->vp_uint32 == 0);
1363
1365}
1366
1368 /*
1369 * Deletion.
1370 */
1371 { "pair_delete_head", test_pair_delete_head },
1372 { "pair_delete_head_abort", test_pair_delete_head_abort },
1373
1374 { "pair_delete_middle", test_pair_delete_middle },
1375 { "pair_delete_middle_abort", test_pair_delete_middle_abort },
1376
1377 { "pair_delete_multiple", test_pair_delete_multiple },
1378 { "pair_delete_multiple_abort", test_pair_delete_multiple_abort },
1379
1380 /*
1381 * Insert after
1382 */
1383 { "pair_insert_after_head", test_pair_insert_after_head },
1384 { "pair_insert_after_head_abort", test_pair_insert_after_head_abort },
1385
1386 { "pair_insert_after_middle", test_pair_insert_after_middle },
1387 { "pair_insert_after_middle_abort", test_pair_insert_after_middle_abort },
1388
1389 /*
1390 * Value modification
1391 */
1392 { "pair_edit_value", test_pair_edit_value },
1393 { "pair_edit_value_abort", test_pair_edit_value_abort },
1394
1395 /*
1396 * Value modification, then deletion
1397 */
1398 { "pair_edit_value_delete", test_pair_edit_value_delete },
1399 { "pair_edit_value_delete_abort", test_pair_edit_value_delete_abort },
1400
1401 /*
1402 * Insert after, then delete
1403 */
1404 { "pair_insert_after_head_delete", test_pair_insert_after_head_delete },
1405 { "pair_insert_after_head_delete_abort", test_pair_insert_after_head_delete_abort },
1406
1407 /*
1408 * Value modification in child list
1409 */
1410 { "pair_edit_child_value", test_pair_edit_child_value },
1411 { "pair_edit_child_value_abort", test_pair_edit_child_value_abort },
1412
1413 /*
1414 * Deletion of tail
1415 */
1416 { "pair_delete_tail", test_pair_delete_tail },
1417 { "pair_delete_tail_abort", test_pair_delete_tail_abort },
1418
1419 /*
1420 * Deletion by da
1421 */
1422 { "pair_delete_by_da", test_pair_delete_by_da },
1423 { "pair_delete_by_da_abort", test_pair_delete_by_da_abort },
1424
1425 /*
1426 * Value replacement (fr_edit_list_replace_pair_value)
1427 */
1428 { "pair_replace_value", test_pair_replace_value },
1429 { "pair_replace_value_abort", test_pair_replace_value_abort },
1430
1431 /*
1432 * Pair replacement (fr_edit_list_replace_pair)
1433 */
1434 { "pair_replace_pair", test_pair_replace_pair },
1435 { "pair_replace_pair_abort", test_pair_replace_pair_abort },
1436
1437 /*
1438 * Insert at tail
1439 */
1440 { "pair_insert_after_tail", test_pair_insert_after_tail },
1441 { "pair_insert_after_tail_abort", test_pair_insert_after_tail_abort },
1442
1443 /*
1444 * Free children of structural pair
1445 */
1446 { "pair_free_children", test_pair_free_children },
1447 { "pair_free_children_abort", test_pair_free_children_abort },
1448
1449 /*
1450 * Insert list at tail
1451 */
1452 { "pair_insert_list_tail", test_pair_insert_list_tail },
1453 { "pair_insert_list_tail_abort", test_pair_insert_list_tail_abort },
1454
1455 /*
1456 * Child commit + parent abort
1457 */
1458 { "pair_edit_child_commit_parent_abort", test_pair_edit_child_commit_parent_abort },
1459
1461};
#define TEST_CHECK(cond)
Definition acutest.h:87
#define TEST_CASE(name)
Definition acutest.h:186
#define TEST_TERMINATOR
Definition acutest.h:64
static TALLOC_CTX * autofree
Definition fuzzer.c:46
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition debug.h:226
fr_dict_attr_t const * fr_dict_attr_test_tlv_string
Definition dict_test.c:65
fr_dict_attr_t const * fr_dict_attr_test_tlv
Definition dict_test.c:64
fr_dict_attr_t const * fr_dict_attr_test_uint32
Definition dict_test.c:47
fr_dict_attr_t const * fr_dict_attr_test_octets
Definition dict_test.c:31
fr_dict_attr_t const * fr_dict_attr_test_string
Definition dict_test.c:30
int fr_dict_test_init(TALLOC_CTX *ctx, fr_dict_t **dict_p, fr_dict_test_attr_t const *test_defs)
Initialise a test dictionary and add our test_defs to it.
Definition dict_test.c:248
fr_dict_attr_t const * fr_dict_attr_test_uint16
Definition dict_test.c:46
static void test_pair_delete_multiple(void)
Definition edit_tests.c:271
static void test_pair_insert_list_tail(void)
static void test_pair_delete_head(void)
Definition edit_tests.c:127
TEST_LIST
static void test_pair_delete_head_abort(void)
Definition edit_tests.c:160
static void test_pair_delete_tail(void)
Definition edit_tests.c:813
static void test_pair_replace_value_abort(void)
static void test_pair_delete_multiple_abort(void)
Definition edit_tests.c:314
static void test_pair_edit_value_delete_abort(void)
Definition edit_tests.c:606
static void test_pair_insert_after_head_delete_abort(void)
Definition edit_tests.c:682
static void test_pair_delete_middle_abort(void)
Definition edit_tests.c:230
static void expect3(fr_pair_list_t *local_pairs)
Definition edit_tests.c:106
static void test_pair_replace_pair(void)
static void test_pair_edit_child_commit_parent_abort(void)
static void test_pair_delete_by_da(void)
Definition edit_tests.c:877
static void test_pair_edit_value(void)
Definition edit_tests.c:363
static void test_pair_free_children(void)
static void test_pair_insert_after_tail_abort(void)
static void test_pair_delete_by_da_abort(void)
Definition edit_tests.c:919
static void test_pair_replace_value(void)
Definition edit_tests.c:965
static void test_pair_insert_after_middle(void)
Definition edit_tests.c:499
static void test_pair_edit_child_value(void)
Definition edit_tests.c:715
static void add_pairs(fr_pair_list_t *local_pairs)
Definition edit_tests.c:82
static void test_pair_insert_after_head_abort(void)
Definition edit_tests.c:467
static void test_pair_insert_after_tail(void)
static void test_pair_insert_after_head(void)
Definition edit_tests.c:434
static void test_pair_insert_after_head_delete(void)
Definition edit_tests.c:646
static void test_pair_edit_child_value_abort(void)
Definition edit_tests.c:764
static void test_pair_delete_middle(void)
Definition edit_tests.c:192
static void test_pair_free_children_abort(void)
static void test_pair_insert_list_tail_abort(void)
static void test_pair_edit_value_delete(void)
Definition edit_tests.c:568
static void test_pair_delete_tail_abort(void)
Definition edit_tests.c:847
static void test_init(void)
Global initialisation.
Definition edit_tests.c:36
static void test_pair_replace_pair_abort(void)
static void test_pair_edit_value_abort(void)
Definition edit_tests.c:397
static void test_pair_insert_after_middle_abort(void)
Definition edit_tests.c:532
@ FR_TYPE_UINT32
32 Bit unsigned integer.
int fr_pair_append(fr_pair_list_t *list, fr_pair_t *to_add)
Add a VP to the end of the list.
Definition pair.c:1354
fr_pair_t * fr_pair_afrom_da(TALLOC_CTX *ctx, fr_dict_attr_t const *da)
Dynamically allocate a new attribute and assign a fr_dict_attr_t.
Definition pair.c:290
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
static fr_pair_list_t test_pairs
static fr_dict_t * test_dict
Helper functions for pair tests.
static int fr_pair_test_list_alloc(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_test_attr_t const *test_defs)
#define fr_assert(_expr)
Definition rad_assert.h:38
#define local_pairs
Convenience macro for accessing the state list.
Definition request.h:160
return count
Definition module.c:155
fr_pair_t * vp
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
#define talloc_autofree_context
The original function is deprecated, so replace it with our version.
Definition talloc.h:51
static fr_event_list_t * el
int fr_edit_list_pair_delete(fr_edit_list_t *el, fr_pair_list_t *list, fr_pair_t *vp)
Delete a VP.
Definition edit.c:607
int fr_edit_list_replace_pair_value(fr_edit_list_t *el, fr_pair_t *vp, fr_value_box_t *box)
Write a new value to the fr_value_box_t.
Definition edit.c:658
void fr_edit_list_commit(fr_edit_list_t *el)
Commit an edit list.
Definition edit.c:852
int fr_edit_list_insert_pair_after(fr_edit_list_t *el, fr_pair_list_t *list, fr_pair_t *pos, fr_pair_t *vp)
Insert a new VP after an existing one.
Definition edit.c:594
int fr_edit_list_save_pair_value(fr_edit_list_t *el, fr_pair_t *vp)
Record the value of a leaf fr_value_box_t.
Definition edit.c:645
void fr_edit_list_abort(fr_edit_list_t *el)
Abort the entries in an edit list.
Definition edit.c:202
int fr_edit_list_replace_pair(fr_edit_list_t *el, fr_pair_list_t *list, fr_pair_t *to_replace, fr_pair_t *vp)
Replace a pair with another one.
Definition edit.c:676
int fr_edit_list_free_pair_children(fr_edit_list_t *el, fr_pair_t *vp)
Free children of a structural pair.
Definition edit.c:722
int fr_edit_list_pair_delete_by_da(fr_edit_list_t *el, fr_pair_list_t *list, fr_dict_attr_t const *da)
Delete VPs with a matching da.
Definition edit.c:621
fr_edit_list_t * fr_edit_list_alloc(TALLOC_CTX *ctx, int hint, fr_edit_list_t *parent)
Allocate an edit list.
Definition edit.c:801
Track a series of edits.
Definition edit.c:101
#define fr_edit_list_insert_pair_tail(_el, _list, _vp)
Definition edit.h:51
#define fr_edit_list_insert_list_tail(_el, _list, _to_insert)
Definition edit.h:74
bool fr_pair_list_empty(fr_pair_list_t const *list)
Is a valuepair list empty.
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
Definition pair_inline.c:69
fr_pair_t * fr_pair_list_tail(fr_pair_list_t const *list)
Get the tail of a valuepair list.
Definition pair_inline.c:55
void fr_pair_list_free(fr_pair_list_t *list)
Free memory used by a valuepair list.
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
Definition pair_inline.c:42
size_t fr_pair_list_num_elements(fr_pair_list_t const *list)
Get the length of a list of fr_pair_t.
void fr_perror(char const *fmt,...)
Print the current error to stderr with a prefix.
Definition strerror.c:732
int fr_check_lib_magic(uint64_t magic)
Check if the application linking to the library has the correct magic number.
Definition version.c:40
#define RADIUSD_MAGIC_NUMBER
Definition version.h:81
#define fr_value_box_init(_vb, _type, _enumv, _tainted)
Initialise a fr_value_box_t.
Definition value.h:610