1 #include "tap.h"
2 #include "test.h"
3 #include "bson.h"
4 
5 #include <string.h>
6 
7 void
test_bson_timestamp(void)8 test_bson_timestamp (void)
9 {
10   bson *b;
11   gint64 l = 9876543210;
12 
13   b = bson_new ();
14   ok (bson_append_timestamp (b, "ts", l), "bson_append_timestamp() works");
15   bson_finish (b);
16 
17   cmp_ok (bson_size (b), "==", 17, "BSON timestamp element size check");
18   ok (memcmp (bson_data (b),
19               "\021\000\000\000\021\164\163\000\352\026\260\114\002\000\000"
20               "\000\000",
21               bson_size (b)) == 0,
22       "BSON timestamp element contents check");
23 
24   bson_free (b);
25 
26   b = bson_new ();
27   ok (bson_append_timestamp (b, NULL, l) == FALSE,
28       "bson_append_timestamp() with a NULL key should fail");
29   ok (bson_append_timestamp (NULL, "ts", l) == FALSE,
30       "bson_append_timestamp() without a BSON object should fail");
31   bson_finish (b);
32   cmp_ok (bson_size (b), "==", 5,
33           "BSON object should be empty");
34 
35   ok (bson_append_timestamp (b, "ts", l) == FALSE,
36       "Appending to a finished element should fail");
37 
38   bson_free (b);
39 }
40 
41 RUN_TEST (7, bson_timestamp);
42