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