~ubuntu-branches/ubuntu/trusty/syslog-ng/trusty-proposed

« back to all changes in this revision

Viewing changes to modules/afmongodb/libmongo-client/tests/unit/mongo/wire/cmd_query.c

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS), Gergely Nagy
  • Date: 2011-10-11 14:30:48 UTC
  • mfrom: (1.3.7)
  • Revision ID: package-import@ubuntu.com-20111011143048-r1iljux9xbvj3lwh
Tags: 3.3.1.dfsg-1
* New upstream release with important fixes from upstream git tree with
  non-free manpages removed.
* Drop syslog-ng.conf(5) (closes: #496521).
* syslog-ng(8) is generated, and does not mention -Q anymore
  (closes: #616069).
* Supports CAP_SYSLOG on recent kernels (closes: #630172).
* Does not use g_timeout_add_seconds anymore (closes: #609154).

[ Gergely Nagy <algernon@madhouse-project.org> ]
* Update debian/copyright to DEP-5 format.
* Simplified the logrotate file by merging identical entries.
* Include local configuration files from /etc/syslog-ng/conf.d/ (Closes:
  #609050).
* Update syslog-ng.conf to be fully 3.3 compliant.
* Compress both source and binaries (except the syslog-ng meta
  package) with xz, instead of gzip.
* Use dpkg triggers to restart syslog-ng when appropriate.
* Include DFSG-free manual pages for all binaries.
* Build with Hardening enabled.
* Mention syslog(3) in /etc/default/syslog-ng, instead of
  <linux/kernel.h> (Closes: #608605)
* Support 'status' in the init script.
  Patch from Peter Eisentraut <petere@debian.org> (Closes: #644458)
* Build-Depend on libevtlog-dev (>= 0.2.12-5~) for correct shlibs.
* Use [linux-any] in Build-Depends instead of hardcoded links.
  (Closes: #634715)
* Use $SYSLOGNG_OPTS in the init script when reloading syslog-ng.
  (Closes: #589081)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "test.h"
 
2
#include "tap.h"
 
3
#include "mongo-wire.h"
 
4
 
 
5
#include <string.h>
 
6
 
 
7
void
 
8
test_mongo_wire_cmd_query (void)
 
9
{
 
10
  bson *q, *s, *tmp;
 
11
  mongo_packet *p;
 
12
 
 
13
  mongo_packet_header hdr;
 
14
  const guint8 *data;
 
15
  gint32 data_size;
 
16
 
 
17
  bson_cursor *c;
 
18
  gint32 pos;
 
19
 
 
20
  q = test_bson_generate_full ();
 
21
  s = bson_new ();
 
22
  bson_append_boolean (s, "_id", TRUE);
 
23
  bson_append_boolean (s, "double", TRUE);
 
24
  bson_finish (s);
 
25
 
 
26
  tmp = bson_new ();
 
27
 
 
28
  ok (mongo_wire_cmd_query (1, NULL, 0, 0, 0, q, s) == NULL,
 
29
      "mongo_wire_cmd_query() fails whith a NULL namespace");
 
30
  ok (mongo_wire_cmd_query (1, "test.ns", 0, 0, 0, NULL, s) == NULL,
 
31
      "mongo_wire_cmd_query() fails with a NULL query");
 
32
  ok (mongo_wire_cmd_query (1, "test.ns", 0, 0, 0, tmp, s) == NULL,
 
33
      "mongo_wire_cmd_query() fails with an unfinished query");
 
34
  ok (mongo_wire_cmd_query (1, "test.ns", 0, 0, 0, q, tmp) == NULL,
 
35
      "mongo_wire_cmd_query() fails with an unfinished selector");
 
36
  bson_free (tmp);
 
37
 
 
38
  ok ((p = mongo_wire_cmd_query (1, "test.ns", 0, 0, 10, q, NULL)) != NULL,
 
39
      "mongo_wire_cmd_query() works with a NULL selector");
 
40
 
 
41
  mongo_wire_packet_get_header (p, &hdr);
 
42
  cmp_ok ((data_size = mongo_wire_packet_get_data (p, &data)), "!=", -1,
 
43
          "Packet data size looks fine");
 
44
  cmp_ok (hdr.length, "==", sizeof (mongo_packet_header) + data_size,
 
45
          "Packet header length is OK");
 
46
  cmp_ok (hdr.id, "==", 1, "Packet request ID is ok");
 
47
  cmp_ok (hdr.resp_to, "==", 0, "Packet reply ID is ok");
 
48
 
 
49
  /* pos = zero + collection_name + NULL + skip + ret */
 
50
  pos = sizeof (gint32) + strlen ("test.ns") + 1 + sizeof (gint32) * 2;
 
51
  ok ((tmp = bson_new_from_data (data + pos,
 
52
                                 bson_stream_doc_size (data, pos) - 1)) != NULL,
 
53
      "Packet contains a valid BSON query document");
 
54
  bson_finish (tmp);
 
55
 
 
56
  ok ((c = bson_find (tmp, "int32")) != NULL,
 
57
      "BSON contains 'int32'");
 
58
  cmp_ok (bson_cursor_type (c), "==", BSON_TYPE_INT32,
 
59
          "int32 has correct type");
 
60
  bson_cursor_next (c);
 
61
  cmp_ok (bson_cursor_type (c), "==", BSON_TYPE_INT64,
 
62
          "next element has correct type too");
 
63
  ok (bson_cursor_next (c) == FALSE,
 
64
      "No more data after the update BSON object");
 
65
  bson_cursor_free (c);
 
66
 
 
67
  cmp_ok (hdr.length, "==", sizeof (mongo_packet_header) + pos +
 
68
          bson_size (q),
 
69
          "Packet header lenght is correct");
 
70
  bson_free (tmp);
 
71
  mongo_wire_packet_free (p);
 
72
 
 
73
  /*
 
74
   * Test again with a selector document
 
75
   */
 
76
 
 
77
  ok ((p = mongo_wire_cmd_query (1, "test.ns", 0, 0, 10, q, s)) != NULL,
 
78
      "mongo_wire_cmd_query() works with a NULL selector");
 
79
 
 
80
  mongo_wire_packet_get_header (p, &hdr);
 
81
  cmp_ok ((data_size = mongo_wire_packet_get_data (p, &data)), "!=", -1,
 
82
          "Packet data size looks fine");
 
83
  cmp_ok (hdr.length, "==", sizeof (mongo_packet_header) + data_size,
 
84
          "Packet header length is OK");
 
85
  cmp_ok (hdr.id, "==", 1, "Packet request ID is ok");
 
86
  cmp_ok (hdr.resp_to, "==", 0, "Packet reply ID is ok");
 
87
 
 
88
  /* pos = zero + collection_name + NULL + skip + ret */
 
89
  pos = sizeof (gint32) + strlen ("test.ns") + 1 + sizeof (gint32) * 2;
 
90
  ok ((tmp = bson_new_from_data (data + pos,
 
91
                                 bson_stream_doc_size (data, pos) - 1)) != NULL,
 
92
      "Packet contains a valid BSON query document");
 
93
  bson_finish (tmp);
 
94
  pos += bson_size (tmp);
 
95
  bson_free (tmp);
 
96
  bson_free (q);
 
97
  bson_free (s);
 
98
 
 
99
  ok ((s = bson_new_from_data (data + pos,
 
100
                               bson_stream_doc_size (data, pos) - 1)) != NULL,
 
101
      "Packet contains a valid BSON selector document");
 
102
  bson_finish (s);
 
103
 
 
104
  ok ((c = bson_find (s, "_id")) != NULL,
 
105
      "BSON contains '_id'");
 
106
  cmp_ok (bson_cursor_type (c), "==", BSON_TYPE_BOOLEAN,
 
107
          "_id has correct type");
 
108
  bson_cursor_next (c);
 
109
  cmp_ok (bson_cursor_type (c), "==", BSON_TYPE_BOOLEAN,
 
110
          "next element has correct type too");
 
111
 
 
112
  bson_cursor_free (c);
 
113
  bson_free (s);
 
114
  mongo_wire_packet_free (p);
 
115
}
 
116
 
 
117
RUN_TEST (25, mongo_wire_cmd_query);