summaryrefslogtreecommitdiff
path: root/tests/unit/bson/bson_new_from_data.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-12-02 10:06:21 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-12-02 10:06:21 +0100
commitfd841e416881cc0392e61ec312c1870f3a0004bd (patch)
tree8357ba56e79d614ba57f722e7878b853591dc339 /tests/unit/bson/bson_new_from_data.c
Initial import of libmongo-client version 0.1.8-2
Diffstat (limited to 'tests/unit/bson/bson_new_from_data.c')
-rw-r--r--tests/unit/bson/bson_new_from_data.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/unit/bson/bson_new_from_data.c b/tests/unit/bson/bson_new_from_data.c
new file mode 100644
index 0000000..740cb6e
--- /dev/null
+++ b/tests/unit/bson/bson_new_from_data.c
@@ -0,0 +1,46 @@
+#include "bson.h"
+#include "test.h"
+#include "tap.h"
+
+#include <string.h>
+
+void
+test_bson_new_from_data (void)
+{
+ bson *orig, *new;
+
+ orig = test_bson_generate_full ();
+
+ ok (bson_new_from_data (NULL, 0) == NULL,
+ "bson_new_from_data (NULL, 0) fails");
+ ok (bson_new_from_data (NULL, bson_size (orig)) == NULL,
+ "bson_new_from_data (NULL, size) fails");
+ ok (bson_new_from_data (bson_data (orig), 0) == NULL,
+ "bson_new_from_data (orig, 0) fails");
+ ok (bson_new_from_data (bson_data (orig), -1) == NULL,
+ "bson_new_from_data (orig, -1) fails");
+ ok (bson_new_from_data (NULL, -1) == NULL,
+ "bson_new_from_data (NULL, -1) fails");
+
+ ok ((new = bson_new_from_data (bson_data (orig),
+ bson_size (orig) - 1)) != NULL,
+ "bson_new_from_data() works");
+ cmp_ok (bson_size (new), "==", -1,
+ "Copied object is unfinished");
+ bson_finish (new);
+
+ ok (orig != new, "Copied BSON object is not the same as the original");
+
+ cmp_ok (bson_size (orig), "==", bson_size (new),
+ "Copied (& finished) object has the same size as the original");
+ ok (bson_data (orig) != bson_data (new),
+ "The copied data is not the same as the original");
+ ok (memcmp (bson_data (orig), bson_data (new),
+ bson_size (orig)) == 0,
+ "The copied data is identical to the original");
+
+ bson_free (orig);
+ bson_free (new);
+}
+
+RUN_TEST (11, bson_new_from_data);