/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
- * Gearmand client and server library.
+ * Libmemcached library
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
- * All rights reserved.
+ * Copyright (C) 2012 Data Differential, http://datadifferential.com/
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
*
*/
-#include <config.h>
+#include <mem_config.h>
-#include <libmemcached/memcached.h>
+/*
+ C++ interface test
+*/
+#include <libmemcached-1.0/memcached.hpp>
+#include <libtest/test.hpp>
-#include "tests/parser.h"
-#include "tests/print.h"
+using namespace libtest;
-struct scanner_string_st {
- const char *c_ptr;
- size_t size;
-};
-
-test_return_t server_test(memcached_st *junk)
+static test_return_t memcached_NULL_string_TEST(void*)
{
- (void)junk;
- memcached_return_t rc;
- memcached_st *memc;
- memc= memcached_create(NULL);
-
- scanner_string_st test_strings[]= {
- { STRING_WITH_LEN("--server=localhost") },
- { STRING_WITH_LEN("--server=10.0.2.1") },
- { STRING_WITH_LEN("--server=example.com") },
- { STRING_WITH_LEN("--server=localhost:30") },
- { STRING_WITH_LEN("--server=10.0.2.1:20") },
- { STRING_WITH_LEN("--server=example.com:1024") },
- { NULL, 0}
- };
-
- for (scanner_string_st *ptr= test_strings; ptr->size; ptr++)
- {
- rc= memcached_parse_options(memc, ptr->c_ptr, ptr->size);
- test_true(rc == MEMCACHED_SUCCESS);
- memcached_servers_reset(memc);
- }
-
- memcached_free(memc);
+ test_null(memcached(NULL, 75));
+ return TEST_SUCCESS;
+}
+static test_return_t memcached_zero_string_length_TEST(void*)
+{
+ test_null(memcached("value", 0));
return TEST_SUCCESS;
}
-test_return_t servers_test(memcached_st *junk)
+static test_return_t putenv_localhost_quoted_TEST(void*)
{
- (void)junk;
- memcached_st *memc;
- memc= memcached_create(NULL);
+ test_zero(setenv("LIBMEMCACHED", "\"--server=localhost\"", 1));
+ test_null(memcached(NULL, 0));
- scanner_string_st test_strings[]= {
- { STRING_WITH_LEN("--servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225") },
- { STRING_WITH_LEN("--servers=a.example.com:80,localhost:80,b.example.com") },
- { STRING_WITH_LEN("--servers=localhost,localhost:80") },
- { NULL, 0}
- };
+ return TEST_SUCCESS;
+}
- for (scanner_string_st *ptr= test_strings; ptr->size; ptr++)
- {
- memcached_return_t rc;
- rc= memcached_parse_options(memc, ptr->c_ptr, ptr->size);
+static test_return_t putenv_NULL_TEST(void*)
+{
+ test_zero(setenv("LIBMEMCACHED", "", 1));
+ memcached_st *memc= memcached(NULL, 0);
+ test_true(memc);
- test_true(rc == MEMCACHED_SUCCESS);
+ memcached_free(memc);
- memcached_server_fn callbacks[1];
- callbacks[0]= server_print_callback;
- memcached_server_cursor(memc, callbacks, memc, 1);
+ return TEST_SUCCESS;
+}
- memcached_servers_reset(memc);
- }
+static test_return_t putenv_localhost_TEST(void*)
+{
+ test_zero(setenv("LIBMEMCACHED", "--server=localhost", 1));
+ memcached_st *memc= memcached(NULL, 0);
+ test_true(memc);
memcached_free(memc);
return TEST_SUCCESS;
}
+
+test_st memcached_TESTS[] ={
+ {"memcached(NULL, 75)", false, (test_callback_fn*)memcached_NULL_string_TEST },
+ {"memcached(\"value\", 0)", false, (test_callback_fn*)memcached_zero_string_length_TEST },
+ {"putenv(LIBMEMCACHED=--server=localhost)", false, (test_callback_fn*)putenv_localhost_TEST },
+ {"putenv(LIBMEMCACHED)", false, (test_callback_fn*)putenv_NULL_TEST },
+ {"putenv(LIBMEMCACHED=--server=\"localhost\")", false, (test_callback_fn*)putenv_localhost_quoted_TEST },
+ {0, 0, 0}
+};
+
+collection_st collection[] ={
+ {"memcached()", 0, 0, memcached_TESTS},
+ {0, 0, 0, 0}
+};
+
+void get_world(libtest::Framework* world)
+{
+ world->collections(collection);
+}
+