Fix lack of free() in bug (quiet valgrind)
[m6w6/libmemcached] / tests / function.c
index 51b4c74afa83f3f4dc7a624a6413933cc1961cb4..514fe3c2fb8673f3977fc49053a353801e48b605 100644 (file)
@@ -889,11 +889,14 @@ uint8_t get_stats_keys(memcached_st *memc)
  return 0;
 }
 
-uint8_t version_string_test(void)
+uint8_t version_string_test(memcached_st *memc)
 {
   const char *version_string;
+
   version_string= memcached_lib_version();
+
   assert(!strcmp(version_string, LIBMEMCACHED_VERSION_STRING));
+
   return 0;
 }
 
@@ -1599,6 +1602,44 @@ uint8_t user_supplied_bug11(memcached_st *memc)
   return 0;
 }
 
+/*
+  Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist.
+*/
+uint8_t user_supplied_bug12(memcached_st *memc)
+{
+  memcached_return rc;
+  uint32_t flags;
+  size_t value_length;
+  char *value;
+  uint64_t number_value;
+
+  value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
+                        &value_length, &flags, &rc);           
+  assert(value == NULL);
+  assert(rc == MEMCACHED_NOTFOUND);
+
+  rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
+                          1, &number_value);
+
+  assert(value == NULL);
+  assert(rc == MEMCACHED_NOTFOUND);
+
+  rc= memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0);
+
+  value= memcached_get(memc, "autoincrement", strlen("autoincrement"),
+                        &value_length, &flags, &rc);           
+  assert(value);
+  assert(rc == MEMCACHED_SUCCESS);
+  free(value);
+
+  rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"),
+                          1, &number_value);
+  assert(number_value == 2);
+  assert(rc == MEMCACHED_SUCCESS);
+
+  return 0;
+}
+
 uint8_t result_static(memcached_st *memc)
 {
   memcached_result_st result;
@@ -1997,6 +2038,7 @@ memcached_return pre_hash_ketama(memcached_st *memc)
 
   return MEMCACHED_SUCCESS;
 }
+
 void my_free(memcached_st *ptr, void *mem)
 {
   free(mem);
@@ -2020,8 +2062,9 @@ memcached_return set_memory_alloc(memcached_st *memc)
 
     rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &my_malloc);
     assert(rc == MEMCACHED_SUCCESS);
-    test_ptr= (memcached_malloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
-    assert(test_ptr == (memcached_malloc_function)my_malloc);
+    test_ptr= (memcached_malloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_MALLOC_FUNCTION, &rc);
+    assert(rc == MEMCACHED_SUCCESS);
+    assert(test_ptr == my_malloc);
   }
 
   {
@@ -2030,7 +2073,8 @@ memcached_return set_memory_alloc(memcached_st *memc)
 
     rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &my_realloc);
     assert(rc == MEMCACHED_SUCCESS);
-    test_ptr= (memcached_realloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
+    test_ptr= (memcached_realloc_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_REALLOC_FUNCTION, &rc);
+    assert(rc == MEMCACHED_SUCCESS);
     assert(test_ptr == my_realloc);
   }
 
@@ -2040,7 +2084,8 @@ memcached_return set_memory_alloc(memcached_st *memc)
 
     rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, my_free);
     assert(rc == MEMCACHED_SUCCESS);
-    test_ptr= (memcached_free_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_USER_DATA, &rc);
+    test_ptr= (memcached_free_function)memcached_callback_get(memc, MEMCACHED_CALLBACK_FREE_FUNCTION, &rc);
+    assert(rc == MEMCACHED_SUCCESS);
     assert(test_ptr == my_free);
   }
 
@@ -2228,6 +2273,7 @@ test_st user_tests[] ={
   {"user_supplied_bug9", 1, user_supplied_bug9 },
   {"user_supplied_bug10", 1, user_supplied_bug10 },
   {"user_supplied_bug11", 1, user_supplied_bug11 },
+  {"user_supplied_bug12", 1, user_supplied_bug12 },
   {0, 0, 0}
 };