summaryrefslogtreecommitdiff
path: root/tests/unit/mongo/wire/reply_packet_get_header.c
blob: 36b548cc4b2ac7fdafc009661df045efa207fa82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "test.h"
#include "tap.h"
#include "mongo-wire.h"

#include <string.h>

void
test_mongo_wire_reply_packet_get_header (void)
{
  mongo_packet *p;
  mongo_packet_header h;
  mongo_reply_packet_header rh;

  p = mongo_wire_packet_new ();
  memset (&h, 0, sizeof (mongo_packet_header));
  h.opcode = 1;
  h.length = sizeof (mongo_packet_header);

  mongo_wire_packet_set_header (p, &h);

  ok (mongo_wire_reply_packet_get_header (NULL, &rh) == FALSE,
      "mongo_wire_reply_packet_get_header() fails with a NULL packet");
  ok (mongo_wire_reply_packet_get_header (p, NULL) == FALSE,
      "mongo_wire_reply_packet_get_header() fails with a NULL header");

  ok (mongo_wire_reply_packet_get_header (p, &rh) == FALSE,
      "mongo_wire_reply_packet_get_header() fails if the packet has "
      "no reply header");

  h.opcode = 2;
  mongo_wire_packet_set_header (p, &h);
  ok (mongo_wire_reply_packet_get_header (p, &rh) == FALSE,
      "mongo_wire_reply_packet_get_header() fails if the packet is "
      "not a reply packet");

  mongo_wire_packet_free (p);

  p = test_mongo_wire_generate_reply (TRUE, 0, FALSE);

  ok (mongo_wire_reply_packet_get_header (p, &rh),
      "mongo_wire_reply_packet_get_header() works");
  cmp_ok (rh.flags, "==", 0,
          "Reply flags are correct");
  ok (rh.cursor_id == (gint64)12345,
      "Cursor ID is correct");
  cmp_ok (rh.start, "==", 0,
          "Reply start document is OK");
  cmp_ok (rh.returned, "==", 0,
          "Number of documents returned is OK");

  mongo_wire_packet_free (p);
}

RUN_TEST (9, mongo_wire_reply_packet_get_header);