WIP
[m6w6/libmemcached] / tests / libmemcached-1.0 / plus.cpp
index 5078f1f5583cea9c07ab32f5524eec8c3b5ed13c..1077ae72fd1a80b8ba98d803d400dfbb5d8dbf5e 100644 (file)
  *
  */
 
-#include <config.h>
+#include "mem_config.h"
 
 /*
   C++ interface test
 */
-#include <libmemcached-1.0/memcached.hpp>
-#include <libtest/test.hpp>
+#include "libmemcached-1.0/memcached.hpp"
+#include "libtest/test.hpp"
 
 #include <cstdio>
 #include <cstdlib>
@@ -49,7 +49,9 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <unistd.h>
+#if HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
 #include <ctime>
 
 #include <string>
@@ -181,6 +183,13 @@ static test_return_t mget_test(memcached_st *original)
   vector<char> return_value;
 
   /* We need to empty the server before we continue the test */
+  bool flush_res= memc.flush();
+  if (flush_res == false)
+  {
+    std::string error_string;
+    ASSERT_TRUE(memc.error(error_string));
+    Error << error_string;
+  }
   test_true(memc.flush());
 
   test_true(memc.mget(keys));
@@ -203,6 +212,36 @@ static test_return_t mget_test(memcached_st *original)
   return TEST_SUCCESS;
 }
 
+static test_return_t lp_1010899_TEST(void*)
+{
+  // Check to see everything is setup internally even when no initial hosts are
+  // given.
+  Memcache memc;
+
+  test_false(memc.increment(__func__, 0, NULL));
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t lp_1010899_with_args_TEST(memcached_st *original)
+{
+  // Check to see everything is setup internally even when a host is specified
+  // on creation.
+  const memcached_instance_st* instance= memcached_server_instance_by_position(original, 0);
+  Memcache memc(memcached_server_name(instance), memcached_server_port(instance));
+
+  test_false(memc.increment(__func__, 0, NULL));
+  test_true(memc.set(__func__, test_literal_param("12"), 0, 0)); 
+  test_true(memc.increment(__func__, 3, NULL));
+
+  std::vector<char> ret_val;
+  test_true(memc.get(__func__, ret_val));
+
+  test_strcmp(&ret_val[0], "15");
+
+  return TEST_SUCCESS;
+}
+
 static test_return_t basic_behavior(memcached_st *original)
 {
   Memcache memc(original);
@@ -273,9 +312,17 @@ test_st tests[] ={
   {0, 0, 0}
 };
 
+test_st regression_TESTS[] ={
+  { "lp:1010899 Memcache()", false, lp_1010899_TEST },
+  { "lp:1010899 Memcache(localhost, port)", false,
+    reinterpret_cast<test_callback_fn*>(lp_1010899_with_args_TEST) },
+  {0, 0, 0}
+};
+
 collection_st collection[] ={
   {"block", 0, 0, tests},
   {"error()", 0, 0, error_tests},
+  {"regression", 0, 0, regression_TESTS},
   {0, 0, 0, 0}
 };
 
@@ -284,21 +331,12 @@ collection_st collection[] ={
 #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT +10
 #include "tests/libmemcached_world.h"
 
-void get_world(Framework *world)
+void get_world(libtest::Framework* world)
 {
-  world->collections= collection;
-
-  world->_create= world_create;
-  world->_destroy= world_destroy;
-
-  world->item._startup= reinterpret_cast<test_callback_fn*>(world_test_startup);
-  world->item._flush= reinterpret_cast<test_callback_fn*>(world_flush);
-  world->item.set_pre(reinterpret_cast<test_callback_fn*>(world_pre_run));
-  world->item.set_post(reinterpret_cast<test_callback_fn*>(world_post_run));
-  world->_on_error= reinterpret_cast<test_callback_error_fn*>(world_on_error);
+  world->collections(collection);
 
-  world->collection_startup= reinterpret_cast<test_callback_fn*>(world_container_startup);
-  world->collection_shutdown= reinterpret_cast<test_callback_fn*>(world_container_shutdown);
+  world->create((test_callback_create_fn*)world_create);
+  world->destroy((test_callback_destroy_fn*)world_destroy);
 
-  world->set_runner(&defualt_libmemcached_runner);
+  world->set_runner(new LibmemcachedRunner);
 }