Update to error messages.
[m6w6/libmemcached] / tests / libmemcached_world.h
index 17561838c05d3967fb217182602e23ac1cfa006f..ad55d17c600ed89e04187f753fc760d05dc13fdf 100644 (file)
@@ -27,18 +27,29 @@ struct libmemcached_test_container_st
   { }
 };
 
-#define SERVERS_TO_CREATE 5
-
 static void *world_create(server_startup_st& servers, test_return_t& error)
 {
-  if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0)
+  if (HAVE_MEMCACHED_BINARY == 0)
+  {
+    error= TEST_FATAL;
+    return NULL;
+  }
+
+  if (servers.sasl() and (LIBMEMCACHED_WITH_SASL_SUPPORT == 0 or MEMCACHED_SASL_BINARY == 0))
   {
     error= TEST_SKIPPED;
     return NULL;
   }
 
-  in_port_t max_port;
-  for (uint32_t x= 0; x < SERVERS_TO_CREATE; x++)
+  // Assume we are running under valgrind, and bail
+  if (servers.sasl() and getenv("TESTS_ENVIRONMENT"))
+  {
+    error= TEST_SKIPPED;
+    return NULL;
+  }
+
+  in_port_t max_port= TEST_PORT_BASE;
+  for (uint32_t x= 0; x < servers.count(); x++)
   {
     in_port_t port;
 
@@ -61,7 +72,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     {
       if (not server_startup(servers, "memcached-sasl", port, 1, argv))
       {
-        error= TEST_FAILURE;
+        error= TEST_FATAL;
         return NULL;
       }
     }
@@ -69,7 +80,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
     {
       if (not server_startup(servers, "memcached", port, 1, argv))
       {
-        error= TEST_FAILURE;
+        error= TEST_FATAL;
         return NULL;
       }
     }
@@ -82,7 +93,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
       const char *argv[1]= { "memcached" };
       if (not servers.start_socket_server("memcached-sasl", max_port +1, 1, argv))
       {
-        error= TEST_FAILURE;
+        error= TEST_FATAL;
         return NULL;
       }
     }
@@ -91,7 +102,7 @@ static void *world_create(server_startup_st& servers, test_return_t& error)
       const char *argv[1]= { "memcached" };
       if (not servers.start_socket_server("memcached", max_port +1, 1, argv))
       {
-        error= TEST_FAILURE;
+        error= TEST_FATAL;
         return NULL;
       }
     }
@@ -119,9 +130,10 @@ static test_return_t world_container_startup(libmemcached_test_container_st *con
                                                     buffer, sizeof(buffer)),
                    container->construct.option_string().c_str());
 
-  test_true(not container->parent);
+  test_null(container->parent);
   container->parent= memcached(container->construct.option_string().c_str(), container->construct.option_string().size());
   test_true(container->parent);
+  test_compare(MEMCACHED_SUCCESS, memcached_version(container->parent));
 
   if (container->construct.sasl())
   {
@@ -163,7 +175,7 @@ static test_return_t world_container_shutdown(libmemcached_test_container_st *co
 static test_return_t world_test_startup(libmemcached_test_container_st *container)
 {
   test_true(container);
-  test_true(not container->memc);
+  test_null(container->memc);
   test_true(container->parent);
   container->memc= memcached_clone(NULL, container->parent);
   test_true(container->memc);
@@ -204,9 +216,8 @@ static test_return_t world_post_run(libmemcached_test_container_st *container)
   return TEST_SUCCESS;
 }
 
-static test_return_t world_on_error(test_return_t test_state, libmemcached_test_container_st *container)
+static test_return_t world_on_error(test_return_t , libmemcached_test_container_st *container)
 {
-  (void)test_state;
   test_true(container->memc);
   memcached_free(container->memc);
   container->memc= NULL;
@@ -237,7 +248,17 @@ static test_return_t _runner_default(libmemcached_test_callback_fn func, libmemc
   {
     test_true(container);
     test_true(container->memc);
-    return func(container->memc);
+    test_return_t ret;
+    try {
+      ret= func(container->memc);
+    }
+    catch (std::exception& e)
+    {
+      Error << e.what();
+      return TEST_FAILURE;
+    }
+
+    return ret;
   }
 
   return TEST_SUCCESS;