1 #include "tap.h"
2 #include "test.h"
3 #include "bson.h"
4 
5 #include <string.h>
6 
7 void
8 test_bson_cursor_get_boolean (void)
9 {
10   bson *b;
11   bson_cursor *c;
12   gboolean d = TRUE;
13 
14   ok (bson_cursor_get_boolean (NULL, &d) == FALSE,
15       "bson_cursor_get_boolean() with a NULL cursor fails");
16 
17   b = test_bson_generate_full ();
18   c = bson_cursor_new (b);
19 
20   ok (bson_cursor_get_boolean (c, NULL) == FALSE,
21       "bson_cursor_get_boolean() with a NULL destination fails");
22   ok (bson_cursor_get_boolean (c, &d) == FALSE,
23       "bson_cursor_get_boolean() at the initial position fails");
24   cmp_ok (d, "==", TRUE,
25           "destination remains unchanged after failed cursor operations");
26   bson_cursor_free (c);
27 
28   c = bson_find (b, "TRUE");
29   ok (bson_cursor_get_boolean (c, &d),
30       "bson_cursor_get_boolean() works");
31   cmp_ok (d, "==", FALSE,
32           "bson_cursor_get_boolean() returns the correct result");
33 
34   bson_cursor_next (c);
35   ok (bson_cursor_get_boolean (c, &d) == FALSE,
36       "bson_cursor_get_boolean() should fail when the cursor points to "
37       "non-double data");
38 
39   bson_cursor_free (c);
40   bson_free (b);
41 }
42 
43 RUN_TEST (7, bson_cursor_get_boolean);
44