Пример #1
0
static void
test_bool (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_bool (&expected, "foo", -1, 1);

   BCON_APPEND (&bcon, "foo", BCON_BOOL (1));

   bson_eq_bson (&bcon, &expected);

   bson_reinit (&bcon);
   bson_reinit (&expected);

   bson_append_bool (&expected, "foo", -1, 0);

   BCON_APPEND (&bcon, "foo", BCON_BOOL (0));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #2
0
static void
test_concat (void)
{
   bson_t bcon, expected, child, child2;

   bson_init (&bcon);
   bson_init (&expected);
   bson_init (&child);
   bson_init (&child2);

   bson_append_utf8 (&child, "hello", -1, "world", -1);
   bson_append_document (&expected, "foo", -1, &child);

   BCON_APPEND (&bcon, "foo", "{", BCON(&child), "}");

   bson_eq_bson (&bcon, &expected);

   bson_reinit (&bcon);
   bson_reinit (&expected);
   bson_reinit (&child);

   bson_append_utf8 (&child, "0", -1, "bar", -1);
   bson_append_utf8 (&child, "1", -1, "baz", -1);
   bson_append_array (&expected, "foo", -1, &child);

   bson_append_utf8 (&child2, "0", -1, "baz", -1);
   BCON_APPEND (&bcon, "foo", "[", "bar", BCON(&child2), "]");

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&child);
   bson_destroy (&child2);
   bson_destroy (&expected);
}
Пример #3
0
static void
test_bson_document (void)
{
   bson_t ochild;
   bson_t *child = BCON_NEW ("bar", "baz");
   bson_t *bcon = BCON_NEW ("foo", BCON_DOCUMENT (child));

   assert (BCON_EXTRACT (bcon, "foo", BCONE_DOCUMENT (ochild)));

   bson_eq_bson (&ochild, child);

   bson_destroy (&ochild);
   bson_destroy (child);
   bson_destroy (bcon);
}
Пример #4
0
static void
test_bson_array (void)
{
   bson_t ochild;
   bson_t *child = BCON_NEW ("0", "baz");
   bson_t *bcon = BCON_NEW ("foo", BCON_ARRAY (child));

   assert (BCON_EXTRACT (bcon, "foo", BCONE_ARRAY (ochild)));

   bson_eq_bson (&ochild, child);

   bson_destroy (&ochild);
   bson_destroy (child);
   bson_destroy (bcon);
}
Пример #5
0
static void
test_minkey (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_minkey (&expected, "foo", -1);
   BCON_APPEND (&bcon, "foo", BCON_MINKEY);

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #6
0
static void
test_regex (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   /* option flags are sorted */
   bson_append_regex (&expected, "foo", -1, "^foo|bar$", "mis");
   BCON_APPEND (&bcon, "foo", BCON_REGEX ("^foo|bar$", "msi"));
   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #7
0
static void
test_double (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_double (&expected, "foo", -1, 1.1);
   BCON_APPEND(&bcon, "foo", BCON_DOUBLE(1.1));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #8
0
static void
test_utf8 (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_utf8 (&expected, "hello", -1, "world", -1);
   BCON_APPEND (&bcon, "hello", "world");

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #9
0
static void
test_bcon_new (void)
{
   bson_t expected;
   bson_t * bcon;

   bson_init (&expected);

   bson_append_utf8 (&expected, "hello", -1, "world", -1);
   bcon = BCON_NEW("hello", "world");

   bson_eq_bson (bcon, &expected);

   bson_destroy (bcon);
   bson_destroy (&expected);
}
Пример #10
0
static void
test_code (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_code (&expected, "foo", -1, "var a = {};");

   BCON_APPEND (&bcon, "foo", BCON_CODE ("var a = {};"));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #11
0
static void
test_symbol (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_symbol (&expected, "foo", -1, "deadbeef", -1);

   BCON_APPEND (&bcon, "foo", BCON_SYMBOL ("deadbeef"));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #12
0
static void
test_int64 (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_int64 (&expected, "foo", -1, 100);

   BCON_APPEND (&bcon, "foo", BCON_INT64 (100));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #13
0
static void
test_undefined (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_undefined (&expected, "foo", -1);

   BCON_APPEND (&bcon, "foo", BCON_UNDEFINED);

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #14
0
static void
test_null (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_null (&expected, "foo", -1);

   BCON_APPEND (&bcon, "foo", BCON_NULL);

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #15
0
static void
test_date_time (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_date_time (&expected, "foo", -1, 10000);

   BCON_APPEND (&bcon, "foo", BCON_DATE_TIME (10000));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #16
0
static void
test_regex (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_regex (&expected, "foo", -1, "^foo|bar$", "i");

   BCON_APPEND (&bcon, "foo", BCON_REGEX ("^foo|bar$", "i"));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #17
0
static void
test_timestamp (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_timestamp (&expected, "foo", -1, 100, 1000);

   BCON_APPEND (&bcon, "foo", BCON_TIMESTAMP (100, 1000));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #18
0
static void
test_decimal128 (void)
{
   bson_t bcon, expected;
   bson_decimal128_t dec;
   bson_decimal128_from_string("120E20", &dec);

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_decimal128 (&expected, "foo", -1, &dec);
   BCON_APPEND(&bcon, "foo", BCON_DECIMAL128(&dec));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #19
0
static void
test_codewscope (void)
{
   const char *code;
   bson_t oscope;

   bson_t *scope = BCON_NEW ("b", BCON_INT32 (10));
   bson_t *bcon = BCON_NEW ("foo", BCON_CODEWSCOPE ("var a = b;", scope));

   assert (BCON_EXTRACT (bcon, "foo", BCONE_CODEWSCOPE (code, oscope)));

   assert (strcmp (code, "var a = b;") == 0);
   bson_eq_bson (&oscope, scope);

   bson_destroy (&oscope);
   bson_destroy (scope);
   bson_destroy (bcon);
}
Пример #20
0
static void
test_iter (void)
{
   bson_t bcon, expected;
   bson_iter_t iter;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_int32 (&expected, "foo", -1, 100);
   bson_iter_init_find (&iter, &expected, "foo");

   BCON_APPEND (&bcon, "foo", BCON_ITER(&iter));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #21
0
static void
test_oid (void)
{
   bson_t bcon, expected;
   bson_oid_t oid;

   bson_init (&bcon);
   bson_init (&expected);

   bson_oid_init (&oid, NULL);

   bson_append_oid (&expected, "foo", -1, &oid);
   BCON_APPEND (&bcon, "foo", BCON_OID (&oid));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #22
0
static void
test_dbpointer (void)
{
   bson_t bcon, expected;
   bson_oid_t oid;

   bson_init (&bcon);
   bson_init (&expected);

   bson_oid_init (&oid, NULL);

   bson_append_dbpointer (&expected, "foo", -1, "collection", &oid);

   BCON_APPEND (&bcon, "foo", BCON_DBPOINTER ("collection", &oid));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #23
0
static void
test_inline_array (void)
{
   bson_t bcon, expected, child;

   bson_init (&bcon);
   bson_init (&expected);
   bson_init (&child);

   bson_append_utf8 (&child, "0", -1, "baz", -1);
   bson_append_array (&expected, "foo", -1, &child);

   BCON_APPEND (&bcon, "foo", "[", "baz", "]");

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&child);
   bson_destroy (&expected);
}
Пример #24
0
static void
test_iter (void)
{
   bson_iter_t iter;
   bson_t *other;

   bson_t *bcon = BCON_NEW ("foo", BCON_INT32 (10));

   assert (BCON_EXTRACT (bcon, "foo", BCONE_ITER (iter)));

   assert (bson_iter_type (&iter) == BSON_TYPE_INT32);
   assert (bson_iter_int32 (&iter) == 10);

   other = BCON_NEW ("foo", BCON_ITER (&iter));

   bson_eq_bson (other, bcon);

   bson_destroy (bcon);
   bson_destroy (other);
}
Пример #25
0
static void
test_inline_doc (void)
{
   bson_t bcon, expected, child;

   bson_init (&bcon);
   bson_init (&expected);
   bson_init (&child);

   bson_append_utf8 (&child, "bar", -1, "baz", -1);
   bson_append_document (&expected, "foo", -1, &child);

   BCON_APPEND (&bcon, "foo", "{", "bar", "baz", "}");

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
   bson_destroy (&child);
}
Пример #26
0
static void
test_binary (void)
{
   bson_t bcon, expected;

   bson_init (&bcon);
   bson_init (&expected);

   bson_append_binary (
      &expected, "foo", -1, BSON_SUBTYPE_BINARY, (uint8_t *) "deadbeef", 8);

   BCON_APPEND (&bcon,
                "foo",
                BCON_BIN (BSON_SUBTYPE_BINARY, (const uint8_t *) "deadbeef", 8),
                NULL);

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
}
Пример #27
0
static void
test_codewscope (void)
{
   bson_t bcon, expected, scope;

   bson_init (&bcon);
   bson_init (&expected);
   bson_init (&scope);

   bson_append_int32(&scope, "b", -1, 10);

   bson_append_code_with_scope (&expected, "foo", -1, "var a = b;", &scope);

   BCON_APPEND (&bcon, "foo", BCON_CODEWSCOPE ("var a = b;", &scope));

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
   bson_destroy (&scope);
}
Пример #28
0
static void test_append_ctx (void)
{
   bson_t bcon, expected, child;

   bson_init (&bcon);
   bson_init (&expected);
   bson_init (&child);

   bson_append_utf8 (&child, "c", -1, "d", -1);
   bson_append_utf8 (&child, "e", -1, "f", -1);

   bson_append_document (&expected, "a", -1, &child);

   test_append_ctx_helper(&bcon, "a", "{", NULL, "add magic", "e", "f", "}", NULL);

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
   bson_destroy (&child);
}
Пример #29
0
static void
test_inline_nested (void)
{
   bson_t bcon, expected, foo, bar, third;

   bson_init (&bcon);
   bson_init (&expected);
   bson_init (&foo);
   bson_init (&bar);
   bson_init (&third);

   bson_append_utf8 (&third, "hello", -1, "world", -1);
   bson_append_int32 (&bar, "0", -1, 1);
   bson_append_int32 (&bar, "1", -1, 2);
   bson_append_document (&bar, "2", -1, &third);
   bson_append_array (&foo, "bar", -1, &bar);
   bson_append_document (&expected, "foo", -1, &foo);

   BCON_APPEND (&bcon,
                "foo",
                "{",
                "bar",
                "[",
                BCON_INT32 (1),
                BCON_INT32 (2),
                "{",
                "hello",
                "world",
                "}",
                "]",
                "}");

   bson_eq_bson (&bcon, &expected);

   bson_destroy (&bcon);
   bson_destroy (&expected);
   bson_destroy (&foo);
   bson_destroy (&bar);
   bson_destroy (&third);
}
Пример #30
0
static void
_test_bson_json_read_compare (const char *json,
                              int         size,
                              ...)
{
   bson_error_t error = { 0 };
   bson_json_reader_t *reader;
   va_list ap;
   int r;
   bson_t *compare;
   bson_t bson = BSON_INITIALIZER;

   reader = bson_json_data_reader_new ((size == 1), size);
   bson_json_data_reader_ingest(reader, (uint8_t *)json, strlen(json));

   va_start (ap, size);

   while ((r = bson_json_reader_read (reader, &bson, &error))) {
      if (r == -1) {
         fprintf (stderr, "%s\n", error.message);
         abort ();
      }

      compare = va_arg (ap, bson_t *);

      assert (compare);

      bson_eq_bson (&bson, compare);

      bson_destroy (compare);

      bson_reinit (&bson);
   }

   va_end (ap);

   bson_json_reader_destroy (reader);
   bson_destroy (&bson);
}