From fd841e416881cc0392e61ec312c1870f3a0004bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Tue, 2 Dec 2014 10:06:21 +0100 Subject: Initial import of libmongo-client version 0.1.8-2 --- tests/unit/mongo/wire/packet_get_set_header_raw.c | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/unit/mongo/wire/packet_get_set_header_raw.c (limited to 'tests/unit/mongo/wire/packet_get_set_header_raw.c') diff --git a/tests/unit/mongo/wire/packet_get_set_header_raw.c b/tests/unit/mongo/wire/packet_get_set_header_raw.c new file mode 100644 index 0000000..d97a8b3 --- /dev/null +++ b/tests/unit/mongo/wire/packet_get_set_header_raw.c @@ -0,0 +1,56 @@ +#include "tap.h" +#include "test.h" +#include "mongo-wire.h" + +#include "libmongo-private.h" + +#include + +void +test_mongo_wire_packet_get_set_header_raw (void) +{ + mongo_packet *p; + mongo_packet_header ph1, ph2; + + p = mongo_wire_packet_new (); + + ok (mongo_wire_packet_get_header_raw (NULL, &ph2) == FALSE, + "mongo_wire_packet_get_header_raw() should fail with a NULL packet"); + ok (mongo_wire_packet_get_header_raw (p, NULL) == FALSE, + "mongo_wire_packet_get_header_raw() should fail with a NULL header"); + ok (mongo_wire_packet_set_header_raw (NULL, &ph1) == FALSE, + "mongo_wire_packet_set_header_raw() should fail with a NULL packet"); + ok (mongo_wire_packet_set_header_raw (p, NULL) == FALSE, + "mongo_wire_packet_set_header_raw() should fail with a NULL header"); + + ok (mongo_wire_packet_get_header_raw (p, &ph2), + "mongo_wire_packet_get_header_raw() works on a fresh packet"); + /* Need to convert from LE, because _new() sets the length to LE. */ + cmp_ok (GINT32_FROM_LE (ph2.length), "==", sizeof (mongo_packet_header), + "Initial packet length is the length of the header"); + + ph1.length = sizeof (mongo_packet_header); + ph1.id = 1; + ph1.resp_to = 0; + ph1.opcode = 1000; + + memset (&ph2, 0, sizeof (mongo_packet_header)); + + ok (mongo_wire_packet_set_header_raw (p, &ph1), + "mongo_wire_packet_set_header_raw() works"); + ok (mongo_wire_packet_get_header_raw (p, &ph2), + "mongo_wire_packet_get_header_raw() works"); + + cmp_ok (ph1.length, "==", ph2.length, + "Packet lengths match"); + cmp_ok (ph1.id, "==", ph2.id, + "Sequence IDs match"); + cmp_ok (ph1.resp_to, "==", ph2.resp_to, + "Response IDs match"); + cmp_ok (ph1.opcode, "==", ph2.opcode, + "OPCodes match"); + + mongo_wire_packet_free (p); +} + +RUN_TEST (12, mongo_wire_packet_get_set_header_raw); -- cgit v1.2.3