2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2015 EfficiOS Inc. and Linux Foundation
5 * Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com>
7 * Babeltrace value objects tests
10 #include <babeltrace2/babeltrace.h>
11 #include "common/assert.h"
20 ok(bt_value_null
, "bt_value_null is not NULL");
21 ok(bt_value_is_null(bt_value_null
),
22 "bt_value_null is a null value object");
23 bt_value_get_ref(bt_value_null
);
24 pass("getting bt_value_null does not cause a crash");
25 bt_value_put_ref(bt_value_null
);
26 pass("putting bt_value_null does not cause a crash");
35 obj
= bt_value_bool_create();
36 ok(obj
&& bt_value_is_bool(obj
),
37 "bt_value_bool_create() returns a boolean value object");
40 value
= bt_value_bool_get(obj
);
41 ok(!value
, "default boolean value object value is BT_FALSE");
43 bt_value_bool_set(obj
, BT_FALSE
);
44 bt_value_bool_set(obj
, BT_TRUE
);
45 value
= bt_value_bool_get(obj
);
46 ok(value
, "bt_value_bool_set() works");
48 BT_VALUE_PUT_REF_AND_RESET(obj
);
49 pass("putting an existing boolean value object does not cause a crash")
52 obj
= bt_value_bool_create_init(BT_TRUE
);
53 ok(obj
&& bt_value_is_bool(obj
),
54 "bt_value_bool_create_init() returns a boolean value object");
55 value
= bt_value_bool_get(obj
);
57 "bt_value_bool_create_init() sets the appropriate initial value");
59 BT_VALUE_PUT_REF_AND_RESET(obj
);
63 void test_unsigned_integer(void)
68 obj
= bt_value_integer_unsigned_create();
69 ok(obj
&& bt_value_is_unsigned_integer(obj
),
70 "bt_value_integer_unsigned_create() returns an unsigned integer value object");
73 value
= bt_value_integer_unsigned_get(obj
);
74 ok(value
== 0, "default unsigned integer value object value is 0");
76 bt_value_integer_unsigned_set(obj
, 98765);
77 value
= bt_value_integer_unsigned_get(obj
);
78 ok(value
== 98765, "bt_value_integer_unsigned_bool_set() works");
80 BT_VALUE_PUT_REF_AND_RESET(obj
);
81 pass("putting an existing unsigned integer value object does not cause a crash")
83 obj
= bt_value_integer_unsigned_create_init(321456987);
84 ok(obj
&& bt_value_is_unsigned_integer(obj
),
85 "bt_value_integer_unsigned_create_init() returns an unsigned integer value object");
86 value
= bt_value_integer_unsigned_get(obj
);
87 ok(value
== 321456987,
88 "bt_value_integer_unsigned_create_init() sets the appropriate initial value");
90 BT_VALUE_PUT_REF_AND_RESET(obj
);
94 void test_signed_integer(void)
99 obj
= bt_value_integer_signed_create();
100 ok(obj
&& bt_value_is_signed_integer(obj
),
101 "bt_value_integer_signed_create() returns a signed integer value object");
104 value
= bt_value_integer_signed_get(obj
);
105 ok(value
== 0, "default signed integer value object value is 0");
107 bt_value_integer_signed_set(obj
, 98765);
108 value
= bt_value_integer_signed_get(obj
);
109 ok(value
== 98765, "bt_value_integer_signed_bool_set() works");
111 BT_VALUE_PUT_REF_AND_RESET(obj
);
112 pass("putting an existing signed integer value object does not cause a crash")
114 obj
= bt_value_integer_signed_create_init(-321456987);
115 ok(obj
&& bt_value_is_signed_integer(obj
),
116 "bt_value_integer_signed_create_init() returns a signed integer value object");
117 value
= bt_value_integer_signed_get(obj
);
118 ok(value
== -321456987,
119 "bt_value_integer_signed_create_init() sets the appropriate initial value");
121 BT_VALUE_PUT_REF_AND_RESET(obj
);
130 obj
= bt_value_real_create();
131 ok(obj
&& bt_value_is_real(obj
),
132 "bt_value_real_create() returns a real number value object");
135 value
= bt_value_real_get(obj
);
137 "default real number value object value is 0");
139 bt_value_real_set(obj
, -3.1416);
140 value
= bt_value_real_get(obj
);
141 ok(value
== -3.1416, "bt_value_real_set() works");
143 BT_VALUE_PUT_REF_AND_RESET(obj
);
144 pass("putting an existing real number value object does not cause a crash")
146 obj
= bt_value_real_create_init(33.1649758);
147 ok(obj
&& bt_value_is_real(obj
),
148 "bt_value_real_create_init() returns a real number value object");
149 value
= bt_value_real_get(obj
);
150 ok(value
== 33.1649758,
151 "bt_value_real_create_init() sets the appropriate initial value");
153 BT_VALUE_PUT_REF_AND_RESET(obj
);
157 void test_string(void)
162 obj
= bt_value_string_create();
163 ok(obj
&& bt_value_is_string(obj
),
164 "bt_value_string_create() returns a string value object");
166 value
= bt_value_string_get(obj
);
167 ok(value
&& strcmp(value
, "") == 0,
168 "default string value object value is \"\"");
170 bt_value_string_set(obj
, "hello worldz");
171 value
= bt_value_string_get(obj
);
172 ok(value
&& strcmp(value
, "hello worldz") == 0,
173 "bt_value_string_get() works");
175 BT_VALUE_PUT_REF_AND_RESET(obj
);
176 pass("putting an existing string value object does not cause a crash")
178 obj
= bt_value_string_create_init("initial value");
179 ok(obj
&& bt_value_is_string(obj
),
180 "bt_value_string_create_init() returns a string value object");
181 value
= bt_value_string_get(obj
);
182 ok(value
&& strcmp(value
, "initial value") == 0,
183 "bt_value_string_create_init() sets the appropriate initial value");
185 BT_VALUE_PUT_REF_AND_RESET(obj
);
189 void test_array(void)
196 const char *string_value
;
198 bt_value
*appended_obj
;
200 array_obj
= bt_value_array_create();
201 ok(array_obj
&& bt_value_is_array(array_obj
),
202 "bt_value_array_create() returns an array value object");
203 ok(bt_value_array_is_empty(array_obj
),
204 "initial array value object size is 0");
206 obj
= bt_value_integer_unsigned_create_init(345);
207 ret
= bt_value_array_append_element(array_obj
, obj
);
208 BT_VALUE_PUT_REF_AND_RESET(obj
);
209 obj
= bt_value_integer_signed_create_init(-507);
210 ret
|= bt_value_array_append_element(array_obj
, obj
);
211 BT_VALUE_PUT_REF_AND_RESET(obj
);
212 obj
= bt_value_real_create_init(-17.45);
213 ret
|= bt_value_array_append_element(array_obj
, obj
);
214 BT_VALUE_PUT_REF_AND_RESET(obj
);
215 obj
= bt_value_bool_create_init(BT_TRUE
);
216 ret
|= bt_value_array_append_element(array_obj
, obj
);
217 BT_VALUE_PUT_REF_AND_RESET(obj
);
218 ret
|= bt_value_array_append_element(array_obj
,
220 ok(!ret
, "bt_value_array_append_element() succeeds");
221 ok(bt_value_array_get_length(array_obj
) == 5,
222 "appending an element to an array value object increment its size");
224 obj
= bt_value_array_borrow_element_by_index(array_obj
, 0);
225 ok(bt_value_is_unsigned_integer(obj
),
226 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (unsigned integer)");
227 int_value
= bt_value_integer_unsigned_get(obj
);
229 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (unsigned integer)");
230 obj
= bt_value_array_borrow_element_by_index(array_obj
, 1);
231 ok(bt_value_is_signed_integer(obj
),
232 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (signed integer)");
233 int_value
= bt_value_integer_signed_get(obj
);
234 ok(int_value
== -507,
235 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (signed integer)");
236 obj
= bt_value_array_borrow_element_by_index(array_obj
, 2);
237 ok(bt_value_is_real(obj
),
238 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)");
239 real_value
= bt_value_real_get(obj
);
240 ok(real_value
== -17.45,
241 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (real number)");
242 obj
= bt_value_array_borrow_element_by_index(array_obj
, 3);
243 ok(bt_value_is_bool(obj
),
244 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)");
245 bool_value
= bt_value_bool_get(obj
);
247 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (boolean)");
248 obj
= bt_value_array_borrow_element_by_index(array_obj
, 4);
250 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)");
252 obj
= bt_value_integer_signed_create_init(1001);
254 ok(!bt_value_array_set_element_by_index(array_obj
, 2, obj
),
255 "bt_value_array_set_element_by_index() succeeds");
256 BT_VALUE_PUT_REF_AND_RESET(obj
);
257 obj
= bt_value_array_borrow_element_by_index(array_obj
, 2);
258 ok(bt_value_is_signed_integer(obj
),
259 "bt_value_array_set_element_by_index() inserts an value object with the appropriate type");
260 int_value
= bt_value_integer_signed_get(obj
);
262 ok(int_value
== 1001,
263 "bt_value_array_set_element_by_index() inserts an value object with the appropriate value");
265 ret
= bt_value_array_append_bool_element(array_obj
,
267 ok(!ret
, "bt_value_array_append_bool_element() succeeds");
268 ret
= bt_value_array_append_unsigned_integer_element(array_obj
,
270 ok(!ret
, "bt_value_array_append_unsigned_integer_element() succeeds");
271 ret
= bt_value_array_append_signed_integer_element(array_obj
,
273 ok(!ret
, "bt_value_array_append_signed_integer_element() succeeds");
274 ret
= bt_value_array_append_real_element(array_obj
,
276 ok(!ret
, "bt_value_array_append_real_element() succeeds");
277 ret
= bt_value_array_append_string_element(array_obj
,
279 ok(!ret
, "bt_value_array_append_string_element() succeeds");
280 ret
= bt_value_array_append_empty_array_element(array_obj
, NULL
);
281 ok(!ret
, "bt_value_array_append_empty_array_element() succeeds");
282 ret
= bt_value_array_append_empty_array_element(array_obj
, &appended_obj
);
283 ok(!ret
, "bt_value_array_append_empty_array_element() with returned value object succeeds");
285 "object returned by bt_value_array_append_empty_array_element() is not NULL");
286 ok(bt_value_is_array(appended_obj
),
287 "object returned by bt_value_array_append_empty_array_element() is an array value");
288 ret
= bt_value_array_append_empty_map_element(array_obj
, NULL
);
289 ok(!ret
, "bt_value_array_append_empty_map_element() succeeds");
290 ret
= bt_value_array_append_empty_map_element(array_obj
, &appended_obj
);
291 ok(!ret
, "bt_value_array_append_empty_map_element() with returned value object succeeds");
293 "object returned by bt_value_array_append_empty_map_element() is not NULL");
294 ok(bt_value_is_map(appended_obj
),
295 "object returned by bt_value_array_append_empty_map_element() is an array value");
297 ok(bt_value_array_get_length(array_obj
) == 14,
298 "the bt_value_array_append_element_*() functions increment the array value object's size");
299 ok(!bt_value_array_is_empty(array_obj
),
300 "map value object is not empty");
302 obj
= bt_value_array_borrow_element_by_index(array_obj
, 5);
303 ok(bt_value_is_bool(obj
),
304 "bt_value_array_append_bool_element() appends a boolean value object");
305 bool_value
= bt_value_bool_get(obj
);
307 "bt_value_array_append_bool_element() appends the appropriate value");
308 obj
= bt_value_array_borrow_element_by_index(array_obj
, 6);
309 ok(bt_value_is_unsigned_integer(obj
),
310 "bt_value_array_append_unsigned_integer_element() appends an unsigned integer value object");
311 int_value
= bt_value_integer_unsigned_get(obj
);
312 ok(int_value
== 98765,
313 "bt_value_array_append_unsigned_integer_element() appends the appropriate value");
314 obj
= bt_value_array_borrow_element_by_index(array_obj
, 7);
315 ok(bt_value_is_signed_integer(obj
),
316 "bt_value_array_append_signed_integer_element() appends a signed integer value object");
317 int_value
= bt_value_integer_signed_get(obj
);
318 ok(int_value
== -10101,
319 "bt_value_array_append_signed_integer_element() appends the appropriate value");
320 obj
= bt_value_array_borrow_element_by_index(array_obj
, 8);
321 ok(bt_value_is_real(obj
),
322 "bt_value_array_append_real_element() appends a real number value object");
323 real_value
= bt_value_real_get(obj
);
324 ok(real_value
== 2.49578,
325 "bt_value_array_append_real_element() appends the appropriate value");
326 obj
= bt_value_array_borrow_element_by_index(array_obj
, 9);
327 ok(bt_value_is_string(obj
),
328 "bt_value_array_append_string_element() appends a string value object");
329 string_value
= bt_value_string_get(obj
);
330 ok(!ret
&& string_value
&& strcmp(string_value
, "bt_value") == 0,
331 "bt_value_array_append_string_element() appends the appropriate value");
332 obj
= bt_value_array_borrow_element_by_index(array_obj
, 10);
333 ok(bt_value_is_array(obj
),
334 "bt_value_array_append_empty_array_element() appends an array value object");
335 ok(bt_value_array_is_empty(obj
),
336 "bt_value_array_append_empty_array_element() an empty array value object");
337 obj
= bt_value_array_borrow_element_by_index(array_obj
, 11);
338 ok(bt_value_is_array(obj
),
339 "bt_value_array_append_empty_array_element() appends an array value object");
340 ok(bt_value_array_is_empty(obj
),
341 "bt_value_array_append_empty_array_element() an empty array value object");
342 obj
= bt_value_array_borrow_element_by_index(array_obj
, 12);
343 ok(bt_value_is_map(obj
),
344 "bt_value_array_append_empty_map_element() appends a map value object");
345 ok(bt_value_map_is_empty(obj
),
346 "bt_value_array_append_empty_map_element() an empty map value object");
347 obj
= bt_value_array_borrow_element_by_index(array_obj
, 13);
348 ok(bt_value_is_map(obj
),
349 "bt_value_array_append_empty_map_element() appends a map value object");
350 ok(bt_value_map_is_empty(obj
),
351 "bt_value_array_append_empty_map_element() an empty map value object");
353 BT_VALUE_PUT_REF_AND_RESET(array_obj
);
354 pass("putting an existing array value object does not cause a crash")
358 bt_value_map_foreach_entry_func_status
test_map_foreach_cb_count(
359 const char *key
__attribute__((unused
)),
360 bt_value
*object
__attribute__((unused
)),
366 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT
;
367 } else if (*count
== 4) {
368 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR
;
369 } else if (*count
== 5) {
370 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR
;
375 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK
;
378 struct map_foreach_checklist
{
395 bt_value_map_foreach_entry_func_status
test_map_foreach_cb_check(
396 const char *key
, bt_value
*object
, void *data
)
398 struct map_foreach_checklist
*checklist
= data
;
400 if (strcmp(key
, "bt_bool") == 0) {
401 if (checklist
->bool1
) {
402 fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\"");
404 bt_bool val
= BT_FALSE
;
406 val
= bt_value_bool_get(object
);
409 pass("test_map_foreach_cb_check(): \"bt_bool\" value object has the right value");
410 checklist
->bool1
= BT_TRUE
;
412 fail("test_map_foreach_cb_check(): \"bt_bool\" value object has the wrong value");
415 } else if (strcmp(key
, "uint") == 0) {
416 if (checklist
->uint
) {
417 fail("test_map_foreach_cb_check(): duplicate key \"uint\"");
421 val
= bt_value_integer_unsigned_get(object
);
424 pass("test_map_foreach_cb_check(): \"uint\" value object has the right value");
425 checklist
->uint
= BT_TRUE
;
427 fail("test_map_foreach_cb_check(): \"uint\" value object has the wrong value");
430 } else if (strcmp(key
, "int") == 0) {
431 if (checklist
->int1
) {
432 fail("test_map_foreach_cb_check(): duplicate key \"int\"");
436 val
= bt_value_integer_signed_get(object
);
439 pass("test_map_foreach_cb_check(): \"int\" value object has the right value");
440 checklist
->int1
= BT_TRUE
;
442 fail("test_map_foreach_cb_check(): \"int\" value object has the wrong value");
445 } else if (strcmp(key
, "real") == 0) {
446 if (checklist
->real1
) {
447 fail("test_map_foreach_cb_check(): duplicate key \"real\"");
451 val
= bt_value_real_get(object
);
454 pass("test_map_foreach_cb_check(): \"real\" value object has the right value");
455 checklist
->real1
= BT_TRUE
;
457 fail("test_map_foreach_cb_check(): \"real\" value object has the wrong value");
460 } else if (strcmp(key
, "null") == 0) {
461 if (checklist
->null1
) {
462 fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\"");
464 ok(bt_value_is_null(object
), "test_map_foreach_cb_check(): success getting \"null\" value object");
465 checklist
->null1
= BT_TRUE
;
467 } else if (strcmp(key
, "bool2") == 0) {
468 if (checklist
->bool2
) {
469 fail("test_map_foreach_cb_check(): duplicate key \"bool2\"");
471 bt_bool val
= BT_FALSE
;
473 val
= bt_value_bool_get(object
);
476 pass("test_map_foreach_cb_check(): \"bool2\" value object has the right value");
477 checklist
->bool2
= BT_TRUE
;
479 fail("test_map_foreach_cb_check(): \"bool2\" value object has the wrong value");
482 } else if (strcmp(key
, "int2") == 0) {
483 if (checklist
->int2
) {
484 fail("test_map_foreach_cb_check(): duplicate key \"int2\"");
488 val
= bt_value_integer_signed_get(object
);
491 pass("test_map_foreach_cb_check(): \"int2\" value object has the right value");
492 checklist
->int2
= BT_TRUE
;
494 fail("test_map_foreach_cb_check(): \"int2\" value object has the wrong value");
497 } else if (strcmp(key
, "real2") == 0) {
498 if (checklist
->real2
) {
499 fail("test_map_foreach_cb_check(): duplicate key \"real2\"");
503 val
= bt_value_real_get(object
);
505 if (val
== -49.0001) {
506 pass("test_map_foreach_cb_check(): \"real2\" value object has the right value");
507 checklist
->real2
= BT_TRUE
;
509 fail("test_map_foreach_cb_check(): \"real2\" value object has the wrong value");
512 } else if (strcmp(key
, "string2") == 0) {
513 if (checklist
->string2
) {
514 fail("test_map_foreach_cb_check(): duplicate key \"string2\"");
518 val
= bt_value_string_get(object
);
520 if (val
&& strcmp(val
, "bt_value") == 0) {
521 pass("test_map_foreach_cb_check(): \"string2\" value object has the right value");
522 checklist
->string2
= BT_TRUE
;
524 fail("test_map_foreach_cb_check(): \"string2\" value object has the wrong value");
527 } else if (strcmp(key
, "array2") == 0) {
528 if (checklist
->array2
) {
529 fail("test_map_foreach_cb_check(): duplicate key \"array2\"");
531 ok(bt_value_is_array(object
), "test_map_foreach_cb_check(): success getting \"array2\" value object");
532 ok(bt_value_array_is_empty(object
),
533 "test_map_foreach_cb_check(): \"array2\" value object is empty");
534 checklist
->array2
= BT_TRUE
;
536 } else if (strcmp(key
, "array3") == 0) {
537 if (checklist
->array3
) {
538 fail("test_map_foreach_cb_check(): duplicate key \"array3\"");
540 ok(bt_value_is_array(object
), "test_map_foreach_cb_check(): success getting \"array3\" value object");
541 ok(bt_value_array_is_empty(object
),
542 "test_map_foreach_cb_check(): \"array3\" value object is empty");
543 checklist
->array3
= BT_TRUE
;
545 } else if (strcmp(key
, "map3") == 0) {
546 if (checklist
->map3
) {
547 fail("test_map_foreach_cb_check(): duplicate key \"map3\"");
549 ok(bt_value_is_map(object
), "test_map_foreach_cb_check(): success getting \"map3\" value object");
550 ok(bt_value_map_is_empty(object
),
551 "test_map_foreach_cb_check(): \"map3\" value object is empty");
552 checklist
->map3
= BT_TRUE
;
554 } else if (strcmp(key
, "map2") == 0) {
555 if (checklist
->map2
) {
556 fail("test_map_foreach_cb_check(): duplicate key \"map2\"");
558 ok(bt_value_is_map(object
), "test_map_foreach_cb_check(): success getting \"map2\" value object");
559 ok(bt_value_map_is_empty(object
),
560 "test_map_foreach_cb_check(): \"map2\" value object is empty");
561 checklist
->map2
= BT_TRUE
;
564 fail("test_map_foreach_cb_check(): unknown map key \"%s\"",
568 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK
;
581 bt_value
*inserted_obj
;
582 struct map_foreach_checklist checklist
;
584 map_obj
= bt_value_map_create();
585 ok(map_obj
&& bt_value_is_map(map_obj
),
586 "bt_value_map_create() returns a map value object");
587 ok(bt_value_map_get_size(map_obj
) == 0,
588 "initial map value object size is 0");
590 obj
= bt_value_integer_unsigned_create_init(19457);
591 ret
= bt_value_map_insert_entry(map_obj
, "uint", obj
);
592 BT_VALUE_PUT_REF_AND_RESET(obj
);
593 obj
= bt_value_integer_signed_create_init(-12345);
594 ret
|= bt_value_map_insert_entry(map_obj
, "int", obj
);
595 BT_VALUE_PUT_REF_AND_RESET(obj
);
596 obj
= bt_value_real_create_init(5.444);
597 ret
|= bt_value_map_insert_entry(map_obj
, "real", obj
);
598 BT_VALUE_PUT_REF_AND_RESET(obj
);
599 obj
= bt_value_bool_create();
600 ret
|= bt_value_map_insert_entry(map_obj
, "bt_bool", obj
);
601 BT_VALUE_PUT_REF_AND_RESET(obj
);
602 ret
|= bt_value_map_insert_entry(map_obj
, "null",
604 ok(!ret
, "bt_value_map_insert_entry() succeeds");
605 ok(bt_value_map_get_size(map_obj
) == 5,
606 "inserting an element into a map value object increment its size");
608 obj
= bt_value_bool_create_init(BT_TRUE
);
609 ret
= bt_value_map_insert_entry(map_obj
, "bt_bool", obj
);
610 BT_VALUE_PUT_REF_AND_RESET(obj
);
611 ok(!ret
, "bt_value_map_insert_entry() accepts an existing key");
613 obj
= bt_value_map_borrow_entry_value(map_obj
, "life");
614 ok(!obj
, "bt_value_map_borrow_entry_value() returns NULL with an non existing key");
615 obj
= bt_value_map_borrow_entry_value(map_obj
, "real");
616 ok(obj
&& bt_value_is_real(obj
),
617 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (real)");
618 real_value
= bt_value_real_get(obj
);
619 ok(real_value
== 5.444,
620 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (real)");
621 obj
= bt_value_map_borrow_entry_value(map_obj
, "uint");
622 ok(obj
&& bt_value_is_unsigned_integer(obj
),
623 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (unsigned integer)");
624 int_value
= bt_value_integer_unsigned_get(obj
);
625 ok(int_value
== 19457,
626 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (unsigned integer)");
627 obj
= bt_value_map_borrow_entry_value(map_obj
, "int");
628 ok(obj
&& bt_value_is_signed_integer(obj
),
629 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (signed integer)");
630 int_value
= bt_value_integer_signed_get(obj
);
631 ok(int_value
== -12345,
632 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (signed integer)");
633 obj
= bt_value_map_borrow_entry_value(map_obj
, "null");
634 ok(obj
&& bt_value_is_null(obj
),
635 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (null)");
636 obj
= bt_value_map_borrow_entry_value(map_obj
, "bt_bool");
637 ok(obj
&& bt_value_is_bool(obj
),
638 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (boolean)");
639 bool_value
= bt_value_bool_get(obj
);
641 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (boolean)");
643 ret
= bt_value_map_insert_bool_entry(map_obj
, "bool2",
645 ok(!ret
, "bt_value_map_insert_bool_entry() succeeds");
646 ret
= bt_value_map_insert_signed_integer_entry(map_obj
, "int2",
648 ok(!ret
, "bt_value_map_insert_signed_integer_entry() succeeds");
649 ret
= bt_value_map_insert_real_entry(map_obj
, "real2",
651 ok(!ret
, "bt_value_map_insert_real_entry() succeeds");
652 ret
= bt_value_map_insert_string_entry(map_obj
, "string2",
654 ok(!ret
, "bt_value_map_insert_string_entry() succeeds");
655 ret
= bt_value_map_insert_empty_array_entry(map_obj
, "array2", NULL
);
656 ok(!ret
, "bt_value_map_insert_empty_array_entry() succeeds");
657 ret
= bt_value_map_insert_empty_array_entry(map_obj
, "array3", &inserted_obj
);
658 ok(!ret
, "bt_value_map_insert_empty_array_entry() with returned value object succeeds");
660 "object returned by bt_value_map_insert_empty_array_entry() is not NULL");
661 ok(bt_value_is_array(inserted_obj
),
662 "object returned by bt_value_map_insert_empty_array_entry() is an array value");
663 ret
= bt_value_map_insert_empty_map_entry(map_obj
, "map2", NULL
);
664 ok(!ret
, "bt_value_map_insert_empty_map_entry() succeeds");
665 ret
= bt_value_map_insert_empty_map_entry(map_obj
, "map3", &inserted_obj
);
666 ok(!ret
, "bt_value_map_insert_empty_map_entry() with returned value object succeeds");
668 "object returned by bt_value_map_insert_empty_map_entry() is not NULL");
669 ok(bt_value_is_map(inserted_obj
),
670 "object returned by bt_value_map_insert_empty_map_entry() is an array value");
672 ok(bt_value_map_get_size(map_obj
) == 13,
673 "the bt_value_map_insert*() functions increment the map value object's size");
675 ok(!bt_value_map_has_entry(map_obj
, "hello"),
676 "map value object does not have key \"hello\"");
677 ok(bt_value_map_has_entry(map_obj
, "bt_bool"),
678 "map value object has key \"bt_bool\"");
679 ok(bt_value_map_has_entry(map_obj
, "uint"),
680 "map value object has key \"uint\"");
681 ok(bt_value_map_has_entry(map_obj
, "int"),
682 "map value object has key \"int\"");
683 ok(bt_value_map_has_entry(map_obj
, "real"),
684 "map value object has key \"real\"");
685 ok(bt_value_map_has_entry(map_obj
, "null"),
686 "map value object has key \"null\"");
687 ok(bt_value_map_has_entry(map_obj
, "bool2"),
688 "map value object has key \"bool2\"");
689 ok(bt_value_map_has_entry(map_obj
, "int2"),
690 "map value object has key \"int2\"");
691 ok(bt_value_map_has_entry(map_obj
, "real2"),
692 "map value object has key \"real2\"");
693 ok(bt_value_map_has_entry(map_obj
, "string2"),
694 "map value object has key \"string2\"");
695 ok(bt_value_map_has_entry(map_obj
, "array2"),
696 "map value object has key \"array2\"");
697 ok(bt_value_map_has_entry(map_obj
, "array3"),
698 "map value object has key \"array3\"");
699 ok(bt_value_map_has_entry(map_obj
, "map2"),
700 "map value object has key \"map2\"");
701 ok(bt_value_map_has_entry(map_obj
, "map3"),
702 "map value object has key \"map3\"");
704 ret
= bt_value_map_foreach_entry(map_obj
, test_map_foreach_cb_count
,
706 ok(ret
== BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED
&& count
== 3,
707 "bt_value_map_foreach_entry() breaks the loop when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT");
710 ret
= bt_value_map_foreach_entry(map_obj
, test_map_foreach_cb_count
,
712 ok(ret
== BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR
,
713 "bt_value_map_foreach_entry() fails when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR");
714 bt_current_thread_clear_error();
717 ret
= bt_value_map_foreach_entry(map_obj
, test_map_foreach_cb_count
,
719 ok(ret
== BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR
,
720 "bt_value_map_foreach_entry() fails when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR");
721 bt_current_thread_clear_error();
723 memset(&checklist
, 0, sizeof(checklist
));
724 ret
= bt_value_map_foreach_entry(map_obj
, test_map_foreach_cb_check
,
726 ok(ret
== BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK
,
727 "bt_value_map_foreach_entry() succeeds with test_map_foreach_cb_check()");
728 ok(checklist
.bool1
&& checklist
.uint
&& checklist
.int1
&&
729 checklist
.real1
&& checklist
.null1
&& checklist
.bool2
&&
730 checklist
.int2
&& checklist
.real2
&& checklist
.string2
&&
731 checklist
.array2
&& checklist
.map2
,
732 "bt_value_map_foreach_entry() iterates over all the map value object's elements");
734 BT_VALUE_PUT_REF_AND_RESET(map_obj
);
735 pass("putting an existing map value object does not cause a crash")
739 void test_types(void)
743 test_unsigned_integer();
744 test_signed_integer();
752 void test_is_equal_null(void)
754 ok(bt_value_is_equal(bt_value_null
, bt_value_null
),
755 "null value objects are equivalent");
759 void test_is_equal_bool(void)
762 bt_value_bool_create_init(BT_FALSE
);
764 bt_value_bool_create_init(BT_TRUE
);
766 bt_value_bool_create_init(BT_FALSE
);
768 BT_ASSERT(bool1
&& bool2
&& bool3
);
769 ok(!bt_value_is_equal(bt_value_null
, bool1
),
770 "cannot compare null value object and bt_bool value object");
771 ok(!bt_value_is_equal(bool1
, bool2
),
772 "boolean value objects are not equivalent (BT_FALSE and BT_TRUE)");
773 ok(bt_value_is_equal(bool1
, bool3
),
774 "boolean value objects are equivalent (BT_FALSE and BT_FALSE)");
776 BT_VALUE_PUT_REF_AND_RESET(bool1
);
777 BT_VALUE_PUT_REF_AND_RESET(bool2
);
778 BT_VALUE_PUT_REF_AND_RESET(bool3
);
782 void test_is_equal_unsigned_integer(void)
785 bt_value_integer_unsigned_create_init(10);
787 bt_value_integer_unsigned_create_init(23);
789 bt_value_integer_unsigned_create_init(10);
791 BT_ASSERT(int1
&& int2
&& int3
);
792 ok(!bt_value_is_equal(bt_value_null
, int1
),
793 "cannot compare null value object and unsigned integer value object");
794 ok(!bt_value_is_equal(int1
, int2
),
795 "unsigned integer value objects are not equivalent (10 and 23)");
796 ok(bt_value_is_equal(int1
, int3
),
797 "unsigned integer value objects are equivalent (10 and 10)");
799 BT_VALUE_PUT_REF_AND_RESET(int1
);
800 BT_VALUE_PUT_REF_AND_RESET(int2
);
801 BT_VALUE_PUT_REF_AND_RESET(int3
);
805 void test_is_equal_signed_integer(void)
808 bt_value_integer_signed_create_init(10);
810 bt_value_integer_signed_create_init(-23);
812 bt_value_integer_signed_create_init(10);
814 BT_ASSERT(int1
&& int2
&& int3
);
815 ok(!bt_value_is_equal(bt_value_null
, int1
),
816 "cannot compare null value object and signed integer value object");
817 ok(!bt_value_is_equal(int1
, int2
),
818 "signed integer value objects are not equivalent (10 and -23)");
819 ok(bt_value_is_equal(int1
, int3
),
820 "signed integer value objects are equivalent (10 and 10)");
822 BT_VALUE_PUT_REF_AND_RESET(int1
);
823 BT_VALUE_PUT_REF_AND_RESET(int2
);
824 BT_VALUE_PUT_REF_AND_RESET(int3
);
828 void test_is_equal_real(void)
831 bt_value_real_create_init(17.38);
833 bt_value_real_create_init(-14.23);
835 bt_value_real_create_init(17.38);
837 BT_ASSERT(real1
&& real2
&& real3
);
839 ok(!bt_value_is_equal(bt_value_null
, real1
),
840 "cannot compare null value object and real number value object");
841 ok(!bt_value_is_equal(real1
, real2
),
842 "real number value objects are not equivalent (17.38 and -14.23)");
843 ok(bt_value_is_equal(real1
, real3
),
844 "real number value objects are equivalent (17.38 and 17.38)");
846 BT_VALUE_PUT_REF_AND_RESET(real1
);
847 BT_VALUE_PUT_REF_AND_RESET(real2
);
848 BT_VALUE_PUT_REF_AND_RESET(real3
);
852 void test_is_equal_string(void)
855 bt_value_string_create_init("hello");
857 bt_value_string_create_init("bt_value");
859 bt_value_string_create_init("hello");
861 BT_ASSERT(string1
&& string2
&& string3
);
863 ok(!bt_value_is_equal(bt_value_null
, string1
),
864 "cannot compare null value object and string value object");
865 ok(!bt_value_is_equal(string1
, string2
),
866 "string value objects are not equivalent (\"hello\" and \"bt_value\")");
867 ok(bt_value_is_equal(string1
, string3
),
868 "string value objects are equivalent (\"hello\" and \"hello\")");
870 BT_VALUE_PUT_REF_AND_RESET(string1
);
871 BT_VALUE_PUT_REF_AND_RESET(string2
);
872 BT_VALUE_PUT_REF_AND_RESET(string3
);
876 void test_is_equal_array(void)
878 bt_value
*array1
= bt_value_array_create();
879 bt_value
*array2
= bt_value_array_create();
880 bt_value
*array3
= bt_value_array_create();
881 bt_value_array_append_element_status append_status
;
883 BT_ASSERT(array1
&& array2
&& array3
);
885 ok(bt_value_is_equal(array1
, array2
),
886 "empty array value objects are equivalent");
888 append_status
= bt_value_array_append_signed_integer_element(array1
, 23);
889 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
890 append_status
= bt_value_array_append_real_element(array1
, 14.2);
891 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
892 append_status
= bt_value_array_append_bool_element(array1
, BT_FALSE
);
893 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
894 append_status
= bt_value_array_append_real_element(array2
, 14.2);
895 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
896 append_status
= bt_value_array_append_signed_integer_element(array2
, 23);
897 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
898 append_status
= bt_value_array_append_bool_element(array2
, BT_FALSE
);
899 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
900 append_status
= bt_value_array_append_signed_integer_element(array3
, 23);
901 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
902 append_status
= bt_value_array_append_real_element(array3
, 14.2);
903 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
904 append_status
= bt_value_array_append_bool_element(array3
, BT_FALSE
);
905 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
906 BT_ASSERT(bt_value_array_get_length(array1
) == 3);
907 BT_ASSERT(bt_value_array_get_length(array2
) == 3);
908 BT_ASSERT(bt_value_array_get_length(array3
) == 3);
910 ok(!bt_value_is_equal(bt_value_null
, array1
),
911 "cannot compare null value object and array value object");
912 ok(!bt_value_is_equal(array1
, array2
),
913 "array value objects are not equivalent ([23, 14.2, BT_FALSE] and [14.2, 23, BT_FALSE])");
914 ok(bt_value_is_equal(array1
, array3
),
915 "array value objects are equivalent ([23, 14.2, BT_FALSE] and [23, 14.2, BT_FALSE])");
917 BT_VALUE_PUT_REF_AND_RESET(array1
);
918 BT_VALUE_PUT_REF_AND_RESET(array2
);
919 BT_VALUE_PUT_REF_AND_RESET(array3
);
923 void test_is_equal_map(void)
925 bt_value
*map1
= bt_value_map_create();
926 bt_value
*map2
= bt_value_map_create();
927 bt_value
*map3
= bt_value_map_create();
928 bt_value_map_insert_entry_status insert_status
;
930 BT_ASSERT(map1
&& map2
&& map3
);
932 ok(bt_value_is_equal(map1
, map2
),
933 "empty map value objects are equivalent");
936 insert_status
= bt_value_map_insert_signed_integer_entry(map1
, "one", 23);
937 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
938 insert_status
= bt_value_map_insert_real_entry(map1
, "two", 14.2);
939 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
940 insert_status
= bt_value_map_insert_bool_entry(map1
, "three",
942 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
943 insert_status
= bt_value_map_insert_real_entry(map2
, "one", 14.2);
944 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
945 insert_status
= bt_value_map_insert_signed_integer_entry(map2
, "two", 23);
946 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
947 insert_status
= bt_value_map_insert_bool_entry(map2
, "three",
949 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
950 insert_status
= bt_value_map_insert_bool_entry(map3
, "three",
952 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
953 insert_status
= bt_value_map_insert_signed_integer_entry(map3
, "one", 23);
954 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
955 insert_status
= bt_value_map_insert_real_entry(map3
, "two", 14.2);
956 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
957 BT_ASSERT(bt_value_map_get_size(map1
) == 3);
958 BT_ASSERT(bt_value_map_get_size(map2
) == 3);
959 BT_ASSERT(bt_value_map_get_size(map3
) == 3);
961 ok(!bt_value_is_equal(bt_value_null
, map1
),
962 "cannot compare null value object and map value object");
963 ok(!bt_value_is_equal(map1
, map2
),
964 "map value objects are not equivalent");
965 ok(bt_value_is_equal(map1
, map3
),
966 "map value objects are equivalent");
968 BT_VALUE_PUT_REF_AND_RESET(map1
);
969 BT_VALUE_PUT_REF_AND_RESET(map2
);
970 BT_VALUE_PUT_REF_AND_RESET(map3
);
974 void test_is_equal(void)
976 test_is_equal_null();
977 test_is_equal_bool();
978 test_is_equal_unsigned_integer();
979 test_is_equal_signed_integer();
980 test_is_equal_real();
981 test_is_equal_string();
982 test_is_equal_array();
990 * Here's the deal here. If we make sure that each value object
991 * of our deep copy has a different address than its source, and
992 * that bt_value_is_equal() returns BT_TRUE for the top-level
993 * value object, taking into account that we test the
994 * correctness of bt_value_is_equal() elsewhere, then the deep
997 bt_value
*null_copy_obj
;
998 bt_value
*bool_obj
, *bool_copy_obj
;
999 bt_value
*unsigned_integer_obj
, *unsigned_integer_copy_obj
;
1000 bt_value
*signed_integer_obj
, *signed_integer_copy_obj
;
1001 bt_value
*real_obj
, *real_copy_obj
;
1002 bt_value
*string_obj
, *string_copy_obj
;
1003 bt_value
*array_obj
, *array_copy_obj
;
1004 bt_value
*map_obj
, *map_copy_obj
;
1005 bt_value_array_append_element_status append_status
;
1006 bt_value_map_insert_entry_status insert_status
;
1007 bt_value_copy_status copy_status
;
1009 bool_obj
= bt_value_bool_create_init(BT_TRUE
);
1010 unsigned_integer_obj
= bt_value_integer_unsigned_create_init(23);
1011 signed_integer_obj
= bt_value_integer_signed_create_init(-47);
1012 real_obj
= bt_value_real_create_init(-3.1416);
1013 string_obj
= bt_value_string_create_init("test");
1014 array_obj
= bt_value_array_create();
1015 map_obj
= bt_value_map_create();
1017 BT_ASSERT(bool_obj
&& unsigned_integer_obj
&& signed_integer_obj
&&
1018 real_obj
&& string_obj
&& array_obj
&& map_obj
);
1020 append_status
= bt_value_array_append_element(array_obj
, bool_obj
);
1021 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1022 append_status
= bt_value_array_append_element(array_obj
, unsigned_integer_obj
);
1023 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1024 append_status
= bt_value_array_append_element(array_obj
, signed_integer_obj
);
1025 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1026 append_status
= bt_value_array_append_element(array_obj
, real_obj
);
1027 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1028 append_status
= bt_value_array_append_element(array_obj
, bt_value_null
);
1029 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1030 insert_status
= bt_value_map_insert_entry(map_obj
, "array", array_obj
);
1031 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1032 insert_status
= bt_value_map_insert_entry(map_obj
, "string", string_obj
);
1033 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1035 copy_status
= bt_value_copy(map_obj
, &map_copy_obj
);
1036 ok(copy_status
== BT_VALUE_COPY_STATUS_OK
&& map_copy_obj
,
1037 "bt_value_copy() succeeds");
1039 ok(map_obj
!= map_copy_obj
,
1040 "bt_value_copy() returns a different pointer (map)");
1041 string_copy_obj
= bt_value_map_borrow_entry_value(map_copy_obj
,
1043 ok(string_copy_obj
!= string_obj
,
1044 "bt_value_copy() returns a different pointer (string)");
1045 array_copy_obj
= bt_value_map_borrow_entry_value(map_copy_obj
,
1047 ok(array_copy_obj
!= array_obj
,
1048 "bt_value_copy() returns a different pointer (array)");
1049 bool_copy_obj
= bt_value_array_borrow_element_by_index(
1051 ok(bool_copy_obj
!= bool_obj
,
1052 "bt_value_copy() returns a different pointer (bool)");
1053 unsigned_integer_copy_obj
= bt_value_array_borrow_element_by_index(
1055 ok(unsigned_integer_copy_obj
!= unsigned_integer_obj
,
1056 "bt_value_copy() returns a different pointer (unsigned integer)");
1057 signed_integer_copy_obj
= bt_value_array_borrow_element_by_index(
1059 ok(signed_integer_copy_obj
!= signed_integer_obj
,
1060 "bt_value_copy() returns a different pointer (signed integer)");
1061 real_copy_obj
= bt_value_array_borrow_element_by_index(
1063 ok(real_copy_obj
!= real_obj
,
1064 "bt_value_copy() returns a different pointer (real)");
1065 null_copy_obj
= bt_value_array_borrow_element_by_index(
1067 ok(null_copy_obj
== bt_value_null
,
1068 "bt_value_copy() returns the same pointer (null)");
1070 ok(bt_value_is_equal(map_obj
, map_copy_obj
),
1071 "source and destination value objects have the same content");
1073 BT_VALUE_PUT_REF_AND_RESET(map_copy_obj
);
1074 BT_VALUE_PUT_REF_AND_RESET(bool_obj
);
1075 BT_VALUE_PUT_REF_AND_RESET(unsigned_integer_obj
);
1076 BT_VALUE_PUT_REF_AND_RESET(signed_integer_obj
);
1077 BT_VALUE_PUT_REF_AND_RESET(real_obj
);
1078 BT_VALUE_PUT_REF_AND_RESET(string_obj
);
1079 BT_VALUE_PUT_REF_AND_RESET(array_obj
);
1080 BT_VALUE_PUT_REF_AND_RESET(map_obj
);
1084 bt_bool
compare_map_elements(const bt_value
*map_a
, const bt_value
*map_b
,
1087 const bt_value
*elem_a
= NULL
;
1088 const bt_value
*elem_b
= NULL
;
1091 elem_a
= bt_value_map_borrow_entry_value_const(map_a
, key
);
1092 elem_b
= bt_value_map_borrow_entry_value_const(map_b
, key
);
1093 equal
= bt_value_is_equal(elem_a
, elem_b
);
1098 void test_extend(void)
1100 bt_value
*base_map
= bt_value_map_create();
1101 bt_value
*extension_map
= bt_value_map_create();
1102 bt_value
*extended_map
= NULL
;
1103 bt_value
*array
= bt_value_array_create();
1104 bt_value_map_insert_entry_status insert_status
;
1105 bt_value_copy_status copy_status
;
1106 bt_value_map_extend_status extend_status
;
1108 BT_ASSERT(base_map
);
1109 BT_ASSERT(extension_map
);
1111 insert_status
= bt_value_map_insert_bool_entry(base_map
, "file",
1113 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1114 insert_status
= bt_value_map_insert_bool_entry(base_map
, "edit",
1116 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1117 insert_status
= bt_value_map_insert_signed_integer_entry(base_map
,
1119 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1120 insert_status
= bt_value_map_insert_signed_integer_entry(base_map
, "find",
1122 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1123 insert_status
= bt_value_map_insert_bool_entry(extension_map
, "edit",
1125 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1126 insert_status
= bt_value_map_insert_signed_integer_entry(extension_map
,
1128 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1129 insert_status
= bt_value_map_insert_real_entry(extension_map
,
1131 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1132 copy_status
= bt_value_copy(base_map
, &extended_map
);
1133 BT_ASSERT(copy_status
== BT_VALUE_COPY_STATUS_OK
);
1134 extend_status
= bt_value_map_extend(extended_map
, extension_map
);
1135 ok(extend_status
== BT_VALUE_MAP_EXTEND_STATUS_OK
&&
1136 extended_map
, "bt_value_map_extend() succeeds");
1137 ok(bt_value_map_get_size(extended_map
) == 5,
1138 "bt_value_map_extend() returns a map object with the correct size");
1139 ok(compare_map_elements(base_map
,
1140 extended_map
, "file"),
1141 "bt_value_map_extend() picks the appropriate element (file)");
1142 ok(compare_map_elements(extension_map
,
1143 extended_map
, "edit"),
1144 "bt_value_map_extend() picks the appropriate element (edit)");
1145 ok(compare_map_elements(base_map
,
1146 extended_map
, "selection"),
1147 "bt_value_map_extend() picks the appropriate element (selection)");
1148 ok(compare_map_elements(extension_map
,
1149 extended_map
, "find"),
1150 "bt_value_map_extend() picks the appropriate element (find)");
1151 ok(compare_map_elements(extension_map
,
1152 extended_map
, "project"),
1153 "bt_value_map_extend() picks the appropriate element (project)");
1155 BT_VALUE_PUT_REF_AND_RESET(array
);
1156 BT_VALUE_PUT_REF_AND_RESET(base_map
);
1157 BT_VALUE_PUT_REF_AND_RESET(extension_map
);
1158 BT_VALUE_PUT_REF_AND_RESET(extended_map
);
1163 plan_tests(NR_TESTS
);
1168 return exit_status();