testing: freebsd on cirrus
[awesomized/libmemcached] / src / bin / memcapable.cc
index 81e619f647d1c63578993de370c077e4a633101b..65ae027fdbd73e46382d8210bc4097a72db11308 100644 (file)
@@ -13,7 +13,7 @@
 /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
 #undef NDEBUG
 
-#include <mem_config.h>
+#include "mem_config.h"
 
 #ifdef HAVE_POLL_H
 #include <poll.h>
@@ -34,7 +34,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <libmemcached-1.0/memcached.h>
+#include "libmemcached-1.0/memcached.h"
 
 #include "libmemcached/socket.hpp"
 #include "libmemcachedprotocol-0.0/binary.h"
@@ -63,6 +63,9 @@ static bool verbose= false;
 /* The number of seconds to wait for an IO-operation */
 static int timeout= 2;
 
+/* v1.6.x is more permissible */
+static bool v16x_or_greater = false;
+
 /*
  * Instead of having to cast between the different datatypes we create
  * a union of all of the different types of pacages we want to send.
@@ -1259,14 +1262,16 @@ static enum test_return receive_error_response(void)
 
 static enum test_return test_ascii_quit(void)
 {
-  /* Verify that quit handles unknown options */
-  execute(send_string("quit foo bar\r\n"));
-  execute(receive_error_response());
-
-  /* quit doesn't support noreply */
-  execute(send_string("quit noreply\r\n"));
-  execute(receive_error_response());
+  if (!v16x_or_greater) {
+    /* Verify that quit handles unknown options */
+    execute(send_string("quit foo bar\r\n"));
+    execute(receive_error_response());
 
+    /* quit doesn't support noreply */
+    execute(send_string("quit noreply\r\n"));
+    execute(receive_error_response());
+  }
+  
   /* Verify that quit works */
   execute(send_string("quit\r\n"));
 
@@ -1279,20 +1284,33 @@ static enum test_return test_ascii_quit(void)
 
 static enum test_return test_ascii_version(void)
 {
-  /* Verify that version command handles unknown options */
-  execute(send_string("version foo bar\r\n"));
-  execute(receive_error_response());
-
-  /* version doesn't support noreply */
-  execute(send_string("version noreply\r\n"));
-  execute(receive_error_response());
-
-  /* Verify that verify works */
+  /* Verify that version works */
   execute(send_string("version\r\n"));
   char buffer[256];
   execute(receive_line(buffer, sizeof(buffer)));
   verify(strncmp(buffer, "VERSION ", 8) == 0);
 
+  char *version = &buffer[sizeof("VERSION") + 2];
+  if (version[0] >= '1' || (version[0] == '1' && version[2] >= '6')) {
+    v16x_or_greater = true;
+  }
+
+  /* Verify that version command handles unknown options */
+  execute(send_string("version foo bar\r\n"));
+  if (v16x_or_greater) {
+    execute(receive_line(buffer, sizeof(buffer)));
+    verify(strncmp(buffer, "VERSION ", 8) == 0);
+  } else {
+    execute(receive_error_response());
+  }
+  /* version doesn't support noreply */
+  execute(send_string("version noreply\r\n"));
+  if (v16x_or_greater) {
+    execute(receive_line(buffer, sizeof(buffer)));
+    verify(strncmp(buffer, "VERSION ", 8) == 0);
+  } else {
+    execute(receive_error_response());
+  }
   return TEST_PASS;
 }
 
@@ -2008,8 +2026,8 @@ struct testcase
 };
 
 struct testcase testcases[]= {
-  { "ascii quit", test_ascii_quit },
   { "ascii version", test_ascii_version },
+  { "ascii quit", test_ascii_quit },
   { "ascii verbosity", test_ascii_verbosity },
   { "ascii set", test_ascii_set },
   { "ascii set noreply", test_ascii_set_noreply },