+/* Count the results */
+memcached_return callback_counter(memcached_st *,
+ memcached_result_st *,
+ void *context)
+{
+ unsigned int *counter= static_cast<unsigned int *>(context);
+
+ *counter= *counter + 1;
+
+ return MEMCACHED_SUCCESS;
+}
+
+test_return mget_result_function(memcached_st *memc)
+{
+ Memcache mc(memc);
+ bool rc;
+ string key1("fudge");
+ string key2("son");
+ string key3("food");
+ vector<string> keys;
+ vector< vector<char> *> values;
+ vector<char> val1;
+ vector<char> val2;
+ vector<char> val3;
+ populate_vector(val1, key1);
+ populate_vector(val2, key2);
+ populate_vector(val3, key3);
+ keys.reserve(3);
+ keys.push_back(key1);
+ keys.push_back(key2);
+ keys.push_back(key3);
+ values.reserve(3);
+ values.push_back(&val1);
+ values.push_back(&val2);
+ values.push_back(&val3);
+ unsigned int counter;
+ memcached_execute_function callbacks[1];
+
+ /* We need to empty the server before we continue the test */
+ rc= mc.flush(0);
+ rc= mc.setAll(keys, values, 50, 9);
+ assert(rc == true);
+
+ rc= mc.mget(keys);
+ assert(rc == true);
+
+ callbacks[0]= &callback_counter;
+ counter= 0;
+ rc= mc.fetchExecute(callbacks, static_cast<void *>(&counter), 1);
+
+ assert(counter == 3);
+
+ return TEST_SUCCESS;
+}
+
+test_return mget_test(memcached_st *memc)
+{
+ Memcache mc(memc);
+ bool rc;
+ memcached_return mc_rc;
+ vector<string> keys;
+ vector< vector<char> *> values;
+ keys.reserve(3);
+ keys.push_back("fudge");
+ keys.push_back("son");
+ keys.push_back("food");
+ vector<char> val1;
+ vector<char> val2;
+ vector<char> val3;
+ populate_vector(val1, "fudge");
+ populate_vector(val2, "son");
+ populate_vector(val3, "food");
+ values.reserve(3);
+ values.push_back(&val1);
+ values.push_back(&val2);
+ values.push_back(&val3);
+
+ string return_key;
+ vector<char> return_value;
+
+ /* We need to empty the server before we continue the test */
+ rc= mc.flush(0);
+ assert(rc == true);
+
+ rc= mc.mget(keys);
+ assert(rc == true);
+
+ while ((mc_rc= mc.fetch(return_key, return_value)) != MEMCACHED_END)
+ {
+ assert(return_value.size() != 0);
+ return_value.clear();
+ }
+ assert(mc_rc == MEMCACHED_END);
+
+ rc= mc.setAll(keys, values, 50, 9);
+ assert(rc == true);
+
+ rc= mc.mget(keys);
+ assert(rc == true);
+
+ while ((mc_rc= mc.fetch(return_key, return_value)) != MEMCACHED_END)
+ {
+ assert(return_key.length() == return_value.size());
+ assert(!memcmp(&return_value[0], return_key.c_str(), return_value.size()));
+ }
+
+ return TEST_SUCCESS;
+}