118
119
return TEST_SUCCESS;
121
static test_return_t __check_AUTO_EJECT_HOSTS(memcached_st *memc, const scanner_string_st &value)
122
static test_return_t __check_REMOVE_FAILED_SERVERS(memcached_st *memc, const scanner_string_st &)
124
test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS));
124
test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS));
125
125
return TEST_SUCCESS;
128
static test_return_t __check_NOREPLY(memcached_st *memc, const scanner_string_st &value)
128
static test_return_t __check_NOREPLY(memcached_st *memc, const scanner_string_st &)
131
130
test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NOREPLY));
132
131
return TEST_SUCCESS;
135
static test_return_t __check_VERIFY_KEY(memcached_st *memc, const scanner_string_st &value)
134
static test_return_t __check_VERIFY_KEY(memcached_st *memc, const scanner_string_st &)
138
136
test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_VERIFY_KEY));
139
137
return TEST_SUCCESS;
142
static test_return_t __check_distribution_RANDOM(memcached_st *memc, const scanner_string_st &value)
140
static test_return_t __check_distribution_RANDOM(memcached_st *memc, const scanner_string_st &)
145
142
test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION) == MEMCACHED_DISTRIBUTION_RANDOM);
146
143
return TEST_SUCCESS;
177
174
scanner_variable_t test_number_options[]= {
178
175
{ ARRAY, make_scanner_string("--CONNECT_TIMEOUT=456"), scanner_string_null, NULL },
179
{ ARRAY, make_scanner_string("--IO_MSG_WATERMARK=456"), make_scanner_string("456"), __check_IO_MSG_WATERMARK },
180
176
{ ARRAY, make_scanner_string("--IO_BYTES_WATERMARK=456"), scanner_string_null, NULL },
181
177
{ ARRAY, make_scanner_string("--IO_KEY_PREFETCH=456"), scanner_string_null, NULL },
178
{ ARRAY, make_scanner_string("--IO_MSG_WATERMARK=456"), make_scanner_string("456"), __check_IO_MSG_WATERMARK },
182
179
{ ARRAY, make_scanner_string("--NUMBER_OF_REPLICAS=456"), scanner_string_null, NULL },
183
180
{ ARRAY, make_scanner_string("--POLL_TIMEOUT=456"), scanner_string_null, NULL },
184
181
{ ARRAY, make_scanner_string("--RCV_TIMEOUT=456"), scanner_string_null, NULL },
182
{ ARRAY, make_scanner_string("--REMOVE-FAILED-SERVERS=3"), scanner_string_null, __check_REMOVE_FAILED_SERVERS },
185
183
{ ARRAY, make_scanner_string("--RETRY_TIMEOUT=456"), scanner_string_null, NULL },
186
{ ARRAY, make_scanner_string("--SERVER_FAILURE_LIMIT=456"), scanner_string_null, NULL },
187
184
{ ARRAY, make_scanner_string("--SND_TIMEOUT=456"), scanner_string_null, NULL },
188
185
{ ARRAY, make_scanner_string("--SOCKET_RECV_SIZE=456"), scanner_string_null, NULL },
189
186
{ ARRAY, make_scanner_string("--SOCKET_SEND_SIZE=456"), scanner_string_null, NULL },
193
190
scanner_variable_t test_boolean_options[]= {
194
{ ARRAY, make_scanner_string("--AUTO_EJECT_HOSTS"), scanner_string_null, __check_AUTO_EJECT_HOSTS },
195
191
{ ARRAY, make_scanner_string("--BINARY_PROTOCOL"), scanner_string_null, NULL },
196
192
{ ARRAY, make_scanner_string("--BUFFER_REQUESTS"), scanner_string_null, NULL },
197
193
{ ARRAY, make_scanner_string("--HASH_WITH_PREFIX_KEY"), scanner_string_null, NULL },
210
206
scanner_variable_t prefix_key_strings[]= {
211
207
{ ARRAY, make_scanner_string("--PREFIX_KEY=foo"), make_scanner_string("foo"), __check_prefix_key },
212
208
{ ARRAY, make_scanner_string("--PREFIX-KEY=\"foo\""), make_scanner_string("foo"), __check_prefix_key },
213
{ ARRAY, make_scanner_string("--PREFIX-KEY=\"This is a very long key\""), make_scanner_string("This is a very long key"), __check_prefix_key },
209
{ ARRAY, make_scanner_string("--PREFIX-KEY=\"This_is_a_very_long_key\""), make_scanner_string("This_is_a_very_long_key"), __check_prefix_key },
214
210
{ NIL, scanner_string_null, scanner_string_null, NULL}
239
235
static test_return_t _test_option(scanner_variable_t *scanner, bool test_true= true)
243
memc= memcached_create(NULL);
245
239
for (scanner_variable_t *ptr= scanner; ptr->type != NIL; ptr++)
247
memcached_return_t rc;
248
rc= memcached_parse_configuration(memc, ptr->option.c_str, ptr->option.size);
242
memc= memcached_create_with_options(ptr->option.c_str, ptr->option.size);
251
if (rc != MEMCACHED_SUCCESS)
253
memcached_error_print(memc);
248
memcached_return_t rc= libmemcached_check_configuration(ptr->option.c_str, ptr->option.size, buffer, sizeof(buffer));
249
std::cerr << "About error for " << memcached_strerror(NULL, rc) << " : " << buffer << std::endl;
256
test_true(rc == MEMCACHED_SUCCESS);
258
254
if (ptr->check_func)
260
256
test_return_t test_rc= (*ptr->check_func)(memc, ptr->result);
261
257
if (test_rc != TEST_SUCCESS)
259
memcached_free(memc);
264
memcached_free(memc);
267
test_false_with(rc == MEMCACHED_SUCCESS, ptr->option.c_str);
268
test_false_with(memc, ptr->option.c_str);
269
memcached_reset(memc);
271
memcached_free(memc);
273
272
return TEST_SUCCESS;
327
326
#define SUPPORT_EXAMPLE_CNF "support/example.cnf"
329
test_return_t memcached_parse_configure_file_test(memcached_st*)
331
if (access(SUPPORT_EXAMPLE_CNF, R_OK))
335
memcached_st *memc_ptr= memcached_create(&memc);
339
memcached_return_t rc= memcached_parse_configure_file(memc_ptr, memcached_string_with_size(SUPPORT_EXAMPLE_CNF));
340
test_true_got(rc == MEMCACHED_SUCCESS, memcached_last_error_message(memc_ptr) ? memcached_last_error_message(memc_ptr) : memcached_strerror(NULL, rc));
341
memcached_free(memc_ptr);
346
328
test_return_t memcached_create_with_options_with_filename(memcached_st*)
348
330
if (access(SUPPORT_EXAMPLE_CNF, R_OK))
481
463
random_options+= " ";
484
memcached_return_t rc;
485
466
memcached_st *memc_ptr= memcached_create(NULL);
486
rc= memcached_parse_configuration(memc_ptr, random_options.c_str(), random_options.size() -1);
487
if (rc == MEMCACHED_PARSE_ERROR)
467
memc_ptr= memcached_create_with_options(random_options.c_str(), random_options.size() -1);
489
std::cerr << std::endl << "Failed to parse(" << memcached_strerror(NULL, rc) << "): " << random_options << std::endl;
490
memcached_error_print(memc_ptr);
473
#if 0 // Testing framework is not smart enough for this just yet.
475
// We will try to find the specific error
477
memcached_return_t rc= libmemcached_check_configuration(random_options.c_str(), random_options.size(), buffer, sizeof(buffer));
478
test_true_got(rc != MEMCACHED_SUCCESS, "memcached_create_with_options() failed whiled libmemcached_check_configuration() was successful");
479
std::cerr << "Error occured on " << random_options.c_str() << " : " << buffer << std::endl;
485
std::cerr << "Failed to allocate memory for memcached_create_with_options()" << std::endl;
488
std::cerr << "Unknown error from memcached_create_with_options?!!" << std::endl;
492
492
memcached_free(memc_ptr);