+test_return_t basic_test(memcached_st *memc)
+{
+ Memcache foo(memc);
+ const string value_set("This is some data");
+ std::vector<char> value;
+ std::vector<char> test_value;
+
+ populate_vector(value, value_set);
+
+ foo.set("mine", value, 0, 0);
+ foo.get("mine", test_value);
+
+ assert((memcmp(&test_value[0], &value[0], test_value.size()) == 0));
+
+ /*
+ * 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_t increment_test(memcached_st *memc)
+{
+ Memcache mcach(memc);
+ bool rc;
+ const string key("blah");
+ const string inc_value("1");
+ std::vector<char> inc_val;
+ vector<char> ret_value;
+ string ret_string;
+ uint64_t int_inc_value;
+ uint64_t int_ret_value;
+
+ populate_vector(inc_val, inc_value);
+
+ rc= mcach.set(key, inc_val, 0, 0);
+ if (rc == false)
+ {
+ return TEST_FAILURE;
+ }
+ mcach.get(key, ret_value);
+ if (ret_value.empty())
+ {
+ return TEST_FAILURE;
+ }
+ copy_vec_to_string(ret_value, ret_string);
+
+ int_inc_value= uint64_t(atol(inc_value.c_str()));
+ int_ret_value= uint64_t(atol(ret_string.c_str()));
+ assert(int_ret_value == int_inc_value);
+
+ rc= mcach.increment(key, 1, &int_ret_value);
+ assert(rc == true);
+ assert(int_ret_value == 2);
+
+ rc= mcach.increment(key, 1, &int_ret_value);
+ assert(rc == true);
+ assert(int_ret_value == 3);
+
+ rc= mcach.increment(key, 5, &int_ret_value);
+ assert(rc == true);
+ assert(int_ret_value == 8);