summaryrefslogtreecommitdiff
path: root/tests/unit/mongo/sync-cursor/sync_cursor_get_data.c
blob: 0dd391cd115235e31d411e10a48ad5357dbc242e (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
#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);