*/
#include <config.h>
+
#include <libtest/test.hpp>
+#include <cstdlib>
+
+using namespace libtest;
+
static test_return_t test_success_test(void *)
{
return TEST_SUCCESS;
}
-static test_return_t local_test(void *)
+static test_return_t test_failure_test(void *)
{
- char buffer[sizeof("LIBTEST_LOCAL=1")];
+ return TEST_SKIPPED; // Only run this when debugging
- snprintf(buffer, sizeof(buffer), "%s", "LIBTEST_LOCAL=1");
- test_compare(0, putenv(buffer));
+ test_compare(1, 2);
+ return TEST_SUCCESS;
+}
- test_true(test_is_local());
+static test_return_t local_test(void *)
+{
+ if (getenv("LIBTEST_LOCAL"))
+ {
+ test_true(test_is_local());
+ }
+ else
+ {
+ test_false(test_is_local());
+ }
return TEST_SUCCESS;
}
static test_return_t local_not_test(void *)
{
- test_compare(0, unsetenv("LIBTEST_LOCAL"));
+ return TEST_SKIPPED;
+ std::string temp;
+
+ const char *ptr;
+ if ((ptr= getenv("LIBTEST_LOCAL")) == NULL)
+ {
+ temp.append(ptr);
+ }
+
+ // unsetenv() will cause issues with valgrind
+ _compare(__FILE__, __LINE__, __func__, 0, unsetenv("LIBTEST_LOCAL"));
+ test_compare(0, unsetenv("LIBTEST_LOCAL"));
test_false(test_is_local());
+ test_compare(0, setenv("LIBTEST_LOCAL", "1", 1));
+ test_true(test_is_local());
+
+ if (temp.empty())
+ {
+ test_compare(0, unsetenv("LIBTEST_LOCAL"));
+ }
+ else
+ {
+ char *old_string= strdup(temp.c_str());
+ test_compare(0, setenv("LIBTEST_LOCAL", old_string, 1));
+ }
+
+ return TEST_SUCCESS;
+}
+
+#if 0
+static test_return_t pause_test(void *)
+{
+ (void)getchar();
return TEST_SUCCESS;
}
+#endif
+
+
+static test_return_t gearmand_cycle_test(void *object)
+{
+ server_startup_st *servers= (server_startup_st*)object;
+ test_true(servers);
+
+#ifndef HAVE_LIBGEARMAN
+ return TEST_SKIPPED;
+#endif
+
+ const char *argv[1]= { "cycle_gearmand" };
+ test_true(server_startup(*servers, "gearmand", 9999, 1, argv));
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t memcached_cycle_test(void *object)
+{
+ server_startup_st *servers= (server_startup_st*)object;
+ test_true(servers);
+
+#if !defined(MEMCACHED_BINARY) || !defined(HAVE_LIBMEMCACHED)
+ return TEST_SKIPPED;
+#endif
+
+ const char *argv[1]= { "cycle_memcached" };
+ test_true(server_startup(*servers, "memcached", 9998, 1, argv));
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t memcached_socket_cycle_test(void *object)
+{
+ server_startup_st *servers= (server_startup_st*)object;
+ test_true(servers);
+
+#if !defined(MEMCACHED_BINARY) || !defined(HAVE_LIBMEMCACHED)
+ return TEST_SKIPPED;
+#endif
+
+ const char *argv[1]= { "cycle_memcached" };
+ test_true(servers->start_socket_server("memcached", 9997, 1, argv));
+
+ return TEST_SUCCESS;
+}
+
+test_st gearmand_tests[] ={
+#if 0
+ {"pause", 0, pause_test },
+#endif
+ {"gearmand startup-shutdown", 0, gearmand_cycle_test },
+ {0, 0, 0}
+};
+
+test_st memcached_tests[] ={
+ {"memcached startup-shutdown", 0, memcached_cycle_test },
+ {"memcached(socket file) startup-shutdown", 0, memcached_socket_cycle_test },
+ {0, 0, 0}
+};
test_st tests_log[] ={
{"TEST_SUCCESS", 0, test_success_test },
+ {"TEST_FAILURE", 0, test_failure_test },
{0, 0, 0}
};
collection_st collection[] ={
{"return values", 0, 0, tests_log},
{"local", 0, 0, local_log},
+ {"gearmand", 0, 0, gearmand_tests},
+ {"memcached", 0, 0, memcached_tests},
{0, 0, 0, 0}
};
-void get_world(Framework *arg)
+static void *world_create(server_startup_st& servers, test_return_t&)
+{
+ return &servers;
+}
+
+void get_world(Framework *world)
{
- arg->collections= collection;
+ world->collections= collection;
+ world->_create= world_create;
}