include: add missing files to dist tarball
[deliverable/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
82fa4539 23#include <babeltrace/babeltrace.h>
25583cd0 24#include <babeltrace/assert-internal.h>
dac5c838
PP
25#include <string.h>
26#include "tap/tap.h"
27
605c62ba 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");
317e35ec 36 bt_value_get_ref(bt_value_null);
dac5c838 37 pass("getting bt_value_null does not cause a crash");
317e35ec 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;
b9879703 46 bt_value *obj;
dac5c838 47
82fa4539 48 obj = bt_value_bool_create();
dac5c838 49 ok(obj && bt_value_is_bool(obj),
82fa4539 50 "bt_value_bool_create() returns a boolean value object");
dac5c838 51
c55a9f58 52 value = BT_TRUE;
605c62ba
PP
53 value = bt_value_bool_get(obj);
54 ok(!value, "default boolean value object value is BT_FALSE");
dac5c838 55
82fa4539
PP
56 bt_value_bool_set(obj, BT_FALSE);
57 bt_value_bool_set(obj, BT_TRUE);
605c62ba 58 value = bt_value_bool_get(obj);
82fa4539 59 ok(value, "bt_value_bool_set() works");
dac5c838 60
317e35ec 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;
82fa4539 65 obj = bt_value_bool_create_init(BT_TRUE);
dac5c838 66 ok(obj && bt_value_is_bool(obj),
82fa4539 67 "bt_value_bool_create_init() returns a boolean value object");
605c62ba
PP
68 value = bt_value_bool_get(obj);
69 ok(value,
82fa4539 70 "bt_value_bool_create_init() sets the appropriate initial value");
dac5c838 71
317e35ec 72 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
73}
74
75static
76void test_integer(void)
77{
dac5c838 78 int64_t value;
b9879703 79 bt_value *obj;
dac5c838 80
82fa4539 81 obj = bt_value_integer_create();
dac5c838 82 ok(obj && bt_value_is_integer(obj),
82fa4539 83 "bt_value_integer_create() returns an integer value object");
dac5c838 84
dac5c838 85 value = 1961;
605c62ba
PP
86 value = bt_value_integer_get(obj);
87 ok(value == 0, "default integer value object value is 0");
dac5c838 88
82fa4539 89 bt_value_integer_set(obj, -98765);
605c62ba
PP
90 value = bt_value_integer_get(obj);
91 ok(value == -98765, "bt_private_integer_bool_set() works");
dac5c838 92
317e35ec 93 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
94 pass("putting an existing integer value object does not cause a crash")
95
82fa4539 96 obj = bt_value_integer_create_init(321456987);
dac5c838 97 ok(obj && bt_value_is_integer(obj),
82fa4539 98 "bt_value_integer_create_init() returns an integer value object");
605c62ba
PP
99 value = bt_value_integer_get(obj);
100 ok(value == 321456987,
82fa4539 101 "bt_value_integer_create_init() sets the appropriate initial value");
dac5c838 102
317e35ec 103 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
104}
105
106static
9db4d871 107void test_real(void)
dac5c838 108{
dac5c838 109 double value;
b9879703 110 bt_value *obj;
dac5c838 111
82fa4539 112 obj = bt_value_real_create();
9db4d871 113 ok(obj && bt_value_is_real(obj),
82fa4539 114 "bt_value_real_create() returns a real number value object");
dac5c838 115
dac5c838 116 value = 17.34;
605c62ba
PP
117 value = bt_value_real_get(obj);
118 ok(value == 0.,
9db4d871 119 "default real number value object value is 0");
dac5c838 120
82fa4539 121 bt_value_real_set(obj, -3.1416);
605c62ba 122 value = bt_value_real_get(obj);
82fa4539 123 ok(value == -3.1416, "bt_value_real_set() works");
dac5c838 124
317e35ec 125 BT_VALUE_PUT_REF_AND_RESET(obj);
9db4d871 126 pass("putting an existing real number value object does not cause a crash")
dac5c838 127
82fa4539 128 obj = bt_value_real_create_init(33.1649758);
9db4d871 129 ok(obj && bt_value_is_real(obj),
82fa4539 130 "bt_value_real_create_init() returns a real number value object");
605c62ba
PP
131 value = bt_value_real_get(obj);
132 ok(value == 33.1649758,
82fa4539 133 "bt_value_real_create_init() sets the appropriate initial value");
dac5c838 134
317e35ec 135 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
136}
137
138static
139void test_string(void)
140{
dac5c838 141 const char *value;
b9879703 142 bt_value *obj;
dac5c838 143
82fa4539 144 obj = bt_value_string_create();
dac5c838 145 ok(obj && bt_value_is_string(obj),
82fa4539 146 "bt_value_string_create() returns a string value object");
dac5c838 147
605c62ba
PP
148 value = bt_value_string_get(obj);
149 ok(value && !strcmp(value, ""),
dac5c838
PP
150 "default string value object value is \"\"");
151
82fa4539 152 bt_value_string_set(obj, "hello worldz");
605c62ba
PP
153 value = bt_value_string_get(obj);
154 ok(value && !strcmp(value, "hello worldz"),
dac5c838
PP
155 "bt_value_string_get() works");
156
317e35ec 157 BT_VALUE_PUT_REF_AND_RESET(obj);
dac5c838
PP
158 pass("putting an existing string value object does not cause a crash")
159
82fa4539 160 obj = bt_value_string_create_init("initial value");
dac5c838 161 ok(obj && bt_value_is_string(obj),
82fa4539 162 "bt_value_string_create_init() returns a string value object");
605c62ba
PP
163 value = bt_value_string_get(obj);
164 ok(value && !strcmp(value, "initial value"),
82fa4539 165 "bt_value_string_create_init() sets the appropriate initial value");
dac5c838 166
317e35ec 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;
9db4d871 176 double real_value;
b9879703 177 bt_value *obj;
dac5c838 178 const char *string_value;
b9879703 179 bt_value *array_obj;
dac5c838 180
82fa4539 181 array_obj = bt_value_array_create();
dac5c838 182 ok(array_obj && bt_value_is_array(array_obj),
82fa4539 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
82fa4539
PP
187 obj = bt_value_integer_create_init(345);
188 ret = bt_value_array_append_element(array_obj, obj);
317e35ec 189 BT_VALUE_PUT_REF_AND_RESET(obj);
82fa4539
PP
190 obj = bt_value_real_create_init(-17.45);
191 ret |= bt_value_array_append_element(array_obj, obj);
317e35ec 192 BT_VALUE_PUT_REF_AND_RESET(obj);
82fa4539
PP
193 obj = bt_value_bool_create_init(BT_TRUE);
194 ret |= bt_value_array_append_element(array_obj, obj);
317e35ec 195 BT_VALUE_PUT_REF_AND_RESET(obj);
82fa4539 196 ret |= bt_value_array_append_element(array_obj,
351704a7 197 bt_value_null);
82fa4539 198 ok(!ret, "bt_value_array_append_element() succeeds");
7fce1b50 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
7fce1b50 202 obj = bt_value_array_borrow_element_by_index(array_obj, 0);
dac5c838 203 ok(obj && bt_value_is_integer(obj),
7fce1b50 204 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (integer)");
605c62ba
PP
205 int_value = bt_value_integer_get(obj);
206 ok(int_value == 345,
7fce1b50
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);
9db4d871 209 ok(obj && bt_value_is_real(obj),
7fce1b50 210 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)");
605c62ba
PP
211 real_value = bt_value_real_get(obj);
212 ok(real_value == -17.45,
7fce1b50
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),
7fce1b50 216 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)");
605c62ba
PP
217 bool_value = bt_value_bool_get(obj);
218 ok(bool_value,
7fce1b50
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,
7fce1b50 222 "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)");
dac5c838 223
82fa4539 224 obj = bt_value_integer_create_init(1001);
25583cd0 225 BT_ASSERT(obj);
82fa4539 226 ok(!bt_value_array_set_element_by_index(array_obj, 2, obj),
7fce1b50 227 "bt_value_array_set_element_by_index() succeeds");
317e35ec 228 BT_VALUE_PUT_REF_AND_RESET(obj);
7fce1b50 229 obj = bt_value_array_borrow_element_by_index(array_obj, 2);
dac5c838 230 ok(obj && bt_value_is_integer(obj),
7fce1b50 231 "bt_value_array_set_element_by_index() inserts an value object with the appropriate type");
605c62ba 232 int_value = bt_value_integer_get(obj);
25583cd0 233 BT_ASSERT(!ret);
dac5c838 234 ok(int_value == 1001,
7fce1b50
PP
235 "bt_value_array_set_element_by_index() inserts an value object with the appropriate value");
236
82fa4539 237 ret = bt_value_array_append_bool_element(array_obj,
351704a7 238 BT_FALSE);
82fa4539
PP
239 ok(!ret, "bt_value_array_append_bool_element() succeeds");
240 ret = bt_value_array_append_integer_element(array_obj,
351704a7 241 98765);
82fa4539
PP
242 ok(!ret, "bt_value_array_append_integer_element() succeeds");
243 ret = bt_value_array_append_real_element(array_obj,
351704a7 244 2.49578);
82fa4539
PP
245 ok(!ret, "bt_value_array_append_real_element() succeeds");
246 ret = bt_value_array_append_string_element(array_obj,
351704a7 247 "bt_value");
82fa4539
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");
7fce1b50
PP
253
254 ok(bt_value_array_get_size(array_obj) == 10,
82fa4539 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
7fce1b50 259 obj = bt_value_array_borrow_element_by_index(array_obj, 4);
dac5c838 260 ok(obj && bt_value_is_bool(obj),
82fa4539 261 "bt_value_array_append_bool_element() appends a boolean value object");
605c62ba
PP
262 bool_value = bt_value_bool_get(obj);
263 ok(!bool_value,
82fa4539 264 "bt_value_array_append_bool_element() appends the appropriate value");
7fce1b50 265 obj = bt_value_array_borrow_element_by_index(array_obj, 5);
dac5c838 266 ok(obj && bt_value_is_integer(obj),
82fa4539 267 "bt_value_array_append_integer_element() appends an integer value object");
605c62ba
PP
268 int_value = bt_value_integer_get(obj);
269 ok(int_value == 98765,
82fa4539 270 "bt_value_array_append_integer_element() appends the appropriate value");
7fce1b50 271 obj = bt_value_array_borrow_element_by_index(array_obj, 6);
9db4d871 272 ok(obj && bt_value_is_real(obj),
82fa4539 273 "bt_value_array_append_real_element() appends a real number value object");
605c62ba
PP
274 real_value = bt_value_real_get(obj);
275 ok(real_value == 2.49578,
82fa4539 276 "bt_value_array_append_real_element() appends the appropriate value");
7fce1b50 277 obj = bt_value_array_borrow_element_by_index(array_obj, 7);
dac5c838 278 ok(obj && bt_value_is_string(obj),
82fa4539 279 "bt_value_array_append_string_element() appends a string value object");
605c62ba 280 string_value = bt_value_string_get(obj);
dac5c838 281 ok(!ret && string_value && !strcmp(string_value, "bt_value"),
82fa4539 282 "bt_value_array_append_string_element() appends the appropriate value");
7fce1b50 283 obj = bt_value_array_borrow_element_by_index(array_obj, 8);
dac5c838 284 ok(obj && bt_value_is_array(obj),
82fa4539 285 "bt_value_array_append_empty_array_element() appends an array value object");
dac5c838 286 ok(bt_value_array_is_empty(obj),
82fa4539 287 "bt_value_array_append_empty_array_element() an empty array value object");
7fce1b50 288 obj = bt_value_array_borrow_element_by_index(array_obj, 9);
dac5c838 289 ok(obj && bt_value_is_map(obj),
82fa4539 290 "bt_value_array_append_empty_map_element() appends a map value object");
dac5c838 291 ok(bt_value_map_is_empty(obj),
82fa4539 292 "bt_value_array_append_empty_map_element() an empty map value object");
dac5c838 293
317e35ec 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
b9879703 299bt_bool test_map_foreach_cb_count(const char *key, 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;
9db4d871 316 bt_bool real1;
c55a9f58
PP
317 bt_bool null1;
318 bt_bool bool2;
319 bt_bool int2;
9db4d871 320 bt_bool real2;
c55a9f58
PP
321 bt_bool string2;
322 bt_bool array2;
323 bt_bool map2;
dac5c838
PP
324};
325
326static
b9879703 327bt_bool test_map_foreach_cb_check(const char *key, 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
605c62ba 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
605c62ba 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 }
9db4d871
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
605c62ba 368 val = bt_value_real_get(object);
dac5c838
PP
369
370 if (val == 5.444) {
9db4d871
PP
371 pass("test_map_foreach_cb_check(): \"real\" value object has the right value");
372 checklist->real1 = BT_TRUE;
dac5c838 373 } else {
9db4d871 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
605c62ba 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
605c62ba 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 }
9db4d871
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
605c62ba 420 val = bt_value_real_get(object);
dac5c838
PP
421
422 if (val == -49.0001) {
9db4d871
PP
423 pass("test_map_foreach_cb_check(): \"real2\" value object has the right value");
424 checklist->real2 = BT_TRUE;
dac5c838 425 } else {
9db4d871 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
605c62ba 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 {
351704a7
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;
9db4d871 477 double real_value;
b9879703
PP
478 bt_value *obj;
479 bt_value *map_obj;
dac5c838
PP
480 struct map_foreach_checklist checklist;
481
82fa4539 482 map_obj = bt_value_map_create();
dac5c838 483 ok(map_obj && bt_value_is_map(map_obj),
82fa4539 484 "bt_value_map_create() returns a map value object");
7fce1b50 485 ok(bt_value_map_get_size(map_obj) == 0,
dac5c838 486 "initial map value object size is 0");
dac5c838 487
82fa4539
PP
488 obj = bt_value_integer_create_init(19457);
489 ret = bt_value_map_insert_entry(map_obj, "int", obj);
317e35ec 490 BT_VALUE_PUT_REF_AND_RESET(obj);
82fa4539
PP
491 obj = bt_value_real_create_init(5.444);
492 ret |= bt_value_map_insert_entry(map_obj, "real", obj);
317e35ec 493 BT_VALUE_PUT_REF_AND_RESET(obj);
82fa4539
PP
494 obj = bt_value_bool_create();
495 ret |= bt_value_map_insert_entry(map_obj, "bt_bool", obj);
317e35ec 496 BT_VALUE_PUT_REF_AND_RESET(obj);
82fa4539 497 ret |= bt_value_map_insert_entry(map_obj, "null",
351704a7 498 bt_value_null);
82fa4539 499 ok(!ret, "bt_value_map_insert_entry() succeeds");
7fce1b50 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
82fa4539
PP
503 obj = bt_value_bool_create_init(BT_TRUE);
504 ret = bt_value_map_insert_entry(map_obj, "bt_bool", obj);
317e35ec 505 BT_VALUE_PUT_REF_AND_RESET(obj);
82fa4539 506 ok(!ret, "bt_value_map_insert_entry() accepts an existing key");
dac5c838 507
7fce1b50
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");
9db4d871 511 ok(obj && bt_value_is_real(obj),
7fce1b50 512 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (real)");
605c62ba
PP
513 real_value = bt_value_real_get(obj);
514 ok(real_value == 5.444,
7fce1b50
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),
7fce1b50 518 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (integer)");
605c62ba
PP
519 int_value = bt_value_integer_get(obj);
520 ok(int_value == 19457,
7fce1b50
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),
7fce1b50
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),
7fce1b50 527 "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (boolean)");
605c62ba
PP
528 bool_value = bt_value_bool_get(obj);
529 ok(bool_value,
7fce1b50
PP
530 "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (boolean)");
531
82fa4539 532 ret = bt_value_map_insert_bool_entry(map_obj, "bool2",
351704a7 533 BT_TRUE);
82fa4539
PP
534 ok(!ret, "bt_value_map_insert_bool_entry() succeeds");
535 ret = bt_value_map_insert_integer_entry(map_obj, "int2",
351704a7 536 98765);
82fa4539
PP
537 ok(!ret, "bt_value_map_insert_integer_entry() succeeds");
538 ret = bt_value_map_insert_real_entry(map_obj, "real2",
351704a7 539 -49.0001);
82fa4539
PP
540 ok(!ret, "bt_value_map_insert_real_entry() succeeds");
541 ret = bt_value_map_insert_string_entry(map_obj, "string2",
351704a7 542 "bt_value");
82fa4539
PP
543 ok(!ret, "bt_value_map_insert_string_entry() succeeds");
544 ret = bt_value_map_insert_empty_array_entry(map_obj,
351704a7 545 "array2");
82fa4539
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");
7fce1b50
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
7fce1b50 553 ok(!bt_value_map_has_entry(map_obj, "hello"),
dac5c838 554 "map value object does not have key \"hello\"");
7fce1b50 555 ok(bt_value_map_has_entry(map_obj, "bt_bool"),
c55a9f58 556 "map value object has key \"bt_bool\"");
7fce1b50 557 ok(bt_value_map_has_entry(map_obj, "int"),
dac5c838 558 "map value object has key \"int\"");
7fce1b50 559 ok(bt_value_map_has_entry(map_obj, "real"),
9db4d871 560 "map value object has key \"real\"");
7fce1b50 561 ok(bt_value_map_has_entry(map_obj, "null"),
dac5c838 562 "map value object has key \"null\"");
7fce1b50 563 ok(bt_value_map_has_entry(map_obj, "bool2"),
dac5c838 564 "map value object has key \"bool2\"");
7fce1b50 565 ok(bt_value_map_has_entry(map_obj, "int2"),
dac5c838 566 "map value object has key \"int2\"");
7fce1b50 567 ok(bt_value_map_has_entry(map_obj, "real2"),
9db4d871 568 "map value object has key \"real2\"");
7fce1b50 569 ok(bt_value_map_has_entry(map_obj, "string2"),
dac5c838 570 "map value object has key \"string2\"");
7fce1b50 571 ok(bt_value_map_has_entry(map_obj, "array2"),
dac5c838 572 "map value object has key \"array2\"");
7fce1b50 573 ok(bt_value_map_has_entry(map_obj, "map2"),
dac5c838
PP
574 "map value object has key \"map2\"");
575
351704a7
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,
7fce1b50 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));
7fce1b50 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,
7fce1b50 585 "bt_value_map_foreach_entry() succeeds with test_map_foreach_cb_check()");
9db4d871 586 ok(checklist.bool1 && checklist.int1 && checklist.real1 &&
dac5c838 587 checklist.null1 && checklist.bool2 && checklist.int2 &&
9db4d871 588 checklist.real2 && checklist.string2 &&
dac5c838 589 checklist.array2 && checklist.map2,
7fce1b50 590 "bt_value_map_foreach_entry() iterates over all the map value object's elements");
dac5c838 591
317e35ec 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();
9db4d871 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{
b9879703 618 bt_value *bool1 =
82fa4539 619 bt_value_bool_create_init(BT_FALSE);
b9879703 620 bt_value *bool2 =
82fa4539 621 bt_value_bool_create_init(BT_TRUE);
b9879703 622 bt_value *bool3 =
82fa4539 623 bt_value_bool_create_init(BT_FALSE);
dac5c838 624
25583cd0 625 BT_ASSERT(bool1 && bool2 && bool3);
351704a7 626 ok(!bt_value_compare(bt_value_null,
82fa4539 627 bool1),
c55a9f58 628 "cannot compare null value object and bt_bool value object");
82fa4539
PP
629 ok(!bt_value_compare(bool1,
630 bool2),
c55a9f58 631 "boolean value objects are not equivalent (BT_FALSE and BT_TRUE)");
82fa4539
PP
632 ok(bt_value_compare(bool1,
633 bool3),
c55a9f58 634 "boolean value objects are equivalent (BT_FALSE and BT_FALSE)");
dac5c838 635
317e35ec
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{
b9879703 644 bt_value *int1 =
82fa4539 645 bt_value_integer_create_init(10);
b9879703 646 bt_value *int2 =
82fa4539 647 bt_value_integer_create_init(-23);
b9879703 648 bt_value *int3 =
82fa4539 649 bt_value_integer_create_init(10);
dac5c838 650
25583cd0 651 BT_ASSERT(int1 && int2 && int3);
351704a7 652 ok(!bt_value_compare(bt_value_null,
82fa4539 653 int1),
dac5c838 654 "cannot compare null value object and integer value object");
82fa4539
PP
655 ok(!bt_value_compare(int1,
656 int2),
dac5c838 657 "integer value objects are not equivalent (10 and -23)");
82fa4539
PP
658 ok(bt_value_compare(int1,
659 int3),
dac5c838
PP
660 "integer value objects are equivalent (10 and 10)");
661
317e35ec
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
9db4d871 668void test_compare_real(void)
dac5c838 669{
b9879703 670 bt_value *real1 =
82fa4539 671 bt_value_real_create_init(17.38);
b9879703 672 bt_value *real2 =
82fa4539 673 bt_value_real_create_init(-14.23);
b9879703 674 bt_value *real3 =
82fa4539 675 bt_value_real_create_init(17.38);
9db4d871
PP
676
677 BT_ASSERT(real1 && real2 && real3);
678
351704a7 679 ok(!bt_value_compare(bt_value_null,
82fa4539 680 real1),
9db4d871 681 "cannot compare null value object and real number value object");
82fa4539
PP
682 ok(!bt_value_compare(real1,
683 real2),
9db4d871 684 "real number value objects are not equivalent (17.38 and -14.23)");
82fa4539
PP
685 ok(bt_value_compare(real1,
686 real3),
9db4d871
PP
687 "real number value objects are equivalent (17.38 and 17.38)");
688
317e35ec
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{
b9879703 697 bt_value *string1 =
82fa4539 698 bt_value_string_create_init("hello");
b9879703 699 bt_value *string2 =
82fa4539 700 bt_value_string_create_init("bt_value");
b9879703 701 bt_value *string3 =
82fa4539 702 bt_value_string_create_init("hello");
dac5c838 703
25583cd0 704 BT_ASSERT(string1 && string2 && string3);
dac5c838 705
351704a7 706 ok(!bt_value_compare(bt_value_null,
82fa4539 707 string1),
dac5c838 708 "cannot compare null value object and string value object");
82fa4539
PP
709 ok(!bt_value_compare(string1,
710 string2),
dac5c838 711 "string value objects are not equivalent (\"hello\" and \"bt_value\")");
82fa4539
PP
712 ok(bt_value_compare(string1,
713 string3),
dac5c838
PP
714 "string value objects are equivalent (\"hello\" and \"hello\")");
715
317e35ec
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{
b9879703
PP
724 bt_value *array1 = bt_value_array_create();
725 bt_value *array2 = bt_value_array_create();
726 bt_value *array3 = bt_value_array_create();
b7c5b62e 727 bt_value_status status;
dac5c838 728
25583cd0 729 BT_ASSERT(array1 && array2 && array3);
dac5c838 730
82fa4539
PP
731 ok(bt_value_compare(array1,
732 array2),
dac5c838
PP
733 "empty array value objects are equivalent");
734
82fa4539 735 status = bt_value_array_append_integer_element(array1, 23);
351704a7 736 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 737 status = bt_value_array_append_real_element(array1, 14.2);
351704a7 738 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 739 status = bt_value_array_append_bool_element(array1, BT_FALSE);
351704a7 740 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 741 status = bt_value_array_append_real_element(array2, 14.2);
351704a7 742 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 743 status = bt_value_array_append_integer_element(array2, 23);
351704a7 744 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 745 status = bt_value_array_append_bool_element(array2, BT_FALSE);
351704a7 746 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 747 status = bt_value_array_append_integer_element(array3, 23);
351704a7 748 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 749 status = bt_value_array_append_real_element(array3, 14.2);
351704a7 750 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 751 status = bt_value_array_append_bool_element(array3, BT_FALSE);
351704a7 752 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539
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);
351704a7
PP
756
757 ok(!bt_value_compare(bt_value_null,
82fa4539 758 array1),
dac5c838 759 "cannot compare null value object and array value object");
82fa4539
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])");
82fa4539
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
317e35ec
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{
b9879703
PP
775 bt_value *map1 = bt_value_map_create();
776 bt_value *map2 = bt_value_map_create();
777 bt_value *map3 = bt_value_map_create();
b7c5b62e 778 bt_value_status status;
dac5c838 779
25583cd0 780 BT_ASSERT(map1 && map2 && map3);
dac5c838 781
82fa4539
PP
782 ok(bt_value_compare(map1,
783 map2),
dac5c838
PP
784 "empty map value objects are equivalent");
785
351704a7 786
82fa4539 787 status = bt_value_map_insert_integer_entry(map1, "one", 23);
351704a7 788 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 789 status = bt_value_map_insert_real_entry(map1, "two", 14.2);
351704a7 790 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 791 status = bt_value_map_insert_bool_entry(map1, "three",
351704a7
PP
792 BT_FALSE);
793 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 794 status = bt_value_map_insert_real_entry(map2, "one", 14.2);
351704a7 795 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 796 status = bt_value_map_insert_integer_entry(map2, "two", 23);
351704a7 797 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 798 status = bt_value_map_insert_bool_entry(map2, "three",
351704a7
PP
799 BT_FALSE);
800 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 801 status = bt_value_map_insert_bool_entry(map3, "three",
351704a7
PP
802 BT_FALSE);
803 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 804 status = bt_value_map_insert_integer_entry(map3, "one", 23);
351704a7 805 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 806 status = bt_value_map_insert_real_entry(map3, "two", 14.2);
351704a7 807 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539
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);
351704a7
PP
811
812 ok(!bt_value_compare(bt_value_null,
82fa4539 813 map1),
dac5c838 814 "cannot compare null value object and map value object");
82fa4539
PP
815 ok(!bt_value_compare(map1,
816 map2),
dac5c838 817 "map value objects are not equivalent");
82fa4539
PP
818 ok(bt_value_compare(map1,
819 map3),
dac5c838
PP
820 "map value objects are equivalent");
821
317e35ec
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();
9db4d871 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 */
b9879703
PP
850 bt_value *null_copy_obj;
851 bt_value *bool_obj, *bool_copy_obj;
852 bt_value *integer_obj, *integer_copy_obj;
853 bt_value *real_obj, *real_copy_obj;
854 bt_value *string_obj, *string_copy_obj;
855 bt_value *array_obj, *array_copy_obj;
856 bt_value *map_obj, *map_copy_obj;
b7c5b62e 857 bt_value_status status;
351704a7 858
82fa4539
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
9db4d871 866 BT_ASSERT(bool_obj && integer_obj && real_obj && string_obj &&
dac5c838
PP
867 array_obj && map_obj);
868
82fa4539
PP
869 status = bt_value_array_append_element(array_obj,
870 bool_obj);
351704a7 871 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539
PP
872 status = bt_value_array_append_element(array_obj,
873 integer_obj);
351704a7 874 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539
PP
875 status = bt_value_array_append_element(array_obj,
876 real_obj);
351704a7 877 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 878 status = bt_value_array_append_element(array_obj,
351704a7
PP
879 bt_value_null);
880 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539
PP
881 status = bt_value_map_insert_entry(map_obj, "array",
882 array_obj);
351704a7 883 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539
PP
884 status = bt_value_map_insert_entry(map_obj, "string",
885 string_obj);
351704a7 886 BT_ASSERT(status == BT_VALUE_STATUS_OK);
dac5c838 887
f59250ff 888 status = bt_value_copy(map_obj, &map_copy_obj);
605c62ba 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)");
82fa4539 894 string_copy_obj = bt_value_map_borrow_entry_value(map_copy_obj,
351704a7 895 "string");
dac5c838
PP
896 ok(string_copy_obj != string_obj,
897 "bt_value_copy() returns a different pointer (string)");
82fa4539 898 array_copy_obj = bt_value_map_borrow_entry_value(map_copy_obj,
351704a7 899 "array");
dac5c838
PP
900 ok(array_copy_obj != array_obj,
901 "bt_value_copy() returns a different pointer (array)");
82fa4539 902 bool_copy_obj = bt_value_array_borrow_element_by_index(
351704a7 903 array_copy_obj, 0);
dac5c838 904 ok(bool_copy_obj != bool_obj,
c55a9f58 905 "bt_value_copy() returns a different pointer (bt_bool)");
82fa4539 906 integer_copy_obj = bt_value_array_borrow_element_by_index(
351704a7 907 array_copy_obj, 1);
dac5c838
PP
908 ok(integer_copy_obj != integer_obj,
909 "bt_value_copy() returns a different pointer (integer)");
82fa4539 910 real_copy_obj = bt_value_array_borrow_element_by_index(
351704a7 911 array_copy_obj, 2);
9db4d871
PP
912 ok(real_copy_obj != real_obj,
913 "bt_value_copy() returns a different pointer (real)");
82fa4539 914 null_copy_obj = bt_value_array_borrow_element_by_index(
351704a7 915 array_copy_obj, 3);
82fa4539 916 ok(null_copy_obj == bt_value_null,
dac5c838
PP
917 "bt_value_copy() returns the same pointer (null)");
918
82fa4539
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
317e35ec
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
b9879703 933bt_bool compare_map_elements(const bt_value *map_a, const bt_value *map_b,
b6ba7620
PP
934 const char *key)
935{
b9879703
PP
936 const bt_value *elem_a = NULL;
937 const bt_value *elem_b = NULL;
c55a9f58 938 bt_bool equal;
b6ba7620 939
82fa4539
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{
b9879703
PP
949 bt_value *base_map = bt_value_map_create();
950 bt_value *extension_map = bt_value_map_create();
951 bt_value *extended_map = NULL;
952 bt_value *array = bt_value_array_create();
b7c5b62e 953 bt_value_status status;
b6ba7620 954
25583cd0
PP
955 BT_ASSERT(base_map);
956 BT_ASSERT(extension_map);
957 BT_ASSERT(array);
82fa4539 958 status = bt_value_map_insert_bool_entry(base_map, "file",
351704a7 959 BT_TRUE);
25583cd0 960 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 961 status = bt_value_map_insert_bool_entry(base_map, "edit",
351704a7 962 BT_FALSE);
25583cd0 963 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 964 status = bt_value_map_insert_integer_entry(base_map,
351704a7 965 "selection", 17);
25583cd0 966 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 967 status = bt_value_map_insert_integer_entry(base_map, "find",
351704a7 968 -34);
25583cd0 969 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 970 status = bt_value_map_insert_bool_entry(extension_map, "edit",
351704a7 971 BT_TRUE);
25583cd0 972 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 973 status = bt_value_map_insert_integer_entry(extension_map,
351704a7 974 "find", 101);
25583cd0 975 BT_ASSERT(status == BT_VALUE_STATUS_OK);
82fa4539 976 status = bt_value_map_insert_real_entry(extension_map,
351704a7 977 "project", -404);
25583cd0 978 BT_ASSERT(status == BT_VALUE_STATUS_OK);
6e887d8f 979 status = bt_value_map_extend(base_map, extension_map, &extended_map);
605c62ba
PP
980 ok(status == BT_VALUE_STATUS_OK &&
981 extended_map, "bt_value_map_extend() succeeds");
82fa4539 982 ok(bt_value_map_get_size(extended_map) == 5,
b6ba7620 983 "bt_value_map_extend() returns a map object with the correct size");
82fa4539
PP
984 ok(compare_map_elements(base_map,
985 extended_map, "file"),
b6ba7620 986 "bt_value_map_extend() picks the appropriate element (file)");
82fa4539
PP
987 ok(compare_map_elements(extension_map,
988 extended_map, "edit"),
b6ba7620 989 "bt_value_map_extend() picks the appropriate element (edit)");
82fa4539
PP
990 ok(compare_map_elements(base_map,
991 extended_map, "selection"),
b6ba7620 992 "bt_value_map_extend() picks the appropriate element (selection)");
82fa4539
PP
993 ok(compare_map_elements(extension_map,
994 extended_map, "find"),
b6ba7620 995 "bt_value_map_extend() picks the appropriate element (find)");
82fa4539
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
317e35ec
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.097654 seconds and 5 git commands to generate.