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
, bt_value
*object
,
365 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT
;
366 } else if (*count
== 4) {
367 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR
;
368 } else if (*count
== 5) {
369 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR
;
374 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK
;
377 struct map_foreach_checklist
{
394 bt_value_map_foreach_entry_func_status
test_map_foreach_cb_check(
395 const char *key
, bt_value
*object
, void *data
)
397 struct map_foreach_checklist
*checklist
= data
;
399 if (strcmp(key
, "bt_bool") == 0) {
400 if (checklist
->bool1
) {
401 fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\"");
403 bt_bool val
= BT_FALSE
;
405 val
= bt_value_bool_get(object
);
408 pass("test_map_foreach_cb_check(): \"bt_bool\" value object has the right value");
409 checklist
->bool1
= BT_TRUE
;
411 fail("test_map_foreach_cb_check(): \"bt_bool\" value object has the wrong value");
414 } else if (strcmp(key
, "uint") == 0) {
415 if (checklist
->uint
) {
416 fail("test_map_foreach_cb_check(): duplicate key \"uint\"");
420 val
= bt_value_integer_unsigned_get(object
);
423 pass("test_map_foreach_cb_check(): \"uint\" value object has the right value");
424 checklist
->uint
= BT_TRUE
;
426 fail("test_map_foreach_cb_check(): \"uint\" value object has the wrong value");
429 } else if (strcmp(key
, "int") == 0) {
430 if (checklist
->int1
) {
431 fail("test_map_foreach_cb_check(): duplicate key \"int\"");
435 val
= bt_value_integer_signed_get(object
);
438 pass("test_map_foreach_cb_check(): \"int\" value object has the right value");
439 checklist
->int1
= BT_TRUE
;
441 fail("test_map_foreach_cb_check(): \"int\" value object has the wrong value");
444 } else if (strcmp(key
, "real") == 0) {
445 if (checklist
->real1
) {
446 fail("test_map_foreach_cb_check(): duplicate key \"real\"");
450 val
= bt_value_real_get(object
);
453 pass("test_map_foreach_cb_check(): \"real\" value object has the right value");
454 checklist
->real1
= BT_TRUE
;
456 fail("test_map_foreach_cb_check(): \"real\" value object has the wrong value");
459 } else if (strcmp(key
, "null") == 0) {
460 if (checklist
->null1
) {
461 fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\"");
463 ok(bt_value_is_null(object
), "test_map_foreach_cb_check(): success getting \"null\" value object");
464 checklist
->null1
= BT_TRUE
;
466 } else if (strcmp(key
, "bool2") == 0) {
467 if (checklist
->bool2
) {
468 fail("test_map_foreach_cb_check(): duplicate key \"bool2\"");
470 bt_bool val
= BT_FALSE
;
472 val
= bt_value_bool_get(object
);
475 pass("test_map_foreach_cb_check(): \"bool2\" value object has the right value");
476 checklist
->bool2
= BT_TRUE
;
478 fail("test_map_foreach_cb_check(): \"bool2\" value object has the wrong value");
481 } else if (strcmp(key
, "int2") == 0) {
482 if (checklist
->int2
) {
483 fail("test_map_foreach_cb_check(): duplicate key \"int2\"");
487 val
= bt_value_integer_signed_get(object
);
490 pass("test_map_foreach_cb_check(): \"int2\" value object has the right value");
491 checklist
->int2
= BT_TRUE
;
493 fail("test_map_foreach_cb_check(): \"int2\" value object has the wrong value");
496 } else if (strcmp(key
, "real2") == 0) {
497 if (checklist
->real2
) {
498 fail("test_map_foreach_cb_check(): duplicate key \"real2\"");
502 val
= bt_value_real_get(object
);
504 if (val
== -49.0001) {
505 pass("test_map_foreach_cb_check(): \"real2\" value object has the right value");
506 checklist
->real2
= BT_TRUE
;
508 fail("test_map_foreach_cb_check(): \"real2\" value object has the wrong value");
511 } else if (strcmp(key
, "string2") == 0) {
512 if (checklist
->string2
) {
513 fail("test_map_foreach_cb_check(): duplicate key \"string2\"");
517 val
= bt_value_string_get(object
);
519 if (val
&& strcmp(val
, "bt_value") == 0) {
520 pass("test_map_foreach_cb_check(): \"string2\" value object has the right value");
521 checklist
->string2
= BT_TRUE
;
523 fail("test_map_foreach_cb_check(): \"string2\" value object has the wrong value");
526 } else if (strcmp(key
, "array2") == 0) {
527 if (checklist
->array2
) {
528 fail("test_map_foreach_cb_check(): duplicate key \"array2\"");
530 ok(bt_value_is_array(object
), "test_map_foreach_cb_check(): success getting \"array2\" value object");
531 ok(bt_value_array_is_empty(object
),
532 "test_map_foreach_cb_check(): \"array2\" value object is empty");
533 checklist
->array2
= BT_TRUE
;
535 } else if (strcmp(key
, "array3") == 0) {
536 if (checklist
->array3
) {
537 fail("test_map_foreach_cb_check(): duplicate key \"array3\"");
539 ok(bt_value_is_array(object
), "test_map_foreach_cb_check(): success getting \"array3\" value object");
540 ok(bt_value_array_is_empty(object
),
541 "test_map_foreach_cb_check(): \"array3\" value object is empty");
542 checklist
->array3
= BT_TRUE
;
544 } else if (strcmp(key
, "map3") == 0) {
545 if (checklist
->map3
) {
546 fail("test_map_foreach_cb_check(): duplicate key \"map3\"");
548 ok(bt_value_is_map(object
), "test_map_foreach_cb_check(): success getting \"map3\" value object");
549 ok(bt_value_map_is_empty(object
),
550 "test_map_foreach_cb_check(): \"map3\" value object is empty");
551 checklist
->map3
= BT_TRUE
;
553 } else if (strcmp(key
, "map2") == 0) {
554 if (checklist
->map2
) {
555 fail("test_map_foreach_cb_check(): duplicate key \"map2\"");
557 ok(bt_value_is_map(object
), "test_map_foreach_cb_check(): success getting \"map2\" value object");
558 ok(bt_value_map_is_empty(object
),
559 "test_map_foreach_cb_check(): \"map2\" value object is empty");
560 checklist
->map2
= BT_TRUE
;
563 fail("test_map_foreach_cb_check(): unknown map key \"%s\"",
567 return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK
;
580 bt_value
*inserted_obj
;
581 struct map_foreach_checklist checklist
;
583 map_obj
= bt_value_map_create();
584 ok(map_obj
&& bt_value_is_map(map_obj
),
585 "bt_value_map_create() returns a map value object");
586 ok(bt_value_map_get_size(map_obj
) == 0,
587 "initial map value object size is 0");
589 obj
= bt_value_integer_unsigned_create_init(19457);
590 ret
= bt_value_map_insert_entry(map_obj
, "uint", obj
);
591 BT_VALUE_PUT_REF_AND_RESET(obj
);
592 obj
= bt_value_integer_signed_create_init(-12345);
593 ret
|= bt_value_map_insert_entry(map_obj
, "int", obj
);
594 BT_VALUE_PUT_REF_AND_RESET(obj
);
595 obj
= bt_value_real_create_init(5.444);
596 ret
|= bt_value_map_insert_entry(map_obj
, "real", obj
);
597 BT_VALUE_PUT_REF_AND_RESET(obj
);
598 obj
= bt_value_bool_create();
599 ret
|= bt_value_map_insert_entry(map_obj
, "bt_bool", obj
);
600 BT_VALUE_PUT_REF_AND_RESET(obj
);
601 ret
|= bt_value_map_insert_entry(map_obj
, "null",
603 ok(!ret
, "bt_value_map_insert_entry() succeeds");
604 ok(bt_value_map_get_size(map_obj
) == 5,
605 "inserting an element into a map value object increment its size");
607 obj
= bt_value_bool_create_init(BT_TRUE
);
608 ret
= bt_value_map_insert_entry(map_obj
, "bt_bool", obj
);
609 BT_VALUE_PUT_REF_AND_RESET(obj
);
610 ok(!ret
, "bt_value_map_insert_entry() accepts an existing key");
612 obj
= bt_value_map_borrow_entry_value(map_obj
, "life");
613 ok(!obj
, "bt_value_map_borrow_entry_value() returns NULL with an non existing key");
614 obj
= bt_value_map_borrow_entry_value(map_obj
, "real");
615 ok(obj
&& bt_value_is_real(obj
),
616 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (real)");
617 real_value
= bt_value_real_get(obj
);
618 ok(real_value
== 5.444,
619 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (real)");
620 obj
= bt_value_map_borrow_entry_value(map_obj
, "uint");
621 ok(obj
&& bt_value_is_unsigned_integer(obj
),
622 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (unsigned integer)");
623 int_value
= bt_value_integer_unsigned_get(obj
);
624 ok(int_value
== 19457,
625 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (unsigned integer)");
626 obj
= bt_value_map_borrow_entry_value(map_obj
, "int");
627 ok(obj
&& bt_value_is_signed_integer(obj
),
628 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (signed integer)");
629 int_value
= bt_value_integer_signed_get(obj
);
630 ok(int_value
== -12345,
631 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (signed integer)");
632 obj
= bt_value_map_borrow_entry_value(map_obj
, "null");
633 ok(obj
&& bt_value_is_null(obj
),
634 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (null)");
635 obj
= bt_value_map_borrow_entry_value(map_obj
, "bt_bool");
636 ok(obj
&& bt_value_is_bool(obj
),
637 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (boolean)");
638 bool_value
= bt_value_bool_get(obj
);
640 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (boolean)");
642 ret
= bt_value_map_insert_bool_entry(map_obj
, "bool2",
644 ok(!ret
, "bt_value_map_insert_bool_entry() succeeds");
645 ret
= bt_value_map_insert_signed_integer_entry(map_obj
, "int2",
647 ok(!ret
, "bt_value_map_insert_signed_integer_entry() succeeds");
648 ret
= bt_value_map_insert_real_entry(map_obj
, "real2",
650 ok(!ret
, "bt_value_map_insert_real_entry() succeeds");
651 ret
= bt_value_map_insert_string_entry(map_obj
, "string2",
653 ok(!ret
, "bt_value_map_insert_string_entry() succeeds");
654 ret
= bt_value_map_insert_empty_array_entry(map_obj
, "array2", NULL
);
655 ok(!ret
, "bt_value_map_insert_empty_array_entry() succeeds");
656 ret
= bt_value_map_insert_empty_array_entry(map_obj
, "array3", &inserted_obj
);
657 ok(!ret
, "bt_value_map_insert_empty_array_entry() with returned value object succeeds");
659 "object returned by bt_value_map_insert_empty_array_entry() is not NULL");
660 ok(bt_value_is_array(inserted_obj
),
661 "object returned by bt_value_map_insert_empty_array_entry() is an array value");
662 ret
= bt_value_map_insert_empty_map_entry(map_obj
, "map2", NULL
);
663 ok(!ret
, "bt_value_map_insert_empty_map_entry() succeeds");
664 ret
= bt_value_map_insert_empty_map_entry(map_obj
, "map3", &inserted_obj
);
665 ok(!ret
, "bt_value_map_insert_empty_map_entry() with returned value object succeeds");
667 "object returned by bt_value_map_insert_empty_map_entry() is not NULL");
668 ok(bt_value_is_map(inserted_obj
),
669 "object returned by bt_value_map_insert_empty_map_entry() is an array value");
671 ok(bt_value_map_get_size(map_obj
) == 13,
672 "the bt_value_map_insert*() functions increment the map value object's size");
674 ok(!bt_value_map_has_entry(map_obj
, "hello"),
675 "map value object does not have key \"hello\"");
676 ok(bt_value_map_has_entry(map_obj
, "bt_bool"),
677 "map value object has key \"bt_bool\"");
678 ok(bt_value_map_has_entry(map_obj
, "uint"),
679 "map value object has key \"uint\"");
680 ok(bt_value_map_has_entry(map_obj
, "int"),
681 "map value object has key \"int\"");
682 ok(bt_value_map_has_entry(map_obj
, "real"),
683 "map value object has key \"real\"");
684 ok(bt_value_map_has_entry(map_obj
, "null"),
685 "map value object has key \"null\"");
686 ok(bt_value_map_has_entry(map_obj
, "bool2"),
687 "map value object has key \"bool2\"");
688 ok(bt_value_map_has_entry(map_obj
, "int2"),
689 "map value object has key \"int2\"");
690 ok(bt_value_map_has_entry(map_obj
, "real2"),
691 "map value object has key \"real2\"");
692 ok(bt_value_map_has_entry(map_obj
, "string2"),
693 "map value object has key \"string2\"");
694 ok(bt_value_map_has_entry(map_obj
, "array2"),
695 "map value object has key \"array2\"");
696 ok(bt_value_map_has_entry(map_obj
, "array3"),
697 "map value object has key \"array3\"");
698 ok(bt_value_map_has_entry(map_obj
, "map2"),
699 "map value object has key \"map2\"");
700 ok(bt_value_map_has_entry(map_obj
, "map3"),
701 "map value object has key \"map3\"");
703 ret
= bt_value_map_foreach_entry(map_obj
, test_map_foreach_cb_count
,
705 ok(ret
== BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED
&& count
== 3,
706 "bt_value_map_foreach_entry() breaks the loop when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT");
709 ret
= bt_value_map_foreach_entry(map_obj
, test_map_foreach_cb_count
,
711 ok(ret
== BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR
,
712 "bt_value_map_foreach_entry() fails when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR");
713 bt_current_thread_clear_error();
716 ret
= bt_value_map_foreach_entry(map_obj
, test_map_foreach_cb_count
,
718 ok(ret
== BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR
,
719 "bt_value_map_foreach_entry() fails when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR");
720 bt_current_thread_clear_error();
722 memset(&checklist
, 0, sizeof(checklist
));
723 ret
= bt_value_map_foreach_entry(map_obj
, test_map_foreach_cb_check
,
725 ok(ret
== BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK
,
726 "bt_value_map_foreach_entry() succeeds with test_map_foreach_cb_check()");
727 ok(checklist
.bool1
&& checklist
.uint
&& checklist
.int1
&&
728 checklist
.real1
&& checklist
.null1
&& checklist
.bool2
&&
729 checklist
.int2
&& checklist
.real2
&& checklist
.string2
&&
730 checklist
.array2
&& checklist
.map2
,
731 "bt_value_map_foreach_entry() iterates over all the map value object's elements");
733 BT_VALUE_PUT_REF_AND_RESET(map_obj
);
734 pass("putting an existing map value object does not cause a crash")
738 void test_types(void)
742 test_unsigned_integer();
743 test_signed_integer();
751 void test_is_equal_null(void)
753 ok(bt_value_is_equal(bt_value_null
, bt_value_null
),
754 "null value objects are equivalent");
758 void test_is_equal_bool(void)
761 bt_value_bool_create_init(BT_FALSE
);
763 bt_value_bool_create_init(BT_TRUE
);
765 bt_value_bool_create_init(BT_FALSE
);
767 BT_ASSERT(bool1
&& bool2
&& bool3
);
768 ok(!bt_value_is_equal(bt_value_null
, bool1
),
769 "cannot compare null value object and bt_bool value object");
770 ok(!bt_value_is_equal(bool1
, bool2
),
771 "boolean value objects are not equivalent (BT_FALSE and BT_TRUE)");
772 ok(bt_value_is_equal(bool1
, bool3
),
773 "boolean value objects are equivalent (BT_FALSE and BT_FALSE)");
775 BT_VALUE_PUT_REF_AND_RESET(bool1
);
776 BT_VALUE_PUT_REF_AND_RESET(bool2
);
777 BT_VALUE_PUT_REF_AND_RESET(bool3
);
781 void test_is_equal_unsigned_integer(void)
784 bt_value_integer_unsigned_create_init(10);
786 bt_value_integer_unsigned_create_init(23);
788 bt_value_integer_unsigned_create_init(10);
790 BT_ASSERT(int1
&& int2
&& int3
);
791 ok(!bt_value_is_equal(bt_value_null
, int1
),
792 "cannot compare null value object and unsigned integer value object");
793 ok(!bt_value_is_equal(int1
, int2
),
794 "unsigned integer value objects are not equivalent (10 and 23)");
795 ok(bt_value_is_equal(int1
, int3
),
796 "unsigned integer value objects are equivalent (10 and 10)");
798 BT_VALUE_PUT_REF_AND_RESET(int1
);
799 BT_VALUE_PUT_REF_AND_RESET(int2
);
800 BT_VALUE_PUT_REF_AND_RESET(int3
);
804 void test_is_equal_signed_integer(void)
807 bt_value_integer_signed_create_init(10);
809 bt_value_integer_signed_create_init(-23);
811 bt_value_integer_signed_create_init(10);
813 BT_ASSERT(int1
&& int2
&& int3
);
814 ok(!bt_value_is_equal(bt_value_null
, int1
),
815 "cannot compare null value object and signed integer value object");
816 ok(!bt_value_is_equal(int1
, int2
),
817 "signed integer value objects are not equivalent (10 and -23)");
818 ok(bt_value_is_equal(int1
, int3
),
819 "signed integer value objects are equivalent (10 and 10)");
821 BT_VALUE_PUT_REF_AND_RESET(int1
);
822 BT_VALUE_PUT_REF_AND_RESET(int2
);
823 BT_VALUE_PUT_REF_AND_RESET(int3
);
827 void test_is_equal_real(void)
830 bt_value_real_create_init(17.38);
832 bt_value_real_create_init(-14.23);
834 bt_value_real_create_init(17.38);
836 BT_ASSERT(real1
&& real2
&& real3
);
838 ok(!bt_value_is_equal(bt_value_null
, real1
),
839 "cannot compare null value object and real number value object");
840 ok(!bt_value_is_equal(real1
, real2
),
841 "real number value objects are not equivalent (17.38 and -14.23)");
842 ok(bt_value_is_equal(real1
, real3
),
843 "real number value objects are equivalent (17.38 and 17.38)");
845 BT_VALUE_PUT_REF_AND_RESET(real1
);
846 BT_VALUE_PUT_REF_AND_RESET(real2
);
847 BT_VALUE_PUT_REF_AND_RESET(real3
);
851 void test_is_equal_string(void)
854 bt_value_string_create_init("hello");
856 bt_value_string_create_init("bt_value");
858 bt_value_string_create_init("hello");
860 BT_ASSERT(string1
&& string2
&& string3
);
862 ok(!bt_value_is_equal(bt_value_null
, string1
),
863 "cannot compare null value object and string value object");
864 ok(!bt_value_is_equal(string1
, string2
),
865 "string value objects are not equivalent (\"hello\" and \"bt_value\")");
866 ok(bt_value_is_equal(string1
, string3
),
867 "string value objects are equivalent (\"hello\" and \"hello\")");
869 BT_VALUE_PUT_REF_AND_RESET(string1
);
870 BT_VALUE_PUT_REF_AND_RESET(string2
);
871 BT_VALUE_PUT_REF_AND_RESET(string3
);
875 void test_is_equal_array(void)
877 bt_value
*array1
= bt_value_array_create();
878 bt_value
*array2
= bt_value_array_create();
879 bt_value
*array3
= bt_value_array_create();
880 bt_value_array_append_element_status append_status
;
882 BT_ASSERT(array1
&& array2
&& array3
);
884 ok(bt_value_is_equal(array1
, array2
),
885 "empty array value objects are equivalent");
887 append_status
= bt_value_array_append_signed_integer_element(array1
, 23);
888 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
889 append_status
= bt_value_array_append_real_element(array1
, 14.2);
890 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
891 append_status
= bt_value_array_append_bool_element(array1
, BT_FALSE
);
892 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
893 append_status
= bt_value_array_append_real_element(array2
, 14.2);
894 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
895 append_status
= bt_value_array_append_signed_integer_element(array2
, 23);
896 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
897 append_status
= bt_value_array_append_bool_element(array2
, BT_FALSE
);
898 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
899 append_status
= bt_value_array_append_signed_integer_element(array3
, 23);
900 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
901 append_status
= bt_value_array_append_real_element(array3
, 14.2);
902 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
903 append_status
= bt_value_array_append_bool_element(array3
, BT_FALSE
);
904 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
905 BT_ASSERT(bt_value_array_get_length(array1
) == 3);
906 BT_ASSERT(bt_value_array_get_length(array2
) == 3);
907 BT_ASSERT(bt_value_array_get_length(array3
) == 3);
909 ok(!bt_value_is_equal(bt_value_null
, array1
),
910 "cannot compare null value object and array value object");
911 ok(!bt_value_is_equal(array1
, array2
),
912 "array value objects are not equivalent ([23, 14.2, BT_FALSE] and [14.2, 23, BT_FALSE])");
913 ok(bt_value_is_equal(array1
, array3
),
914 "array value objects are equivalent ([23, 14.2, BT_FALSE] and [23, 14.2, BT_FALSE])");
916 BT_VALUE_PUT_REF_AND_RESET(array1
);
917 BT_VALUE_PUT_REF_AND_RESET(array2
);
918 BT_VALUE_PUT_REF_AND_RESET(array3
);
922 void test_is_equal_map(void)
924 bt_value
*map1
= bt_value_map_create();
925 bt_value
*map2
= bt_value_map_create();
926 bt_value
*map3
= bt_value_map_create();
927 bt_value_map_insert_entry_status insert_status
;
929 BT_ASSERT(map1
&& map2
&& map3
);
931 ok(bt_value_is_equal(map1
, map2
),
932 "empty map value objects are equivalent");
935 insert_status
= bt_value_map_insert_signed_integer_entry(map1
, "one", 23);
936 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
937 insert_status
= bt_value_map_insert_real_entry(map1
, "two", 14.2);
938 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
939 insert_status
= bt_value_map_insert_bool_entry(map1
, "three",
941 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
942 insert_status
= bt_value_map_insert_real_entry(map2
, "one", 14.2);
943 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
944 insert_status
= bt_value_map_insert_signed_integer_entry(map2
, "two", 23);
945 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
946 insert_status
= bt_value_map_insert_bool_entry(map2
, "three",
948 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
949 insert_status
= bt_value_map_insert_bool_entry(map3
, "three",
951 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
952 insert_status
= bt_value_map_insert_signed_integer_entry(map3
, "one", 23);
953 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
954 insert_status
= bt_value_map_insert_real_entry(map3
, "two", 14.2);
955 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
956 BT_ASSERT(bt_value_map_get_size(map1
) == 3);
957 BT_ASSERT(bt_value_map_get_size(map2
) == 3);
958 BT_ASSERT(bt_value_map_get_size(map3
) == 3);
960 ok(!bt_value_is_equal(bt_value_null
, map1
),
961 "cannot compare null value object and map value object");
962 ok(!bt_value_is_equal(map1
, map2
),
963 "map value objects are not equivalent");
964 ok(bt_value_is_equal(map1
, map3
),
965 "map value objects are equivalent");
967 BT_VALUE_PUT_REF_AND_RESET(map1
);
968 BT_VALUE_PUT_REF_AND_RESET(map2
);
969 BT_VALUE_PUT_REF_AND_RESET(map3
);
973 void test_is_equal(void)
975 test_is_equal_null();
976 test_is_equal_bool();
977 test_is_equal_unsigned_integer();
978 test_is_equal_signed_integer();
979 test_is_equal_real();
980 test_is_equal_string();
981 test_is_equal_array();
989 * Here's the deal here. If we make sure that each value object
990 * of our deep copy has a different address than its source, and
991 * that bt_value_is_equal() returns BT_TRUE for the top-level
992 * value object, taking into account that we test the
993 * correctness of bt_value_is_equal() elsewhere, then the deep
996 bt_value
*null_copy_obj
;
997 bt_value
*bool_obj
, *bool_copy_obj
;
998 bt_value
*unsigned_integer_obj
, *unsigned_integer_copy_obj
;
999 bt_value
*signed_integer_obj
, *signed_integer_copy_obj
;
1000 bt_value
*real_obj
, *real_copy_obj
;
1001 bt_value
*string_obj
, *string_copy_obj
;
1002 bt_value
*array_obj
, *array_copy_obj
;
1003 bt_value
*map_obj
, *map_copy_obj
;
1004 bt_value_array_append_element_status append_status
;
1005 bt_value_map_insert_entry_status insert_status
;
1006 bt_value_copy_status copy_status
;
1008 bool_obj
= bt_value_bool_create_init(BT_TRUE
);
1009 unsigned_integer_obj
= bt_value_integer_unsigned_create_init(23);
1010 signed_integer_obj
= bt_value_integer_signed_create_init(-47);
1011 real_obj
= bt_value_real_create_init(-3.1416);
1012 string_obj
= bt_value_string_create_init("test");
1013 array_obj
= bt_value_array_create();
1014 map_obj
= bt_value_map_create();
1016 BT_ASSERT(bool_obj
&& unsigned_integer_obj
&& signed_integer_obj
&&
1017 real_obj
&& string_obj
&& array_obj
&& map_obj
);
1019 append_status
= bt_value_array_append_element(array_obj
, bool_obj
);
1020 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1021 append_status
= bt_value_array_append_element(array_obj
, unsigned_integer_obj
);
1022 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1023 append_status
= bt_value_array_append_element(array_obj
, signed_integer_obj
);
1024 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1025 append_status
= bt_value_array_append_element(array_obj
, real_obj
);
1026 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1027 append_status
= bt_value_array_append_element(array_obj
, bt_value_null
);
1028 BT_ASSERT(append_status
== BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK
);
1029 insert_status
= bt_value_map_insert_entry(map_obj
, "array", array_obj
);
1030 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1031 insert_status
= bt_value_map_insert_entry(map_obj
, "string", string_obj
);
1032 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1034 copy_status
= bt_value_copy(map_obj
, &map_copy_obj
);
1035 ok(copy_status
== BT_VALUE_COPY_STATUS_OK
&& map_copy_obj
,
1036 "bt_value_copy() succeeds");
1038 ok(map_obj
!= map_copy_obj
,
1039 "bt_value_copy() returns a different pointer (map)");
1040 string_copy_obj
= bt_value_map_borrow_entry_value(map_copy_obj
,
1042 ok(string_copy_obj
!= string_obj
,
1043 "bt_value_copy() returns a different pointer (string)");
1044 array_copy_obj
= bt_value_map_borrow_entry_value(map_copy_obj
,
1046 ok(array_copy_obj
!= array_obj
,
1047 "bt_value_copy() returns a different pointer (array)");
1048 bool_copy_obj
= bt_value_array_borrow_element_by_index(
1050 ok(bool_copy_obj
!= bool_obj
,
1051 "bt_value_copy() returns a different pointer (bool)");
1052 unsigned_integer_copy_obj
= bt_value_array_borrow_element_by_index(
1054 ok(unsigned_integer_copy_obj
!= unsigned_integer_obj
,
1055 "bt_value_copy() returns a different pointer (unsigned integer)");
1056 signed_integer_copy_obj
= bt_value_array_borrow_element_by_index(
1058 ok(signed_integer_copy_obj
!= signed_integer_obj
,
1059 "bt_value_copy() returns a different pointer (signed integer)");
1060 real_copy_obj
= bt_value_array_borrow_element_by_index(
1062 ok(real_copy_obj
!= real_obj
,
1063 "bt_value_copy() returns a different pointer (real)");
1064 null_copy_obj
= bt_value_array_borrow_element_by_index(
1066 ok(null_copy_obj
== bt_value_null
,
1067 "bt_value_copy() returns the same pointer (null)");
1069 ok(bt_value_is_equal(map_obj
, map_copy_obj
),
1070 "source and destination value objects have the same content");
1072 BT_VALUE_PUT_REF_AND_RESET(map_copy_obj
);
1073 BT_VALUE_PUT_REF_AND_RESET(bool_obj
);
1074 BT_VALUE_PUT_REF_AND_RESET(unsigned_integer_obj
);
1075 BT_VALUE_PUT_REF_AND_RESET(signed_integer_obj
);
1076 BT_VALUE_PUT_REF_AND_RESET(real_obj
);
1077 BT_VALUE_PUT_REF_AND_RESET(string_obj
);
1078 BT_VALUE_PUT_REF_AND_RESET(array_obj
);
1079 BT_VALUE_PUT_REF_AND_RESET(map_obj
);
1083 bt_bool
compare_map_elements(const bt_value
*map_a
, const bt_value
*map_b
,
1086 const bt_value
*elem_a
= NULL
;
1087 const bt_value
*elem_b
= NULL
;
1090 elem_a
= bt_value_map_borrow_entry_value_const(map_a
, key
);
1091 elem_b
= bt_value_map_borrow_entry_value_const(map_b
, key
);
1092 equal
= bt_value_is_equal(elem_a
, elem_b
);
1097 void test_extend(void)
1099 bt_value
*base_map
= bt_value_map_create();
1100 bt_value
*extension_map
= bt_value_map_create();
1101 bt_value
*extended_map
= NULL
;
1102 bt_value
*array
= bt_value_array_create();
1103 bt_value_map_insert_entry_status insert_status
;
1104 bt_value_copy_status copy_status
;
1105 bt_value_map_extend_status extend_status
;
1107 BT_ASSERT(base_map
);
1108 BT_ASSERT(extension_map
);
1110 insert_status
= bt_value_map_insert_bool_entry(base_map
, "file",
1112 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1113 insert_status
= bt_value_map_insert_bool_entry(base_map
, "edit",
1115 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1116 insert_status
= bt_value_map_insert_signed_integer_entry(base_map
,
1118 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1119 insert_status
= bt_value_map_insert_signed_integer_entry(base_map
, "find",
1121 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1122 insert_status
= bt_value_map_insert_bool_entry(extension_map
, "edit",
1124 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1125 insert_status
= bt_value_map_insert_signed_integer_entry(extension_map
,
1127 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1128 insert_status
= bt_value_map_insert_real_entry(extension_map
,
1130 BT_ASSERT(insert_status
== BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK
);
1131 copy_status
= bt_value_copy(base_map
, &extended_map
);
1132 BT_ASSERT(copy_status
== BT_VALUE_COPY_STATUS_OK
);
1133 extend_status
= bt_value_map_extend(extended_map
, extension_map
);
1134 ok(extend_status
== BT_VALUE_MAP_EXTEND_STATUS_OK
&&
1135 extended_map
, "bt_value_map_extend() succeeds");
1136 ok(bt_value_map_get_size(extended_map
) == 5,
1137 "bt_value_map_extend() returns a map object with the correct size");
1138 ok(compare_map_elements(base_map
,
1139 extended_map
, "file"),
1140 "bt_value_map_extend() picks the appropriate element (file)");
1141 ok(compare_map_elements(extension_map
,
1142 extended_map
, "edit"),
1143 "bt_value_map_extend() picks the appropriate element (edit)");
1144 ok(compare_map_elements(base_map
,
1145 extended_map
, "selection"),
1146 "bt_value_map_extend() picks the appropriate element (selection)");
1147 ok(compare_map_elements(extension_map
,
1148 extended_map
, "find"),
1149 "bt_value_map_extend() picks the appropriate element (find)");
1150 ok(compare_map_elements(extension_map
,
1151 extended_map
, "project"),
1152 "bt_value_map_extend() picks the appropriate element (project)");
1154 BT_VALUE_PUT_REF_AND_RESET(array
);
1155 BT_VALUE_PUT_REF_AND_RESET(base_map
);
1156 BT_VALUE_PUT_REF_AND_RESET(extension_map
);
1157 BT_VALUE_PUT_REF_AND_RESET(extended_map
);
1162 plan_tests(NR_TESTS
);
1167 return exit_status();