X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fplus.cpp;h=ee898d4e4662379123a621ce4b355bd62b8bb49c;hb=b4de8d3fd063b9017797dd9809ab3acb8a537606;hp=6b43164433cfeafa8741918b66af8d02e3d3ee5d;hpb=2424a380bc89c1507a9c1d35952c318423c9a100;p=m6w6%2Flibmemcached diff --git a/tests/plus.cpp b/tests/plus.cpp index 6b431644..ee898d4e 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -17,17 +17,19 @@ #include "test.h" #include +#include using namespace std; using namespace memcache; extern "C" { - test_return basic_test(memcached_st *memc); - test_return increment_test(memcached_st *memc); - test_return basic_master_key_test(memcached_st *memc); - test_return mget_result_function(memcached_st *memc); - test_return mget_test(memcached_st *memc); - memcached_return callback_counter(memcached_st *, + test_return_t basic_test(memcached_st *memc); + test_return_t increment_test(memcached_st *memc); + test_return_t basic_master_key_test(memcached_st *memc); + test_return_t mget_result_function(memcached_st *memc); + test_return_t basic_behavior(memcached_st *memc); + test_return_t mget_test(memcached_st *memc); + memcached_return_t callback_counter(memcached_st *, memcached_result_st *, void *context); void *world_create(void); @@ -49,7 +51,7 @@ static void copy_vec_to_string(vector &vec, string &str) } } -test_return basic_test(memcached_st *memc) +test_return_t basic_test(memcached_st *memc) { Memcache foo(memc); const string value_set("This is some data"); @@ -63,10 +65,23 @@ test_return basic_test(memcached_st *memc) assert((memcmp(&test_value[0], &value[0], test_value.size()) == 0)); - return TEST_SUCCESS; + /* + * Simple test of the exceptions here...this should throw an exception + * saying that the key is empty. + */ + try + { + foo.set("", value, 0, 0); + } + catch (Error &err) + { + return TEST_SUCCESS; + } + + return TEST_FAILURE; } -test_return increment_test(memcached_st *memc) +test_return_t increment_test(memcached_st *memc) { Memcache mcach(memc); bool rc; @@ -111,7 +126,7 @@ test_return increment_test(memcached_st *memc) return TEST_SUCCESS; } -test_return basic_master_key_test(memcached_st *memc) +test_return_t basic_master_key_test(memcached_st *memc) { Memcache foo(memc); const string value_set("Data for server A"); @@ -137,9 +152,9 @@ test_return basic_master_key_test(memcached_st *memc) } /* Count the results */ -memcached_return callback_counter(memcached_st *, - memcached_result_st *, - void *context) +memcached_return_t callback_counter(memcached_st *, + memcached_result_st *, + void *context) { unsigned int *counter= static_cast(context); @@ -148,7 +163,7 @@ memcached_return callback_counter(memcached_st *, return MEMCACHED_SUCCESS; } -test_return mget_result_function(memcached_st *memc) +test_return_t mget_result_function(memcached_st *memc) { Memcache mc(memc); bool rc; @@ -172,7 +187,7 @@ test_return mget_result_function(memcached_st *memc) values.push_back(&val2); values.push_back(&val3); unsigned int counter; - memcached_execute_function callbacks[1]; + memcached_execute_fn callbacks[1]; /* We need to empty the server before we continue the test */ rc= mc.flush(0); @@ -191,11 +206,11 @@ test_return mget_result_function(memcached_st *memc) return TEST_SUCCESS; } -test_return mget_test(memcached_st *memc) +test_return_t mget_test(memcached_st *memc) { Memcache mc(memc); bool rc; - memcached_return mc_rc; + memcached_return_t mc_rc; vector keys; vector< vector *> values; keys.reserve(3); @@ -245,12 +260,26 @@ test_return mget_test(memcached_st *memc) return TEST_SUCCESS; } +test_return_t basic_behavior(memcached_st *memc) +{ + Memcache mc(memc); + bool rc; + uint64_t value = 1; + rc = mc.setBehavior(MEMCACHED_BEHAVIOR_VERIFY_KEY, value); + assert(rc); + uint64_t behavior = mc.getBehavior(MEMCACHED_BEHAVIOR_VERIFY_KEY); + assert(behavior == value); + + return TEST_SUCCESS; +} + test_st tests[] ={ { "basic", 0, basic_test }, { "basic_master_key", 0, basic_master_key_test }, { "increment_test", 0, increment_test }, { "mget", 1, mget_test }, { "mget_result_function", 1, mget_result_function }, + { "basic_behavior", 0, basic_behavior }, {0, 0, 0} };