c++: fix -Wbad-function-cast
[awesomized/libmemcached] / tests / memcapable.cc
index 60fd00ada4820c0d68080279439a30045cfa11c0..4e7c957da441a8648b941a1a833a7c7ac35c2526 100644 (file)
   Test that we are cycling the servers we are creating during testing.
 */
 
-#include <config.h>
+#include <mem_config.h>
 
 #include <libtest/test.hpp>
-#include <libmemcached/memcached.h>
+#include <libmemcached-1.0/memcached.h>
 
 using namespace libtest;
 
 #ifndef __INTEL_COMPILER
-#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+# pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #endif
 
 static std::string executable;
 
 static test_return_t quiet_test(void *)
 {
-  const char *args[]= { "-q", 0 };
+  char buffer[1024];
+  snprintf(buffer, sizeof(buffer), "%d", int(get_free_port()));
+  const char *args[]= { "-p", buffer, "-q", 0 };
+
+  test_compare(EXIT_FAILURE, exec_cmdline(executable, args, true));
 
-  test_true(exec_cmdline(executable, args));
   return TEST_SUCCESS;
 }
 
 static test_return_t help_test(void *)
 {
-  const char *args[]= { "-q", "--help", 0 };
+  const char *args[]= { "-h", 0 };
+
+  test_compare(EXIT_SUCCESS, exec_cmdline(executable, args, true));
 
-  test_true(exec_cmdline(executable, args));
   return TEST_SUCCESS;
 }
 
 static test_return_t ascii_test(void *)
 {
   char buffer[1024];
-  snprintf(buffer, sizeof(buffer), "-p %d", int(default_port()));
-  const char *args[]= { "-q", buffer, " -a ", 0 };
+  snprintf(buffer, sizeof(buffer), "%d", int(default_port()));
+  const char *args[]= { "-p", buffer, "-a", 0 };
+
+  test_true(exec_cmdline(executable, args, true) <= EXIT_FAILURE);
 
-  test_true(exec_cmdline(executable, args));
   return TEST_SUCCESS;
 }
 
 static test_return_t binary_test(void *)
 {
   char buffer[1024];
-  snprintf(buffer, sizeof(buffer), "-p %d", int(default_port()));
-  const char *args[]= { "-q", buffer, " -b ", 0 };
+  snprintf(buffer, sizeof(buffer), "%d", int(default_port()));
+  const char *args[]= { "-p", buffer, "-b", 0 };
+
+  test_true(exec_cmdline(executable, args, true) <= EXIT_FAILURE);
 
-  test_true(exec_cmdline(executable, args));
   return TEST_SUCCESS;
 }
 
 test_st memcapable_tests[] ={
   {"--quiet", 0, quiet_test},
-  {"--help", 0, help_test},
+  {"-h", 0, help_test},
   {"-a, ascii", 0, ascii_test},
   {"-b, binary", 0, binary_test},
   {0, 0, 0}
@@ -101,28 +107,20 @@ collection_st collection[] ={
   {0, 0, 0, 0}
 };
 
-static void *world_create(server_startup_st& servers, test_return_t& error)
+static void *world_create(server_startup_st& servers, test_return_t&)
 {
-  if (HAVE_MEMCACHED_BINARY == 0)
-  {
-    error= TEST_FATAL;
-    return NULL;
-  }
-
-  const char *argv[1]= { "memcapable" };
-  if (not server_startup(servers, "memcached", MEMCACHED_DEFAULT_PORT +10, 1, argv))
-  {
-    error= TEST_FAILURE;
-  }
+  SKIP_UNLESS(libtest::has_memcached());
+
+  SKIP_UNLESS(server_startup(servers, "memcached", libtest::default_port(), NULL));
 
   return &servers;
 }
 
 
-void get_world(Framework *world)
+void get_world(libtest::Framework* world)
 {
   executable= "./clients/memcapable";
-  world->collections= collection;
-  world->_create= world_create;
+  world->collections(collection);
+  world->create(world_create);
 }