diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-12-02 10:06:21 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2014-12-02 10:06:21 +0100 |
commit | fd841e416881cc0392e61ec312c1870f3a0004bd (patch) | |
tree | 8357ba56e79d614ba57f722e7878b853591dc339 /tests/unit/bson/bson_append_symbol.c |
Initial import of libmongo-client version 0.1.8-2
Diffstat (limited to 'tests/unit/bson/bson_append_symbol.c')
-rw-r--r-- | tests/unit/bson/bson_append_symbol.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/unit/bson/bson_append_symbol.c b/tests/unit/bson/bson_append_symbol.c new file mode 100644 index 0000000..6c16301 --- /dev/null +++ b/tests/unit/bson/bson_append_symbol.c @@ -0,0 +1,61 @@ +#include "tap.h" +#include "test.h" +#include "bson.h" + +#include <string.h> + +void +test_bson_symbol (void) +{ + bson *b; + + /* Test #1: A single symbol element, with default size. */ + b = bson_new (); + ok (bson_append_symbol (b, "hello", "world", -1), + "bson_append_symbol() works"); + bson_finish (b); + cmp_ok (bson_size (b), "==", 22, "BSON symbol element size check"); + ok (memcmp (bson_data (b), + "\026\000\000\000\016\150\145\154\154\157\000\006\000\000\000" + "\167\157\162\154\144\000\000", + bson_size (b)) == 0, + "BSON symbol element contents check"); + bson_free (b); + + /* Test #2: A single symbol element, with explicit length. */ + b = bson_new (); + ok (bson_append_symbol (b, "goodbye", + "cruel world, this garbage is gone.", + strlen ("cruel world")), + "bson_append_symbol() with explicit length works"); + bson_finish (b); + + cmp_ok (bson_size (b), "==", 30, "BSON symbol element size check, #2"); + ok (memcmp (bson_data (b), + "\036\000\000\000\016\147\157\157\144\142\171\145\000\014\000" + "\000\000\143\162\165\145\154\040\167\157\162\154\144\000\000", + bson_size (b)) == 0, + "BSON symbol element contents check, #2"); + bson_free (b); + + /* Test #3: Negative test, passing invalid arguments. */ + b = bson_new (); + ok (bson_append_symbol (b, "hello", "world", -42) == FALSE, + "bson_append_symbol() should fail with invalid length"); + ok (bson_append_symbol (b, "hello", NULL, -1) == FALSE, + "bson_append_symbol() should fail without a string"); + ok (bson_append_symbol (b, NULL, "world", -1) == FALSE, + "bson_append_symbol() should fail without a key name"); + ok (bson_append_symbol (NULL, "hello", "world", -1) == FALSE, + "bson_append_symbol() should fail without a BSON object"); + bson_finish (b); + cmp_ok (bson_size (b), "==", 5, + "BSON object should be empty"); + + ok (bson_append_symbol (b, "hello", "world", -1) == FALSE, + "Appending to a finished element should fail"); + + bson_free (b); +} + +RUN_TEST (12, bson_symbol); |