1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "mem_config.h"
38 #include "libtest/test.hpp"
44 #include "libmemcached-1.0/memcached.h"
45 #include "tests/libmemcached-1.0/memcached_get.h"
46 #include "tests/libmemcached-1.0/setup_and_teardowns.h"
48 test_return_t
get_test(memcached_st
*memc
)
50 uint64_t query_id
= memcached_query_id(memc
);
51 memcached_return_t rc
= memcached_delete(memc
,
52 test_literal_param(__func__
),
54 test_true(rc
== MEMCACHED_BUFFERED
or rc
== MEMCACHED_NOTFOUND
);
55 test_compare(query_id
+1, memcached_query_id(memc
));
59 char *string
= memcached_get(memc
,
60 test_literal_param(__func__
),
61 &string_length
, &flags
, &rc
);
63 test_compare(MEMCACHED_NOTFOUND
, rc
);
64 test_false(string_length
);
70 test_return_t
get_test2(memcached_st
*memc
)
72 const char *value
= "when we sanitize";
74 uint64_t query_id
= memcached_query_id(memc
);
75 test_compare(return_value_based_on_buffering(memc
),
77 test_literal_param(__func__
),
79 time_t(0), uint32_t(0)));
80 test_compare(query_id
+1, memcached_query_id(memc
));
82 query_id
= memcached_query_id(memc
);
87 memcached_return_t rc
;
88 char *string
= memcached_get(memc
,
89 test_literal_param(__func__
),
90 &string_length
, &flags
, &rc
);
91 test_compare(query_id
+1, memcached_query_id(memc
));
93 test_compare(MEMCACHED_SUCCESS
, rc
);
94 test_compare(MEMCACHED_SUCCESS
, memcached_last_error(memc
));
96 test_compare(strlen(value
), string_length
);
97 test_memcmp(string
, value
, string_length
);
104 test_return_t
get_test3(memcached_st
*memc
)
106 size_t value_length
= 8191;
108 libtest::vchar_t value
;
109 value
.reserve(value_length
);
110 for (uint32_t x
= 0; x
< value_length
; x
++)
112 value
.push_back(char(x
% 127));
115 test_compare(return_value_based_on_buffering(memc
),
117 test_literal_param(__func__
),
118 &value
[0], value
.size(),
119 time_t(0), uint32_t(0)));
121 size_t string_length
;
123 memcached_return_t rc
;
124 char *string
= memcached_get(memc
,
125 test_literal_param(__func__
),
126 &string_length
, &flags
, &rc
);
128 test_compare(MEMCACHED_SUCCESS
, rc
);
130 test_compare(value
.size(), string_length
);
131 test_memcmp(string
, &value
[0], string_length
);
138 test_return_t
get_test4(memcached_st
*memc
)
140 size_t value_length
= 8191;
142 libtest::vchar_t value
;
143 value
.reserve(value_length
);
144 for (uint32_t x
= 0; x
< value_length
; x
++)
146 value
.push_back(char(x
% 127));
149 test_compare(return_value_based_on_buffering(memc
),
151 test_literal_param(__func__
),
152 &value
[0], value
.size(),
153 time_t(0), uint32_t(0)));
155 for (uint32_t x
= 0; x
< 10; x
++)
158 size_t string_length
;
159 memcached_return_t rc
;
160 char *string
= memcached_get(memc
,
161 test_literal_param(__func__
),
162 &string_length
, &flags
, &rc
);
164 test_compare(MEMCACHED_SUCCESS
, rc
);
166 test_compare(value
.size(), string_length
);
167 test_memcmp(string
, &value
[0], string_length
);
175 * This test verifies that memcached_read_one_response doesn't try to
176 * dereference a NIL-pointer if you issue a multi-get and don't read out all
177 * responses before you execute a storage command.
179 test_return_t
get_test5(memcached_st
*memc
)
182 ** Request the same key twice, to ensure that we hash to the same server
183 ** (so that we have multiple response values queued up) ;-)
185 const char *keys
[]= { "key", "key" };
186 size_t lengths
[]= { 3, 3 };
190 test_compare(return_value_based_on_buffering(memc
),
191 memcached_set(memc
, keys
[0], lengths
[0],
193 time_t(0), uint32_t(0)));
194 test_compare(MEMCACHED_SUCCESS
, memcached_mget(memc
, keys
, lengths
, test_array_length(keys
)));
196 memcached_result_st results_obj
;
197 memcached_result_st
*results
= memcached_result_create(memc
, &results_obj
);
200 memcached_return_t rc
;
201 results
= memcached_fetch_result(memc
, &results_obj
, &rc
);
204 memcached_result_free(&results_obj
);
206 /* Don't read out the second result, but issue a set instead.. */
207 test_compare(MEMCACHED_SUCCESS
, memcached_set(memc
, keys
[0], lengths
[0], keys
[0], lengths
[0], 0, 0));
209 char *val
= memcached_get_by_key(memc
, keys
[0], lengths
[0], "yek", 3,
212 test_compare(MEMCACHED_NOTFOUND
, rc
);
213 val
= memcached_get(memc
, keys
[0], lengths
[0], &rlen
, &flags
, &rc
);
215 test_compare(MEMCACHED_SUCCESS
, rc
);