File: sync_cursor_get_data.c

package info (click to toggle)
libmongo-client 0.1.5-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,256 kB
  • sloc: ansic: 13,795; makefile: 297; perl: 137; sh: 41
file content (51 lines) | stat: -rw-r--r-- 1,148 bytes parent folder | download | duplicates (2)
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
#include "test.h"
#include "mongo.h"
#include "config.h"

#include "libmongo-private.h"

#include <errno.h>

void
test_mongo_sync_cursor_get_data (void)
{
  mongo_sync_connection *conn;
  mongo_packet *p;
  bson *b;
  mongo_sync_cursor *c;

  test_env_setup ();

  p = test_mongo_wire_generate_reply (TRUE, 4, TRUE);
  conn = test_make_fake_sync_conn (-1, FALSE);

  c = mongo_sync_cursor_new (conn, config.ns, p);

  errno = 0;
  b = mongo_sync_cursor_get_data (NULL);
  ok (b == NULL && errno == EINVAL,
      "mongo_sync_cursor_get_data(NULL) should fail");

  b = mongo_sync_cursor_get_data (c);
  ok (b == NULL,
      "mongo_sync_cursor_get_data() should fail without _cursor_next()");

  mongo_sync_cursor_next (c);
  b = mongo_sync_cursor_get_data (c);
  ok (b != NULL,
      "mongo_sync_cursor_get_data() works");
  
  c->offset = 5;

  errno = 0;
  b = mongo_sync_cursor_get_data (c);
  ok (b == NULL && errno == ERANGE,
      "mongo_sync_cursor_get_data() should fail if the cursor is "
      "out of range");

  mongo_sync_cursor_free (c);
  mongo_sync_disconnect (conn);
  test_env_free ();
}

RUN_TEST (4, mongo_sync_cursor_get_data);