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 size_t 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;
555 size_t count;
556
557 TEST_CASE("Add 3 pairs, change the value of the first one, and delete it");
558
560
562 fr_assert(vp != NULL);
563
564 el = fr_edit_list_alloc(NULL, 5, NULL);
565 fr_assert(el != NULL);
566
568 TEST_CHECK(rcode == 0);
569
570 TEST_CHECK(vp->vp_uint32 == 0);
571
572 vp->vp_uint32 = 1;
573 TEST_CHECK(vp->vp_uint32 == 1);
574
576 TEST_CHECK(rcode == 0);
577
579
582
584 TEST_CASE("Expected (count == 2) after deleting the edited pair");
585 TEST_CHECK(count == 2);
586}
587
589{
590 fr_pair_t *vp;
593 int rcode;
594
595 TEST_CASE("Add 3 pairs, change the value of the first one, and delete it, then abort");
596
598
600 fr_assert(vp != NULL);
601
602 el = fr_edit_list_alloc(NULL, 5, NULL);
603 fr_assert(el != NULL);
604
606 TEST_CHECK(rcode == 0);
607
608 TEST_CHECK(vp->vp_uint32 == 0);
609
610 vp->vp_uint32 = 1;
611 TEST_CHECK(vp->vp_uint32 == 1);
612
614 TEST_CHECK(rcode == 0);
615
616 /*
617 * Abort the edit
618 */
620
623 TEST_CHECK(vp->vp_uint32 == 0);
624
626}
627
629{
630 fr_pair_t *vp;
632 size_t count;
634 int rcode;
635
636 TEST_CASE("Add 3 pairs and insert a new one at the head, and delete it");
637
639
640 el = fr_edit_list_alloc(NULL, 5, NULL);
641 fr_assert(el != NULL);
642
644 fr_assert(vp != NULL);
646 TEST_CHECK(rcode == 0);
647
649 TEST_CASE("Expected (count == 4) after inserting a new one");
650 TEST_CHECK(count == 4);
651
653 TEST_CHECK(rcode == 0);
654
656 TEST_CASE("Expected (count == 3) after deleting the just inserted on");
657 TEST_CHECK(count == 3);
658
660
662}
663
665{
666 fr_pair_t *vp;
668 size_t count;
670 int rcode;
671
672 TEST_CASE("Add 3 pairs and insert a new one at the head and delete it, then abort");
673
675
676 el = fr_edit_list_alloc(NULL, 5, NULL);
677 fr_assert(el != NULL);
678
680 fr_assert(vp != NULL);
682 TEST_CHECK(rcode == 0);
683
685 TEST_CASE("Expected (count == 4) after inserting a new one");
686 TEST_CHECK(count == 4);
687
688 /*
689 * Abort the edit
690 */
692
694}
695
696
698{
699 fr_pair_t *vp;
701 fr_edit_list_t *el, *child;
702 int rcode;
703
704 TEST_CASE("Add 3 pairs and change the value of the first one in a child transaction");
705
707
709 fr_assert(vp != NULL);
710
711 el = fr_edit_list_alloc(NULL, 5, NULL);
712 fr_assert(el != NULL);
713
715 TEST_CHECK(rcode == 0);
716
717 TEST_CHECK(vp->vp_uint32 == 0);
718
719 vp->vp_uint32 = 1;
720 TEST_CHECK(vp->vp_uint32 == 1);
721
722 child = fr_edit_list_alloc(NULL, 5, el);
723 fr_assert(child != NULL);
724
725 rcode = fr_edit_list_save_pair_value(child, vp); /* CHILD */
726 TEST_CHECK(rcode == 0);
727
728 TEST_CHECK(vp->vp_uint32 == 1);
729
730 vp->vp_uint32 = 2;
731 TEST_CHECK(vp->vp_uint32 == 2);
732
733 fr_edit_list_commit(child); /* should do nothing */
734
735 TEST_CHECK(vp->vp_uint32 == 2);
736
738
741 TEST_CHECK(vp->vp_uint32 == 2);
742
744}
745
747{
748 fr_pair_t *vp;
750 fr_edit_list_t *el, *child;
751 int rcode;
752
753 TEST_CASE("Add 3 pairs and change the value of the first one, then abort");
754
756
758 fr_assert(vp != NULL);
759
760 el = fr_edit_list_alloc(NULL, 5, NULL);
761 fr_assert(el != NULL);
762
764 TEST_CHECK(rcode == 0);
765
766 TEST_CHECK(vp->vp_uint32 == 0);
767
768 vp->vp_uint32 = 1;
769 TEST_CHECK(vp->vp_uint32 == 1);
770
771 child = fr_edit_list_alloc(NULL, 5, el);
772 fr_assert(child != NULL);
773
774 rcode = fr_edit_list_save_pair_value(child, vp); /* CHILD */
775 TEST_CHECK(rcode == 0);
776
777 TEST_CHECK(vp->vp_uint32 == 1);
778
779 vp->vp_uint32 = 2;
780 TEST_CHECK(vp->vp_uint32 == 2);
781
782 fr_edit_list_abort(child); /* CHILD */
783
784 TEST_CHECK(vp->vp_uint32 == 1);
785
787
790 TEST_CHECK(vp->vp_uint32 == 1);
791
793}
794
795static void test_pair_delete_tail(void)
796{
797 fr_pair_t *vp;
799 size_t count;
801 int rcode;
802
803 TEST_CASE("Add 3 pairs and delete the tail");
804
806
808 fr_assert(vp != NULL);
810
811 el = fr_edit_list_alloc(NULL, 5, NULL);
812 fr_assert(el != NULL);
813
815 TEST_CHECK(rcode == 0);
816
818
820 TEST_CASE("Expected (count == 2) after deleting the tail");
821 TEST_CHECK(count == 2);
822
825
827}
828
830{
831 fr_pair_t *vp;
833 size_t count;
835 int rcode;
836
837 TEST_CASE("Add 3 pairs and delete the tail, then abort");
838
840
842 fr_assert(vp != NULL);
844
845 el = fr_edit_list_alloc(NULL, 5, NULL);
846 fr_assert(el != NULL);
847
849 TEST_CHECK(rcode == 0);
850
852 TEST_CHECK(count == 2);
853
855
857}
858
859static void test_pair_delete_by_da(void)
860{
861 fr_pair_t *vp;
863 size_t count;
865 int rcode;
866
867 TEST_CASE("Add pairs and delete all with a matching da");
868
870
871 /* Add another uint32 at the tail */
873 fr_assert(vp != NULL);
874 vp->vp_uint32 = 42;
876
878 TEST_CHECK(count == 4);
879
880 el = fr_edit_list_alloc(NULL, 5, NULL);
881 fr_assert(el != NULL);
882
884 TEST_CHECK(rcode == 0);
885
887
889 TEST_CASE("Expected (count == 2) after deleting all uint32 pairs");
890 TEST_CHECK(count == 2);
891
894
897
899}
900
902{
903 fr_pair_t *vp;
905 size_t count;
907 int rcode;
908
909 TEST_CASE("Add pairs and delete all with a matching da, then abort");
910
912
914 fr_assert(vp != NULL);
915 vp->vp_uint32 = 42;
917
919 TEST_CHECK(count == 4);
920
921 el = fr_edit_list_alloc(NULL, 5, NULL);
922 fr_assert(el != NULL);
923
925 TEST_CHECK(rcode == 0);
926
928 TEST_CHECK(count == 2);
929
931
933 TEST_CASE("Expected (count == 4) after aborting the delete");
934 TEST_CHECK(count == 4);
935
938 TEST_CHECK(vp->vp_uint32 == 0);
939
942 TEST_CHECK(vp->vp_uint32 == 42);
943
945}
946
947static void test_pair_replace_value(void)
948{
949 fr_pair_t *vp;
952 int rcode;
953 fr_value_box_t box;
954
955 TEST_CASE("Add 3 pairs and replace the value of the first one");
956
958
960 fr_assert(vp != NULL);
961
962 el = fr_edit_list_alloc(NULL, 5, NULL);
963 fr_assert(el != NULL);
964
965 TEST_CHECK(vp->vp_uint32 == 0);
966
967 fr_value_box_init(&box, FR_TYPE_UINT32, NULL, false);
968 box.vb_uint32 = 42;
969
970 rcode = fr_edit_list_replace_pair_value(el, vp, &box);
971 TEST_CHECK(rcode == 0);
972 TEST_CHECK(vp->vp_uint32 == 42);
973
975
978 TEST_CHECK(vp->vp_uint32 == 42);
979
981}
982
984{
985 fr_pair_t *vp;
988 int rcode;
989 fr_value_box_t box;
990
991 TEST_CASE("Add 3 pairs and replace the value of the first one, then abort");
992
994
996 fr_assert(vp != NULL);
997
998 el = fr_edit_list_alloc(NULL, 5, NULL);
999 fr_assert(el != NULL);
1000
1001 TEST_CHECK(vp->vp_uint32 == 0);
1002
1003 fr_value_box_init(&box, FR_TYPE_UINT32, NULL, false);
1004 box.vb_uint32 = 42;
1005
1006 rcode = fr_edit_list_replace_pair_value(el, vp, &box);
1007 TEST_CHECK(rcode == 0);
1008 TEST_CHECK(vp->vp_uint32 == 42);
1009
1011
1014 TEST_CHECK(vp->vp_uint32 == 0);
1015
1017}
1018
1019static void test_pair_replace_pair(void)
1020{
1021 fr_pair_t *vp, *new_vp;
1023 size_t count;
1025 int rcode;
1026
1027 TEST_CASE("Add 3 pairs and replace the head with a new pair");
1028
1030
1032 fr_assert(vp != NULL);
1033
1034 el = fr_edit_list_alloc(NULL, 5, NULL);
1035 fr_assert(el != NULL);
1036
1038 fr_assert(new_vp != NULL);
1039 new_vp->vp_uint32 = 99;
1040
1041 rcode = fr_edit_list_replace_pair(el, &local_pairs, vp, new_vp);
1042 TEST_CHECK(rcode == 0);
1043
1045
1047 TEST_CASE("Expected (count == 3) after replacing a pair");
1048 TEST_CHECK(count == 3);
1049
1052 TEST_CHECK(vp->vp_uint32 == 99);
1053
1055}
1056
1058{
1059 fr_pair_t *vp, *new_vp;
1062 int rcode;
1063
1064 TEST_CASE("Add 3 pairs and replace the head, then abort");
1065
1067
1069 fr_assert(vp != NULL);
1070
1071 el = fr_edit_list_alloc(NULL, 5, NULL);
1072 fr_assert(el != NULL);
1073
1075 fr_assert(new_vp != NULL);
1076 new_vp->vp_uint32 = 99;
1077
1078 rcode = fr_edit_list_replace_pair(el, &local_pairs, vp, new_vp);
1079 TEST_CHECK(rcode == 0);
1080
1082 TEST_CHECK(vp->vp_uint32 == 99);
1083
1085
1088 TEST_CHECK(vp->vp_uint32 == 0);
1089
1091}
1092
1094{
1095 fr_pair_t *vp;
1097 size_t count;
1099 int rcode;
1100
1101 TEST_CASE("Add 3 pairs and insert a new one at the tail");
1102
1104
1105 el = fr_edit_list_alloc(NULL, 5, NULL);
1106 fr_assert(el != NULL);
1107
1109 fr_assert(vp != NULL);
1111 TEST_CHECK(rcode == 0);
1112
1114
1116 TEST_CASE("Expected (count == 4) after inserting at the tail");
1117 TEST_CHECK(count == 4);
1118
1121
1123}
1124
1126{
1127 fr_pair_t *vp;
1129 size_t count;
1131 int rcode;
1132
1133 TEST_CASE("Add 3 pairs and insert a new one at the tail, then abort");
1134
1136
1137 el = fr_edit_list_alloc(NULL, 5, NULL);
1138 fr_assert(el != NULL);
1139
1141 fr_assert(vp != NULL);
1143 TEST_CHECK(rcode == 0);
1144
1146 TEST_CHECK(count == 4);
1147
1149
1151}
1152
1154{
1155 fr_pair_t *vp, *child;
1157 size_t count;
1159 int rcode;
1160
1161 TEST_CASE("Add children to a TLV pair and free them");
1162
1164
1167
1169 fr_assert(child != NULL);
1170 fr_pair_append(&vp->vp_group, child);
1171 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1172
1173 el = fr_edit_list_alloc(NULL, 5, NULL);
1174 fr_assert(el != NULL);
1175
1177 TEST_CHECK(rcode == 0);
1178 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1179
1181
1182 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1183
1185 TEST_CHECK(count == 3);
1186
1188}
1189
1191{
1192 fr_pair_t *vp, *child;
1195 int rcode;
1196
1197 TEST_CASE("Add children to a TLV pair, free them, then abort");
1198
1200
1203
1205 fr_assert(child != NULL);
1206 fr_pair_append(&vp->vp_group, child);
1207 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1208
1209 el = fr_edit_list_alloc(NULL, 5, NULL);
1210 fr_assert(el != NULL);
1211
1213 TEST_CHECK(rcode == 0);
1214 TEST_CHECK(fr_pair_list_empty(&vp->vp_group));
1215
1217
1218 TEST_CHECK(fr_pair_list_num_elements(&vp->vp_group) == 1);
1219
1220 child = fr_pair_list_head(&vp->vp_group);
1222
1224}
1225
1227{
1228 fr_pair_t *vp;
1229 fr_pair_list_t local_pairs, to_insert;
1230 size_t count;
1232 int rcode;
1233
1234 TEST_CASE("Add 3 pairs and insert a list of 2 at the tail");
1235
1237
1238 fr_pair_list_init(&to_insert);
1239
1241 fr_assert(vp != NULL);
1242 fr_pair_append(&to_insert, vp);
1243
1245 fr_assert(vp != NULL);
1246 fr_pair_append(&to_insert, vp);
1247
1248 el = fr_edit_list_alloc(NULL, 5, NULL);
1249 fr_assert(el != NULL);
1250
1251 rcode = fr_edit_list_insert_list_tail(el, &local_pairs, &to_insert);
1252 TEST_CHECK(rcode == 0);
1253
1255
1257 TEST_CASE("Expected (count == 5) after inserting a list of 2");
1258 TEST_CHECK(count == 5);
1259
1262
1264}
1265
1267{
1268 fr_pair_t *vp;
1269 fr_pair_list_t local_pairs, to_insert;
1270 size_t count;
1272 int rcode;
1273
1274 TEST_CASE("Add 3 pairs and insert a list of 2 at the tail, then abort");
1275
1277
1278 fr_pair_list_init(&to_insert);
1279
1281 fr_assert(vp != NULL);
1282 fr_pair_append(&to_insert, vp);
1283
1285 fr_assert(vp != NULL);
1286 fr_pair_append(&to_insert, vp);
1287
1288 el = fr_edit_list_alloc(NULL, 5, NULL);
1289 fr_assert(el != NULL);
1290
1291 rcode = fr_edit_list_insert_list_tail(el, &local_pairs, &to_insert);
1292 TEST_CHECK(rcode == 0);
1293
1295 TEST_CHECK(count == 5);
1296
1298
1300}
1301
1303{
1304 fr_pair_t *vp;
1306 fr_edit_list_t *el, *child;
1307 int rcode;
1308
1309 TEST_CASE("Child commits value change, parent aborts - everything reverted");
1310
1312
1314 fr_assert(vp != NULL);
1315
1316 el = fr_edit_list_alloc(NULL, 5, NULL);
1317 fr_assert(el != NULL);
1318
1320 TEST_CHECK(rcode == 0);
1321
1322 TEST_CHECK(vp->vp_uint32 == 0);
1323
1324 vp->vp_uint32 = 1;
1325 TEST_CHECK(vp->vp_uint32 == 1);
1326
1327 child = fr_edit_list_alloc(NULL, 5, el);
1328 fr_assert(child != NULL);
1329
1330 rcode = fr_edit_list_save_pair_value(child, vp);
1331 TEST_CHECK(rcode == 0);
1332
1333 vp->vp_uint32 = 2;
1334 TEST_CHECK(vp->vp_uint32 == 2);
1335
1336 fr_edit_list_commit(child); /* does nothing, value stays at 2 */
1337 TEST_CHECK(vp->vp_uint32 == 2);
1338
1339 /* Abort parent - everything should revert */
1341
1344 TEST_CHECK(vp->vp_uint32 == 0);
1345
1347}
1348
1350 /*
1351 * Deletion.
1352 */
1353 { "pair_delete_head", test_pair_delete_head },
1354 { "pair_delete_head_abort", test_pair_delete_head_abort },
1355
1356 { "pair_delete_middle", test_pair_delete_middle },
1357 { "pair_delete_middle_abort", test_pair_delete_middle_abort },
1358
1359 { "pair_delete_multiple", test_pair_delete_multiple },
1360 { "pair_delete_multiple_abort", test_pair_delete_multiple_abort },
1361
1362 /*
1363 * Insert after
1364 */
1365 { "pair_insert_after_head", test_pair_insert_after_head },
1366 { "pair_insert_after_head_abort", test_pair_insert_after_head_abort },
1367
1368 { "pair_insert_after_middle", test_pair_insert_after_middle },
1369 { "pair_insert_after_middle_abort", test_pair_insert_after_middle_abort },
1370
1371 /*
1372 * Value modification
1373 */
1374 { "pair_edit_value", test_pair_edit_value },
1375 { "pair_edit_value_abort", test_pair_edit_value_abort },
1376
1377 /*
1378 * Value modification, then deletion
1379 */
1380 { "pair_edit_value_delete", test_pair_edit_value_delete },
1381 { "pair_edit_value_delete_abort", test_pair_edit_value_delete_abort },
1382
1383 /*
1384 * Insert after, then delete
1385 */
1386 { "pair_insert_after_head_delete", test_pair_insert_after_head_delete },
1387 { "pair_insert_after_head_delete_abort", test_pair_insert_after_head_delete_abort },
1388
1389 /*
1390 * Value modification in child list
1391 */
1392 { "pair_edit_child_value", test_pair_edit_child_value },
1393 { "pair_edit_child_value_abort", test_pair_edit_child_value_abort },
1394
1395 /*
1396 * Deletion of tail
1397 */
1398 { "pair_delete_tail", test_pair_delete_tail },
1399 { "pair_delete_tail_abort", test_pair_delete_tail_abort },
1400
1401 /*
1402 * Deletion by da
1403 */
1404 { "pair_delete_by_da", test_pair_delete_by_da },
1405 { "pair_delete_by_da_abort", test_pair_delete_by_da_abort },
1406
1407 /*
1408 * Value replacement (fr_edit_list_replace_pair_value)
1409 */
1410 { "pair_replace_value", test_pair_replace_value },
1411 { "pair_replace_value_abort", test_pair_replace_value_abort },
1412
1413 /*
1414 * Pair replacement (fr_edit_list_replace_pair)
1415 */
1416 { "pair_replace_pair", test_pair_replace_pair },
1417 { "pair_replace_pair_abort", test_pair_replace_pair_abort },
1418
1419 /*
1420 * Insert at tail
1421 */
1422 { "pair_insert_after_tail", test_pair_insert_after_tail },
1423 { "pair_insert_after_tail_abort", test_pair_insert_after_tail_abort },
1424
1425 /*
1426 * Free children of structural pair
1427 */
1428 { "pair_free_children", test_pair_free_children },
1429 { "pair_free_children_abort", test_pair_free_children_abort },
1430
1431 /*
1432 * Insert list at tail
1433 */
1434 { "pair_insert_list_tail", test_pair_insert_list_tail },
1435 { "pair_insert_list_tail_abort", test_pair_insert_list_tail_abort },
1436
1437 /*
1438 * Child commit + parent abort
1439 */
1440 { "pair_edit_child_commit_parent_abort", test_pair_edit_child_commit_parent_abort },
1441
1443};
#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:795
static TALLOC_CTX * autofree
Definition edit_tests.c:35
static void test_pair_replace_value_abort(void)
Definition edit_tests.c:983
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:588
static void test_pair_insert_after_head_delete_abort(void)
Definition edit_tests.c:664
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:859
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:901
static void test_pair_replace_value(void)
Definition edit_tests.c:947
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:697
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:628
static void test_pair_edit_child_value_abort(void)
Definition edit_tests.c:746
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:829
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:1306
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