Merge of build
[m6w6/libmemcached] / tests / parser.cc
index 5d23e9d4f0e3c444688084a313da4c6d4b75428c..898fdb54a73494e9b21403e94e2f365b393c98a8 100644 (file)
  *
  */
 
-#include <libtest/common.h>
+#include <config.h>
+#include <libtest/test.hpp>
+
+using namespace libtest;
 
 #include <vector>
 #include <iostream>
@@ -43,9 +46,7 @@
 #include <cerrno>
 #include <cassert>
 
-#define BUILDING_LIBMEMCACHED
-// !NEVER use common.h, always use memcached.h in your own apps
-#include <libmemcached/common.h>
+#include <libmemcached/memcached.h>
 #include <libmemcached/util.h>
 
 #include <tests/parser.h>
@@ -220,12 +221,9 @@ scanner_variable_t distribution_strings[]= {
 scanner_variable_t hash_strings[]= {
   { ARRAY,  make_scanner_string("--HASH=CRC"), scanner_string_null, NULL },
   { ARRAY,  make_scanner_string("--HASH=FNV1A_32"), scanner_string_null, NULL },
-  { ARRAY,  make_scanner_string("--HASH=FNV1A_64"), scanner_string_null, NULL },
   { ARRAY,  make_scanner_string("--HASH=FNV1_32"), scanner_string_null, NULL },
-  { ARRAY,  make_scanner_string("--HASH=FNV1_64"), scanner_string_null, NULL },
   { ARRAY,  make_scanner_string("--HASH=JENKINS"), scanner_string_null, NULL },
   { ARRAY,  make_scanner_string("--HASH=MD5"), scanner_string_null, NULL },
-  { ARRAY,  make_scanner_string("--HASH=MURMUR"), scanner_string_null, NULL },
   { NIL, scanner_string_null, scanner_string_null, NULL}
 };
 
@@ -235,20 +233,24 @@ static test_return_t _test_option(scanner_variable_t *scanner, bool test_true_op
   for (scanner_variable_t *ptr= scanner; ptr->type != NIL; ptr++)
   {
     memcached_st *memc= memcached(ptr->option.c_str, ptr->option.size);
-    if (test_true_opt)
+    
+    // The case that it should have parsed, but it didn't. We will inspect
+    // for an error with libmemcached_check_configuration()
+    if (not memc and test_true_opt)
     {
       char buffer[2048];
-      if (not memc)
-      {
-        libmemcached_check_configuration(ptr->option.c_str, ptr->option.size, buffer, sizeof(buffer));
-      }
+      bool success= libmemcached_check_configuration(ptr->option.c_str, ptr->option.size, buffer, sizeof(buffer));
 
       std::string temp(buffer);
       temp+= " with option string:";
       temp+= ptr->option.c_str;
+      test_true_got(success, temp.c_str());
 
-      test_true_got(memc, temp.c_str());
+      return TEST_FAILURE; // The line above should fail since memc should be null
+    }
 
+    if (test_true_opt)
+    {
       if (ptr->check_func)
       {
         test_return_t test_rc= (*ptr->check_func)(memc, ptr->result);
@@ -336,7 +338,6 @@ test_return_t memcached_create_with_options_with_filename(memcached_st*)
   memcached_st *memc_ptr;
   memc_ptr= memcached(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\""));
   test_true_got(memc_ptr, "memcached() failed");
-  test_strcmp(SUPPORT_EXAMPLE_CNF, memcached_array_string(memc_ptr->configure.filename));
   memcached_free(memc_ptr);
 
   return TEST_SUCCESS;
@@ -367,8 +368,8 @@ test_return_t libmemcached_check_configuration_test(memcached_st*)
   memcached_return_t rc;
   char buffer[BUFSIZ];
 
-  rc= libmemcached_check_configuration(test_literal_param("--server=localhost"), buffer, sizeof(buffer));
-  test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+  test_compare(MEMCACHED_SUCCESS,
+               libmemcached_check_configuration(test_literal_param("--server=localhost"), buffer, sizeof(buffer)));
 
   rc= libmemcached_check_configuration(test_literal_param("--dude=localhost"), buffer, sizeof(buffer));
   test_false_with(rc == MEMCACHED_SUCCESS, buffer);
@@ -396,9 +397,8 @@ test_return_t test_include_keyword(memcached_st*)
     return TEST_SKIPPED;
 
   char buffer[BUFSIZ];
-  memcached_return_t rc;
-  rc= libmemcached_check_configuration(test_literal_param("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer));
-  test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+  test_compare(MEMCACHED_SUCCESS, 
+               libmemcached_check_configuration(test_literal_param("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer)));
 
   return TEST_SUCCESS;
 }
@@ -406,9 +406,8 @@ test_return_t test_include_keyword(memcached_st*)
 test_return_t test_end_keyword(memcached_st*)
 {
   char buffer[BUFSIZ];
-  memcached_return_t rc;
-  rc= libmemcached_check_configuration(test_literal_param("--server=localhost END bad keywords"), buffer, sizeof(buffer));
-  test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+  test_compare(MEMCACHED_SUCCESS, 
+               libmemcached_check_configuration(test_literal_param("--server=localhost END bad keywords"), buffer, sizeof(buffer)));
 
   return TEST_SUCCESS;
 }
@@ -416,9 +415,8 @@ test_return_t test_end_keyword(memcached_st*)
 test_return_t test_reset_keyword(memcached_st*)
 {
   char buffer[BUFSIZ];
-  memcached_return_t rc;
-  rc= libmemcached_check_configuration(test_literal_param("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer));
-  test_true_got(rc == MEMCACHED_SUCCESS, buffer);
+  test_compare(MEMCACHED_SUCCESS,
+               libmemcached_check_configuration(test_literal_param("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer)));
 
   return TEST_SUCCESS;
 }
@@ -531,10 +529,8 @@ test_return_t test_hostname_port_weight(memcached_st *)
   const char *server_string= "--server=localhost:8888/?2 --server=localhost:8889/?3 --server=localhost:8890/?4 --server=localhost:8891/?5 --server=localhost:8892/?3";
   char buffer[BUFSIZ];
 
-  memcached_return_t rc;
   test_compare_got(MEMCACHED_SUCCESS,
-                   rc= libmemcached_check_configuration(server_string, strlen(server_string), buffer, sizeof(buffer)),
-                   memcached_strerror(NULL, rc));
+                   libmemcached_check_configuration(server_string, strlen(server_string), buffer, sizeof(buffer)), buffer);
 
   memcached_st *memc= memcached(server_string, strlen(server_string));
   test_true(memc);
@@ -615,17 +611,17 @@ test_return_t regression_bug_71231153_connect(memcached_st *)
     return TEST_SKIPPED;
 
   { // Test the connect-timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE
-    memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --CONNECT-TIMEOUT=0"));
+    memcached_st *memc= memcached(test_literal_param("--SERVER=10.0.2.252 --CONNECT-TIMEOUT=0"));
     test_true(memc);
-    test_compare(0, memc->connect_timeout);
+    test_zero(memc->connect_timeout);
     test_compare(MEMCACHED_DEFAULT_TIMEOUT, memc->poll_timeout);
 
     memcached_return_t rc;
     size_t value_len;
-    char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc);
+    char *value= memcached_get(memc, test_literal_param("test"), &value_len, NULL, &rc);
     test_false(value);
-    test_compare(0, value_len);
-    test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(NULL, rc));
+    test_zero(value_len);
+    test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc));
 
     memcached_free(memc);
   }
@@ -639,17 +635,21 @@ test_return_t regression_bug_71231153_poll(memcached_st *)
     return TEST_SKIPPED;
 
   { // Test the poll timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE
-    memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --POLL-TIMEOUT=0"));
+    memcached_st *memc= memcached(test_literal_param("--SERVER=10.0.2.252 --POLL-TIMEOUT=0"));
     test_true(memc);
     test_compare(MEMCACHED_DEFAULT_CONNECT_TIMEOUT, memc->connect_timeout);
-    test_compare(0, memc->poll_timeout);
+    test_zero(memc->poll_timeout);
 
     memcached_return_t rc;
     size_t value_len;
-    char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc);
+    char *value= memcached_get(memc, test_literal_param("test"), &value_len, NULL, &rc);
     test_false(value);
-    test_compare(0, value_len);
-    test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(NULL, rc));
+    test_zero(value_len);
+#ifdef __APPLE__
+    test_compare_got(MEMCACHED_CONNECTION_FAILURE, rc, memcached_last_error_message(memc));
+#else
+    test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc));
+#endif
 
     memcached_free(memc);
   }