More tests, and new code for append/prepend.
[m6w6/libmemcached] / tests / function.c
1 /*
2 Sample test application.
3 */
4 #include <assert.h>
5 #include <memcached.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/time.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <unistd.h>
13 #include <time.h>
14 #include "../lib/common.h"
15 #include "../src/generator.h"
16 #include "../src/execute.h"
17
18 #include "test.h"
19
20 #define GLOBAL_COUNT 100000
21 static pairs_st *global_pairs;
22 static char *global_keys[GLOBAL_COUNT];
23 static size_t global_keys_length[GLOBAL_COUNT];
24
25 uint8_t init_test(memcached_st *not_used)
26 {
27 memcached_st memc;
28
29 (void)memcached_create(&memc);
30 memcached_free(&memc);
31
32 return 0;
33 }
34
35 uint8_t allocation_test(memcached_st *not_used)
36 {
37 memcached_st *memc;
38 memc= memcached_create(NULL);
39 assert(memc);
40 memcached_free(memc);
41
42 return 0;
43 }
44
45 uint8_t clone_test(memcached_st *memc)
46 {
47 /* All null? */
48 {
49 memcached_st *clone;
50 clone= memcached_clone(NULL, NULL);
51 assert(clone);
52 memcached_free(clone);
53 }
54
55 /* Can we init from null? */
56 {
57 memcached_st *clone;
58 clone= memcached_clone(NULL, memc);
59 assert(clone);
60 memcached_free(clone);
61 }
62
63 /* Can we init from struct? */
64 {
65 memcached_st declared_clone;
66 memcached_st *clone;
67 clone= memcached_clone(&declared_clone, NULL);
68 assert(clone);
69 memcached_free(clone);
70 }
71
72 /* Can we init from struct? */
73 {
74 memcached_st declared_clone;
75 memcached_st *clone;
76 clone= memcached_clone(&declared_clone, memc);
77 assert(clone);
78 memcached_free(clone);
79 }
80
81 return 0;
82 }
83
84 uint8_t connection_test(memcached_st *memc)
85 {
86 memcached_return rc;
87
88 rc= memcached_server_add(memc, "localhost", 0);
89 assert(rc == MEMCACHED_SUCCESS);
90
91 return 0;
92 }
93
94 uint8_t error_test(memcached_st *memc)
95 {
96 memcached_return rc;
97
98 for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
99 {
100 printf("Error %d -> %s\n", rc, memcached_strerror(memc, rc));
101 }
102
103 return 0;
104 }
105
106 uint8_t set_test(memcached_st *memc)
107 {
108 memcached_return rc;
109 char *key= "foo";
110 char *value= "when we sanitize";
111
112 rc= memcached_set(memc, key, strlen(key),
113 value, strlen(value),
114 (time_t)0, (uint16_t)0);
115 assert(rc == MEMCACHED_SUCCESS);
116
117 return 0;
118 }
119
120 uint8_t append_test(memcached_st *memc)
121 {
122 memcached_return rc;
123 char *key= "fig";
124 char *value= "we";
125 size_t value_length;
126 uint16_t flags;
127
128 rc= memcached_flush(memc, 0);
129 assert(rc == MEMCACHED_SUCCESS);
130
131 rc= memcached_set(memc, key, strlen(key),
132 value, strlen(value),
133 (time_t)0, (uint16_t)0);
134 assert(rc == MEMCACHED_SUCCESS);
135
136 rc= memcached_append(memc, key, strlen(key),
137 " the", strlen(" the"),
138 (time_t)0, (uint16_t)0);
139 assert(rc == MEMCACHED_SUCCESS);
140
141 rc= memcached_append(memc, key, strlen(key),
142 " people", strlen(" people"),
143 (time_t)0, (uint16_t)0);
144 assert(rc == MEMCACHED_SUCCESS);
145
146 value= memcached_get(memc, key, strlen(key),
147 &value_length, &flags, &rc);
148 assert(!memcmp(value, "we the people", strlen("we the people")));
149 assert(strlen("we the people") == value_length);
150 assert(rc == MEMCACHED_SUCCESS);
151
152 return 0;
153 }
154
155 uint8_t cas_test(memcached_st *memc)
156 {
157 memcached_return rc;
158 char *key= "fun";
159 size_t key_length= strlen("fun");
160 char *value= "we the people";
161 size_t value_length= strlen("we the people");
162 memcached_result_st results_obj;
163 memcached_result_st *results;
164
165 rc= memcached_flush(memc, 0);
166 assert(rc == MEMCACHED_SUCCESS);
167
168 rc= memcached_set(memc, key, strlen(key),
169 value, strlen(value),
170 (time_t)0, (uint16_t)0);
171 assert(rc == MEMCACHED_SUCCESS);
172
173 rc= memcached_mget(memc, &key, &key_length, 1);
174
175 results= memcached_result_create(memc, &results_obj);
176
177 results= memcached_fetch_result(memc, &results_obj, &rc);
178 assert(results);
179 assert(rc == MEMCACHED_SUCCESS);
180 WATCHPOINT_NUMBER(memcached_result_cas(results));
181 WATCHPOINT_ASSERT(memcached_result_cas(results));
182
183 assert(!memcmp(value, "we the people", strlen("we the people")));
184 assert(strlen("we the people") == value_length);
185 assert(rc == MEMCACHED_SUCCESS);
186
187 memcached_result_free(&results_obj);
188
189 return 0;
190 }
191
192 uint8_t prepend_test(memcached_st *memc)
193 {
194 memcached_return rc;
195 char *key= "fig";
196 char *value= "people";
197 size_t value_length;
198 uint16_t flags;
199
200 rc= memcached_flush(memc, 0);
201 assert(rc == MEMCACHED_SUCCESS);
202
203 rc= memcached_set(memc, key, strlen(key),
204 value, strlen(value),
205 (time_t)0, (uint16_t)0);
206 assert(rc == MEMCACHED_SUCCESS);
207
208 rc= memcached_prepend(memc, key, strlen(key),
209 "the ", strlen("the "),
210 (time_t)0, (uint16_t)0);
211 assert(rc == MEMCACHED_SUCCESS);
212
213 rc= memcached_prepend(memc, key, strlen(key),
214 "we ", strlen("we "),
215 (time_t)0, (uint16_t)0);
216 assert(rc == MEMCACHED_SUCCESS);
217
218 value= memcached_get(memc, key, strlen(key),
219 &value_length, &flags, &rc);
220 assert(!memcmp(value, "we the people", strlen("we the people")));
221 assert(strlen("we the people") == value_length);
222 assert(rc == MEMCACHED_SUCCESS);
223
224 return 0;
225 }
226
227 uint8_t add_test(memcached_st *memc)
228 {
229 memcached_return rc;
230 char *key= "foo";
231 char *value= "when we sanitize";
232
233 rc= memcached_add(memc, key, strlen(key),
234 value, strlen(value),
235 (time_t)0, (uint16_t)0);
236 assert(rc == MEMCACHED_NOTSTORED);
237
238 return 0;
239 }
240
241 uint8_t replace_test(memcached_st *memc)
242 {
243 memcached_return rc;
244 char *key= "foo";
245 char *value= "when we sanitize";
246
247 rc= memcached_replace(memc, key, strlen(key),
248 value, strlen(value),
249 (time_t)0, (uint16_t)0);
250 assert(rc == MEMCACHED_SUCCESS);
251
252 return 0;
253 }
254
255 uint8_t delete_test(memcached_st *memc)
256 {
257 memcached_return rc;
258 char *key= "foo";
259 char *value= "when we sanitize";
260
261 rc= memcached_set(memc, key, strlen(key),
262 value, strlen(value),
263 (time_t)0, (uint16_t)0);
264 assert(rc == MEMCACHED_SUCCESS);
265
266 rc= memcached_delete(memc, key, strlen(key), (time_t)0);
267 assert(rc == MEMCACHED_SUCCESS);
268
269 return 0;
270 }
271
272 uint8_t flush_test(memcached_st *memc)
273 {
274 memcached_return rc;
275
276 rc= memcached_flush(memc, 0);
277 assert(rc == MEMCACHED_SUCCESS);
278
279 return 0;
280 }
281
282 uint8_t get_test(memcached_st *memc)
283 {
284 memcached_return rc;
285 char *key= "foo";
286 char *string;
287 size_t string_length;
288 uint16_t flags;
289
290 rc= memcached_delete(memc, key, strlen(key), (time_t)0);
291 assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND);
292
293 string= memcached_get(memc, key, strlen(key),
294 &string_length, &flags, &rc);
295
296 assert(rc == MEMCACHED_NOTFOUND);
297 assert(string_length == 0);
298 assert(!string);
299
300 return 0;
301 }
302
303 uint8_t get_test2(memcached_st *memc)
304 {
305 memcached_return rc;
306 char *key= "foo";
307 char *value= "when we sanitize";
308 char *string;
309 size_t string_length;
310 uint16_t flags;
311
312 rc= memcached_set(memc, key, strlen(key),
313 value, strlen(value),
314 (time_t)0, (uint16_t)0);
315 assert(rc == MEMCACHED_SUCCESS);
316
317 string= memcached_get(memc, key, strlen(key),
318 &string_length, &flags, &rc);
319
320 assert(string);
321 assert(rc == MEMCACHED_SUCCESS);
322 assert(string_length == strlen(value));
323 assert(!memcmp(string, value, string_length));
324
325 free(string);
326
327 return 0;
328 }
329
330 uint8_t set_test2(memcached_st *memc)
331 {
332 memcached_return rc;
333 char *key= "foo";
334 char *value= "train in the brain";
335 size_t value_length= strlen(value);
336 unsigned int x;
337
338 for (x= 0; x < 10; x++)
339 {
340 rc= memcached_set(memc, key, strlen(key),
341 value, value_length,
342 (time_t)0, (uint16_t)0);
343 assert(rc == MEMCACHED_SUCCESS);
344 }
345
346 return 0;
347 }
348
349 uint8_t set_test3(memcached_st *memc)
350 {
351 memcached_return rc;
352 char *key= "foo";
353 char *value;
354 size_t value_length= 8191;
355 unsigned int x;
356
357 value = (char*)malloc(value_length);
358 assert(value);
359
360 for (x= 0; x < value_length; x++)
361 value[x] = (char) (x % 127);
362
363 for (x= 0; x < 1; x++)
364 {
365 rc= memcached_set(memc, key, strlen(key),
366 value, value_length,
367 (time_t)0, (uint16_t)0);
368 assert(rc == MEMCACHED_SUCCESS);
369 }
370
371 free(value);
372
373 return 0;
374 }
375
376 uint8_t get_test3(memcached_st *memc)
377 {
378 memcached_return rc;
379 char *key= "foo";
380 char *value;
381 size_t value_length= 8191;
382 char *string;
383 size_t string_length;
384 uint16_t flags;
385 int x;
386
387 value = (char*)malloc(value_length);
388 assert(value);
389
390 for (x= 0; x < value_length; x++)
391 value[x] = (char) (x % 127);
392
393 rc= memcached_set(memc, key, strlen(key),
394 value, value_length,
395 (time_t)0, (uint16_t)0);
396 assert(rc == MEMCACHED_SUCCESS);
397
398 string= memcached_get(memc, key, strlen(key),
399 &string_length, &flags, &rc);
400
401 assert(rc == MEMCACHED_SUCCESS);
402 assert(string);
403 assert(string_length == value_length);
404 assert(!memcmp(string, value, string_length));
405
406 free(string);
407 free(value);
408
409 return 0;
410 }
411
412 uint8_t get_test4(memcached_st *memc)
413 {
414 memcached_return rc;
415 char *key= "foo";
416 char *value;
417 size_t value_length= 8191;
418 char *string;
419 size_t string_length;
420 uint16_t flags;
421 int x;
422
423 value = (char*)malloc(value_length);
424 assert(value);
425
426 for (x= 0; x < value_length; x++)
427 value[x] = (char) (x % 127);
428
429 rc= memcached_set(memc, key, strlen(key),
430 value, value_length,
431 (time_t)0, (uint16_t)0);
432 assert(rc == MEMCACHED_SUCCESS);
433
434 for (x= 0; x < 10; x++)
435 {
436 string= memcached_get(memc, key, strlen(key),
437 &string_length, &flags, &rc);
438
439 assert(rc == MEMCACHED_SUCCESS);
440 assert(string);
441 assert(string_length == value_length);
442 assert(!memcmp(string, value, string_length));
443 free(string);
444 }
445
446 free(value);
447
448 return 0;
449 }
450
451 uint8_t stats_servername_test(memcached_st *memc)
452 {
453 memcached_return rc;
454 memcached_stat_st stat;
455 rc= memcached_stat_servername(&stat, NULL,
456 "localhost",
457 MEMCACHED_DEFAULT_PORT);
458
459 return 0;
460 }
461
462 uint8_t increment_test(memcached_st *memc)
463 {
464 uint64_t new_number;
465 memcached_return rc;
466 char *key= "number";
467 char *value= "0";
468
469 rc= memcached_set(memc, key, strlen(key),
470 value, strlen(value),
471 (time_t)0, (uint16_t)0);
472 assert(rc == MEMCACHED_SUCCESS);
473
474 rc= memcached_increment(memc, key, strlen(key),
475 1, &new_number);
476 assert(rc == MEMCACHED_SUCCESS);
477 assert(new_number == 1);
478
479 rc= memcached_increment(memc, key, strlen(key),
480 1, &new_number);
481 assert(rc == MEMCACHED_SUCCESS);
482 assert(new_number == 2);
483
484 return 0;
485 }
486
487 uint8_t decrement_test(memcached_st *memc)
488 {
489 uint64_t new_number;
490 memcached_return rc;
491 char *key= "number";
492 char *value= "3";
493
494 rc= memcached_set(memc, key, strlen(key),
495 value, strlen(value),
496 (time_t)0, (uint16_t)0);
497 assert(rc == MEMCACHED_SUCCESS);
498
499 rc= memcached_decrement(memc, key, strlen(key),
500 1, &new_number);
501 assert(rc == MEMCACHED_SUCCESS);
502 assert(new_number == 2);
503
504 rc= memcached_decrement(memc, key, strlen(key),
505 1, &new_number);
506 assert(rc == MEMCACHED_SUCCESS);
507 assert(new_number == 1);
508
509 return 0;
510 }
511
512 uint8_t quit_test(memcached_st *memc)
513 {
514 memcached_return rc;
515 char *key= "fudge";
516 char *value= "sanford and sun";
517
518 rc= memcached_set(memc, key, strlen(key),
519 value, strlen(value),
520 (time_t)10, (uint16_t)3);
521 assert(rc == MEMCACHED_SUCCESS);
522 memcached_quit(memc);
523
524 rc= memcached_set(memc, key, strlen(key),
525 value, strlen(value),
526 (time_t)50, (uint16_t)9);
527 assert(rc == MEMCACHED_SUCCESS);
528
529 return 0;
530 }
531
532 uint8_t mget_result_test(memcached_st *memc)
533 {
534 memcached_return rc;
535 char *keys[]= {"fudge", "son", "food"};
536 size_t key_length[]= {5, 3, 4};
537 unsigned int x;
538
539 memcached_result_st results_obj;
540 memcached_result_st *results;
541
542 results= memcached_result_create(memc, &results_obj);
543 assert(results);
544 assert(&results_obj == results);
545
546 /* We need to empty the server before continueing test */
547 rc= memcached_flush(memc, 0);
548 assert(rc == MEMCACHED_SUCCESS);
549
550 rc= memcached_mget(memc, keys, key_length, 3);
551 assert(rc == MEMCACHED_SUCCESS);
552
553 while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
554 {
555 assert(results);
556 }
557 while ((results= memcached_fetch_result(memc, &results_obj, &rc)) != NULL)
558 assert(!results);
559 assert(rc == MEMCACHED_NOTFOUND);
560
561 for (x= 0; x < 3; x++)
562 {
563 rc= memcached_set(memc, keys[x], key_length[x],
564 keys[x], key_length[x],
565 (time_t)50, (uint16_t)9);
566 assert(rc == MEMCACHED_SUCCESS);
567 }
568
569 rc= memcached_mget(memc, keys, key_length, 3);
570 assert(rc == MEMCACHED_SUCCESS);
571
572 while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
573 {
574 assert(results);
575 assert(&results_obj == results);
576 assert(rc == MEMCACHED_SUCCESS);
577 assert(memcached_result_key_length(results) == memcached_result_length(results));
578 assert(!memcmp(memcached_result_key_value(results),
579 memcached_result_value(results),
580 memcached_result_length(results)));
581 }
582
583 memcached_result_free(&results_obj);
584
585 return 0;
586 }
587
588 uint8_t mget_result_alloc_test(memcached_st *memc)
589 {
590 memcached_return rc;
591 char *keys[]= {"fudge", "son", "food"};
592 size_t key_length[]= {5, 3, 4};
593 unsigned int x;
594
595 memcached_result_st *results;
596
597 /* We need to empty the server before continueing test */
598 rc= memcached_flush(memc, 0);
599 assert(rc == MEMCACHED_SUCCESS);
600
601 rc= memcached_mget(memc, keys, key_length, 3);
602 assert(rc == MEMCACHED_SUCCESS);
603
604 while ((results= memcached_fetch_result(memc, NULL, &rc)) != NULL)
605 {
606 assert(results);
607 }
608 assert(!results);
609 assert(rc == MEMCACHED_NOTFOUND);
610
611 for (x= 0; x < 3; x++)
612 {
613 rc= memcached_set(memc, keys[x], key_length[x],
614 keys[x], key_length[x],
615 (time_t)50, (uint16_t)9);
616 assert(rc == MEMCACHED_SUCCESS);
617 }
618
619 rc= memcached_mget(memc, keys, key_length, 3);
620 assert(rc == MEMCACHED_SUCCESS);
621
622 x= 0;
623 while ((results= memcached_fetch_result(memc, NULL, &rc)))
624 {
625 assert(results);
626 assert(rc == MEMCACHED_SUCCESS);
627 assert(memcached_result_key_length(results) == memcached_result_length(results));
628 assert(!memcmp(memcached_result_key_value(results),
629 memcached_result_value(results),
630 memcached_result_length(results)));
631 memcached_result_free(results);
632 x++;
633 }
634
635 return 0;
636 }
637
638 uint8_t mget_test(memcached_st *memc)
639 {
640 memcached_return rc;
641 char *keys[]= {"fudge", "son", "food"};
642 size_t key_length[]= {5, 3, 4};
643 unsigned int x;
644 uint16_t flags;
645
646 char return_key[MEMCACHED_MAX_KEY];
647 size_t return_key_length;
648 char *return_value;
649 size_t return_value_length;
650
651 /* We need to empty the server before continueing test */
652 rc= memcached_flush(memc, 0);
653 assert(rc == MEMCACHED_SUCCESS);
654
655 rc= memcached_mget(memc, keys, key_length, 3);
656 assert(rc == MEMCACHED_SUCCESS);
657
658 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
659 &return_value_length, &flags, &rc)) != NULL)
660 {
661 assert(return_value);
662 }
663 assert(!return_value);
664 assert(return_value_length == 0);
665 assert(rc == MEMCACHED_NOTFOUND);
666
667 for (x= 0; x < 3; x++)
668 {
669 rc= memcached_set(memc, keys[x], key_length[x],
670 keys[x], key_length[x],
671 (time_t)50, (uint16_t)9);
672 assert(rc == MEMCACHED_SUCCESS);
673 }
674
675 rc= memcached_mget(memc, keys, key_length, 3);
676 assert(rc == MEMCACHED_SUCCESS);
677
678 x= 0;
679 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
680 &return_value_length, &flags, &rc)))
681 {
682 assert(return_value);
683 assert(rc == MEMCACHED_SUCCESS);
684 assert(return_key_length == return_value_length);
685 assert(!memcmp(return_value, return_key, return_value_length));
686 free(return_value);
687 x++;
688 }
689
690 return 0;
691 }
692
693 uint8_t get_stats_keys(memcached_st *memc)
694 {
695 char **list;
696 char **ptr;
697 memcached_stat_st stat;
698 memcached_return rc;
699
700 list= memcached_stat_get_keys(memc, &stat, &rc);
701 assert(rc == MEMCACHED_SUCCESS);
702 for (ptr= list; *ptr; ptr++)
703 printf("Found key %s\n", *ptr);
704 fflush(stdout);
705
706 free(list);
707
708 return 0;
709 }
710
711 uint8_t get_stats(memcached_st *memc)
712 {
713 unsigned int x;
714 char **list;
715 char **ptr;
716 memcached_return rc;
717 memcached_stat_st *stat;
718
719 stat= memcached_stat(memc, NULL, &rc);
720 assert(rc == MEMCACHED_SUCCESS);
721
722 assert(rc == MEMCACHED_SUCCESS);
723 assert(stat);
724
725 for (x= 0; x < memcached_server_count(memc); x++)
726 {
727 list= memcached_stat_get_keys(memc, &stat[x], &rc);
728 assert(rc == MEMCACHED_SUCCESS);
729 for (ptr= list; *ptr; ptr++)
730 printf("Found key %s\n", *ptr);
731
732 free(list);
733 }
734
735 memcached_stat_free(NULL, stat);
736
737 return 0;
738 }
739
740 uint8_t add_host_test(memcached_st *memc)
741 {
742 unsigned int x;
743 memcached_server_st *servers;
744 memcached_return rc;
745 char servername[]= "0.example.com";
746
747 servers= memcached_server_list_append(NULL, servername, 400, &rc);
748 assert(servers);
749 assert(1 == memcached_server_list_count(servers));
750
751 for (x= 2; x < 20; x++)
752 {
753 char buffer[SMALL_STRING_LEN];
754
755 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
756 servers= memcached_server_list_append(servers, buffer, 401,
757 &rc);
758 assert(rc == MEMCACHED_SUCCESS);
759 assert(x == memcached_server_list_count(servers));
760 }
761
762 rc= memcached_server_push(memc, servers);
763 assert(rc == MEMCACHED_SUCCESS);
764 rc= memcached_server_push(memc, servers);
765 assert(rc == MEMCACHED_SUCCESS);
766
767 memcached_server_list_free(servers);
768
769 return 0;
770 }
771
772 /* We don't test the behavior itself, we test the switches */
773 uint8_t behavior_test(memcached_st *memc)
774 {
775 unsigned long long value;
776 unsigned int set= 1;
777
778 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
779 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
780 assert(value == 1);
781
782 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
783 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
784 assert(value == 1);
785
786 set= MEMCACHED_HASH_MD5;
787 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
788 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
789 assert(value == MEMCACHED_HASH_MD5);
790
791 set= 0;
792
793 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
794 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
795 assert(value == 0);
796
797 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
798 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
799 assert(value == 0);
800
801 set= MEMCACHED_HASH_DEFAULT;
802 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
803 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
804 assert(value == MEMCACHED_HASH_DEFAULT);
805
806 set= MEMCACHED_HASH_CRC;
807 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set);
808 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
809 assert(value == MEMCACHED_HASH_CRC);
810
811 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
812 assert(value > 0);
813
814 value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
815 assert(value > 0);
816
817 return 0;
818 }
819
820 /* Test case provided by Cal Haldenbrand */
821 uint8_t user_supplied_bug1(memcached_st *memc)
822 {
823 unsigned int setter= 1;
824 unsigned int x;
825
826 unsigned long long total= 0;
827 int size= 0;
828 char key[10];
829 char randomstuff[6 * 1024];
830 memcached_return rc;
831
832 memset(randomstuff, 0, 6 * 1024);
833
834 /* We just keep looking at the same values over and over */
835 srandom(10);
836
837 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
838 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
839
840
841 /* add key */
842 for (x= 0 ; total < 20 * 1024576 ; x++ )
843 {
844 unsigned int j= 0;
845
846 size= (rand() % ( 5 * 1024 ) ) + 400;
847 memset(randomstuff, 0, 6 * 1024);
848 assert(size < 6 * 1024); /* Being safe here */
849
850 for (j= 0 ; j < size ;j++)
851 randomstuff[j] = (char) (rand() % 26) + 97;
852
853 total += size;
854 sprintf(key, "%d", x);
855 rc = memcached_set(memc, key, strlen(key),
856 randomstuff, strlen(randomstuff), 10, 0);
857 /* If we fail, lets try again */
858 if (rc != MEMCACHED_SUCCESS)
859 rc = memcached_set(memc, key, strlen(key),
860 randomstuff, strlen(randomstuff), 10, 0);
861 assert(rc == MEMCACHED_SUCCESS);
862 }
863
864 return 0;
865 }
866
867 /* Test case provided by Cal Haldenbrand */
868 uint8_t user_supplied_bug2(memcached_st *memc)
869 {
870 int errors;
871 unsigned int setter;
872 unsigned int x;
873 unsigned long long total;
874
875 setter= 1;
876 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
877 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
878 #ifdef NOT_YET
879 setter = 20 * 1024576;
880 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, &setter);
881 setter = 20 * 1024576;
882 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter);
883 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
884 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
885
886 for (x= 0, errors= 0, total= 0 ; total < 20 * 1024576 ; x++)
887 #endif
888
889 for (x= 0, errors= 0, total= 0 ; total < 24576 ; x++)
890 {
891 memcached_return rc= MEMCACHED_SUCCESS;
892 char buffer[SMALL_STRING_LEN];
893 uint16_t flags= 0;
894 size_t val_len= 0;
895 char *getval;
896
897 memset(buffer, 0, SMALL_STRING_LEN);
898
899 snprintf(buffer, SMALL_STRING_LEN, "%u", x);
900 getval= memcached_get(memc, buffer, strlen(buffer),
901 &val_len, &flags, &rc);
902 if (rc != MEMCACHED_SUCCESS)
903 {
904 if (rc == MEMCACHED_NOTFOUND)
905 errors++;
906 else
907 assert(0);
908
909 continue;
910 }
911 total+= val_len;
912 errors= 0;
913 free(getval);
914 }
915
916 return 0;
917 }
918
919 /* Do a large mget() over all the keys we think exist */
920 #define KEY_COUNT 3000 // * 1024576
921 uint8_t user_supplied_bug3(memcached_st *memc)
922 {
923 memcached_return rc;
924 unsigned int setter;
925 unsigned int x;
926 char **keys;
927 size_t key_lengths[KEY_COUNT];
928
929 setter= 1;
930 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &setter);
931 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &setter);
932 #ifdef NOT_YET
933 setter = 20 * 1024576;
934 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, &setter);
935 setter = 20 * 1024576;
936 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, &setter);
937 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
938 getter = memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
939 #endif
940
941 keys= (char **)malloc(sizeof(char *) * KEY_COUNT);
942 assert(keys);
943 memset(keys, 0, (sizeof(char *) * KEY_COUNT));
944 for (x= 0; x < KEY_COUNT; x++)
945 {
946 char buffer[30];
947
948 snprintf(buffer, 30, "%u", x);
949 keys[x]= strdup(buffer);
950 key_lengths[x]= strlen(keys[x]);
951 }
952
953 rc= memcached_mget(memc, keys, key_lengths, KEY_COUNT);
954 assert(rc == MEMCACHED_SUCCESS);
955
956 /* Turn this into a help function */
957 {
958 char return_key[MEMCACHED_MAX_KEY];
959 size_t return_key_length;
960 char *return_value;
961 size_t return_value_length;
962 uint16_t flags;
963
964 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
965 &return_value_length, &flags, &rc)))
966 {
967 assert(return_value);
968 assert(rc == MEMCACHED_SUCCESS);
969 free(return_value);
970 }
971 }
972
973 for (x= 0; x < KEY_COUNT; x++)
974 free(keys[x]);
975 free(keys);
976
977 return 0;
978 }
979
980 /* Make sure we behave properly if server list has no values */
981 uint8_t user_supplied_bug4(memcached_st *memc)
982 {
983 memcached_return rc;
984 char *keys[]= {"fudge", "son", "food"};
985 size_t key_length[]= {5, 3, 4};
986 unsigned int x;
987 uint16_t flags;
988
989 /* Here we free everything before running a bunch of mget tests */
990 {
991 memcached_server_list_free(memc->hosts);
992 memc->hosts= NULL;
993 memc->number_of_hosts= 0;
994 }
995
996 char return_key[MEMCACHED_MAX_KEY];
997 size_t return_key_length;
998 char *return_value;
999 size_t return_value_length;
1000
1001 /* We need to empty the server before continueing test */
1002 rc= memcached_flush(memc, 0);
1003 assert(rc == MEMCACHED_NO_SERVERS);
1004
1005 rc= memcached_mget(memc, keys, key_length, 3);
1006 assert(rc == MEMCACHED_NO_SERVERS);
1007
1008 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1009 &return_value_length, &flags, &rc)) != NULL)
1010 {
1011 assert(return_value);
1012 }
1013 assert(!return_value);
1014 assert(return_value_length == 0);
1015 assert(rc == MEMCACHED_NO_SERVERS);
1016
1017 for (x= 0; x < 3; x++)
1018 {
1019 rc= memcached_set(memc, keys[x], key_length[x],
1020 keys[x], key_length[x],
1021 (time_t)50, (uint16_t)9);
1022 assert(rc == MEMCACHED_NO_SERVERS);
1023 }
1024
1025 rc= memcached_mget(memc, keys, key_length, 3);
1026 assert(rc == MEMCACHED_NO_SERVERS);
1027
1028 x= 0;
1029 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1030 &return_value_length, &flags, &rc)))
1031 {
1032 assert(return_value);
1033 assert(rc == MEMCACHED_SUCCESS);
1034 assert(return_key_length == return_value_length);
1035 assert(!memcmp(return_value, return_key, return_value_length));
1036 free(return_value);
1037 x++;
1038 }
1039
1040 return 0;
1041 }
1042
1043 #define VALUE_SIZE_BUG5 1048064
1044 uint8_t user_supplied_bug5(memcached_st *memc)
1045 {
1046 memcached_return rc;
1047 char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1048 size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1049 char return_key[MEMCACHED_MAX_KEY];
1050 size_t return_key_length;
1051 char *value;
1052 size_t value_length;
1053 uint16_t flags;
1054 unsigned int count;
1055 unsigned int x;
1056 char insert_data[VALUE_SIZE_BUG5];
1057
1058 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1059 insert_data[x]= rand();
1060
1061 memcached_flush(memc, 0);
1062 value= memcached_get(memc, keys[0], key_length[0],
1063 &value_length, &flags, &rc);
1064 assert(value == NULL);
1065 rc= memcached_mget(memc, keys, key_length, 4);
1066
1067 count= 0;
1068 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1069 &value_length, &flags, &rc)))
1070 count++;
1071 assert(count == 0);
1072
1073 for (x= 0; x < 4; x++)
1074 {
1075 rc= memcached_set(memc, keys[x], key_length[x],
1076 insert_data, VALUE_SIZE_BUG5,
1077 (time_t)0, (uint16_t)0);
1078 assert(rc == MEMCACHED_SUCCESS);
1079 }
1080
1081 for (x= 0; x < 10; x++)
1082 {
1083 value= memcached_get(memc, keys[0], key_length[0],
1084 &value_length, &flags, &rc);
1085 assert(value);
1086 free(value);
1087
1088 rc= memcached_mget(memc, keys, key_length, 4);
1089 count= 0;
1090 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1091 &value_length, &flags, &rc)))
1092 {
1093 count++;
1094 free(value);
1095 }
1096 assert(count == 4);
1097 }
1098
1099 return 0;
1100 }
1101
1102 uint8_t user_supplied_bug6(memcached_st *memc)
1103 {
1104 memcached_return rc;
1105 char *keys[]= {"036790384900", "036790384902", "036790384904", "036790384906"};
1106 size_t key_length[]= {strlen("036790384900"), strlen("036790384902"), strlen("036790384904"), strlen("036790384906")};
1107 char return_key[MEMCACHED_MAX_KEY];
1108 size_t return_key_length;
1109 char *value;
1110 size_t value_length;
1111 uint16_t flags;
1112 unsigned int count;
1113 unsigned int x;
1114 char insert_data[VALUE_SIZE_BUG5];
1115
1116 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1117 insert_data[x]= rand();
1118
1119 memcached_flush(memc, 0);
1120 value= memcached_get(memc, keys[0], key_length[0],
1121 &value_length, &flags, &rc);
1122 assert(value == NULL);
1123 rc= memcached_mget(memc, keys, key_length, 4);
1124
1125 count= 0;
1126 while ((value= memcached_fetch(memc, return_key, &return_key_length,
1127 &value_length, &flags, &rc)))
1128 count++;
1129 assert(count == 0);
1130
1131 for (x= 0; x < 4; x++)
1132 {
1133 rc= memcached_set(memc, keys[x], key_length[x],
1134 insert_data, VALUE_SIZE_BUG5,
1135 (time_t)0, (uint16_t)0);
1136 assert(rc == MEMCACHED_SUCCESS);
1137 }
1138
1139 for (x= 0; x < 10; x++)
1140 {
1141 value= memcached_get(memc, keys[0], key_length[0],
1142 &value_length, &flags, &rc);
1143 assert(value);
1144 free(value);
1145
1146 rc= memcached_mget(memc, keys, key_length, 4);
1147 count= 3;
1148 /* We test for purge of partial complete fetches */
1149 for (count= 3; count; count--)
1150 {
1151 value= memcached_fetch(memc, return_key, &return_key_length,
1152 &value_length, &flags, &rc);
1153 free(value);
1154 assert(rc == MEMCACHED_SUCCESS);
1155 }
1156 }
1157
1158 return 0;
1159 }
1160
1161 /* Test flag store/retrieve */
1162 uint8_t user_supplied_bug7(memcached_st *memc)
1163 {
1164 memcached_return rc;
1165 char *keys= "036790384900";
1166 size_t key_length= strlen("036790384900");
1167 char return_key[MEMCACHED_MAX_KEY];
1168 size_t return_key_length;
1169 char *value;
1170 size_t value_length;
1171 uint16_t flags;
1172 unsigned int x;
1173 char insert_data[VALUE_SIZE_BUG5];
1174
1175 for (x= 0; x < VALUE_SIZE_BUG5; x++)
1176 insert_data[x]= rand();
1177
1178 memcached_flush(memc, 0);
1179
1180 flags= 245;
1181 rc= memcached_set(memc, keys, key_length,
1182 insert_data, VALUE_SIZE_BUG5,
1183 (time_t)0, flags);
1184 assert(rc == MEMCACHED_SUCCESS);
1185
1186 flags= 0;
1187 value= memcached_get(memc, keys, key_length,
1188 &value_length, &flags, &rc);
1189 assert(flags == 245);
1190 assert(value);
1191 free(value);
1192
1193 rc= memcached_mget(memc, &keys, &key_length, 1);
1194
1195 flags= 0;
1196 value= memcached_fetch(memc, return_key, &return_key_length,
1197 &value_length, &flags, &rc);
1198 assert(flags == 245);
1199 assert(value);
1200 free(value);
1201
1202
1203 return 0;
1204 }
1205
1206 uint8_t result_static(memcached_st *memc)
1207 {
1208 memcached_result_st result;
1209 memcached_result_st *result_ptr;
1210
1211 result_ptr= memcached_result_create(memc, &result);
1212 assert(result.is_allocated == MEMCACHED_NOT_ALLOCATED);
1213 assert(result_ptr);
1214 memcached_result_free(&result);
1215
1216 return 0;
1217 }
1218
1219 uint8_t result_alloc(memcached_st *memc)
1220 {
1221 memcached_result_st *result;
1222
1223 result= memcached_result_create(memc, NULL);
1224 assert(result);
1225 memcached_result_free(result);
1226
1227 return 0;
1228 }
1229
1230 uint8_t string_static_null(memcached_st *memc)
1231 {
1232 memcached_string_st string;
1233 memcached_string_st *string_ptr;
1234
1235 string_ptr= memcached_string_create(memc, &string, 0);
1236 assert(string.is_allocated == MEMCACHED_NOT_ALLOCATED);
1237 assert(string_ptr);
1238 memcached_string_free(&string);
1239
1240 return 0;
1241 }
1242
1243 uint8_t string_alloc_null(memcached_st *memc)
1244 {
1245 memcached_string_st *string;
1246
1247 string= memcached_string_create(memc, NULL, 0);
1248 assert(string);
1249 memcached_string_free(string);
1250
1251 return 0;
1252 }
1253
1254 uint8_t string_alloc_with_size(memcached_st *memc)
1255 {
1256 memcached_string_st *string;
1257
1258 string= memcached_string_create(memc, NULL, 1024);
1259 assert(string);
1260 memcached_string_free(string);
1261
1262 return 0;
1263 }
1264
1265 uint8_t string_alloc_with_size_toobig(memcached_st *memc)
1266 {
1267 memcached_string_st *string;
1268
1269 string= memcached_string_create(memc, NULL, INT64_MAX);
1270 assert(string == NULL);
1271
1272 return 0;
1273 }
1274
1275 uint8_t string_alloc_append(memcached_st *memc)
1276 {
1277 unsigned int x;
1278 char buffer[SMALL_STRING_LEN];
1279 memcached_string_st *string;
1280
1281 /* Ring the bell! */
1282 memset(buffer, 6, SMALL_STRING_LEN);
1283
1284 string= memcached_string_create(memc, NULL, 100);
1285 assert(string);
1286
1287 for (x= 0; x < 1024; x++)
1288 {
1289 memcached_return rc;
1290 rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
1291 assert(rc == MEMCACHED_SUCCESS);
1292 }
1293 memcached_string_free(string);
1294
1295 return 0;
1296 }
1297
1298 uint8_t string_alloc_append_toobig(memcached_st *memc)
1299 {
1300 memcached_return rc;
1301 unsigned int x;
1302 char buffer[SMALL_STRING_LEN];
1303 memcached_string_st *string;
1304
1305 /* Ring the bell! */
1306 memset(buffer, 6, SMALL_STRING_LEN);
1307
1308 string= memcached_string_create(memc, NULL, 100);
1309 assert(string);
1310
1311 for (x= 0; x < 1024; x++)
1312 {
1313 rc= memcached_string_append(string, buffer, SMALL_STRING_LEN);
1314 assert(rc == MEMCACHED_SUCCESS);
1315 }
1316 rc= memcached_string_append(string, buffer, INT64_MAX);
1317 assert(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE);
1318 memcached_string_free(string);
1319
1320 return 0;
1321 }
1322
1323 uint8_t generate_data(memcached_st *memc)
1324 {
1325 unsigned long long x;
1326 global_pairs= pairs_generate(GLOBAL_COUNT);
1327 execute_set(memc, global_pairs, GLOBAL_COUNT);
1328
1329 for (x= 0; x < GLOBAL_COUNT; x++)
1330 {
1331 global_keys[x]= global_pairs[x].key;
1332 global_keys_length[x]= global_pairs[x].key_length;
1333 }
1334
1335 return 0;
1336 }
1337
1338 uint8_t get_read(memcached_st *memc)
1339 {
1340 unsigned int x;
1341 memcached_return rc;
1342
1343 {
1344 char *return_value;
1345 size_t return_value_length;
1346 uint16_t flags;
1347
1348 for (x= 0; x < GLOBAL_COUNT; x++)
1349 {
1350 return_value= memcached_get(memc, global_keys[x], global_keys_length[x],
1351 &return_value_length, &flags, &rc);
1352 /*
1353 assert(return_value);
1354 assert(rc == MEMCACHED_SUCCESS);
1355 */
1356 if (rc == MEMCACHED_SUCCESS && return_value)
1357 free(return_value);
1358 }
1359 }
1360
1361 return 0;
1362 }
1363
1364 uint8_t mget_read(memcached_st *memc)
1365 {
1366 memcached_return rc;
1367
1368 rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
1369 assert(rc == MEMCACHED_SUCCESS);
1370 /* Turn this into a help function */
1371 {
1372 char return_key[MEMCACHED_MAX_KEY];
1373 size_t return_key_length;
1374 char *return_value;
1375 size_t return_value_length;
1376 uint16_t flags;
1377
1378 while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
1379 &return_value_length, &flags, &rc)))
1380 {
1381 assert(return_value);
1382 assert(rc == MEMCACHED_SUCCESS);
1383 free(return_value);
1384 }
1385 }
1386
1387 return 0;
1388 }
1389
1390 uint8_t mget_read_result(memcached_st *memc)
1391 {
1392 memcached_return rc;
1393
1394 rc= memcached_mget(memc, global_keys, global_keys_length, GLOBAL_COUNT);
1395 assert(rc == MEMCACHED_SUCCESS);
1396 /* Turn this into a help function */
1397 {
1398 memcached_result_st results_obj;
1399 memcached_result_st *results;
1400
1401 results= memcached_result_create(memc, &results_obj);
1402
1403 while ((results= memcached_fetch_result(memc, &results_obj, &rc)))
1404 {
1405 assert(results);
1406 assert(rc == MEMCACHED_SUCCESS);
1407 }
1408
1409 memcached_result_free(&results_obj);
1410 }
1411
1412 return 0;
1413 }
1414
1415 uint8_t free_data(memcached_st *memc)
1416 {
1417 pairs_free(global_pairs);
1418
1419 return 0;
1420 }
1421
1422 uint8_t add_host_test1(memcached_st *memc)
1423 {
1424 unsigned int x;
1425 memcached_return rc;
1426 char servername[]= "0.example.com";
1427 memcached_server_st *servers;
1428
1429 servers= memcached_server_list_append(NULL, servername, 400, &rc);
1430 assert(servers);
1431 assert(1 == memcached_server_list_count(servers));
1432
1433 for (x= 2; x < 20; x++)
1434 {
1435 char buffer[SMALL_STRING_LEN];
1436
1437 snprintf(buffer, SMALL_STRING_LEN, "%u.example.com", 400+x);
1438 servers= memcached_server_list_append(servers, buffer, 401,
1439 &rc);
1440 assert(rc == MEMCACHED_SUCCESS);
1441 assert(x == memcached_server_list_count(servers));
1442 }
1443
1444 rc= memcached_server_push(memc, servers);
1445 assert(rc == MEMCACHED_SUCCESS);
1446 rc= memcached_server_push(memc, servers);
1447 assert(rc == MEMCACHED_SUCCESS);
1448
1449 memcached_server_list_free(servers);
1450
1451 return 0;
1452 }
1453
1454 memcached_return pre_nonblock(memcached_st *memc)
1455 {
1456 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
1457
1458 return MEMCACHED_SUCCESS;
1459 }
1460
1461 memcached_return pre_md5(memcached_st *memc)
1462 {
1463 memcached_hash value= MEMCACHED_HASH_MD5;
1464 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1465
1466 return MEMCACHED_SUCCESS;
1467 }
1468
1469 memcached_return pre_crc(memcached_st *memc)
1470 {
1471 memcached_hash value= MEMCACHED_HASH_CRC;
1472 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1473
1474 return MEMCACHED_SUCCESS;
1475 }
1476
1477 memcached_return pre_hash_fnv1_64(memcached_st *memc)
1478 {
1479 memcached_hash value= MEMCACHED_HASH_FNV1_64;
1480 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1481
1482 return MEMCACHED_SUCCESS;
1483 }
1484
1485 memcached_return pre_hash_fnv1a_64(memcached_st *memc)
1486 {
1487 memcached_hash value= MEMCACHED_HASH_FNV1A_64;
1488 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1489
1490 return MEMCACHED_SUCCESS;
1491 }
1492
1493 memcached_return pre_hash_fnv1_32(memcached_st *memc)
1494 {
1495 memcached_hash value= MEMCACHED_HASH_FNV1_32;
1496 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1497
1498 return MEMCACHED_SUCCESS;
1499 }
1500
1501 memcached_return pre_hash_fnv1a_32(memcached_st *memc)
1502 {
1503 memcached_hash value= MEMCACHED_HASH_FNV1A_32;
1504 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1505
1506 return MEMCACHED_SUCCESS;
1507 }
1508
1509 memcached_return pre_hash_ketama(memcached_st *memc)
1510 {
1511 memcached_hash value= MEMCACHED_HASH_KETAMA;
1512 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &value);
1513
1514 return MEMCACHED_SUCCESS;
1515 }
1516
1517 memcached_return check_for_1_2_3(memcached_st *memc)
1518 {
1519 memcached_version(memc);
1520
1521 if (memc->hosts[0].major_version >= 1 &&
1522 memc->hosts[0].minor_version >= 2 &&
1523 memc->hosts[0].micro_version >= 4)
1524 return MEMCACHED_SUCCESS;
1525
1526 return MEMCACHED_FAILURE;
1527 }
1528
1529 memcached_return pre_unix_socket(memcached_st *memc)
1530 {
1531 memcached_return rc;
1532 struct stat buf;
1533
1534 memcached_server_list_free(memc->hosts);
1535 memc->hosts= NULL;
1536 memc->number_of_hosts= 0;
1537
1538 if (stat("/tmp/memcached.socket", &buf))
1539 return MEMCACHED_FAILURE;
1540
1541 rc= memcached_server_add_unix_socket(memc, "/tmp/memcached.socket");
1542
1543 return rc;
1544 }
1545
1546 memcached_return pre_udp(memcached_st *memc)
1547 {
1548 memcached_return rc;
1549
1550 memcached_server_list_free(memc->hosts);
1551 memc->hosts= NULL;
1552 memc->number_of_hosts= 0;
1553
1554 if (0)
1555 return MEMCACHED_FAILURE;
1556
1557 rc= memcached_server_add_udp(memc, "localhost", MEMCACHED_DEFAULT_PORT);
1558
1559 return rc;
1560 }
1561
1562 memcached_return pre_nodelay(memcached_st *memc)
1563 {
1564 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL);
1565 memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL);
1566
1567 return MEMCACHED_SUCCESS;
1568 }
1569
1570
1571 /* Clean the server before beginning testing */
1572 test_st tests[] ={
1573 {"flush", 0, flush_test },
1574 {"init", 0, init_test },
1575 {"allocation", 0, allocation_test },
1576 {"clone_test", 0, clone_test },
1577 {"error", 0, error_test },
1578 {"set", 0, set_test },
1579 {"set2", 0, set_test2 },
1580 {"set3", 0, set_test3 },
1581 {"add", 0, add_test },
1582 {"replace", 0, replace_test },
1583 {"delete", 1, delete_test },
1584 {"get", 1, get_test },
1585 {"get2", 0, get_test2 },
1586 {"get3", 0, get_test3 },
1587 {"get4", 0, get_test4 },
1588 {"stats_servername", 0, stats_servername_test },
1589 {"increment", 0, increment_test },
1590 {"decrement", 0, decrement_test },
1591 {"quit", 0, quit_test },
1592 {"mget", 1, mget_test },
1593 {"mget_result", 1, mget_result_test },
1594 {"mget_result_alloc", 1, mget_result_alloc_test },
1595 {"get_stats", 0, get_stats },
1596 {"add_host_test", 0, add_host_test },
1597 {"get_stats_keys", 0, get_stats_keys },
1598 {"behavior_test", 0, get_stats_keys },
1599 {0, 0, 0}
1600 };
1601
1602 test_st string_tests[] ={
1603 {"string static with null", 0, string_static_null },
1604 {"string alloc with null", 0, string_alloc_null },
1605 {"string alloc with 1K", 0, string_alloc_with_size },
1606 {"string alloc with malloc failure", 0, string_alloc_with_size_toobig },
1607 {"string append", 0, string_alloc_append },
1608 {"string append failure (too big)", 0, string_alloc_append_toobig },
1609 {0, 0, 0}
1610 };
1611
1612 test_st result_tests[] ={
1613 {"result static", 0, result_static},
1614 {"result alloc", 0, result_alloc},
1615 {0, 0, 0}
1616 };
1617
1618 test_st version_1_2_3[] ={
1619 {"append", 0, append_test },
1620 {"prepend", 0, prepend_test },
1621 // {"cas", 0, cas_test },
1622 {0, 0, 0}
1623 };
1624
1625 test_st user_tests[] ={
1626 {"user_supplied_bug1", 0, user_supplied_bug1 },
1627 {"user_supplied_bug2", 0, user_supplied_bug2 },
1628 {"user_supplied_bug3", 0, user_supplied_bug3 },
1629 {"user_supplied_bug4", 0, user_supplied_bug4 },
1630 {"user_supplied_bug5", 1, user_supplied_bug5 },
1631 {"user_supplied_bug6", 1, user_supplied_bug6 },
1632 {"user_supplied_bug7", 1, user_supplied_bug7 },
1633 {0, 0, 0}
1634 };
1635
1636 test_st generate_tests[] ={
1637 {"generate_data", 0, generate_data },
1638 {"get_read", 0, get_read },
1639 {"mget_read", 0, mget_read },
1640 {"mget_read_result", 0, mget_read_result },
1641 {0, 0, 0}
1642 };
1643
1644
1645 collection_st collection[] ={
1646 {"block", 0, 0, tests},
1647 {"nonblock", pre_nonblock, 0, tests},
1648 {"nodelay", pre_nodelay, 0, tests},
1649 {"md5", pre_md5, 0, tests},
1650 {"crc", pre_crc, 0, tests},
1651 {"fnv1_64", pre_hash_fnv1_64, 0, tests},
1652 {"fnv1a_64", pre_hash_fnv1a_64, 0, tests},
1653 {"fnv1_32", pre_hash_fnv1_32, 0, tests},
1654 {"fnv1a_32", pre_hash_fnv1a_32, 0, tests},
1655 {"ketama", pre_hash_ketama, 0, tests},
1656 {"unix_socket", pre_unix_socket, 0, tests},
1657 {"unix_socket_nodelay", pre_nodelay, 0, tests},
1658 // {"udp", pre_udp, 0, tests},
1659 {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},
1660 {"string", 0, 0, string_tests},
1661 {"result", 0, 0, result_tests},
1662 {"user", 0, 0, user_tests},
1663 {"generate", 0, 0, generate_tests},
1664 {"generate_nonblock", pre_nonblock, 0, generate_tests},
1665 {0, 0, 0, 0}
1666 };
1667
1668 collection_st *gets_collections(void)
1669 {
1670 return collection;
1671 }