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 (); }
void test_mongo_sync_gridfs_stream_new (void) { mongo_sync_connection *conn; mongo_sync_gridfs *gfs; mongo_sync_gridfs_stream *stream; bson *meta; mongo_util_oid_init (0); meta = bson_build (BSON_TYPE_STRING, "my-id", "sync_gridfs_stream_new", -1, BSON_TYPE_NONE); bson_finish (meta); ok (mongo_sync_gridfs_stream_new (NULL, meta) == FALSE, "mongo_sync_gridfs_stream_new() should fail with a NULL connection"); begin_network_tests (2); 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 (stream != NULL, "mongo_sync_gridfs_stream_new() works with NULL metadata"); mongo_sync_gridfs_stream_close (stream); stream = mongo_sync_gridfs_stream_new (gfs, meta); ok (stream != NULL, "mongo_sync_gridfs_stream_new() works with metadata"); mongo_sync_gridfs_stream_close (stream); mongo_sync_gridfs_free (gfs, TRUE); end_network_tests (); bson_free (meta); }
void test_mongo_sync_gridfs_stream_write (void) { mongo_sync_connection *conn; mongo_sync_gridfs *gfs; mongo_sync_gridfs_stream *stream; bson *meta; guint8 buffer[4096]; mongo_util_oid_init (0); meta = bson_build (BSON_TYPE_STRING, "my-id", "sync_gridfs_stream_write", -1, BSON_TYPE_NONE); bson_finish (meta); ok (mongo_sync_gridfs_stream_write (NULL, buffer, sizeof (buffer)) == FALSE, "mongo_sync_gridfs_stream_write() should fail with a NULL connection"); begin_network_tests (4); 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, meta); ok (mongo_sync_gridfs_stream_write (stream, NULL, sizeof (buffer)) == FALSE, "mongo_sync_gridfs_stream_write() should fail with a NULL buffer"); ok (mongo_sync_gridfs_stream_write (stream, buffer, 0) == FALSE, "mongo_sync_gridfs_stream_write() should fail with 0 size"); ok (mongo_sync_gridfs_stream_write (stream, buffer, sizeof (buffer)) == TRUE, "mongo_sync_gridfs_stream_write() works"); stream->file.type = LMC_GRIDFS_FILE_STREAM_READER; ok (mongo_sync_gridfs_stream_write (stream, buffer, sizeof (buffer)) == FALSE, "mongo_sync_gridfs_stream_write() should fail with a read stream"); mongo_sync_gridfs_stream_close (stream); mongo_sync_gridfs_free (gfs, TRUE); end_network_tests (); bson_free (meta); }
void test_mongo_sync_gridfs_stream_read (void) { mongo_sync_connection *conn; mongo_sync_gridfs *gfs; mongo_sync_gridfs_stream *stream; guint8 buffer[4096]; mongo_util_oid_init (0); ok (mongo_sync_gridfs_stream_read (NULL, buffer, sizeof (buffer)) == -1, "mongo_sync_gridfs_stream_read() should fail with a NULL connection"); begin_network_tests (3); 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_read (stream, buffer, sizeof (buffer)) == -1, "mongo-sync_gridfs_stream_read() should fail when the stream is " "write-only"); stream->file.type = LMC_GRIDFS_FILE_STREAM_READER; ok (mongo_sync_gridfs_stream_read (stream, NULL, sizeof (buffer)) == -1, "mongo_sync_gridfs_stream_read() should fail with a NULL buffer"); ok (mongo_sync_gridfs_stream_read (stream, buffer, 0) == -1, "mongo_sync_gridfs_stream_read() should fail with a 0 size"); mongo_sync_gridfs_stream_close (stream); mongo_sync_gridfs_free (gfs, TRUE); end_network_tests (); }