X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fplus.cpp;h=90f7a0daaf58774c72d33547298d7a00aedf7b13;hb=48171051f3c496c6bb2841a3abadbe9faa9cad07;hp=c4b671153269ea9724082dec199549172c3d4504;hpb=ae6bc7501efd5aeaaee92dabe2da0ec2d1625c5b;p=m6w6%2Flibmemcached diff --git a/tests/plus.cpp b/tests/plus.cpp index c4b67115..90f7a0da 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -1,7 +1,47 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2009 Brian Aker All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + /* C++ interface test */ #include +#include #include #include @@ -12,15 +52,12 @@ #include #include -#include - -#include - #include #include using namespace std; using namespace memcache; +using namespace libtest; extern "C" { test_return_t basic_test(memcached_st *memc); @@ -91,13 +128,13 @@ test_return_t increment_test(memcached_st *original) test_compare(int_inc_value, int_ret_value); test_true(mcach.increment(key, 1, &int_ret_value)); - test_compare(2, int_ret_value); + test_compare(2UL, int_ret_value); test_true(mcach.increment(key, 1, &int_ret_value)); - test_compare(3, int_ret_value); + test_compare(3UL, int_ret_value); test_true(mcach.increment(key, 5, &int_ret_value)); - test_compare(8, int_ret_value); + test_compare(8UL, int_ret_value); return TEST_SUCCESS; } @@ -114,15 +151,18 @@ test_return_t basic_master_key_test(memcached_st *original) populate_vector(value, value_set); - foo.setByKey(master_key_a, key, value, 0, 0); - foo.getByKey(master_key_a, key, test_value); + test_true(foo.setByKey(master_key_a, key, value, 0, 0)); + test_true(foo.getByKey(master_key_a, key, test_value)); - test_true((memcmp(&value[0], &test_value[0], value.size()) == 0)); + test_compare(value.size(), test_value.size()); + test_memcmp(&value[0], &test_value[0], value.size()); test_value.clear(); - foo.getByKey(master_key_b, key, test_value); - test_true((memcmp(&value[0], &test_value[0], value.size()) == 0)); +#if 0 + test_false(foo.getByKey(master_key_b, key, test_value)); + test_zero(test_value.size()); +#endif return TEST_SUCCESS; } @@ -134,7 +174,7 @@ memcached_return_t callback_counter(const memcached_st *, { unsigned int *counter= static_cast(context); - *counter= *counter + 1; + *counter= *counter +1; return MEMCACHED_SUCCESS; } @@ -164,26 +204,24 @@ test_return_t mget_test(memcached_st *original) vector return_value; /* We need to empty the server before we continue the test */ - test_true(memc.flush(0)); + test_true(memc.flush()); test_true(memc.mget(keys)); - while ((mc_rc= memc.fetch(return_key, return_value)) != MEMCACHED_END) - { - test_true(return_value.size()); - return_value.clear(); - } - test_compare(mc_rc, MEMCACHED_END); + test_compare(MEMCACHED_NOTFOUND, + memc.fetch(return_key, return_value)); test_true(memc.setAll(keys, values, 50, 9)); test_true(memc.mget(keys)); - - while ((mc_rc= memc.fetch(return_key, return_value)) != MEMCACHED_END) + size_t count= 0; + while (memcached_success(mc_rc= memc.fetch(return_key, return_value))) { test_compare(return_key.length(), return_value.size()); test_memcmp(&return_value[0], return_key.c_str(), return_value.size()); + count++; } + test_compare(values.size(), count); return TEST_SUCCESS; } @@ -201,15 +239,15 @@ test_return_t basic_behavior(memcached_st *original) test_st tests[] ={ { "basic", 0, - reinterpret_cast(basic_test) }, + reinterpret_cast(basic_test) }, { "basic_master_key", 0, - reinterpret_cast(basic_master_key_test) }, + reinterpret_cast(basic_master_key_test) }, { "increment_test", 0, - reinterpret_cast(increment_test) }, + reinterpret_cast(increment_test) }, { "mget", 1, - reinterpret_cast(mget_test) }, + reinterpret_cast(mget_test) }, { "basic_behavior", 0, - reinterpret_cast(basic_behavior) }, + reinterpret_cast(basic_behavior) }, {0, 0, 0} }; @@ -222,21 +260,21 @@ collection_st collection[] ={ #include "libmemcached_world.h" -void get_world(world_st *world) +void get_world(Framework *world) { world->collections= collection; - world->create= reinterpret_cast(world_create); - world->destroy= reinterpret_cast(world_destroy); + world->_create= world_create; + world->_destroy= world_destroy; - world->test.startup= reinterpret_cast(world_test_startup); - world->test.flush= reinterpret_cast(world_flush); - world->test.pre_run= reinterpret_cast(world_pre_run); - world->test.post_run= reinterpret_cast(world_post_run); - world->test.on_error= reinterpret_cast(world_on_error); + world->item._startup= reinterpret_cast(world_test_startup); + world->item._flush= reinterpret_cast(world_flush); + world->item.set_pre(reinterpret_cast(world_pre_run)); + world->item.set_post(reinterpret_cast(world_post_run)); + world->_on_error= reinterpret_cast(world_on_error); - world->collection.startup= reinterpret_cast(world_container_startup); - world->collection.shutdown= reinterpret_cast(world_container_shutdown); + world->collection_startup= reinterpret_cast(world_container_startup); + world->collection_shutdown= reinterpret_cast(world_container_shutdown); - world->runner= &defualt_libmemcached_runner; + world->set_runner(&defualt_libmemcached_runner); }