Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 65 lines (50 sloc) 1.518 kb
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
1 /* count_delete.c */
2
6c6af36 @RedBeard0531 passing all tests on windows CDRIVER-9
RedBeard0531 authored
3 #include "test.h"
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
4 #include "mongo.h"
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8
70bc545 @banker minor: astyle
banker authored
9 int main() {
48fa350 @banker Remove bson_buffer objects; use bson objects only.
banker authored
10 mongo conn[1];
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
11 bson b;
12 int i;
13
70bc545 @banker minor: astyle
banker authored
14 const char *db = "test";
15 const char *col = "c.simple";
16 const char *ns = "test.c.simple";
6c6af36 @RedBeard0531 passing all tests on windows CDRIVER-9
RedBeard0531 authored
17
18 INIT_SOCKETS_FOR_WINDOWS;
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
19
70bc545 @banker minor: astyle
banker authored
20 if ( mongo_connect( conn , TEST_SERVER , 27017 ) ) {
21 printf( "failed to connect\n" );
22 exit( 1 );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
23 }
24
25 /* if the collection doesn't exist dropping it will fail */
70bc545 @banker minor: astyle
banker authored
26 if ( !mongo_cmd_drop_collection( conn, "test", col, NULL )
27 && mongo_count( conn, db, col, NULL ) != 0 ) {
28 printf( "failed to drop collection\n" );
29 exit( 1 );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
30 }
31
70bc545 @banker minor: astyle
banker authored
32 for( i=0; i< 5; i++ ) {
48fa350 @banker Remove bson_buffer objects; use bson objects only.
banker authored
33 bson_init( &b );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
34
48fa350 @banker Remove bson_buffer objects; use bson objects only.
banker authored
35 bson_append_new_oid( &b, "_id" );
36 bson_append_int( &b , "a" , i+1 ); /* 1 to 5 */
70bc545 @banker minor: astyle
banker authored
37 bson_finish( &b );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
38
c4c4aa0 @RedBeard0531 Make conn a 1 element array rather than a variable
RedBeard0531 authored
39 mongo_insert( conn , ns , &b );
70bc545 @banker minor: astyle
banker authored
40 bson_destroy( &b );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
41 }
42
43 /* query: {a: {$gt: 3}} */
48fa350 @banker Remove bson_buffer objects; use bson objects only.
banker authored
44 bson_init( &b );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
45 {
70bc545 @banker minor: astyle
banker authored
46 bson_append_start_object( &b, "a" );
47 bson_append_int( &b, "$gt", 3 );
48 bson_append_finish_object( &b );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
49 }
70bc545 @banker minor: astyle
banker authored
50 bson_finish( &b );
48fa350 @banker Remove bson_buffer objects; use bson objects only.
banker authored
51
70bc545 @banker minor: astyle
banker authored
52 ASSERT( mongo_count( conn, db, col, NULL ) == 5 );
53 ASSERT( mongo_count( conn, db, col, &b ) == 2 );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
54
70bc545 @banker minor: astyle
banker authored
55 mongo_remove( conn, ns, &b );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
56
70bc545 @banker minor: astyle
banker authored
57 ASSERT( mongo_count( conn, db, col, NULL ) == 3 );
58 ASSERT( mongo_count( conn, db, col, &b ) == 0 );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
59
48fa350 @banker Remove bson_buffer objects; use bson objects only.
banker authored
60 bson_destroy( &b );
70bc545 @banker minor: astyle
banker authored
61 mongo_cmd_drop_db( conn, db );
62 mongo_destroy( conn );
2a09ec8 @RedBeard0531 Added mongo_count. renamed tests for easier glob
RedBeard0531 authored
63 return 0;
64 }
Something went wrong with that request. Please try again.