1 #include "tap.h"
2 #include "test.h"
3 #include "bson.h"
4
5 #include <string.h>
6
7 void
test_bson_null(void)8 test_bson_null (void)
9 {
10 bson *b;
11
12 b = bson_new ();
13 ok (bson_append_null (b, "null"),
14 "bson_append_null() works");
15 bson_finish (b);
16
17 cmp_ok (bson_size (b), "==", 11, "BSON NULL element size check");
18 ok (memcmp (bson_data (b),
19 "\013\000\000\000\012\156\165\154\154\000\000",
20 bson_size (b)) == 0,
21 "BSON NULL element contents check");
22
23 bson_free (b);
24
25 b = bson_new ();
26 ok (bson_append_null (b, NULL) == FALSE,
27 "bson_append_null() should fail without a key name");
28 ok (bson_append_null (NULL, "null") == FALSE,
29 "bson_append_null() should fail without a BSON object");
30 bson_finish (b);
31 cmp_ok (bson_size (b), "==", 5,
32 "BSON object should be empty");
33
34 ok (bson_append_null (b, "null") == FALSE,
35 "Appending to a finished element should fail");
36
37 bson_free (b);
38 }
39
40 RUN_TEST (7, bson_null);
41