Clarified return type for prefix key in cases where it is too long.
[awesomized/libmemcached] / tests / function.c
index cc63daddcd4dbad3a6c09aceacbc1b8aac9b5e9a..fb2f4bca42cd7caff2c898f7988f6296172e2f9e 100644 (file)
@@ -633,7 +633,7 @@ test_return read_through(memcached_st *memc)
   return 0;
 }
 
-memcached_return delete_trigger(memcached_st *ptr,  char *key, size_t key_length)
+memcached_return delete_trigger(memcached_st *ptr,  const char *key, size_t key_length)
 {
   assert(key);
 
@@ -2003,6 +2003,32 @@ test_return user_supplied_bug15(memcached_st *memc)
   return 0;
 }
 
+/* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */
+test_return user_supplied_bug16(memcached_st *memc)
+{
+  memcached_return rc;
+  char *key= "mykey";
+  char *value;
+  size_t length;
+  uint32_t flags;
+
+  rc= memcached_set(memc, key, strlen(key), 
+                    NULL, 0,
+                    (time_t)0, UINT32_MAX);
+
+  assert(rc == MEMCACHED_SUCCESS);
+
+  value= memcached_get(memc, key, strlen(key),
+                       &length, &flags, &rc);
+
+  assert(rc == MEMCACHED_SUCCESS);
+  assert(value == NULL);
+  assert(length == 0);
+  assert(flags == UINT32_MAX);
+
+  return 0;
+}
+
 test_return result_static(memcached_st *memc)
 {
   memcached_result_st result;
@@ -2175,6 +2201,42 @@ test_return generate_buffer_data(memcached_st *memc)
   return 0;
 }
 
+test_return get_read_count(memcached_st *memc)
+{
+  unsigned int x;
+  memcached_return rc;
+  memcached_st *clone;
+
+  clone= memcached_clone(NULL, memc);
+  assert(clone);
+
+  memcached_server_add(clone, "localhost", 6666);
+
+  {
+    char *return_value;
+    size_t return_value_length;
+    uint32_t flags;
+    uint32_t count;
+
+    for (x= count= 0; x < global_count; x++)
+    {
+      return_value= memcached_get(clone, global_keys[x], global_keys_length[x],
+                                  &return_value_length, &flags, &rc);
+      if (rc == MEMCACHED_SUCCESS)
+      {
+        count++;
+        if (return_value)
+          free(return_value);
+      }
+    }
+    fprintf(stderr, "\t%u -> %u", global_count, count);
+  }
+
+  memcached_free(clone);
+
+  return 0;
+}
+
 test_return get_read(memcached_st *memc)
 {
   unsigned int x;
@@ -2427,6 +2489,56 @@ void *my_realloc(memcached_st *ptr, void *mem, const size_t size)
   return realloc(mem, size);
 }
 
+memcached_return set_prefix(memcached_st *memc)
+{
+  memcached_return rc;
+  const char *key= "mine";
+  char *value;
+
+  /* Make sure be default none exists */
+  value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+  assert(rc == MEMCACHED_FAILURE);
+
+  /* Test a clean set */
+  rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key);
+  assert(rc == MEMCACHED_SUCCESS);
+
+  value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+  assert(memcmp(value, key, 4) == 0);
+  assert(rc == MEMCACHED_SUCCESS);
+
+  /* Test that we can turn it off */
+  rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL);
+  assert(rc == MEMCACHED_SUCCESS);
+
+  value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+  assert(rc == MEMCACHED_FAILURE);
+
+  /* Now setup for main test */
+  rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, (void *)key);
+  assert(rc == MEMCACHED_SUCCESS);
+
+  value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+  assert(rc == MEMCACHED_SUCCESS);
+  assert(memcmp(value, key, 4) == 0);
+
+  /* Set to Zero, and then Set to something too large */
+  {
+    char *long_key= "This is more then the allotted number of characters";
+    rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL);
+    assert(rc == MEMCACHED_SUCCESS);
+
+    value= memcached_callback_get(memc, MEMCACHED_CALLBACK_PREFIX_KEY, &rc);
+    assert(rc == MEMCACHED_FAILURE);
+    assert(value == NULL);
+
+    rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_PREFIX_KEY, long_key);
+    assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
+  }
+
+  return MEMCACHED_SUCCESS;
+}
+
 memcached_return set_memory_alloc(memcached_st *memc)
 {
   {
@@ -2673,6 +2785,7 @@ test_st user_tests[] ={
   {"user_supplied_bug13", 1, user_supplied_bug13 },
   {"user_supplied_bug14", 1, user_supplied_bug14 },
   {"user_supplied_bug15", 1, user_supplied_bug15 },
+  {"user_supplied_bug16", 1, user_supplied_bug16 },
   {0, 0, 0}
 };
 
@@ -2695,6 +2808,13 @@ test_st generate_tests[] ={
   {0, 0, 0}
 };
 
+test_st consistent_tests[] ={
+  {"generate_pairs", 1, generate_pairs },
+  {"generate_data", 1, generate_data },
+  {"get_read", 0, get_read_count },
+  {"cleanup", 1, cleanup_pairs },
+  {0, 0, 0}
+};
 
 collection_st collection[] ={
   {"block", 0, 0, tests},
@@ -2715,6 +2835,7 @@ collection_st collection[] ={
   {"consistent", enable_consistent, 0, tests},
   {"wheel", enable_wheel, 0, tests},
   {"memory_allocators", set_memory_alloc, 0, tests},
+  {"prefix", set_prefix, 0, tests},
 //  {"udp", pre_udp, 0, tests},
   {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},
   {"string", 0, 0, string_tests},
@@ -2728,6 +2849,9 @@ collection_st collection[] ={
   {"generate_md5", pre_md5, 0, generate_tests},
   {"generate_murmur", pre_murmur, 0, generate_tests},
   {"generate_nonblock", pre_nonblock, 0, generate_tests},
+  {"consistent_not", 0, 0, consistent_tests},
+  {"consistent_ketama", pre_behavior_ketama, 0, consistent_tests},
+  {"consistent_wheel", enable_wheel, 0, consistent_tests},
   {0, 0, 0, 0}
 };