lib: make public reference count functions have strict types
[babeltrace.git] / tests / lib / test_bt_values.c
CommitLineData
dac5c838
PP
1/*
2 * test_bt_values.c
3 *
705b853d 4 * Babeltrace value objects tests
dac5c838
PP
5 *
6 * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
7 * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; under version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
05e21286 23#include <babeltrace/babeltrace.h>
25583cd0 24#include <babeltrace/assert-internal.h>
dac5c838
PP
25#include <string.h>
26#include "tap/tap.h"
27
601b0d3c 28#define NR_TESTS 147
8bbe269d 29
dac5c838
PP
30static
31void test_null(void)
32{
33 ok(bt_value_null, "bt_value_null is not NULL");
34 ok(bt_value_is_null(bt_value_null),
35 "bt_value_null is a null value object");
c5b9b441 36 bt_value_get_ref(bt_value_null);
dac5c838 37 pass("getting bt_value_null does not cause a crash");
c5b9b441 38 bt_value_put_ref(bt_value_null);
dac5c838 39 pass("putting bt_value_null does not cause a crash");
dac5c838
PP
40}
41
42static
43void test_bool(void)
44{
c55a9f58 45 bt_bool value;
dac5c838
PP
46 struct bt_value *obj;
47
05e21286 48 obj = bt_value_bool_create();
dac5c838 49 ok(obj && bt_value_is_bool(obj),
05e21286 50 "bt_value_bool_create() returns a boolean value object");
dac5c838 51
c55a9f58 52 value = BT_TRUE;
601b0d3c
PP
53 value = bt_value_bool_get(obj);
54 ok(!value, "default boolean value object value is BT_FALSE");
dac5c838 55
05e21286
PP
56 bt_value_bool_set(obj, BT_FALSE);
57 bt_value_bool_set(obj, BT_TRUE);
601b0d3c 58 value = bt_value_bool_get(obj);
05e21286 59 ok(value, "bt_value_bool_set() works");
dac5c838 60
c5b9b441 61 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
62 pass("putting an existing boolean value object does not cause a crash")
63
c55a9f58 64 value = BT_FALSE;
05e21286 65 obj = bt_value_bool_create_init(BT_TRUE);
dac5c838 66 ok(obj && bt_value_is_bool(obj),
05e21286 67 "bt_value_bool_create_init() returns a boolean value object");
601b0d3c
PP
68 value = bt_value_bool_get(obj);
69 ok(value,
05e21286 70 "bt_value_bool_create_init() sets the appropriate initial value");
dac5c838 71
c5b9b441 72 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
73}
74
75static
76void test_integer(void)
77{
dac5c838
PP
78 int64_t value;
79 struct bt_value *obj;
80
05e21286 81 obj = bt_value_integer_create();
dac5c838 82 ok(obj && bt_value_is_integer(obj),
05e21286 83 "bt_value_integer_create() returns an integer value object");
dac5c838 84
dac5c838 85 value = 1961;
601b0d3c
PP
86 value = bt_value_integer_get(obj);
87 ok(value == 0, "default integer value object value is 0");
dac5c838 88
05e21286 89 bt_value_integer_set(obj, -98765);
601b0d3c
PP
90 value = bt_value_integer_get(obj);
91 ok(value == -98765, "bt_private_integer_bool_set() works");
dac5c838 92
c5b9b441 93 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
94 pass("putting an existing integer value object does not cause a crash")
95
05e21286 96 obj = bt_value_integer_create_init(321456987);
dac5c838 97 ok(obj && bt_value_is_integer(obj),
05e21286 98 "bt_value_integer_create_init() returns an integer value object");
601b0d3c
PP
99 value = bt_value_integer_get(obj);
100 ok(value == 321456987,
05e21286 101 "bt_value_integer_create_init() sets the appropriate initial value");
dac5c838 102
c5b9b441 103 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
104}
105
106static
a373bf69 107void test_real(void)
dac5c838 108{
dac5c838
PP
109 double value;
110 struct bt_value *obj;
111
05e21286 112 obj = bt_value_real_create();
a373bf69 113 ok(obj && bt_value_is_real(obj),
05e21286 114 "bt_value_real_create() returns a real number value object");
dac5c838 115
dac5c838 116 value = 17.34;
601b0d3c
PP
117 value = bt_value_real_get(obj);
118 ok(value == 0.,
a373bf69 119 "default real number value object value is 0");
dac5c838 120
05e21286 121 bt_value_real_set(obj, -3.1416);
601b0d3c 122 value = bt_value_real_get(obj);
05e21286 123 ok(value == -3.1416, "bt_value_real_set() works");
dac5c838 124
c5b9b441 125 BT_VALUE_PUT_REF_AND_RESET(obj);
a373bf69 126 pass("putting an existing real number value object does not cause a crash")
dac5c838 127
05e21286 128 obj = bt_value_real_create_init(33.1649758);
a373bf69 129 ok(obj && bt_value_is_real(obj),
05e21286 130 "bt_value_real_create_init() returns a real number value object");
601b0d3c
PP
131 value = bt_value_real_get(obj);
132 ok(value == 33.1649758,
05e21286 133 "bt_value_real_create_init() sets the appropriate initial value");
dac5c838 134
c5b9b441 135 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
136}
137
138static
139void test_string(void)
140{
dac5c838
PP
141 const char *value;
142 struct bt_value *obj;
143
05e21286 144 obj = bt_value_string_create();
dac5c838 145 ok(obj && bt_value_is_string(obj),
05e21286 146 "bt_value_string_create() returns a string value object");
dac5c838 147
601b0d3c
PP
148 value = bt_value_string_get(obj);
149 ok(value && !strcmp(value, ""),
dac5c838
PP
150 "default string value object value is \"\"");
151
05e21286 152 bt_value_string_set(obj, "hello worldz");
601b0d3c
PP
153 value = bt_value_string_get(obj);
154 ok(value && !strcmp(value, "hello worldz"),
dac5c838
PP
155 "bt_value_string_get() works");
156
c5b9b441 157 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
158 pass("putting an existing string value object does not cause a crash")
159
05e21286 160 obj = bt_value_string_create_init("initial value");
dac5c838 161 ok(obj && bt_value_is_string(obj),
05e21286 162 "bt_value_string_create_init() returns a string value object");
601b0d3c
PP
163 value = bt_value_string_get(obj);
164 ok(value && !strcmp(value, "initial value"),
05e21286 165 "bt_value_string_create_init() sets the appropriate initial value");
dac5c838 166
c5b9b441 167 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
168}
169
170static
171void test_array(void)
172{
173 int ret;
c55a9f58 174 bt_bool bool_value;
dac5c838 175 int64_t int_value;
a373bf69 176 double real_value;
dac5c838
PP
177 struct bt_value *obj;
178 const char *string_value;
179 struct bt_value *array_obj;
180
05e21286 181 array_obj = bt_value_array_create();
dac5c838 182 ok(array_obj && bt_value_is_array(array_obj),
05e21286 183 "bt_value_array_create() returns an array value object");
dac5c838
PP
184 ok(bt_value_array_is_empty(array_obj),
185 "initial array value object size is 0");
dac5c838 186
05e21286
PP
187 obj = bt_value_integer_create_init(345);
188 ret = bt_value_array_append_element(array_obj, obj);
c5b9b441 189 BT_VALUE_PUT_REF_AND_RESET(obj);
05e21286
PP
190 obj = bt_value_real_create_init(-17.45);
191 ret |= bt_value_array_append_element(array_obj, obj);
c5b9b441 192 BT_VALUE_PUT_REF_AND_RESET(obj);
05e21286
PP
193 obj = bt_value_bool_create_init(BT_TRUE);
194 ret |= bt_value_array_append_element(array_obj, obj);
c5b9b441 195 BT_VALUE_PUT_REF_AND_RESET(obj);
05e21286 196 ret |= bt_value_array_append_element(array_obj,
da91b29a 197 bt_value_null);
05e21286 198 ok(!ret, "bt_value_array_append_element() succeeds");
07208d85 199 ok(bt_value_array_get_size(array_obj) == 4,
dac5c838
PP
200 "appending an element to an array value object increment its size");
201
07208d85 202 obj = bt_value_array_borrow_element_by_index(array_obj, 0);
dac5c838 203 ok(obj && bt_value_is_integer(obj),
07208d85 204 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (integer)");
601b0d3c
PP
205 int_value = bt_value_integer_get(obj);
206 ok(int_value == 345,
07208d85
PP
207 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (integer)");
208 obj = bt_value_array_borrow_element_by_index(array_obj, 1);
a373bf69 209 ok(obj && bt_value_is_real(obj),
07208d85 210 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)");
601b0d3c
PP
211 real_value = bt_value_real_get(obj);
212 ok(real_value == -17.45,
07208d85
PP
213 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (real number)");
214 obj = bt_value_array_borrow_element_by_index(array_obj, 2);
dac5c838 215 ok(obj && bt_value_is_bool(obj),
07208d85 216 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)");
601b0d3c
PP
217 bool_value = bt_value_bool_get(obj);
218 ok(bool_value,
07208d85
PP
219 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (boolean)");
220 obj = bt_value_array_borrow_element_by_index(array_obj, 3);
dac5c838 221 ok(obj == bt_value_null,
07208d85 222 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)");
dac5c838 223
05e21286 224 obj = bt_value_integer_create_init(1001);
25583cd0 225 BT_ASSERT(obj);
05e21286 226 ok(!bt_value_array_set_element_by_index(array_obj, 2, obj),
07208d85 227 "bt_value_array_set_element_by_index() succeeds");
c5b9b441 228 BT_VALUE_PUT_REF_AND_RESET(obj);
07208d85 229 obj = bt_value_array_borrow_element_by_index(array_obj, 2);
dac5c838 230 ok(obj && bt_value_is_integer(obj),
07208d85 231 "bt_value_array_set_element_by_index() inserts an value object with the appropriate type");
601b0d3c 232 int_value = bt_value_integer_get(obj);
25583cd0 233 BT_ASSERT(!ret);
dac5c838 234 ok(int_value == 1001,
07208d85
PP
235 "bt_value_array_set_element_by_index() inserts an value object with the appropriate value");
236
05e21286 237 ret = bt_value_array_append_bool_element(array_obj,
da91b29a 238 BT_FALSE);
05e21286
PP
239 ok(!ret, "bt_value_array_append_bool_element() succeeds");
240 ret = bt_value_array_append_integer_element(array_obj,
da91b29a 241 98765);
05e21286
PP
242 ok(!ret, "bt_value_array_append_integer_element() succeeds");
243 ret = bt_value_array_append_real_element(array_obj,
da91b29a 244 2.49578);
05e21286
PP
245 ok(!ret, "bt_value_array_append_real_element() succeeds");
246 ret = bt_value_array_append_string_element(array_obj,
da91b29a 247 "bt_value");
05e21286
PP
248 ok(!ret, "bt_value_array_append_string_element() succeeds");
249 ret = bt_value_array_append_empty_array_element(array_obj);
250 ok(!ret, "bt_value_array_append_empty_array_element() succeeds");
251 ret = bt_value_array_append_empty_map_element(array_obj);
252 ok(!ret, "bt_value_array_append_empty_map_element() succeeds");
07208d85
PP
253
254 ok(bt_value_array_get_size(array_obj) == 10,
05e21286 255 "the bt_value_array_append_element_*() functions increment the array value object's size");
dac5c838
PP
256 ok(!bt_value_array_is_empty(array_obj),
257 "map value object is not empty");
258
07208d85 259 obj = bt_value_array_borrow_element_by_index(array_obj, 4);
dac5c838 260 ok(obj && bt_value_is_bool(obj),
05e21286 261 "bt_value_array_append_bool_element() appends a boolean value object");
601b0d3c
PP
262 bool_value = bt_value_bool_get(obj);
263 ok(!bool_value,
05e21286 264 "bt_value_array_append_bool_element() appends the appropriate value");
07208d85 265 obj = bt_value_array_borrow_element_by_index(array_obj, 5);
dac5c838 266 ok(obj && bt_value_is_integer(obj),
05e21286 267 "bt_value_array_append_integer_element() appends an integer value object");
601b0d3c
PP
268 int_value = bt_value_integer_get(obj);
269 ok(int_value == 98765,
05e21286 270 "bt_value_array_append_integer_element() appends the appropriate value");
07208d85 271 obj = bt_value_array_borrow_element_by_index(array_obj, 6);
a373bf69 272 ok(obj && bt_value_is_real(obj),
05e21286 273 "bt_value_array_append_real_element() appends a real number value object");
601b0d3c
PP
274 real_value = bt_value_real_get(obj);
275 ok(real_value == 2.49578,
05e21286 276 "bt_value_array_append_real_element() appends the appropriate value");
07208d85 277 obj = bt_value_array_borrow_element_by_index(array_obj, 7);
dac5c838 278 ok(obj && bt_value_is_string(obj),
05e21286 279 "bt_value_array_append_string_element() appends a string value object");
601b0d3c 280 string_value = bt_value_string_get(obj);
dac5c838 281 ok(!ret && string_value && !strcmp(string_value, "bt_value"),
05e21286 282 "bt_value_array_append_string_element() appends the appropriate value");
07208d85 283 obj = bt_value_array_borrow_element_by_index(array_obj, 8);
dac5c838 284 ok(obj && bt_value_is_array(obj),
05e21286 285 "bt_value_array_append_empty_array_element() appends an array value object");
dac5c838 286 ok(bt_value_array_is_empty(obj),
05e21286 287 "bt_value_array_append_empty_array_element() an empty array value object");
07208d85 288 obj = bt_value_array_borrow_element_by_index(array_obj, 9);
dac5c838 289 ok(obj && bt_value_is_map(obj),
05e21286 290 "bt_value_array_append_empty_map_element() appends a map value object");
dac5c838 291 ok(bt_value_map_is_empty(obj),
05e21286 292 "bt_value_array_append_empty_map_element() an empty map value object");
dac5c838 293
c5b9b441 294 BT_VALUE_PUT_REF_AND_RESET(array_obj);
dac5c838
PP
295 pass("putting an existing array value object does not cause a crash")
296}
297
298static
c55a9f58 299bt_bool test_map_foreach_cb_count(const char *key, struct bt_value *object,
dac5c838
PP
300 void *data)
301{
302 int *count = data;
303
304 if (*count == 3) {
c55a9f58 305 return BT_FALSE;
dac5c838
PP
306 }
307
308 (*count)++;
309
c55a9f58 310 return BT_TRUE;
dac5c838
PP
311}
312
313struct map_foreach_checklist {
c55a9f58
PP
314 bt_bool bool1;
315 bt_bool int1;
a373bf69 316 bt_bool real1;
c55a9f58
PP
317 bt_bool null1;
318 bt_bool bool2;
319 bt_bool int2;
a373bf69 320 bt_bool real2;
c55a9f58
PP
321 bt_bool string2;
322 bt_bool array2;
323 bt_bool map2;
dac5c838
PP
324};
325
326static
c55a9f58 327bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object,
dac5c838
PP
328 void *data)
329{
dac5c838
PP
330 struct map_foreach_checklist *checklist = data;
331
c55a9f58 332 if (!strcmp(key, "bt_bool")) {
dac5c838 333 if (checklist->bool1) {
c55a9f58 334 fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\"");
dac5c838 335 } else {
c55a9f58 336 bt_bool val = BT_FALSE;
dac5c838 337
601b0d3c 338 val = bt_value_bool_get(object);
dac5c838
PP
339
340 if (val) {
c55a9f58
PP
341 pass("test_map_foreach_cb_check(): \"bt_bool\" value object has the right value");
342 checklist->bool1 = BT_TRUE;
dac5c838 343 } else {
c55a9f58 344 fail("test_map_foreach_cb_check(): \"bt_bool\" value object has the wrong value");
dac5c838
PP
345 }
346 }
347 } else if (!strcmp(key, "int")) {
348 if (checklist->int1) {
349 fail("test_map_foreach_cb_check(): duplicate key \"int\"");
350 } else {
351 int64_t val = 0;
352
601b0d3c 353 val = bt_value_integer_get(object);
dac5c838
PP
354
355 if (val == 19457) {
356 pass("test_map_foreach_cb_check(): \"int\" value object has the right value");
c55a9f58 357 checklist->int1 = BT_TRUE;
dac5c838
PP
358 } else {
359 fail("test_map_foreach_cb_check(): \"int\" value object has the wrong value");
360 }
361 }
a373bf69
PP
362 } else if (!strcmp(key, "real")) {
363 if (checklist->real1) {
364 fail("test_map_foreach_cb_check(): duplicate key \"real\"");
dac5c838
PP
365 } else {
366 double val = 0;
367
601b0d3c 368 val = bt_value_real_get(object);
dac5c838
PP
369
370 if (val == 5.444) {
a373bf69
PP
371 pass("test_map_foreach_cb_check(): \"real\" value object has the right value");
372 checklist->real1 = BT_TRUE;
dac5c838 373 } else {
a373bf69 374 fail("test_map_foreach_cb_check(): \"real\" value object has the wrong value");
dac5c838
PP
375 }
376 }
377 } else if (!strcmp(key, "null")) {
378 if (checklist->null1) {
c55a9f58 379 fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\"");
dac5c838
PP
380 } else {
381 ok(bt_value_is_null(object), "test_map_foreach_cb_check(): success getting \"null\" value object");
c55a9f58 382 checklist->null1 = BT_TRUE;
dac5c838
PP
383 }
384 } else if (!strcmp(key, "bool2")) {
385 if (checklist->bool2) {
386 fail("test_map_foreach_cb_check(): duplicate key \"bool2\"");
387 } else {
c55a9f58 388 bt_bool val = BT_FALSE;
dac5c838 389
601b0d3c 390 val = bt_value_bool_get(object);
dac5c838
PP
391
392 if (val) {
393 pass("test_map_foreach_cb_check(): \"bool2\" value object has the right value");
c55a9f58 394 checklist->bool2 = BT_TRUE;
dac5c838
PP
395 } else {
396 fail("test_map_foreach_cb_check(): \"bool2\" value object has the wrong value");
397 }
398 }
399 } else if (!strcmp(key, "int2")) {
400 if (checklist->int2) {
401 fail("test_map_foreach_cb_check(): duplicate key \"int2\"");
402 } else {
403 int64_t val = 0;
404
601b0d3c 405 val = bt_value_integer_get(object);
dac5c838
PP
406
407 if (val == 98765) {
408 pass("test_map_foreach_cb_check(): \"int2\" value object has the right value");
c55a9f58 409 checklist->int2 = BT_TRUE;
dac5c838
PP
410 } else {
411 fail("test_map_foreach_cb_check(): \"int2\" value object has the wrong value");
412 }
413 }
a373bf69
PP
414 } else if (!strcmp(key, "real2")) {
415 if (checklist->real2) {
416 fail("test_map_foreach_cb_check(): duplicate key \"real2\"");
dac5c838
PP
417 } else {
418 double val = 0;
419
601b0d3c 420 val = bt_value_real_get(object);
dac5c838
PP
421
422 if (val == -49.0001) {
a373bf69
PP
423 pass("test_map_foreach_cb_check(): \"real2\" value object has the right value");
424 checklist->real2 = BT_TRUE;
dac5c838 425 } else {
a373bf69 426 fail("test_map_foreach_cb_check(): \"real2\" value object has the wrong value");
dac5c838
PP
427 }
428 }
429 } else if (!strcmp(key, "string2")) {
430 if (checklist->string2) {
431 fail("test_map_foreach_cb_check(): duplicate key \"string2\"");
432 } else {
433 const char *val;
434
601b0d3c 435 val = bt_value_string_get(object);
dac5c838
PP
436
437 if (val && !strcmp(val, "bt_value")) {
438 pass("test_map_foreach_cb_check(): \"string2\" value object has the right value");
c55a9f58 439 checklist->string2 = BT_TRUE;
dac5c838
PP
440 } else {
441 fail("test_map_foreach_cb_check(): \"string2\" value object has the wrong value");
442 }
443 }
444 } else if (!strcmp(key, "array2")) {
445 if (checklist->array2) {
446 fail("test_map_foreach_cb_check(): duplicate key \"array2\"");
447 } else {
448 ok(bt_value_is_array(object), "test_map_foreach_cb_check(): success getting \"array2\" value object");
449 ok(bt_value_array_is_empty(object),
450 "test_map_foreach_cb_check(): \"array2\" value object is empty");
c55a9f58 451 checklist->array2 = BT_TRUE;
dac5c838
PP
452 }
453 } else if (!strcmp(key, "map2")) {
454 if (checklist->map2) {
455 fail("test_map_foreach_cb_check(): duplicate key \"map2\"");
456 } else {
457 ok(bt_value_is_map(object), "test_map_foreach_cb_check(): success getting \"map2\" value object");
458 ok(bt_value_map_is_empty(object),
459 "test_map_foreach_cb_check(): \"map2\" value object is empty");
c55a9f58 460 checklist->map2 = BT_TRUE;
dac5c838
PP
461 }
462 } else {
da91b29a
PP
463 fail("test_map_foreach_cb_check(): unknown map key \"%s\"",
464 key);
dac5c838
PP
465 }
466
c55a9f58 467 return BT_TRUE;
dac5c838
PP
468}
469
470static
471void test_map(void)
472{
473 int ret;
474 int count = 0;
c55a9f58 475 bt_bool bool_value;
dac5c838 476 int64_t int_value;
a373bf69 477 double real_value;
dac5c838
PP
478 struct bt_value *obj;
479 struct bt_value *map_obj;
480 struct map_foreach_checklist checklist;
481
05e21286 482 map_obj = bt_value_map_create();
dac5c838 483 ok(map_obj && bt_value_is_map(map_obj),
05e21286 484 "bt_value_map_create() returns a map value object");
07208d85 485 ok(bt_value_map_get_size(map_obj) == 0,
dac5c838 486 "initial map value object size is 0");
dac5c838 487
05e21286
PP
488 obj = bt_value_integer_create_init(19457);
489 ret = bt_value_map_insert_entry(map_obj, "int", obj);
c5b9b441 490 BT_VALUE_PUT_REF_AND_RESET(obj);
05e21286
PP
491 obj = bt_value_real_create_init(5.444);
492 ret |= bt_value_map_insert_entry(map_obj, "real", obj);
c5b9b441 493 BT_VALUE_PUT_REF_AND_RESET(obj);
05e21286
PP
494 obj = bt_value_bool_create();
495 ret |= bt_value_map_insert_entry(map_obj, "bt_bool", obj);
c5b9b441 496 BT_VALUE_PUT_REF_AND_RESET(obj);
05e21286 497 ret |= bt_value_map_insert_entry(map_obj, "null",
da91b29a 498 bt_value_null);
05e21286 499 ok(!ret, "bt_value_map_insert_entry() succeeds");
07208d85 500 ok(bt_value_map_get_size(map_obj) == 4,
dac5c838
PP
501 "inserting an element into a map value object increment its size");
502
05e21286
PP
503 obj = bt_value_bool_create_init(BT_TRUE);
504 ret = bt_value_map_insert_entry(map_obj, "bt_bool", obj);
c5b9b441 505 BT_VALUE_PUT_REF_AND_RESET(obj);
05e21286 506 ok(!ret, "bt_value_map_insert_entry() accepts an existing key");
dac5c838 507
07208d85
PP
508 obj = bt_value_map_borrow_entry_value(map_obj, "life");
509 ok(!obj, "bt_value_map_borrow_entry_value() returns NULL with an non existing key");
510 obj = bt_value_map_borrow_entry_value(map_obj, "real");
a373bf69 511 ok(obj && bt_value_is_real(obj),
07208d85 512 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (real)");
601b0d3c
PP
513 real_value = bt_value_real_get(obj);
514 ok(real_value == 5.444,
07208d85
PP
515 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (real)");
516 obj = bt_value_map_borrow_entry_value(map_obj, "int");
dac5c838 517 ok(obj && bt_value_is_integer(obj),
07208d85 518 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (integer)");
601b0d3c
PP
519 int_value = bt_value_integer_get(obj);
520 ok(int_value == 19457,
07208d85
PP
521 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (integer)");
522 obj = bt_value_map_borrow_entry_value(map_obj, "null");
dac5c838 523 ok(obj && bt_value_is_null(obj),
07208d85
PP
524 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (null)");
525 obj = bt_value_map_borrow_entry_value(map_obj, "bt_bool");
dac5c838 526 ok(obj && bt_value_is_bool(obj),
07208d85 527 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (boolean)");
601b0d3c
PP
528 bool_value = bt_value_bool_get(obj);
529 ok(bool_value,
07208d85
PP
530 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (boolean)");
531
05e21286 532 ret = bt_value_map_insert_bool_entry(map_obj, "bool2",
da91b29a 533 BT_TRUE);
05e21286
PP
534 ok(!ret, "bt_value_map_insert_bool_entry() succeeds");
535 ret = bt_value_map_insert_integer_entry(map_obj, "int2",
da91b29a 536 98765);
05e21286
PP
537 ok(!ret, "bt_value_map_insert_integer_entry() succeeds");
538 ret = bt_value_map_insert_real_entry(map_obj, "real2",
da91b29a 539 -49.0001);
05e21286
PP
540 ok(!ret, "bt_value_map_insert_real_entry() succeeds");
541 ret = bt_value_map_insert_string_entry(map_obj, "string2",
da91b29a 542 "bt_value");
05e21286
PP
543 ok(!ret, "bt_value_map_insert_string_entry() succeeds");
544 ret = bt_value_map_insert_empty_array_entry(map_obj,
da91b29a 545 "array2");
05e21286
PP
546 ok(!ret, "bt_value_map_insert_empty_array_entry() succeeds");
547 ret = bt_value_map_insert_empty_map_entry(map_obj, "map2");
548 ok(!ret, "bt_value_map_insert_empty_map_entry() succeeds");
07208d85
PP
549
550 ok(bt_value_map_get_size(map_obj) == 10,
dac5c838
PP
551 "the bt_value_map_insert*() functions increment the map value object's size");
552
07208d85 553 ok(!bt_value_map_has_entry(map_obj, "hello"),
dac5c838 554 "map value object does not have key \"hello\"");
07208d85 555 ok(bt_value_map_has_entry(map_obj, "bt_bool"),
c55a9f58 556 "map value object has key \"bt_bool\"");
07208d85 557 ok(bt_value_map_has_entry(map_obj, "int"),
dac5c838 558 "map value object has key \"int\"");
07208d85 559 ok(bt_value_map_has_entry(map_obj, "real"),
a373bf69 560 "map value object has key \"real\"");
07208d85 561 ok(bt_value_map_has_entry(map_obj, "null"),
dac5c838 562 "map value object has key \"null\"");
07208d85 563 ok(bt_value_map_has_entry(map_obj, "bool2"),
dac5c838 564 "map value object has key \"bool2\"");
07208d85 565 ok(bt_value_map_has_entry(map_obj, "int2"),
dac5c838 566 "map value object has key \"int2\"");
07208d85 567 ok(bt_value_map_has_entry(map_obj, "real2"),
a373bf69 568 "map value object has key \"real2\"");
07208d85 569 ok(bt_value_map_has_entry(map_obj, "string2"),
dac5c838 570 "map value object has key \"string2\"");
07208d85 571 ok(bt_value_map_has_entry(map_obj, "array2"),
dac5c838 572 "map value object has key \"array2\"");
07208d85 573 ok(bt_value_map_has_entry(map_obj, "map2"),
dac5c838
PP
574 "map value object has key \"map2\"");
575
da91b29a
PP
576 ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_count,
577 &count);
f6ccaed9 578 ok(ret == BT_VALUE_STATUS_CANCELED && count == 3,
07208d85 579 "bt_value_map_foreach_entry() breaks the loop when the user function returns BT_FALSE");
dac5c838
PP
580
581 memset(&checklist, 0, sizeof(checklist));
07208d85 582 ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_check,
dac5c838
PP
583 &checklist);
584 ok(ret == BT_VALUE_STATUS_OK,
07208d85 585 "bt_value_map_foreach_entry() succeeds with test_map_foreach_cb_check()");
a373bf69 586 ok(checklist.bool1 && checklist.int1 && checklist.real1 &&
dac5c838 587 checklist.null1 && checklist.bool2 && checklist.int2 &&
a373bf69 588 checklist.real2 && checklist.string2 &&
dac5c838 589 checklist.array2 && checklist.map2,
07208d85 590 "bt_value_map_foreach_entry() iterates over all the map value object's elements");
dac5c838 591
c5b9b441 592 BT_VALUE_PUT_REF_AND_RESET(map_obj);
dac5c838
PP
593 pass("putting an existing map value object does not cause a crash")
594}
595
596static
597void test_types(void)
598{
599 test_null();
600 test_bool();
601 test_integer();
a373bf69 602 test_real();
dac5c838
PP
603 test_string();
604 test_array();
605 test_map();
606}
607
608static
609void test_compare_null(void)
610{
dac5c838
PP
611 ok(bt_value_compare(bt_value_null, bt_value_null),
612 "null value objects are equivalent");
613}
614
615static
616void test_compare_bool(void)
617{
05e21286
PP
618 struct bt_value *bool1 =
619 bt_value_bool_create_init(BT_FALSE);
620 struct bt_value *bool2 =
621 bt_value_bool_create_init(BT_TRUE);
622 struct bt_value *bool3 =
623 bt_value_bool_create_init(BT_FALSE);
dac5c838 624
25583cd0 625 BT_ASSERT(bool1 && bool2 && bool3);
da91b29a 626 ok(!bt_value_compare(bt_value_null,
05e21286 627 bool1),
c55a9f58 628 "cannot compare null value object and bt_bool value object");
05e21286
PP
629 ok(!bt_value_compare(bool1,
630 bool2),
c55a9f58 631 "boolean value objects are not equivalent (BT_FALSE and BT_TRUE)");
05e21286
PP
632 ok(bt_value_compare(bool1,
633 bool3),
c55a9f58 634 "boolean value objects are equivalent (BT_FALSE and BT_FALSE)");
dac5c838 635
c5b9b441
PP
636 BT_VALUE_PUT_REF_AND_RESET(bool1);
637 BT_VALUE_PUT_REF_AND_RESET(bool2);
638 BT_VALUE_PUT_REF_AND_RESET(bool3);
dac5c838
PP
639}
640
641static
642void test_compare_integer(void)
643{
05e21286
PP
644 struct bt_value *int1 =
645 bt_value_integer_create_init(10);
646 struct bt_value *int2 =
647 bt_value_integer_create_init(-23);
648 struct bt_value *int3 =
649 bt_value_integer_create_init(10);
dac5c838 650
25583cd0 651 BT_ASSERT(int1 && int2 && int3);
da91b29a 652 ok(!bt_value_compare(bt_value_null,
05e21286 653 int1),
dac5c838 654 "cannot compare null value object and integer value object");
05e21286
PP
655 ok(!bt_value_compare(int1,
656 int2),
dac5c838 657 "integer value objects are not equivalent (10 and -23)");
05e21286
PP
658 ok(bt_value_compare(int1,
659 int3),
dac5c838
PP
660 "integer value objects are equivalent (10 and 10)");
661
c5b9b441
PP
662 BT_VALUE_PUT_REF_AND_RESET(int1);
663 BT_VALUE_PUT_REF_AND_RESET(int2);
664 BT_VALUE_PUT_REF_AND_RESET(int3);
dac5c838
PP
665}
666
667static
a373bf69 668void test_compare_real(void)
dac5c838 669{
05e21286
PP
670 struct bt_value *real1 =
671 bt_value_real_create_init(17.38);
672 struct bt_value *real2 =
673 bt_value_real_create_init(-14.23);
674 struct bt_value *real3 =
675 bt_value_real_create_init(17.38);
a373bf69
PP
676
677 BT_ASSERT(real1 && real2 && real3);
678
da91b29a 679 ok(!bt_value_compare(bt_value_null,
05e21286 680 real1),
a373bf69 681 "cannot compare null value object and real number value object");
05e21286
PP
682 ok(!bt_value_compare(real1,
683 real2),
a373bf69 684 "real number value objects are not equivalent (17.38 and -14.23)");
05e21286
PP
685 ok(bt_value_compare(real1,
686 real3),
a373bf69
PP
687 "real number value objects are equivalent (17.38 and 17.38)");
688
c5b9b441
PP
689 BT_VALUE_PUT_REF_AND_RESET(real1);
690 BT_VALUE_PUT_REF_AND_RESET(real2);
691 BT_VALUE_PUT_REF_AND_RESET(real3);
dac5c838
PP
692}
693
694static
695void test_compare_string(void)
696{
05e21286
PP
697 struct bt_value *string1 =
698 bt_value_string_create_init("hello");
699 struct bt_value *string2 =
700 bt_value_string_create_init("bt_value");
701 struct bt_value *string3 =
702 bt_value_string_create_init("hello");
dac5c838 703
25583cd0 704 BT_ASSERT(string1 && string2 && string3);
dac5c838 705
da91b29a 706 ok(!bt_value_compare(bt_value_null,
05e21286 707 string1),
dac5c838 708 "cannot compare null value object and string value object");
05e21286
PP
709 ok(!bt_value_compare(string1,
710 string2),
dac5c838 711 "string value objects are not equivalent (\"hello\" and \"bt_value\")");
05e21286
PP
712 ok(bt_value_compare(string1,
713 string3),
dac5c838
PP
714 "string value objects are equivalent (\"hello\" and \"hello\")");
715
c5b9b441
PP
716 BT_VALUE_PUT_REF_AND_RESET(string1);
717 BT_VALUE_PUT_REF_AND_RESET(string2);
718 BT_VALUE_PUT_REF_AND_RESET(string3);
dac5c838
PP
719}
720
721static
722void test_compare_array(void)
723{
05e21286
PP
724 struct bt_value *array1 = bt_value_array_create();
725 struct bt_value *array2 = bt_value_array_create();
726 struct bt_value *array3 = bt_value_array_create();
da91b29a 727 enum bt_value_status status;
dac5c838 728
25583cd0 729 BT_ASSERT(array1 && array2 && array3);
dac5c838 730
05e21286
PP
731 ok(bt_value_compare(array1,
732 array2),
dac5c838
PP
733 "empty array value objects are equivalent");
734
05e21286 735 status = bt_value_array_append_integer_element(array1, 23);
da91b29a 736 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 737 status = bt_value_array_append_real_element(array1, 14.2);
da91b29a 738 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 739 status = bt_value_array_append_bool_element(array1, BT_FALSE);
da91b29a 740 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 741 status = bt_value_array_append_real_element(array2, 14.2);
da91b29a 742 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 743 status = bt_value_array_append_integer_element(array2, 23);
da91b29a 744 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 745 status = bt_value_array_append_bool_element(array2, BT_FALSE);
da91b29a 746 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 747 status = bt_value_array_append_integer_element(array3, 23);
da91b29a 748 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 749 status = bt_value_array_append_real_element(array3, 14.2);
da91b29a 750 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 751 status = bt_value_array_append_bool_element(array3, BT_FALSE);
da91b29a 752 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286
PP
753 BT_ASSERT(bt_value_array_get_size(array1) == 3);
754 BT_ASSERT(bt_value_array_get_size(array2) == 3);
755 BT_ASSERT(bt_value_array_get_size(array3) == 3);
da91b29a
PP
756
757 ok(!bt_value_compare(bt_value_null,
05e21286 758 array1),
dac5c838 759 "cannot compare null value object and array value object");
05e21286
PP
760 ok(!bt_value_compare(array1,
761 array2),
c55a9f58 762 "array value objects are not equivalent ([23, 14.2, BT_FALSE] and [14.2, 23, BT_FALSE])");
05e21286
PP
763 ok(bt_value_compare(array1,
764 array3),
c55a9f58 765 "array value objects are equivalent ([23, 14.2, BT_FALSE] and [23, 14.2, BT_FALSE])");
dac5c838 766
c5b9b441
PP
767 BT_VALUE_PUT_REF_AND_RESET(array1);
768 BT_VALUE_PUT_REF_AND_RESET(array2);
769 BT_VALUE_PUT_REF_AND_RESET(array3);
dac5c838
PP
770}
771
772static
773void test_compare_map(void)
774{
05e21286
PP
775 struct bt_value *map1 = bt_value_map_create();
776 struct bt_value *map2 = bt_value_map_create();
777 struct bt_value *map3 = bt_value_map_create();
da91b29a 778 enum bt_value_status status;
dac5c838 779
25583cd0 780 BT_ASSERT(map1 && map2 && map3);
dac5c838 781
05e21286
PP
782 ok(bt_value_compare(map1,
783 map2),
dac5c838
PP
784 "empty map value objects are equivalent");
785
da91b29a 786
05e21286 787 status = bt_value_map_insert_integer_entry(map1, "one", 23);
da91b29a 788 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 789 status = bt_value_map_insert_real_entry(map1, "two", 14.2);
da91b29a 790 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 791 status = bt_value_map_insert_bool_entry(map1, "three",
da91b29a
PP
792 BT_FALSE);
793 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 794 status = bt_value_map_insert_real_entry(map2, "one", 14.2);
da91b29a 795 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 796 status = bt_value_map_insert_integer_entry(map2, "two", 23);
da91b29a 797 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 798 status = bt_value_map_insert_bool_entry(map2, "three",
da91b29a
PP
799 BT_FALSE);
800 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 801 status = bt_value_map_insert_bool_entry(map3, "three",
da91b29a
PP
802 BT_FALSE);
803 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 804 status = bt_value_map_insert_integer_entry(map3, "one", 23);
da91b29a 805 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 806 status = bt_value_map_insert_real_entry(map3, "two", 14.2);
da91b29a 807 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286
PP
808 BT_ASSERT(bt_value_map_get_size(map1) == 3);
809 BT_ASSERT(bt_value_map_get_size(map2) == 3);
810 BT_ASSERT(bt_value_map_get_size(map3) == 3);
da91b29a
PP
811
812 ok(!bt_value_compare(bt_value_null,
05e21286 813 map1),
dac5c838 814 "cannot compare null value object and map value object");
05e21286
PP
815 ok(!bt_value_compare(map1,
816 map2),
dac5c838 817 "map value objects are not equivalent");
05e21286
PP
818 ok(bt_value_compare(map1,
819 map3),
dac5c838
PP
820 "map value objects are equivalent");
821
c5b9b441
PP
822 BT_VALUE_PUT_REF_AND_RESET(map1);
823 BT_VALUE_PUT_REF_AND_RESET(map2);
824 BT_VALUE_PUT_REF_AND_RESET(map3);
dac5c838
PP
825}
826
827static
828void test_compare(void)
829{
dac5c838
PP
830 test_compare_null();
831 test_compare_bool();
832 test_compare_integer();
a373bf69 833 test_compare_real();
dac5c838
PP
834 test_compare_string();
835 test_compare_array();
836 test_compare_map();
837}
838
839static
840void test_copy(void)
841{
842 /*
843 * Here's the deal here. If we make sure that each value object
844 * of our deep copy has a different address than its source,
c55a9f58 845 * and that bt_value_compare() returns BT_TRUE for the top-level
dac5c838
PP
846 * value object, taking into account that we test the correctness of
847 * bt_value_compare() elsewhere, then the deep copy is a
848 * success.
849 */
05e21286
PP
850 struct bt_value *null_copy_obj;
851 struct bt_value *bool_obj, *bool_copy_obj;
852 struct bt_value *integer_obj, *integer_copy_obj;
853 struct bt_value *real_obj, *real_copy_obj;
854 struct bt_value *string_obj, *string_copy_obj;
855 struct bt_value *array_obj, *array_copy_obj;
856 struct bt_value *map_obj, *map_copy_obj;
da91b29a
PP
857 enum bt_value_status status;
858
05e21286
PP
859 bool_obj = bt_value_bool_create_init(BT_TRUE);
860 integer_obj = bt_value_integer_create_init(23);
861 real_obj = bt_value_real_create_init(-3.1416);
862 string_obj = bt_value_string_create_init("test");
863 array_obj = bt_value_array_create();
864 map_obj = bt_value_map_create();
dac5c838 865
a373bf69 866 BT_ASSERT(bool_obj && integer_obj && real_obj && string_obj &&
dac5c838
PP
867 array_obj && map_obj);
868
05e21286
PP
869 status = bt_value_array_append_element(array_obj,
870 bool_obj);
da91b29a 871 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286
PP
872 status = bt_value_array_append_element(array_obj,
873 integer_obj);
da91b29a 874 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286
PP
875 status = bt_value_array_append_element(array_obj,
876 real_obj);
da91b29a 877 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 878 status = bt_value_array_append_element(array_obj,
da91b29a
PP
879 bt_value_null);
880 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286
PP
881 status = bt_value_map_insert_entry(map_obj, "array",
882 array_obj);
da91b29a 883 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286
PP
884 status = bt_value_map_insert_entry(map_obj, "string",
885 string_obj);
da91b29a 886 BT_ASSERT(status == BT_VALUE_STATUS_OK);
dac5c838 887
6be5a99e 888 status = bt_value_copy(map_obj, &map_copy_obj);
601b0d3c 889 ok(status == BT_VALUE_STATUS_OK && map_copy_obj,
dac5c838
PP
890 "bt_value_copy() succeeds");
891
892 ok(map_obj != map_copy_obj,
893 "bt_value_copy() returns a different pointer (map)");
05e21286 894 string_copy_obj = bt_value_map_borrow_entry_value(map_copy_obj,
da91b29a 895 "string");
dac5c838
PP
896 ok(string_copy_obj != string_obj,
897 "bt_value_copy() returns a different pointer (string)");
05e21286 898 array_copy_obj = bt_value_map_borrow_entry_value(map_copy_obj,
da91b29a 899 "array");
dac5c838
PP
900 ok(array_copy_obj != array_obj,
901 "bt_value_copy() returns a different pointer (array)");
05e21286 902 bool_copy_obj = bt_value_array_borrow_element_by_index(
da91b29a 903 array_copy_obj, 0);
dac5c838 904 ok(bool_copy_obj != bool_obj,
c55a9f58 905 "bt_value_copy() returns a different pointer (bt_bool)");
05e21286 906 integer_copy_obj = bt_value_array_borrow_element_by_index(
da91b29a 907 array_copy_obj, 1);
dac5c838
PP
908 ok(integer_copy_obj != integer_obj,
909 "bt_value_copy() returns a different pointer (integer)");
05e21286 910 real_copy_obj = bt_value_array_borrow_element_by_index(
da91b29a 911 array_copy_obj, 2);
a373bf69
PP
912 ok(real_copy_obj != real_obj,
913 "bt_value_copy() returns a different pointer (real)");
05e21286 914 null_copy_obj = bt_value_array_borrow_element_by_index(
da91b29a 915 array_copy_obj, 3);
05e21286 916 ok(null_copy_obj == bt_value_null,
dac5c838
PP
917 "bt_value_copy() returns the same pointer (null)");
918
05e21286
PP
919 ok(bt_value_compare(map_obj,
920 map_copy_obj),
dac5c838
PP
921 "source and destination value objects have the same content");
922
c5b9b441
PP
923 BT_VALUE_PUT_REF_AND_RESET(map_copy_obj);
924 BT_VALUE_PUT_REF_AND_RESET(bool_obj);
925 BT_VALUE_PUT_REF_AND_RESET(integer_obj);
926 BT_VALUE_PUT_REF_AND_RESET(real_obj);
927 BT_VALUE_PUT_REF_AND_RESET(string_obj);
928 BT_VALUE_PUT_REF_AND_RESET(array_obj);
929 BT_VALUE_PUT_REF_AND_RESET(map_obj);
dac5c838
PP
930}
931
b6ba7620 932static
05e21286 933bt_bool compare_map_elements(const struct bt_value *map_a, const struct bt_value *map_b,
b6ba7620
PP
934 const char *key)
935{
05e21286
PP
936 const struct bt_value *elem_a = NULL;
937 const struct bt_value *elem_b = NULL;
c55a9f58 938 bt_bool equal;
b6ba7620 939
05e21286
PP
940 elem_a = bt_value_map_borrow_entry_value_const(map_a, key);
941 elem_b = bt_value_map_borrow_entry_value_const(map_b, key);
b6ba7620 942 equal = bt_value_compare(elem_a, elem_b);
b6ba7620
PP
943 return equal;
944}
945
946static
947void test_extend(void)
948{
05e21286
PP
949 struct bt_value *base_map = bt_value_map_create();
950 struct bt_value *extension_map = bt_value_map_create();
951 struct bt_value *extended_map = NULL;
952 struct bt_value *array = bt_value_array_create();
b6ba7620
PP
953 enum bt_value_status status;
954
25583cd0
PP
955 BT_ASSERT(base_map);
956 BT_ASSERT(extension_map);
957 BT_ASSERT(array);
05e21286 958 status = bt_value_map_insert_bool_entry(base_map, "file",
da91b29a 959 BT_TRUE);
25583cd0 960 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 961 status = bt_value_map_insert_bool_entry(base_map, "edit",
da91b29a 962 BT_FALSE);
25583cd0 963 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 964 status = bt_value_map_insert_integer_entry(base_map,
da91b29a 965 "selection", 17);
25583cd0 966 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 967 status = bt_value_map_insert_integer_entry(base_map, "find",
da91b29a 968 -34);
25583cd0 969 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 970 status = bt_value_map_insert_bool_entry(extension_map, "edit",
da91b29a 971 BT_TRUE);
25583cd0 972 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 973 status = bt_value_map_insert_integer_entry(extension_map,
da91b29a 974 "find", 101);
25583cd0 975 BT_ASSERT(status == BT_VALUE_STATUS_OK);
05e21286 976 status = bt_value_map_insert_real_entry(extension_map,
da91b29a 977 "project", -404);
25583cd0 978 BT_ASSERT(status == BT_VALUE_STATUS_OK);
35294e83 979 status = bt_value_map_extend(base_map, extension_map, &extended_map);
601b0d3c
PP
980 ok(status == BT_VALUE_STATUS_OK &&
981 extended_map, "bt_value_map_extend() succeeds");
05e21286 982 ok(bt_value_map_get_size(extended_map) == 5,
b6ba7620 983 "bt_value_map_extend() returns a map object with the correct size");
05e21286
PP
984 ok(compare_map_elements(base_map,
985 extended_map, "file"),
b6ba7620 986 "bt_value_map_extend() picks the appropriate element (file)");
05e21286
PP
987 ok(compare_map_elements(extension_map,
988 extended_map, "edit"),
b6ba7620 989 "bt_value_map_extend() picks the appropriate element (edit)");
05e21286
PP
990 ok(compare_map_elements(base_map,
991 extended_map, "selection"),
b6ba7620 992 "bt_value_map_extend() picks the appropriate element (selection)");
05e21286
PP
993 ok(compare_map_elements(extension_map,
994 extended_map, "find"),
b6ba7620 995 "bt_value_map_extend() picks the appropriate element (find)");
05e21286
PP
996 ok(compare_map_elements(extension_map,
997 extended_map, "project"),
b6ba7620
PP
998 "bt_value_map_extend() picks the appropriate element (project)");
999
c5b9b441
PP
1000 BT_VALUE_PUT_REF_AND_RESET(array);
1001 BT_VALUE_PUT_REF_AND_RESET(base_map);
1002 BT_VALUE_PUT_REF_AND_RESET(extension_map);
1003 BT_VALUE_PUT_REF_AND_RESET(extended_map);
b6ba7620
PP
1004}
1005
dac5c838
PP
1006int main(void)
1007{
8bbe269d 1008 plan_tests(NR_TESTS);
dac5c838
PP
1009 test_types();
1010 test_compare();
1011 test_copy();
b6ba7620 1012 test_extend();
dac5c838
PP
1013 return 0;
1014}
This page took 0.096161 seconds and 4 git commands to generate.