diff --git a/SConstruct b/SConstruct index fda27ce..9d71675 100644 --- a/SConstruct +++ b/SConstruct @@ -1,5 +1,15 @@ # -*- mode: python; -*- + +# --- options ---- +AddOption('--test-server', + dest='test_server', + default='127.0.0.1', + type='string', + nargs=1, + action='store', + help='IP address of server to use for testing') + import os import sys @@ -25,6 +35,7 @@ env.Default( env.Alias( "lib" , [ m[0] , b[0] ] ) ) testEnv = env.Clone() testEnv.Append( LIBS=["json"] ) testEnv.Append( LIBS=["mongoc","bson"] ) +testEnv.Append( CFLAGS=['-DTEST_SERVER=\\"%s\\"'%GetOption('test_server')] ) testEnv.Prepend( LIBPATH=["."] ) testCoreFiles = [ "test/md5.c" ] diff --git a/src/mongo.c b/src/mongo.c index 4cc13d3..17f8fcf 100644 --- a/src/mongo.c +++ b/src/mongo.c @@ -70,17 +70,14 @@ mongo_message * mongo_message_create( int len , int id , int responseTo , int op int mongo_connect( mongo_connection * conn , mongo_connection_options * options ){ int x = 1; - conn->options.port = 27017; conn->connected = 0; if ( options ){ memcpy( &(conn->options) , options , sizeof( mongo_connection_options ) ); - printf( "can't handle options to mongo_connect yet" ); - exit(-2); - return -2; } else { strcpy( conn->options.host , "127.0.0.1" ); + conn->options.port = 27017; } /* setup */ diff --git a/test/simple.c b/test/simple.c index 40dc38b..9746cb3 100644 --- a/test/simple.c +++ b/test/simple.c @@ -2,9 +2,11 @@ #include "mongo.h" #include +#include int main(){ mongo_connection conn; + mongo_connection_options opts; bson_buffer bb; bson b; @@ -12,7 +14,11 @@ int main(){ bson_append_double( &bb , "a" , 17 ); bson_init( &b , bson_finish( &bb ) , 1 ); - mongo_exit_on_error( mongo_connect( &conn , 0 ) ); + strncpy(opts.host, TEST_SERVER, 255); + opts.host[254] = '\0'; + opts.port = 27017; + + mongo_exit_on_error( mongo_connect( &conn , &opts ) ); mongo_exit_on_error( mongo_insert( &conn , "test.cc" , &b ) ); mongo_query( &conn , "test.cc" , &b , 0 , 0 , 0 , 0 );