The FreeRADIUS server $Id: a4e7f8c94e8038b7627bcf52356b7ed15955c1d7 $
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
24static void test_init(void);
25#define TEST_GLOBAL_INIT test_init()
26
27#include "acutest_common_init.h"
28#include "acutest_helpers.h"
29#include "pair_test_helpers.h"
30
31#include <freeradius-devel/util/conf.h>
32#include <freeradius-devel/util/dict.h>
33#include <freeradius-devel/util/edit.h>
34
35static TALLOC_CTX *autofree;
38
39/** Global initialisation
40 */
41static void test_init(void)
42{
44 if (!autofree) {
45 error:
46 fr_perror("edit_tests");
47 fr_exit_now(EXIT_FAILURE);
48 }
49
50 /*
51 * Mismatch between the binary and the libraries it depends on
52 */
53 if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) goto error;
54
55 if (fr_dict_test_init(autofree, &test_dict, NULL) < 0) goto error;
56
57 /* Initialize the "test_pairs" list */
59
60 if (fr_pair_test_list_alloc(autofree, &test_pairs, NULL) < 0) goto error;
61}
62
86
88{
89 int count;
91
93 TEST_CASE("Expected (count == 3) after undoing the edits");
94 TEST_CHECK(count == 3);
95
98
101
103}
104
105/*
106 * Tests functions
107 */
108static void test_pair_delete_head(void)
109{
110 fr_pair_t *vp;
112 size_t count;
114 int rcode;
115
116 TEST_CASE("Add 3 pairs and delete the first one");
117
119
121
122 el = fr_edit_list_alloc(NULL, 5, NULL);
123 fr_assert(el != NULL);
124
126 TEST_CHECK(rcode == 0);
127
129
131 TEST_CASE("Expected (count == 2) after deleting the head");
132 TEST_CHECK(count == 2);
133
135 TEST_CASE("head is now what was the second pair");
137
139}
140
142{
143 fr_pair_t *vp;
145 size_t count;
147 int rcode;
148
149 TEST_CASE("Add 3 pairs and delete the first one");
150
152
154
155 el = fr_edit_list_alloc(NULL, 5, NULL);
156 fr_assert(el != NULL);
157
159 TEST_CHECK(rcode == 0);
160
162 TEST_CASE("Expected (count == 2) after deleting the head");
163 TEST_CHECK(count == 2);
164
165 /*
166 * Abort the edit
167 */
169
171}
172
173static void test_pair_delete_middle(void)
174{
175 fr_pair_t *vp;
177 size_t count;
179 int rcode;
180
181 TEST_CASE("Add 3 pairs and delete the middle one");
182
184
187 fr_assert(vp != NULL);
188
189 el = fr_edit_list_alloc(NULL, 5, NULL);
190 fr_assert(el != NULL);
191
193 TEST_CHECK(rcode == 0);
194
196
197 /* let's count */
199 TEST_CASE("Expected (count == 2) after deleting the middle");
200 TEST_CHECK(count == 2);
201
204
207
209}
210
212{
213 fr_pair_t *vp, *middle;
215 size_t count;
217 int rcode;
218
219 TEST_CASE("Add 3 pairs and delete the middle one, then abort");
220
222
224 middle = fr_pair_list_next(&local_pairs, vp);
225 fr_assert(middle != NULL);
227
228 el = fr_edit_list_alloc(NULL, 5, NULL);
229 fr_assert(el != NULL);
230
231 rcode = fr_edit_list_pair_delete(el, &local_pairs, middle);
232 TEST_CHECK(rcode == 0);
233
235 TEST_CASE("Expected (count == 2) after deleting the middle");
236 TEST_CHECK(count == 2);
237
240
243
244 /*
245 * Abort the edit
246 */
248
250}
251
253{
254 fr_pair_t *vp;
256 size_t count;
258 int rcode;
259
260 TEST_CASE("Add 3 pairs and delete the last 2");
261
263
266 fr_assert(vp != NULL);
267
268 el = fr_edit_list_alloc(NULL, 5, NULL);
269 fr_assert(el != NULL);
270
271 rcode = fr_edit_list_pair_delete(el, &local_pairs, vp); /* middle */
272 TEST_CHECK(rcode == 0);
273
275 fr_assert(vp != NULL);
276
277 rcode = fr_edit_list_pair_delete(el, &local_pairs, vp); /* tail */
278 TEST_CHECK(rcode == 0);
279
281
283 TEST_CASE("Expected (count == 1) after deleting the last 2");
284 TEST_CHECK(count == 1);
285
288
290 TEST_CHECK(vp->da == fr_dict_attr_test_uint32); /* head == tail */
291
293}
294
296{
297 fr_pair_t *vp;
299 size_t count;
301 int rcode;
302
303 TEST_CASE("Add 3 pairs and delete the last two, then abort");
304
306
308 fr_assert(vp != NULL);
310 fr_assert(vp != NULL);
312
313 el = fr_edit_list_alloc(NULL, 5, NULL);
314 fr_assert(el != NULL);
315
316 rcode = fr_edit_list_pair_delete(el, &local_pairs, vp); /* middle */
317 TEST_CHECK(rcode == 0);
318
320 fr_assert(vp != NULL);
321
322 rcode = fr_edit_list_pair_delete(el, &local_pairs, vp); /* tail */
323 TEST_CHECK(rcode == 0);
324
326 TEST_CASE("Expected (count == 1) after deleting the last 2");
327 TEST_CHECK(count == 1);
328
331
334
335 /*
336 * Abort the edit
337 */
339
341}
342
343
344static void test_pair_edit_value(void)
345{
346 fr_pair_t *vp;
349 int rcode;
350
351 TEST_CASE("Add 3 pairs and change the value of the first one");
352
354
356 fr_assert(vp != NULL);
357
358 el = fr_edit_list_alloc(NULL, 5, NULL);
359 fr_assert(el != NULL);
360
362 TEST_CHECK(rcode == 0);
363
364 TEST_CHECK(vp->vp_uint32 == 0);
365
366 vp->vp_uint32 = 1;
367 TEST_CHECK(vp->vp_uint32 == 1);
368
370
373 TEST_CHECK(vp->vp_uint32 == 1);
374
376}
377
379{
380 fr_pair_t *vp;
383 int rcode;
384
385 TEST_CASE("Add 3 pairs and change the value of the first one, then abort");
386
388
390 fr_assert(vp != NULL);
391
392 el = fr_edit_list_alloc(NULL, 5, NULL);
393 fr_assert(el != NULL);
394
396 TEST_CHECK(rcode == 0);
397
398 TEST_CHECK(vp->vp_uint32 == 0);
399
400 vp->vp_uint32 = 1;
401 TEST_CHECK(vp->vp_uint32 == 1);
402
403 /*
404 * Abort the edit
405 */
407
410 TEST_CHECK(vp->vp_uint32 == 0);
411
413}
414
416{
417 fr_pair_t *vp;
419 size_t count;
421 int rcode;
422
423 TEST_CASE("Add 3 pairs and insert a new one at the head");
424
426
427 el = fr_edit_list_alloc(NULL, 5, NULL);
428 fr_assert(el != NULL);
429
431 fr_assert(vp != NULL);
433 TEST_CHECK(rcode == 0);
434
436
438 TEST_CASE("Expected (count == 4) after inserting a new one");
439 TEST_CHECK(count == 4);
440
442 TEST_CASE("head is now what was the second pair");
444
446}
447
449{
450 fr_pair_t *vp;
452 size_t count;
454 int rcode;
455
456 TEST_CASE("Add 3 pairs and insert a new one at the head, then abort");
457
459
460 el = fr_edit_list_alloc(NULL, 5, NULL);
461 fr_assert(el != NULL);
462
464 fr_assert(vp != NULL);
466 TEST_CHECK(rcode == 0);
467
469 TEST_CASE("Expected (count == 4) after inserting a new one");
470 TEST_CHECK(count == 4);
471
472 /*
473 * Abort the edit
474 */
476
478}
479
481{
482 fr_pair_t *vp, *middle;
484 size_t count;
486 int rcode;
487
488 TEST_CASE("Add 3 pairs and insert a new one at the head");
489
491
493 middle = fr_pair_list_next(&local_pairs, vp);
494 fr_assert(middle != NULL);
495
496 el = fr_edit_list_alloc(NULL, 5, NULL);
497 fr_assert(el != NULL);
498
500 fr_assert(vp != NULL);
502 TEST_CHECK(rcode == 0);
503
505
507 TEST_CASE("Expected (count == 4) after inserting a new one");
508 TEST_CHECK(count == 4);
509
511}
512
514{
515 fr_pair_t *vp, *middle;
517 size_t count;
519 int rcode;
520
521 TEST_CASE("Add 3 pairs and insert a new one at the head, then abort");
522
524
526 middle = fr_pair_list_next(&local_pairs, vp);
527 fr_assert(middle != NULL);
528
529 el = fr_edit_list_alloc(NULL, 5, NULL);
530 fr_assert(el != NULL);
531
533 fr_assert(vp != NULL);
535 TEST_CHECK(rcode == 0);
536
538 TEST_CASE("Expected (count == 4) after inserting a new one");
539 TEST_CHECK(count == 4);
540
541 /*
542 * Abort the edit
543 */
545
547}
548
550{
551 fr_pair_t *vp;
554 int rcode, count;
555
556 TEST_CASE("Add 3 pairs, change the value of the first one, and delete it");
557
559
561 fr_assert(vp != NULL);
562
563 el = fr_edit_list_alloc(NULL, 5, NULL);
564 fr_assert(el != NULL);
565
567 TEST_CHECK(rcode == 0);
568
569 TEST_CHECK(vp->vp_uint32 == 0);
570
571 vp->vp_uint32 = 1;
572 TEST_CHECK(vp->vp_uint32 == 1);
573
575 TEST_CHECK(rcode == 0);
576
578
581
583 TEST_CASE("Expected (count == 2) after deleting the edited pair");
584 TEST_CHECK(count == 2);
585}
586
588{
589 fr_pair_t *vp;
592 int rcode;
593
594 TEST_CASE("Add 3 pairs, change the value of the first one, and delete it, then abort");
595
597
599 fr_assert(vp != NULL);
600
601 el = fr_edit_list_alloc(NULL, 5, NULL);
602 fr_assert(el != NULL);
603
605 TEST_CHECK(rcode == 0);
606
607 TEST_CHECK(vp->vp_uint32 == 0);
608
609 vp->vp_uint32 = 1;
610 TEST_CHECK(vp->vp_uint32 == 1);
611
613 TEST_CHECK(rcode == 0);
614
615 /*
616 * Abort the edit
617 */
619
622 TEST_CHECK(vp->vp_uint32 == 0);
623
625}
626
628{
629 fr_pair_t *vp;
631 size_t count;
633 int rcode;
634
635 TEST_CASE("Add 3 pairs and insert a new one at the head, and delete it");
636
638
639 el = fr_edit_list_alloc(NULL, 5, NULL);
640 fr_assert(el != NULL);
641
643 fr_assert(vp != NULL);
645 TEST_CHECK(rcode == 0);
646
648 TEST_CASE("Expected (count == 4) after inserting a new one");
649 TEST_CHECK(count == 4);
650
652 TEST_CHECK(rcode == 0);
653
655 TEST_CASE("Expected (count == 3) after deleting the just inserted on");
656 TEST_CHECK(count == 3);
657
659
661}
662
664{
665 fr_pair_t *vp;
667 size_t count;
669 int rcode;
670
671 TEST_CASE("Add 3 pairs and insert a new one at the head and delete it, then abort");
672
674
675 el = fr_edit_list_alloc(NULL, 5, NULL);
676 fr_assert(el != NULL);
677
679 fr_assert(vp != NULL);
681 TEST_CHECK(rcode == 0);
682
684 TEST_CASE("Expected (count == 4) after inserting a new one");
685 TEST_CHECK(count == 4);
686
687 /*
688 * Abort the edit
689 */
691
693}
694
695
697{
698 fr_pair_t *vp;
700 fr_edit_list_t *el, *child;
701 int rcode;
702
703 TEST_CASE("Add 3 pairs and change the value of the first one in a child transaction");
704
706
708 fr_assert(vp != NULL);
709
710 el = fr_edit_list_alloc(NULL, 5, NULL);
711 fr_assert(el != NULL);
712
714 TEST_CHECK(rcode == 0);
715
716 TEST_CHECK(vp->vp_uint32 == 0);
717
718 vp->vp_uint32 = 1;
719 TEST_CHECK(vp->vp_uint32 == 1);
720
721 child = fr_edit_list_alloc(NULL, 5, el);
722 fr_assert(child != NULL);
723
724 rcode = fr_edit_list_save_pair_value(child, vp); /* CHILD */
725 TEST_CHECK(rcode == 0);
726
727 TEST_CHECK(vp->vp_uint32 == 1);
728
729 vp->vp_uint32 = 2;
730 TEST_CHECK(vp->vp_uint32 == 2);
731
732 fr_edit_list_commit(child); /* should do nothing */
733
734 TEST_CHECK(vp->vp_uint32 == 2);
735
737
740 TEST_CHECK(vp->vp_uint32 == 2);
741
743}
744
746{
747 fr_pair_t *vp;
749 fr_edit_list_t *el, *child;
750 int rcode;
751
752 TEST_CASE("Add 3 pairs and change the value of the first one, then abort");
753
755
757 fr_assert(vp != NULL);
758
759 el = fr_edit_list_alloc(NULL, 5, NULL);
760 fr_assert(el != NULL);
761
763 TEST_CHECK(rcode == 0);
764
765 TEST_CHECK(vp->vp_uint32 == 0);
766
767 vp->vp_uint32 = 1;
768 TEST_CHECK(vp->vp_uint32 == 1);
769
770 child = fr_edit_list_alloc(NULL, 5, el);
771 fr_assert(child != NULL);
772
773 rcode = fr_edit_list_save_pair_value(child, vp); /* CHILD */
774 TEST_CHECK(rcode == 0);
775
776 TEST_CHECK(vp->vp_uint32 == 1);
777
778 vp->vp_uint32 = 2;
779 TEST_CHECK(vp->vp_uint32 == 2);
780
781 fr_edit_list_abort(child); /* CHILD */
782
783 TEST_CHECK(vp->vp_uint32 == 1);
784
786
789 TEST_CHECK(vp->vp_uint32 == 1);
790
792}
793
794static void test_pair_delete_tail(void)
795{
796 fr_pair_t *vp;
798 size_t count;
800 int rcode;
801
802 TEST_CASE("Add 3 pairs and delete the tail");
803
805
807 fr_assert(vp != NULL);
809
810 el = fr_edit_list_alloc(NULL, 5, NULL);
811 fr_assert(el != NULL);
812
814 TEST_CHECK(rcode == 0);
815
817
819 TEST_CASE("Expected (count == 2) after deleting the tail");
820 TEST_CHECK(count == 2);
821
824
826}
827
829{
830 fr_pair_t *vp;
832 size_t count;
834 int rcode;
835
836 TEST_CASE("Add 3 pairs and delete the tail, then abort");
837
839
841 fr_assert(vp != NULL);
843
844 el = fr_edit_list_alloc(NULL, 5, NULL);
845 fr_assert(el != NULL);
846
848 TEST_CHECK(rcode == 0);
849
851 TEST_CHECK(count == 2);
852
854
856}
857
858static void test_pair_delete_by_da(void)
859{
860 fr_pair_t *vp;
862 size_t count;
864 int rcode;
865
866 TEST_CASE("Add pairs and delete all with a matching da");
867
869
870 /* Add another uint32 at the tail */
872 fr_assert(vp != NULL);
873 vp->vp_uint32 = 42;
875
877 TEST_CHECK(count == 4);
878
879 el = fr_edit_list_alloc(NULL, 5, NULL);
880 fr_assert(el != NULL);
881
883 TEST_CHECK(rcode == 0);
884
886
888 TEST_CASE("Expected (count == 2) after deleting all uint32 pairs");
889 TEST_CHECK(count == 2);
890
893
896
898}
899
901{
902 fr_pair_t *vp;
904 size_t count;
906 int rcode;
907
908 TEST_CASE("Add pairs and delete all with a matching da, then abort");
909
911
913 fr_assert(vp != NULL);
914 vp->vp_uint32 = 42;
916
918 TEST_CHECK(count == 4);
919
920 el = fr_edit_list_alloc(NULL, 5, NULL);
921 fr_assert(el != NULL);
922
924 TEST_CHECK(rcode == 0);
925
927 TEST_CHECK(count == 2);
928
930
932 TEST_CASE("Expected (count == 4) after aborting the delete");
933 TEST_CHECK(count == 4);
934
937 TEST_CHECK(vp->vp_uint32 == 0);
938
941 TEST_CHECK(vp->vp_uint32 == 42);
942
944}
945
946static void test_pair_replace_value(void)
947{
948 fr_pair_t *vp;
951 int rcode;
952 fr_value_box_t box;
953
954 TEST_CASE("Add 3 pairs and replace the value of the first one");
955
957
959 fr_assert(vp != NULL);
960
961 el = fr_edit_list_alloc(NULL, 5, NULL);
962 fr_assert(el != NULL);
963
964 TEST_CHECK(vp->vp_uint32 == 0);
965
966 fr_value_box_init(&box, FR_TYPE_UINT32, NULL, false);
967 box.vb_uint32 = 42;
968
969 rcode = fr_edit_list_replace_pair_value(el, vp, &box);
970 TEST_CHECK(rcode == 0);
971 TEST_CHECK(vp->vp_uint32 == 42);
972
974
977 TEST_CHECK(vp->vp_uint32 == 42);
978
980}
981
983{
984 fr_pair_t *vp;
987 int rcode;
988 fr_value_box_t box;
989
990 TEST_CASE("Add 3 pairs and replace the value of the first one, then abort");
991
993
995 fr_assert(vp != NULL);
996
997 el = fr_edit_list_alloc(NULL, 5, NULL);
998 fr_assert(el != NULL);
999
1000 TEST_CHECK(vp->vp_uint32 == 0);
1001
1002 fr_value_box_init(&box, FR_TYPE_UINT32, NULL, false);
1003 box.vb_uint32 = 42;
1004
1005 rcode = fr_edit_list_replace_pair_value(el, vp, &box);
1006 TEST_CHECK(rcode == 0);
1007 TEST_CHECK(vp->vp_uint32 == 42);
1008
1010
1013 TEST_CHECK(vp->vp_uint32 == 0);
1014
1016}
1017
1018static void test_pair_replace_pair(void)
1019{
1020 fr_pair_t *vp, *new_vp;
1022 size_t count;
1024 int rcode;
1025
1026 TEST_CASE("Add 3 pairs and replace the head with a new pair");
1027
1029
1031 fr_assert(vp != NULL);
1032
1033 el = fr_edit_list_alloc(NULL, 5, NULL);
1034 fr_assert(el != NULL);
1035
1037 fr_assert(new_vp != NULL);
1038 new_vp->vp_uint32 = 99;
1039
1040 rcode = fr_edit_list_replace_pair(el, &local_pairs, vp, new_vp);
1041 TEST_CHECK(rcode == 0);
1042
1044
1046 TEST_CASE("Expected (count == 3) after replacing a pair");
1047 TEST_CHECK(count == 3);
1048
1051 TEST_CHECK(vp->vp_uint32 == 99);
1052
1054}
1055
1057{
1058 fr_pair_t *vp, *new_vp;
1061 int rcode;
1062
1063 TEST_CASE("Add 3 pairs and replace the head, then abort");
1064
1066
1068 fr_assert(vp != NULL);
1069
1070 el = fr_edit_list_alloc(NULL, 5, NULL);
1071 fr_assert(el != NULL);
1072
1074 fr_assert(new_vp != NULL);
1075 new_vp->vp_uint32 = 99;
1076
1077 rcode = fr_edit_list_replace_pair(el, &local_pairs, vp, new_vp);
1078 TEST_CHECK(rcode == 0);
1079
1081 TEST_CHECK(vp->vp_uint32 == 99);
1082
1084
1087 TEST_CHECK(vp->vp_uint32 == 0);
1088
1090}
1091
1093{
1094 fr_pair_t *vp;
1096 size_t count;
1098 int rcode;
1099
1100 TEST_CASE("Add 3 pairs and insert a new one at the tail");
1101
1103
1104 el = fr_edit_list_alloc(NULL, 5, NULL);
1105 fr_assert(el != NULL);
1106
1108 fr_assert(vp != NULL);
1110 TEST_CHECK(rcode == 0);
1111
1113
1115 TEST_CASE("Expected (count == 4) after inserting at the tail");
1116 TEST_CHECK(count == 4);
1117
1120
1122}
1123
1125{
1126 fr_pair_t *vp;
1128 size_t count;
1130 int rcode;
1131
1132 TEST_CASE("Add 3 pairs and insert a new one at the tail, then abort");
1133
1135
1136 el = fr_edit_list_alloc(NULL, 5, NULL);
1137 fr_assert(el != NULL);
1138
1140 fr_assert(vp != NULL);
1142 TEST_CHECK(rcode == 0);
1143
1145 TEST_CHECK(count == 4);
1146
1148
1150}
1151
1153{
1154 fr_pair_t *vp, *child;
1156 size_t count;
1158 int rcode;
1159
1160 TEST_CASE("Add children to a TLV pair and free them");
1161
1163
1166
1168 fr_assert(child != NULL);
1169 fr_pair_append(&vp->vp_group, child);
1170 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1171
1172 el = fr_edit_list_alloc(NULL, 5, NULL);
1173 fr_assert(el != NULL);
1174
1176 TEST_CHECK(rcode == 0);
1177 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1178
1180
1181 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1182
1184 TEST_CHECK(count == 3);
1185
1187}
1188
1190{
1191 fr_pair_t *vp, *child;
1194 int rcode;
1195
1196 TEST_CASE("Add children to a TLV pair, free them, then abort");
1197
1199
1202
1204 fr_assert(child != NULL);
1205 fr_pair_append(&vp->vp_group, child);
1206 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1207
1208 el = fr_edit_list_alloc(NULL, 5, NULL);
1209 fr_assert(el != NULL);
1210
1212 TEST_CHECK(rcode == 0);
1213 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1214
1216
1217 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1218
1219 child = fr_pair_list_head(&vp->vp_group);
1221
1223}
1224
1226{
1227 fr_pair_t *vp;
1228 fr_pair_list_t local_pairs, to_insert;
1229 size_t count;
1231 int rcode;
1232
1233 TEST_CASE("Add 3 pairs and insert a list of 2 at the tail");
1234
1236
1237 fr_pair_list_init(&to_insert);
1238
1240 fr_assert(vp != NULL);
1241 fr_pair_append(&to_insert, vp);
1242
1244 fr_assert(vp != NULL);
1245 fr_pair_append(&to_insert, vp);
1246
1247 el = fr_edit_list_alloc(NULL, 5, NULL);
1248 fr_assert(el != NULL);
1249
1250 rcode = fr_edit_list_insert_list_tail(el, &local_pairs, &to_insert);
1251 TEST_CHECK(rcode == 0);
1252
1254
1256 TEST_CASE("Expected (count == 5) after inserting a list of 2");
1257 TEST_CHECK(count == 5);
1258
1261
1263}
1264
1266{
1267 fr_pair_t *vp;
1268 fr_pair_list_t local_pairs, to_insert;
1269 size_t count;
1271 int rcode;
1272
1273 TEST_CASE("Add 3 pairs and insert a list of 2 at the tail, then abort");
1274
1276
1277 fr_pair_list_init(&to_insert);
1278
1280 fr_assert(vp != NULL);
1281 fr_pair_append(&to_insert, vp);
1282
1284 fr_assert(vp != NULL);
1285 fr_pair_append(&to_insert, vp);
1286
1287 el = fr_edit_list_alloc(NULL, 5, NULL);
1288 fr_assert(el != NULL);
1289
1290 rcode = fr_edit_list_insert_list_tail(el, &local_pairs, &to_insert);
1291 TEST_CHECK(rcode == 0);
1292
1294 TEST_CHECK(count == 5);
1295
1297
1299}
1300
1302{
1303 fr_pair_t *vp;
1305 fr_edit_list_t *el, *child;
1306 int rcode;
1307
1308 TEST_CASE("Child commits value change, parent aborts - everything reverted");
1309
1311
1313 fr_assert(vp != NULL);
1314
1315 el = fr_edit_list_alloc(NULL, 5, NULL);
1316 fr_assert(el != NULL);
1317
1319 TEST_CHECK(rcode == 0);
1320
1321 TEST_CHECK(vp->vp_uint32 == 0);
1322
1323 vp->vp_uint32 = 1;
1324 TEST_CHECK(vp->vp_uint32 == 1);
1325
1326 child = fr_edit_list_alloc(NULL, 5, el);
1327 fr_assert(child != NULL);
1328
1329 rcode = fr_edit_list_save_pair_value(child, vp);
1330 TEST_CHECK(rcode == 0);
1331
1332 vp->vp_uint32 = 2;
1333 TEST_CHECK(vp->vp_uint32 == 2);
1334
1335 fr_edit_list_commit(child); /* does nothing, value stays at 2 */
1336 TEST_CHECK(vp->vp_uint32 == 2);
1337
1338 /* Abort parent - everything should revert */
1340
1343 TEST_CHECK(vp->vp_uint32 == 0);
1344
1346}
1347
1349 /*
1350 * Deletion.
1351 */
1352 { "pair_delete_head", test_pair_delete_head },
1353 { "pair_delete_head_abort", test_pair_delete_head_abort },
1354
1355 { "pair_delete_middle", test_pair_delete_middle },
1356 { "pair_delete_middle_abort", test_pair_delete_middle_abort },
1357
1358 { "pair_delete_multiple", test_pair_delete_multiple },
1359 { "pair_delete_multiple_abort", test_pair_delete_multiple_abort },
1360
1361 /*
1362 * Insert after
1363 */
1364 { "pair_insert_after_head", test_pair_insert_after_head },
1365 { "pair_insert_after_head_abort", test_pair_insert_after_head_abort },
1366
1367 { "pair_insert_after_middle", test_pair_insert_after_middle },
1368 { "pair_insert_after_middle_abort", test_pair_insert_after_middle_abort },
1369
1370 /*
1371 * Value modification
1372 */
1373 { "pair_edit_value", test_pair_edit_value },
1374 { "pair_edit_value_abort", test_pair_edit_value_abort },
1375
1376 /*
1377 * Value modification, then deletion
1378 */
1379 { "pair_edit_value_delete", test_pair_edit_value_delete },
1380 { "pair_edit_value_delete_abort", test_pair_edit_value_delete_abort },
1381
1382 /*
1383 * Insert after, then delete
1384 */
1385 { "pair_insert_after_head_delete", test_pair_insert_after_head_delete },
1386 { "pair_insert_after_head_delete_abort", test_pair_insert_after_head_delete_abort },
1387
1388 /*
1389 * Value modification in child list
1390 */
1391 { "pair_edit_child_value", test_pair_edit_child_value },
1392 { "pair_edit_child_value_abort", test_pair_edit_child_value_abort },
1393
1394 /*
1395 * Deletion of tail
1396 */
1397 { "pair_delete_tail", test_pair_delete_tail },
1398 { "pair_delete_tail_abort", test_pair_delete_tail_abort },
1399
1400 /*
1401 * Deletion by da
1402 */
1403 { "pair_delete_by_da", test_pair_delete_by_da },
1404 { "pair_delete_by_da_abort", test_pair_delete_by_da_abort },
1405
1406 /*
1407 * Value replacement (fr_edit_list_replace_pair_value)
1408 */
1409 { "pair_replace_value", test_pair_replace_value },
1410 { "pair_replace_value_abort", test_pair_replace_value_abort },
1411
1412 /*
1413 * Pair replacement (fr_edit_list_replace_pair)
1414 */
1415 { "pair_replace_pair", test_pair_replace_pair },
1416 { "pair_replace_pair_abort", test_pair_replace_pair_abort },
1417
1418 /*
1419 * Insert at tail
1420 */
1421 { "pair_insert_after_tail", test_pair_insert_after_tail },
1422 { "pair_insert_after_tail_abort", test_pair_insert_after_tail_abort },
1423
1424 /*
1425 * Free children of structural pair
1426 */
1427 { "pair_free_children", test_pair_free_children },
1428 { "pair_free_children_abort", test_pair_free_children_abort },
1429
1430 /*
1431 * Insert list at tail
1432 */
1433 { "pair_insert_list_tail", test_pair_insert_list_tail },
1434 { "pair_insert_list_tail_abort", test_pair_insert_list_tail_abort },
1435
1436 /*
1437 * Child commit + parent abort
1438 */
1439 { "pair_edit_child_commit_parent_abort", test_pair_edit_child_commit_parent_abort },
1440
1442};
#define TEST_CHECK(cond)
Definition acutest.h:101
#define TEST_CASE(name)
Definition acutest.h:203
#define TEST_TERMINATOR
Definition acutest.h:77
Common initialisation for acutest binaries.
#define fr_exit_now(_x)
Exit without calling atexit() handlers, producing a log message in debug builds.
Definition debug.h:272
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:252
static void test_pair_insert_list_tail(void)
static void test_pair_delete_head(void)
Definition edit_tests.c:108
TEST_LIST
static void test_pair_delete_head_abort(void)
Definition edit_tests.c:141
static void test_pair_delete_tail(void)
Definition edit_tests.c:794
static TALLOC_CTX * autofree
Definition edit_tests.c:35
static void test_pair_replace_value_abort(void)
Definition edit_tests.c:982
static void test_pair_delete_multiple_abort(void)
Definition edit_tests.c:295
static void test_pair_edit_value_delete_abort(void)
Definition edit_tests.c:587
static void test_pair_insert_after_head_delete_abort(void)
Definition edit_tests.c:663
static void test_pair_delete_middle_abort(void)
Definition edit_tests.c:211
static void expect3(fr_pair_list_t *local_pairs)
Definition edit_tests.c:87
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:858
static void test_pair_edit_value(void)
Definition edit_tests.c:344
static void test_pair_free_children(void)
static void test_pair_insert_after_tail_abort(void)
static fr_pair_list_t test_pairs
Definition edit_tests.c:36
static void test_pair_delete_by_da_abort(void)
Definition edit_tests.c:900
static void test_pair_replace_value(void)
Definition edit_tests.c:946
static void test_pair_insert_after_middle(void)
Definition edit_tests.c:480
static void test_pair_edit_child_value(void)
Definition edit_tests.c:696
static void add_pairs(fr_pair_list_t *local_pairs)
Definition edit_tests.c:63
static fr_dict_t * test_dict
Definition edit_tests.c:37
static void test_pair_insert_after_head_abort(void)
Definition edit_tests.c:448
static void test_pair_insert_after_tail(void)
static void test_pair_insert_after_head(void)
Definition edit_tests.c:415
static void test_pair_insert_after_head_delete(void)
Definition edit_tests.c:627
static void test_pair_edit_child_value_abort(void)
Definition edit_tests.c:745
static void test_pair_delete_middle(void)
Definition edit_tests.c:173
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:549
static void test_pair_delete_tail_abort(void)
Definition edit_tests.c:828
static void test_init(void)
Global initialisation.
Definition edit_tests.c:41
static void test_pair_replace_pair_abort(void)
static void test_pair_edit_value_abort(void)
Definition edit_tests.c:378
static void test_pair_insert_after_middle_abort(void)
Definition edit_tests.c:513
@ 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:1297
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:284
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:47
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:37
#define local_pairs
Convenience macro for accessing the state list.
Definition request.h:161
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:55
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:608
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:659
void fr_edit_list_commit(fr_edit_list_t *el)
Commit an edit list.
Definition edit.c:853
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:595
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:646
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:677
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:723
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:622
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:802
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:737
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:634