/
helpers_test.c
62 lines (42 loc) · 1.19 KB
/
helpers_test.c
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
/* helpers.c */
#include "test.h"
#include "mongo.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
void test_index_helper( mongo *conn ) {
int ret;
bson b, out;
bson_iterator it;
bson_init( &b );
bson_append_int( &b, "foo", -1 );
bson_finish( &b );
mongo_create_index( conn, "test.bar", &b, NULL, MONGO_INDEX_SPARSE | MONGO_INDEX_UNIQUE, &out );
bson_destroy( &b );
bson_destroy( &out );
bson_init( &b );
bson_append_start_object( &b, "key" );
bson_append_int( &b, "foo", -1 );
bson_append_finish_object( &b );
bson_finish( &b );
ret = mongo_find_one( conn, "test.system.indexes", &b, NULL, &out );
ASSERT( ret == MONGO_OK );
bson_print( &out );
bson_iterator_init( &it, &out );
ASSERT( bson_find( &it, &out, "unique" ) );
ASSERT( bson_find( &it, &out, "sparse" ) );
bson_destroy( &b );
bson_destroy( &out );
}
int main() {
mongo conn[1];
INIT_SOCKETS_FOR_WINDOWS;
if( mongo_client( conn, TEST_SERVER, 27017 ) != MONGO_OK ) {
printf( "Failed to connect" );
exit( 1 );
}
test_index_helper( conn );
mongo_destroy( conn );
return 0;
}