summaryrefslogtreecommitdiff
path: root/tests/unit/mongo/sync-gridfs-stream/sync_gridfs_stream_seek.c
blob: 49547bc3abd350bd4c23633d0ac906c21b06b745 (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
55
56
57
58
59
60
61
62
63
64
65
#include "test.h"
#include "mongo.h"

#include "libmongo-private.h"

#include <unistd.h>

void
test_mongo_sync_gridfs_stream_seek (void)
{
  mongo_sync_connection *conn;
  mongo_sync_gridfs *gfs;
  mongo_sync_gridfs_stream *stream;

  mongo_util_oid_init (0);

  ok (mongo_sync_gridfs_stream_seek (NULL, 0, SEEK_SET) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with a NULL stream");

  begin_network_tests (8);

  conn = mongo_sync_connect (config.primary_host, config.primary_port, FALSE);
  gfs = mongo_sync_gridfs_new (conn, config.gfs_prefix);

  stream = mongo_sync_gridfs_stream_new (gfs, NULL);

  ok (mongo_sync_gridfs_stream_seek (stream, 0, SEEK_SET) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with a write stream");

  stream->file.type = LMC_GRIDFS_FILE_STREAM_READER;

  ok (mongo_sync_gridfs_stream_seek (stream, -1, SEEK_SET) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with SEEK_SET and a negative "
      "position");

  ok (mongo_sync_gridfs_stream_seek (stream, 10, SEEK_SET) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with SEEK_SET and a position "
      "past EOF");

  ok (mongo_sync_gridfs_stream_seek (stream, -1, SEEK_CUR) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with SEEK_CUR and a position "
      "before the start");

  ok (mongo_sync_gridfs_stream_seek (stream, 10, SEEK_CUR) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with SEEK_CUR and a position "
      "past EOF");

  ok (mongo_sync_gridfs_stream_seek (stream, 1, SEEK_END) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with SEEK_END and a position "
      "past EOF");

  ok (mongo_sync_gridfs_stream_seek (stream, -1, SEEK_END) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with SEEK_END and a position "
      "before the start");

  ok (mongo_sync_gridfs_stream_seek (stream, 0, 42) == FALSE,
      "mongo_sync_gridfs_stream_seek() fails with an invalid whence");

  mongo_sync_gridfs_stream_close (stream);
  mongo_sync_gridfs_free (gfs, TRUE);

  end_network_tests ();
}

RUN_TEST (9, mongo_sync_gridfs_stream_seek);