+/* Count the results */
+static memcached_return callback_counter(memcached_st *ptr __attribute__((unused)),
+ memcached_result_st *result __attribute__((unused)),
+ void *context)
+{
+ unsigned int *counter= static_cast<unsigned int *>(context);
+
+ *counter= *counter + 1;
+
+ return MEMCACHED_SUCCESS;
+}
+
+static test_return mget_result_function(memcached_st *memc)
+{
+ Memcached mc(memc);
+ bool rc;
+ string key1("fudge");
+ string key2("son");
+ string key3("food");
+ vector<string> keys;
+ keys.reserve(3);
+ keys.push_back(key1);
+ keys.push_back(key2);
+ keys.push_back(key3);
+ 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.set_all(keys, keys, 50, 9);
+ assert(rc == true);
+
+ rc= mc.mget(keys);
+ assert(rc == true);
+
+ callbacks[0]= &callback_counter;
+ counter= 0;
+ rc= mc.fetch_execute(callbacks, static_cast<void *>(&counter), 1);
+
+ assert(counter == 3);
+
+ return TEST_SUCCESS;
+}
+
+static test_return mget_test(memcached_st *memc)
+{
+ Memcached mc(memc);
+ bool rc;
+ memcached_return mc_rc;
+ vector<string> keys;
+ keys.reserve(3);
+ keys.push_back("fudge");
+ keys.push_back("son");
+ keys.push_back("food");
+ uint32_t flags;
+
+ string return_key;
+ size_t return_key_length;
+ string return_value;
+ size_t return_value_length;
+
+ /* 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.fetch(return_key, return_value, &return_key_length,
+ &return_value_length, &flags, &mc_rc))
+ {
+ assert(return_value.length() != 0);
+ }
+ assert(return_value_length == 0);
+ assert(mc_rc == MEMCACHED_END);
+
+ rc= mc.set_all(keys, keys, 50, 9);
+ assert(rc == true);
+
+ rc= mc.mget(keys);
+ assert(rc == true);
+
+ while ((mc.fetch(return_key, return_value, &return_key_length,
+ &return_value_length, &flags, &mc_rc)))
+ {
+ assert(return_value.length() != 0);
+ assert(mc_rc == MEMCACHED_SUCCESS);
+ assert(return_key_length == return_value_length);
+ assert(!memcmp(return_value.c_str(), return_key.c_str(), return_value_length));
+ }
+
+ return TEST_SUCCESS;
+}