clang-tidy
[awesomized/libmemcached] / test / lib / random.cpp
index 3681fcc8727a3aaeec768f5abe27eee25c6ce883..6aab887597f087e75b823f24773cf0515845c11d 100644 (file)
@@ -4,17 +4,17 @@
 #include <unistd.h> // getpid()
 
 unsigned random_port() {
-  retry:
-  auto port = random_num(2<<9, 2<<15);
-  Connection conn(port);
+  do {
+    auto port = random_num(5000, 32000);
+    Connection conn(port);
 
-  if (!conn.open()) {
-    return port;
-  }
-  if (!conn.isOpen()) {
-    return port;
-  }
-  goto retry;
+    if (!conn.open()) {
+      return port;
+    }
+    if (!conn.isOpen()) {
+      return port;
+    }
+  } while(true);
 }
 
 string random_port_string(const string &) {
@@ -62,3 +62,21 @@ pair<string, string> random_ascii_pair(size_t minlen, size_t maxlen) {
       random_ascii_string(random_num(minlen, maxlen))
   };
 }
+
+#include <climits>
+
+char random_binary() {
+  return random_num(CHAR_MIN, CHAR_MAX);
+}
+
+string random_binary_string(size_t len) {
+  string s;
+  s.reserve(len + 1);
+
+  for (size_t rem = 0; rem < len; ++rem) {
+    s += random_binary();
+  }
+  s[len] = 0;
+
+  return s;
+}