1 #include "tap.h"
2 #include "test.h"
3 #include "bson.h"
4 
5 #include <string.h>
6 
7 void
test_bson_int32(void)8 test_bson_int32 (void)
9 {
10   bson *b;
11   gint32 i = 1984;
12 
13   b = bson_new ();
14   ok (bson_append_int32 (b, "i32", i), "bson_append_int32() works");
15   bson_finish (b);
16 
17   cmp_ok (bson_size (b), "==", 14, "BSON int32 element size check");
18   ok (memcmp (bson_data (b),
19               "\016\000\000\000\020\151\063\062\000\300\007\000\000\000",
20               bson_size (b)) == 0,
21       "BSON int32 element contents check");
22 
23   bson_free (b);
24 
25   b = bson_new ();
26   ok (bson_append_int32 (b, NULL, i) == FALSE,
27       "bson_append_int32() with a NULL key should fail");
28   ok (bson_append_int32 (NULL, "i32", i) == FALSE,
29       "bson_append_int32() without a BSON object should fail");
30   bson_finish (b);
31   cmp_ok (bson_size (b), "==", 5,
32           "BSON object should be empty");
33 
34   ok (bson_append_int32 (b, "i32", i) == FALSE,
35       "Appending to a finished element should fail");
36 
37   bson_free (b);
38 }
39 
40 RUN_TEST (7, bson_int32);
41