コード例 #1
0
ファイル: test-bcon-extract.c プロジェクト: 3rduncle/libbson
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);
}
コード例 #2
0
ファイル: test-bcon-extract.c プロジェクト: jonrangel/libbson
static void
test_dbpointer (void)
{
   const char *collection;
   bson_oid_t oid;
   const bson_oid_t *ooid;

   bson_oid_init (&oid, NULL);

   bson_t *bcon = BCON_NEW ("foo", BCON_DBPOINTER ("collection", &oid));

   assert (BCON_EXTRACT (bcon, "foo", BCONE_DBPOINTER (collection, ooid)));

   assert (strcmp (collection, "collection") == 0);
   assert (bson_oid_equal (ooid, &oid));

   bson_destroy (bcon);
}
コード例 #3
0
ファイル: test-bcon-extract.c プロジェクト: Cabriter/abelkhan
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);
}
コード例 #4
0
ファイル: test-bcon-extract.c プロジェクト: Cabriter/abelkhan
static void
test_inline_array (void)
{
   int32_t a, b;

   bson_t *bcon = BCON_NEW (
      "foo", "[",
         BCON_INT32 (1), BCON_INT32 (2),
      "]"
   );

   assert (BCON_EXTRACT (bcon,
      "foo", "[",
         BCONE_INT32 (a), BCONE_INT32 (b),
      "]"
   ));

   assert (a == 1);
   assert (b == 2);

   bson_destroy (bcon);
}
コード例 #5
0
ファイル: test-bcon-extract.c プロジェクト: Cabriter/abelkhan
static void
test_binary (void)
{
   bson_subtype_t subtype;
   uint32_t len;
   const uint8_t *binary;

   bson_t *bcon = BCON_NEW (
      "foo", BCON_BIN (
         BSON_SUBTYPE_BINARY,
         (uint8_t *)"deadbeef",
         8
         )
      );

   assert (BCON_EXTRACT (bcon, "foo", BCONE_BIN (subtype, binary, len)));

   assert (subtype == BSON_SUBTYPE_BINARY);
   assert (len == 8);
   assert (memcmp (binary, "deadbeef", 8) == 0);

   bson_destroy (bcon);
}
コード例 #6
0
static void
test_nested (void)
{
   const char *utf8;
   int i32;

   bson_t *bcon =
      BCON_NEW ("hello", "world", "foo", "{", "bar", BCON_INT32 (10), "}");

   assert (BCON_EXTRACT (bcon,
                         "hello",
                         BCONE_UTF8 (utf8),
                         "foo",
                         "{",
                         "bar",
                         BCONE_INT32 (i32),
                         "}"));

   assert (strcmp ("world", utf8) == 0);
   assert (i32 == 10);

   bson_destroy (bcon);
}
コード例 #7
0
ファイル: test-bcon-extract.c プロジェクト: jonrangel/libbson
static void
test_inline_doc (void)
{
   bson_int32_t a, b;

   bson_t *bcon = BCON_NEW (
      "foo", "{",
         "b", BCON_INT32 (2),
         "a", BCON_INT32 (1),
      "}"
   );

   assert (BCON_EXTRACT (bcon,
      "foo", "{",
         "a", BCONE_INT32 (a),
         "b", BCONE_INT32 (b),
      "}"
   ));

   assert (a == 1);
   assert (b == 2);

   bson_destroy (bcon);
}