Added basic print output.
[m6w6/libmemcached] / tests / test.c
index dabb00f4779ac23b6d0bb7e7ac84b7de4b54a8b5..c60b48104738f1981ed34dee712aea0b2ed124f9 100644 (file)
@@ -211,11 +211,13 @@ void get_test3(void)
   char *string;
   size_t string_length;
   uint16_t flags;
-  int i;
+  int x;
 
-  value = (char*) malloc(value_length);
-  for (i=0; i<value_length; i++)
-    value[i] = (char) (i % 127);
+  value = (char*)malloc(value_length);
+  assert(value);
+
+  for (x= 0; x < value_length; x++)
+    value[x] = (char) (x % 127);
 
   memc= memcached_init(NULL);
   assert(memc);
@@ -230,6 +232,8 @@ void get_test3(void)
   string= memcached_get(memc, key, strlen(key),
                         &string_length, &flags, &rc);
 
+  assert(rc == MEMCACHED_SUCCESS);
+  assert(string);
   assert(string_length == value_length);
   assert(!memcmp(string, value, string_length));
 
@@ -239,6 +243,51 @@ void get_test3(void)
   memcached_deinit(memc);
 }
 
+void get_test4(void)
+{
+  memcached_st *memc;
+  memcached_return rc;
+  char *key= "foo";
+  char *value;
+  size_t value_length= 8191;
+  char *string;
+  size_t string_length;
+  uint16_t flags;
+  int x;
+
+  value = (char*)malloc(value_length);
+  assert(value);
+
+  for (x= 0; x < value_length; x++)
+    value[x] = (char) (x % 127);
+
+  memc= memcached_init(NULL);
+  assert(memc);
+  rc= memcached_server_add(memc, "localhost", 0);
+  assert(rc == MEMCACHED_SUCCESS);
+
+  rc= memcached_set(memc, key, strlen(key), 
+                    value, value_length,
+                    (time_t)0, (uint16_t)0);
+  assert(rc == MEMCACHED_SUCCESS);
+
+  for (x= 0; x < 10; x++)
+  {
+    string= memcached_get(memc, key, strlen(key),
+                          &string_length, &flags, &rc);
+
+    assert(rc == MEMCACHED_SUCCESS);
+    assert(string);
+    assert(string_length == value_length);
+    assert(!memcmp(string, value, string_length));
+    free(string);
+  }
+
+  free(value);
+
+  memcached_deinit(memc);
+}
+
 void stats_servername_test(void)
 {
   memcached_return rc;
@@ -383,8 +432,8 @@ void mget_test(void)
   assert(rc == MEMCACHED_SUCCESS);
 
   x= 0;
-  while (return_value= memcached_fetch(memc, return_key, &return_key_length, 
-                      &return_value_length, &flags, &rc))
+  while ((return_value= memcached_fetch(memc, return_key, &return_key_length, 
+                                        &return_value_length, &flags, &rc)))
   {
     assert(return_value);
     assert(rc == MEMCACHED_SUCCESS);
@@ -488,7 +537,7 @@ void get_stats_multiple(void)
 }
 
 
-int main(int argc, char argvp[])
+int main(int argc, char *argv[])
 {
   /* Clean the server before beginning testing */
   flush_test();
@@ -505,6 +554,7 @@ int main(int argc, char argvp[])
   get_test();
   get_test2();
   get_test3();
+  get_test4();
   stats_servername_test();
 
   increment_test();