You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/03/21 02:46:42 UTC

svn commit: r1459127 - in /incubator/mesos/trunk/third_party/libprocess/third_party/stout: ./ tests/

Author: benh
Date: Thu Mar 21 01:46:42 2013
New Revision: 1459127

URL: http://svn.apache.org/r1459127
Log:
Split apart the stout tests.

From: Ben Mahler <be...@gmail.com>
Review: https://reviews.apache.org/r/9863

Added:
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/bytes_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/duration_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/error_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/gzip_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/hashset_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/json_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/main.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multihashmap_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/none_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/strings_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/uuid_tests.cpp
Removed:
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/tests.cpp
Modified:
    incubator/mesos/trunk/third_party/libprocess/third_party/stout/Makefile.am

Modified: incubator/mesos/trunk/third_party/libprocess/third_party/stout/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/Makefile.am?rev=1459127&r1=1459126&r2=1459127&view=diff
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/Makefile.am (original)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/Makefile.am Thu Mar 21 01:46:42 2013
@@ -39,4 +39,15 @@ EXTRA_DIST =					\
   include/stout/try.hpp				\
   include/stout/utils.hpp			\
   include/stout/uuid.hpp			\
-  tests/tests.cpp
+  tests/bytes_tests.cpp				\
+  tests/duration_tests.cpp			\
+  tests/error_tests.cpp				\
+  tests/gzip_tests.cpp				\
+  tests/hashset_tests.cpp			\
+  tests/json_tests.cpp				\
+  tests/main.cpp				\
+  tests/multihashmap_tests.cpp			\
+  tests/none_tests.cpp				\
+  tests/os_tests.cpp				\
+  tests/strings_tests.cpp			\
+  tests/uuid_tests.cpp

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/bytes_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/bytes_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/bytes_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/bytes_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,38 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <stout/bytes.hpp>
+#include <stout/gtest.hpp>
+#include <stout/stringify.hpp>
+#include <stout/try.hpp>
+
+
+TEST(Stout, Bytes)
+{
+  Try<Bytes> _1terabyte = Bytes::parse("1TB");
+
+  EXPECT_SOME_EQ(Terabytes(1), _1terabyte);
+  EXPECT_SOME_EQ(Gigabytes(1024), _1terabyte);
+  EXPECT_SOME_EQ(Megabytes(1024 * 1024), _1terabyte);
+  EXPECT_SOME_EQ(Kilobytes(1024 * 1024 * 1024), _1terabyte);
+  EXPECT_SOME_EQ(Bytes(1024LLU * 1024 * 1024 * 1024), _1terabyte);
+
+  EXPECT_EQ(Bytes(1024), Kilobytes(1));
+  EXPECT_LT(Bytes(1023), Kilobytes(1));
+  EXPECT_GT(Bytes(1025), Kilobytes(1));
+
+  EXPECT_NE(Megabytes(1023), Gigabytes(1));
+
+  EXPECT_EQ("0B", stringify(Bytes()));
+
+  EXPECT_EQ("1KB", stringify(Kilobytes(1)));
+  EXPECT_EQ("1MB", stringify(Megabytes(1)));
+  EXPECT_EQ("1GB", stringify(Gigabytes(1)));
+  EXPECT_EQ("1TB", stringify(Terabytes(1)));
+
+  EXPECT_EQ("1023B", stringify(Bytes(1023)));
+  EXPECT_EQ("1023KB", stringify(Kilobytes(1023)));
+  EXPECT_EQ("1023MB", stringify(Megabytes(1023)));
+  EXPECT_EQ("1023GB", stringify(Gigabytes(1023)));
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/duration_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/duration_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/duration_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/duration_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,35 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <stout/duration.hpp>
+#include <stout/gtest.hpp>
+#include <stout/try.hpp>
+
+
+TEST(DurationTest, Test)
+{
+  Try<Duration> _3hrs = Duration::parse("3hrs");
+  ASSERT_SOME(_3hrs);
+
+  EXPECT_EQ(Hours(3.0), _3hrs.get());
+  EXPECT_EQ(Minutes(180.0), _3hrs.get());
+  EXPECT_EQ(Seconds(10800.0), _3hrs.get());
+  EXPECT_EQ(Milliseconds(10800000.0), _3hrs.get());
+
+  EXPECT_EQ(Milliseconds(1000.0), Seconds(1.0));
+
+  EXPECT_GT(Weeks(1.0), Days(6.0));
+
+  EXPECT_LT(Hours(23.0), Days(1.0));
+
+  EXPECT_LE(Hours(24.0), Days(1.0));
+  EXPECT_GE(Hours(24.0), Days(1.0));
+
+  EXPECT_NE(Minutes(59.0), Hours(1.0));
+
+  Try<Duration> _3_5hrs = Duration::parse("3.5hrs");
+  ASSERT_SOME(_3_5hrs);
+
+  EXPECT_EQ(Hours(3.5), _3_5hrs.get());
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/error_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/error_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/error_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/error_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,60 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/option.hpp>
+#include <stout/result.hpp>
+#include <stout/try.hpp>
+
+using std::string;
+
+
+Error error1()
+{
+  return Error("Failed to ...");
+}
+
+
+Try<string> error2()
+{
+  return Error("Failed to ...");
+}
+
+
+Try<string> error3(const Try<string>& t)
+{
+  return t;
+}
+
+
+Result<string> error4()
+{
+  return Error("Failed to ...");
+}
+
+
+Result<string> error5(const Result<string>& r)
+{
+  return r;
+}
+
+
+TEST(ErrorTest, Test)
+{
+  Try<string> t = error1();
+  EXPECT_TRUE(t.isError());
+  t = error2();
+  EXPECT_TRUE(t.isError());
+  t = error3(error1());
+  EXPECT_TRUE(t.isError());
+
+  Result<string> r = error1();
+  EXPECT_TRUE(r.isError());
+  r = error4();
+  EXPECT_TRUE(r.isError());
+  r = error5(error1());
+  EXPECT_TRUE(r.isError());
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/gzip_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/gzip_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/gzip_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/gzip_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,53 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <string>
+
+#include <stout/gtest.hpp>
+#include <stout/gzip.hpp>
+
+using std::string;
+
+
+#ifdef HAVE_LIBZ
+TEST(GzipTest, CompressDecompressString)
+{
+  // Test bad compression levels, outside of [-1, Z_BEST_COMPRESSION].
+  ASSERT_ERROR(gzip::compress("", -2));
+  ASSERT_ERROR(gzip::compress("", Z_BEST_COMPRESSION + 1));
+
+  string s =
+    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
+    "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad "
+    "minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
+    "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit "
+    "in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "
+    "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui "
+    "officia deserunt mollit anim id est laborum.";
+
+  Try<string> compressed = gzip::compress(s);
+  ASSERT_SOME(compressed);
+  Try<string> decompressed = gzip::decompress(compressed.get());
+  ASSERT_SOME(decompressed);
+  ASSERT_EQ(s, decompressed.get());
+
+  // Test with a 1MB random string!
+  s = "";
+  while (s.length() < (1024 * 1024)) {
+    s.append(1, ' ' + (rand() % ('~' - ' ')));
+  }
+  compressed = gzip::compress(s);
+  ASSERT_SOME(compressed);
+  decompressed = gzip::decompress(compressed.get());
+  ASSERT_SOME(decompressed);
+  ASSERT_EQ(s, decompressed.get());
+
+  s = "";
+  compressed = gzip::compress(s);
+  ASSERT_SOME(compressed);
+  decompressed = gzip::decompress(compressed.get());
+  ASSERT_SOME(decompressed);
+  ASSERT_EQ(s, decompressed.get());
+}
+#endif // HAVE_LIBZ

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/hashset_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/hashset_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/hashset_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/hashset_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,25 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <string>
+
+#include <stout/hashset.hpp>
+
+using std::string;
+
+
+TEST(HashsetTest, Insert)
+{
+  hashset<string> hs1;
+  hs1.insert(string("HS1"));
+  hs1.insert(string("HS3"));
+
+  hashset<string> hs2;
+  hs2.insert(string("HS2"));
+
+  hs1 = hs2;
+  ASSERT_EQ(1u, hs1.size());
+  ASSERT_TRUE(hs1.contains("HS2"));
+  ASSERT_TRUE(hs1 == hs2);
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/json_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/json_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/json_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/json_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,19 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <string>
+
+#include <stout/json.hpp>
+#include <stout/stringify.hpp>
+
+using std::string;
+
+
+TEST(JsonTest, BinaryData)
+{
+  JSON::String s(string("\"\\/\b\f\n\r\t\x00\x19 !#[]\x7F\xFF", 17));
+
+  EXPECT_EQ("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007F\\u00FF\"",
+            stringify(s));
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/main.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/main.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/main.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/main.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,11 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+int main(int argc, char** argv)
+{
+  // Initialize Google Mock/Test.
+  testing::InitGoogleMock(&argc, argv);
+
+  return RUN_ALL_TESTS();
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multihashmap_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multihashmap_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multihashmap_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/multihashmap_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,126 @@
+#include <stdint.h>
+
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <string>
+
+#include <stout/multihashmap.hpp>
+
+using std::string;
+
+
+TEST(MultihashmapTest, Put)
+{
+  multihashmap<string, uint16_t> map;
+
+  map.put("foo", 1024);
+  ASSERT_EQ(1u, map.get("foo").size());
+
+  map.put("foo", 1025);
+  ASSERT_EQ(2u, map.get("foo").size());
+
+  ASSERT_EQ(2u, map.size());
+
+  map.put("bar", 1024);
+  ASSERT_EQ(1u, map.get("bar").size());
+
+  map.put("bar", 1025);
+  ASSERT_EQ(2u, map.get("bar").size());
+
+  ASSERT_EQ(4u, map.size());
+}
+
+
+TEST(MultihashmapTest, Remove)
+{
+  multihashmap<string, uint16_t> map;
+
+  map.put("foo", 1024);
+  map.remove("foo", 1024);
+  ASSERT_EQ(0u, map.get("foo").size());
+
+  ASSERT_EQ(0u, map.size());
+
+  map.put("foo", 1024);
+  map.put("foo", 1025);
+  ASSERT_EQ(2u, map.get("foo").size());
+
+  ASSERT_EQ(2u, map.size());
+
+  map.remove("foo");
+  ASSERT_EQ(0u, map.get("foo").size());
+  ASSERT_EQ(0u, map.size());
+}
+
+
+TEST(MultihashmapTest, Size)
+{
+  multihashmap<string, uint16_t> map;
+
+  map.put("foo", 1024);
+  map.put("foo", 1025);
+  ASSERT_EQ(2u, map.get("foo").size());
+  ASSERT_TRUE(map.contains("foo", 1024));
+  ASSERT_TRUE(map.contains("foo", 1025));
+  ASSERT_EQ(2u, map.size());
+
+  map.put("bar", 1024);
+  map.put("bar", 1025);
+  ASSERT_EQ(2u, map.get("bar").size());
+  ASSERT_TRUE(map.contains("bar", 1024));
+  ASSERT_TRUE(map.contains("bar", 1025));
+  ASSERT_EQ(4u, map.size());
+}
+
+
+TEST(MultihashmapTest, Iterator)
+{
+  multihashmap<string, uint16_t> map;
+
+  map.put("foo", 1024);
+  map.put("foo", 1025);
+  ASSERT_EQ(2u, map.get("foo").size());
+  ASSERT_TRUE(map.contains("foo", 1024));
+  ASSERT_TRUE(map.contains("foo", 1025));
+
+  multihashmap<string, uint16_t>::iterator i = map.begin();
+
+  ASSERT_TRUE(i != map.end());
+
+  ASSERT_EQ("foo", i->first);
+  ASSERT_EQ(1024, i->second);
+
+  ++i;
+  ASSERT_TRUE(i != map.end());
+
+  ASSERT_EQ("foo", i->first);
+  ASSERT_EQ(1025, i->second);
+
+  ++i;
+  ASSERT_TRUE(i == map.end());
+}
+
+
+TEST(MultihashmapTest, Foreach)
+{
+  multihashmap<string, uint16_t> map;
+
+  map.put("foo", 1024);
+  map.put("bar", 1025);
+  ASSERT_EQ(1u, map.get("foo").size());
+  ASSERT_EQ(1u, map.get("bar").size());
+  ASSERT_TRUE(map.contains("foo", 1024));
+  ASSERT_TRUE(map.contains("bar", 1025));
+
+  foreachpair (const string& key, uint16_t value, map) {
+    if (key == "foo") {
+      ASSERT_EQ(1024, value);
+    } else if (key == "bar") {
+      ASSERT_EQ(1025, value);
+    } else {
+      FAIL() << "Unexpected key/value in multihashmap";
+    }
+  }
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/none_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/none_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/none_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/none_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,59 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <string>
+
+#include <stout/none.hpp>
+#include <stout/option.hpp>
+#include <stout/result.hpp>
+
+using std::string;
+
+
+None none1()
+{
+  return None();
+}
+
+
+Option<string> none2()
+{
+  return None();
+}
+
+
+Option<string> none3(const Option<string>& o)
+{
+  return o;
+}
+
+
+Result<string> none4()
+{
+  return None();
+}
+
+
+Result<string> none5(const Result<string>& r)
+{
+  return r;
+}
+
+
+TEST(NoneTest, Test)
+{
+  Option<string> o = none1();
+  EXPECT_TRUE(o.isNone());
+  o = none2();
+  EXPECT_TRUE(o.isNone());
+  o = none3(none1());
+  EXPECT_TRUE(o.isNone());
+
+  Result<string> r = none1();
+  EXPECT_TRUE(r.isNone());
+  r = none4();
+  EXPECT_TRUE(r.isNone());
+  r = none5(none1());
+  EXPECT_TRUE(r.isNone());
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/os_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,196 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <cstdlib> // For rand.
+#include <string>
+
+#include <stout/foreach.hpp>
+#include <stout/gtest.hpp>
+#include <stout/hashset.hpp>
+#include <stout/os.hpp>
+#include <stout/try.hpp>
+#include <stout/uuid.hpp>
+
+using std::string;
+
+
+static hashset<string> listfiles(const string& directory)
+{
+  hashset<string> fileset;
+  foreach (const string& file, os::ls(directory)) {
+    fileset.insert(file);
+  }
+  return fileset;
+}
+
+
+class OsTest : public ::testing::Test
+{
+protected:
+  virtual void SetUp()
+  {
+    Try<string> mkdtemp = os::mkdtemp();
+    ASSERT_SOME(mkdtemp);
+    tmpdir = mkdtemp.get();
+  }
+
+  virtual void TearDown()
+  {
+    ASSERT_SOME(os::rmdir(tmpdir));
+  }
+
+  string tmpdir;
+};
+
+
+TEST_F(OsTest, rmdir)
+{
+  const hashset<string> EMPTY;
+
+  hashset<string> expectedListing = EMPTY;
+  EXPECT_EQ(expectedListing, listfiles(tmpdir));
+
+  os::mkdir(tmpdir + "/a/b/c");
+  os::mkdir(tmpdir + "/a/b/d");
+  os::mkdir(tmpdir + "/e/f");
+
+  expectedListing = EMPTY;
+  expectedListing.insert("a");
+  expectedListing.insert("e");
+  EXPECT_EQ(expectedListing, listfiles(tmpdir));
+
+  expectedListing = EMPTY;
+  expectedListing.insert("b");
+  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/a"));
+
+  expectedListing = EMPTY;
+  expectedListing.insert("c");
+  expectedListing.insert("d");
+  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/a/b"));
+
+  expectedListing = EMPTY;
+  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/a/b/c"));
+  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/a/b/d"));
+
+  expectedListing.insert("f");
+  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/e"));
+
+  expectedListing = EMPTY;
+  EXPECT_EQ(expectedListing, listfiles(tmpdir + "/e/f"));
+}
+
+
+TEST_F(OsTest, nonblock)
+{
+  int pipes[2];
+  ASSERT_NE(-1, pipe(pipes));
+
+  Try<bool> isNonBlock = false;
+
+  isNonBlock = os::isNonblock(pipes[0]);
+  ASSERT_SOME(isNonBlock);
+  EXPECT_FALSE(isNonBlock.get());
+
+  ASSERT_SOME(os::nonblock(pipes[0]));
+
+  isNonBlock = os::isNonblock(pipes[0]);
+  ASSERT_SOME(isNonBlock);
+  EXPECT_TRUE(isNonBlock.get());
+
+  close(pipes[0]);
+  close(pipes[1]);
+
+  EXPECT_ERROR(os::nonblock(pipes[0]));
+  EXPECT_ERROR(os::nonblock(pipes[0]));
+}
+
+
+TEST_F(OsTest, touch)
+{
+  const string& testfile  = tmpdir + "/" + UUID::random().toString();
+
+  ASSERT_SOME(os::touch(testfile));
+  ASSERT_TRUE(os::exists(testfile));
+}
+
+
+TEST_F(OsTest, readWriteString)
+{
+  const string& testfile  = tmpdir + "/" + UUID::random().toString();
+  const string& teststr = "test";
+
+  ASSERT_SOME(os::write(testfile, teststr));
+
+  Try<string> readstr = os::read(testfile);
+
+  ASSERT_SOME(readstr);
+  EXPECT_EQ(teststr, readstr.get());
+}
+
+
+TEST_F(OsTest, find)
+{
+  const string& testdir = tmpdir + "/" + UUID::random().toString();
+  const string& subdir = testdir + "/test1";
+  ASSERT_SOME(os::mkdir(subdir)); // Create the directories.
+
+  // Now write some files.
+  const string& file1 = testdir + "/file1.txt";
+  const string& file2 = subdir + "/file2.txt";
+  const string& file3 = subdir + "/file3.jpg";
+
+  ASSERT_SOME(os::touch(file1));
+  ASSERT_SOME(os::touch(file2));
+  ASSERT_SOME(os::touch(file3));
+
+  // Find "*.txt" files.
+  Try<std::list<string> > result = os::find(testdir, ".txt");
+  ASSERT_SOME(result);
+
+  hashset<string> files;
+  foreach (const string& file, result.get()) {
+    files.insert(file);
+  }
+
+  ASSERT_EQ(2u, files.size());
+  ASSERT_TRUE(files.contains(file1));
+  ASSERT_TRUE(files.contains(file2));
+}
+
+
+TEST_F(OsTest, uname)
+{
+  Try<os::UTSInfo> info = os::uname();
+
+  ASSERT_SOME(info);
+#ifdef __linux__
+  EXPECT_EQ(info.get().sysname, "Linux");
+#endif
+#ifdef __APPLE__
+  EXPECT_EQ(info.get().sysname, "Darwin");
+#endif
+}
+
+
+TEST_F(OsTest, sysname)
+{
+  Try<string> name = os::sysname();
+
+  ASSERT_SOME(name);
+#ifdef __linux__
+  EXPECT_EQ(name.get(), "Linux");
+#endif
+#ifdef __APPLE__
+  EXPECT_EQ(name.get(), "Darwin");
+#endif
+}
+
+
+TEST_F(OsTest, release)
+{
+  Try<os::Release> info = os::release();
+
+  ASSERT_SOME(info);
+}
+

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/strings_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/strings_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/strings_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/strings_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,255 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include <stout/format.hpp>
+#include <stout/gtest.hpp>
+#include <stout/strings.hpp>
+#include <stout/try.hpp>
+
+using std::map;
+using std::string;
+using std::vector;
+
+
+TEST(StringsTest, Format)
+{
+  Try<std::string> result = strings::format("%s %s", "hello", "world");
+  ASSERT_SOME(result);
+  EXPECT_EQ("hello world", result.get());
+
+  result = strings::format("hello %d", 42);
+  ASSERT_SOME(result);
+  EXPECT_EQ("hello 42", result.get());
+
+  result = strings::format("hello %s", "fourty-two");
+  ASSERT_SOME(result);
+  EXPECT_EQ("hello fourty-two", result.get());
+
+  string hello = "hello";
+
+  result = strings::format("%s %s", hello, "fourty-two");
+  ASSERT_SOME(result);
+  EXPECT_EQ("hello fourty-two", result.get());
+}
+
+
+TEST(StringsTest, Remove)
+{
+  EXPECT_EQ("heo word", strings::remove("hello world", "l"));
+  EXPECT_EQ("hel world", strings::remove("hello world", "lo"));
+  EXPECT_EQ("home/", strings::remove("/home/", "/", strings::PREFIX));
+  EXPECT_EQ("/home", strings::remove("/home/", "/", strings::SUFFIX));
+}
+
+
+TEST(StringsTest, Replace)
+{
+  EXPECT_EQ("hello*", strings::replace("hello/", "/", "*"));
+  EXPECT_EQ("*hello", strings::replace("/hello", "/", "*"));
+  EXPECT_EQ("*hello*world*", strings::replace("/hello/world/", "/", "*"));
+  EXPECT_EQ("*", strings::replace("/", "/", "*"));
+  EXPECT_EQ("hello world", strings::replace("hello world", "/", "*"));
+  EXPECT_EQ("***1***2***3***", strings::replace("/1/2/3/", "/", "***"));
+  EXPECT_EQ("123", strings::replace("/1/2/3/", "/", ""));
+  EXPECT_EQ("/1/2/3**", strings::replace("***1***2***3**", "***", "/"));
+  EXPECT_EQ("/1/2/3/", strings::replace("/1/2/3/", "", "*"));
+}
+
+
+TEST(StringsTest, Trim)
+{
+  EXPECT_EQ("", strings::trim("", " "));
+  EXPECT_EQ("", strings::trim("    ", " "));
+  EXPECT_EQ("hello world", strings::trim("hello world", " "));
+  EXPECT_EQ("hello world", strings::trim("  hello world", " "));
+  EXPECT_EQ("hello world", strings::trim("hello world  ", " "));
+  EXPECT_EQ("hello world", strings::trim("  hello world  ", " "));
+  EXPECT_EQ("hello world", strings::trim(" \t hello world\t  ", " \t"));
+  EXPECT_EQ("hello world", strings::trim(" \t hello world\t \n\r "));
+}
+
+
+TEST(StringsTest, Tokenize)
+{
+  vector<string> tokens = strings::tokenize("hello world,  what's up?", " ");
+  ASSERT_EQ(4u, tokens.size());
+  EXPECT_EQ("hello",  tokens[0]);
+  EXPECT_EQ("world,", tokens[1]);
+  EXPECT_EQ("what's", tokens[2]);
+  EXPECT_EQ("up?",    tokens[3]);
+}
+
+
+TEST(StringsTest, TokenizeStringWithDelimsAtStart)
+{
+  vector<string> tokens = strings::tokenize("  hello world,  what's up?", " ");
+  ASSERT_EQ(4u, tokens.size());
+  EXPECT_EQ("hello",  tokens[0]);
+  EXPECT_EQ("world,", tokens[1]);
+  EXPECT_EQ("what's", tokens[2]);
+  EXPECT_EQ("up?",    tokens[3]);
+}
+
+
+TEST(StringsTest, TokenizeStringWithDelimsAtEnd)
+{
+  vector<string> tokens = strings::tokenize("hello world,  what's up?  ", " ");
+  ASSERT_EQ(4u, tokens.size());
+  EXPECT_EQ("hello",  tokens[0]);
+  EXPECT_EQ("world,", tokens[1]);
+  EXPECT_EQ("what's", tokens[2]);
+  EXPECT_EQ("up?",    tokens[3]);
+}
+
+
+TEST(StringsTest, TokenizeStringWithDelimsAtStartAndEnd)
+{
+  vector<string> tokens = strings::tokenize("  hello world,  what's up?  ", " ");
+  ASSERT_EQ(4u, tokens.size());
+  EXPECT_EQ("hello",  tokens[0]);
+  EXPECT_EQ("world,", tokens[1]);
+  EXPECT_EQ("what's", tokens[2]);
+  EXPECT_EQ("up?",    tokens[3]);
+}
+
+
+TEST(StringsTest, TokenizeWithMultipleDelims)
+{
+  vector<string> tokens = strings::tokenize("hello\tworld,  \twhat's up?",
+                                            " \t");
+  ASSERT_EQ(4u, tokens.size());
+  EXPECT_EQ("hello",  tokens[0]);
+  EXPECT_EQ("world,", tokens[1]);
+  EXPECT_EQ("what's", tokens[2]);
+  EXPECT_EQ("up?",    tokens[3]);
+}
+
+
+TEST(StringsTest, TokenizeEmptyString)
+{
+  vector<string> tokens = strings::tokenize("", " ");
+  ASSERT_EQ(0u, tokens.size());
+}
+
+
+TEST(StringsTest, TokenizeDelimOnlyString)
+{
+  vector<string> tokens = strings::tokenize("   ", " ");
+  ASSERT_EQ(0u, tokens.size());
+}
+
+
+TEST(StringsTest, SplitEmptyString)
+{
+  vector<string> tokens = strings::split("", ",");
+  ASSERT_EQ(1u, tokens.size());
+  EXPECT_EQ("", tokens[0]);
+}
+
+
+TEST(StringsTest, SplitDelimOnlyString)
+{
+  vector<string> tokens = strings::split(",,,", ",");
+  ASSERT_EQ(4u, tokens.size());
+  EXPECT_EQ("", tokens[0]);
+  EXPECT_EQ("", tokens[1]);
+  EXPECT_EQ("", tokens[2]);
+  EXPECT_EQ("", tokens[3]);
+}
+
+
+TEST(StringsTest, Split)
+{
+  vector<string> tokens = strings::split("foo,bar,,baz", ",");
+  ASSERT_EQ(4u, tokens.size());
+  EXPECT_EQ("foo", tokens[0]);
+  EXPECT_EQ("bar", tokens[1]);
+  EXPECT_EQ("",    tokens[2]);
+  EXPECT_EQ("baz", tokens[3]);
+}
+
+
+TEST(StringsTest, SplitStringWithDelimsAtStart)
+{
+  vector<string> tokens = strings::split(",,foo,bar,,baz", ",");
+  ASSERT_EQ(6u, tokens.size());
+  EXPECT_EQ("",    tokens[0]);
+  EXPECT_EQ("",    tokens[1]);
+  EXPECT_EQ("foo", tokens[2]);
+  EXPECT_EQ("bar", tokens[3]);
+  EXPECT_EQ("",    tokens[4]);
+  EXPECT_EQ("baz", tokens[5]);
+}
+
+
+TEST(StringsTest, SplitStringWithDelimsAtEnd)
+{
+  vector<string> tokens = strings::split("foo,bar,,baz,,", ",");
+  ASSERT_EQ(6u, tokens.size());
+  EXPECT_EQ("foo", tokens[0]);
+  EXPECT_EQ("bar", tokens[1]);
+  EXPECT_EQ("",    tokens[2]);
+  EXPECT_EQ("baz", tokens[3]);
+  EXPECT_EQ("",    tokens[4]);
+  EXPECT_EQ("",    tokens[5]);
+}
+
+
+TEST(StringsTest, SplitStringWithDelimsAtStartAndEnd)
+{
+  vector<string> tokens = strings::split(",,foo,bar,,", ",");
+  ASSERT_EQ(6u, tokens.size());
+  EXPECT_EQ("",    tokens[0]);
+  EXPECT_EQ("",    tokens[1]);
+  EXPECT_EQ("foo", tokens[2]);
+  EXPECT_EQ("bar", tokens[3]);
+  EXPECT_EQ("",    tokens[4]);
+  EXPECT_EQ("",    tokens[5]);
+}
+
+
+TEST(StringsTest, SplitWithMultipleDelims)
+{
+  vector<string> tokens = strings::split("foo.bar,.,.baz.", ",.");
+  ASSERT_EQ(7u, tokens.size());
+  EXPECT_EQ("foo", tokens[0]);
+  EXPECT_EQ("bar", tokens[1]);
+  EXPECT_EQ("",    tokens[2]);
+  EXPECT_EQ("",    tokens[3]);
+  EXPECT_EQ("",    tokens[4]);
+  EXPECT_EQ("baz", tokens[5]);
+  EXPECT_EQ("",    tokens[6]);
+}
+
+
+TEST(StringsTest, Pairs)
+{
+  map<string, vector<string> > pairs = strings::pairs("one=1,two=2", ",", "=");
+  ASSERT_EQ(2u, pairs.size());
+  ASSERT_EQ(1u, pairs.count("one"));
+  ASSERT_EQ(1u, pairs["one"].size());
+  EXPECT_EQ("1", pairs["one"].front());
+  ASSERT_EQ(1u, pairs.count("two"));
+  ASSERT_EQ(1u, pairs["two"].size());
+  EXPECT_EQ("2", pairs["two"].front());
+}
+
+
+TEST(StringsTest, StartsWith)
+{
+  EXPECT_TRUE(strings::startsWith("hello world", "hello"));
+  EXPECT_FALSE(strings::startsWith("hello world", "no"));
+  EXPECT_FALSE(strings::startsWith("hello world", "ello"));
+}
+
+
+TEST(StringsTest, Contains)
+{
+  EXPECT_TRUE(strings::contains("hello world", "world"));
+  EXPECT_FALSE(strings::contains("hello world", "no"));
+}

Added: incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/uuid_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/uuid_tests.cpp?rev=1459127&view=auto
==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/uuid_tests.cpp (added)
+++ incubator/mesos/trunk/third_party/libprocess/third_party/stout/tests/uuid_tests.cpp Thu Mar 21 01:46:42 2013
@@ -0,0 +1,37 @@
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <string>
+
+#include <stout/uuid.hpp>
+
+using std::string;
+
+
+TEST(UUIDTest, test)
+{
+  UUID uuid1 = UUID::random();
+  UUID uuid2 = UUID::fromBytes(uuid1.toBytes());
+  UUID uuid3 = uuid2;
+
+  EXPECT_EQ(uuid1, uuid2);
+  EXPECT_EQ(uuid2, uuid3);
+  EXPECT_EQ(uuid1, uuid3);
+
+  string bytes1 = uuid1.toBytes();
+  string bytes2 = uuid2.toBytes();
+  string bytes3 = uuid3.toBytes();
+
+  EXPECT_EQ(bytes1, bytes2);
+  EXPECT_EQ(bytes2, bytes3);
+  EXPECT_EQ(bytes1, bytes3);
+
+  string string1 = uuid1.toString();
+  string string2 = uuid2.toString();
+  string string3 = uuid3.toString();
+
+  EXPECT_EQ(string1, string2);
+  EXPECT_EQ(string2, string3);
+  EXPECT_EQ(string1, string3);
+}