aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 19:44:10 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 19:44:10 +0000
commit3b45d51c00381afa7d83e718bab37d743447529b (patch)
treedc5c447e03bc06a28467288485fca5945fc98cda
parentabba25627d06352dbd98f38682fe22a0772eec03 (diff)
downloadpaludis-3b45d51c00381afa7d83e718bab37d743447529b.tar.gz
paludis-3b45d51c00381afa7d83e718bab37d743447529b.tar.xz
gtest more
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/fs_path_TEST.cc206
2 files changed, 88 insertions, 120 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index 30341cb..95d9301 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -39,7 +39,7 @@ add(`extract_host_from_url', `hh', `cc', `fwd', `gtest')
add(`fd_holder', `hh')
add(`fs_iterator', `hh', `cc', `fwd', `se', `test', `testscript')
add(`fs_error', `hh', `cc')
-add(`fs_path', `hh', `cc', `fwd', `se', `test', `testscript')
+add(`fs_path', `hh', `cc', `fwd', `se', `gtest', `testscript')
add(`fs_stat', `hh', `cc', `fwd', `gtest', `testscript')
add(`graph', `hh', `cc', `fwd', `impl', `gtest')
add(`hashes', `hh', `cc', `gtest')
diff --git a/paludis/util/fs_path_TEST.cc b/paludis/util/fs_path_TEST.cc
index 9cae029..095db0f 100644
--- a/paludis/util/fs_path_TEST.cc
+++ b/paludis/util/fs_path_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010 Ciaran McCreesh
+ * Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Ciaran McCreesh
* Copyright (c) 2006 Mark Loeser
*
* This file is part of the Paludis package manager. Paludis is free software;
@@ -21,132 +21,100 @@
#include <paludis/util/fs_path.hh>
#include <paludis/util/fs_error.hh>
#include <paludis/util/timestamp.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
+#include <paludis/util/stringify.hh>
+
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <ctime>
+#include <gtest/gtest.h>
+
using namespace paludis;
-using namespace test;
-namespace test_cases
+TEST(FSPath, Manipulation)
+{
+ FSPath f("/foo/bar");
+ FSPath c(f);
+ EXPECT_EQ(FSPath("/foo/bar"), f);
+ EXPECT_EQ(FSPath("/foo/bar"), c);
+ f = FSPath("/baz");
+ EXPECT_EQ(FSPath("/baz"), f);
+ EXPECT_EQ(FSPath("/foo/bar"), c);
+ c /= "moo";
+ EXPECT_EQ(FSPath("/baz"), f);
+ EXPECT_EQ(FSPath("/foo/bar/moo"), c);
+ f = c / f;
+ EXPECT_EQ(FSPath("/foo/bar/moo/baz"), f);
+ EXPECT_EQ(FSPath("/foo/bar/moo"), c);
+
+ f = FSPath::cwd();
+
+ EXPECT_EQ(f, f / FSPath("/"));
+}
+
+TEST(FSPath, Realpath)
{
- struct FSPathManipulationTest : TestCase
- {
- FSPathManipulationTest() : TestCase("construction and manipulation") { }
-
- void run()
- {
- FSPath f("/foo/bar");
- FSPath c(f);
- TEST_CHECK_EQUAL(f, FSPath("/foo/bar"));
- TEST_CHECK_EQUAL(c, FSPath("/foo/bar"));
- f = FSPath("/baz");
- TEST_CHECK_EQUAL(f, FSPath("/baz"));
- TEST_CHECK_EQUAL(c, FSPath("/foo/bar"));
- c /= "moo";
- TEST_CHECK_EQUAL(f, FSPath("/baz"));
- TEST_CHECK_EQUAL(c, FSPath("/foo/bar/moo"));
- f = c / f;
- TEST_CHECK_EQUAL(f, FSPath("/foo/bar/moo/baz"));
- TEST_CHECK_EQUAL(c, FSPath("/foo/bar/moo"));
-
- f = FSPath::cwd();
-
- TEST_CHECK_EQUAL(f, f / FSPath("/"));
- }
- } test_fs_path_manipulation;
-
- struct FSPathRealpathTest : TestCase
- {
- FSPathRealpathTest() : TestCase("realpath") { }
-
- void run()
- {
- FSPath f("fs_path_TEST_dir/symlink_to_dir_a/file_in_a");
- FSPath r(f.realpath());
- std::string g("fs_path_TEST_dir/dir_a/file_in_a");
- TEST_CHECK_EQUAL(stringify(r).substr(stringify(r).length() - g.length()), g);
- }
- } test_fs_path_realpath;
-
- struct FSPathSymlink : TestCase
- {
- FSPathSymlink() : TestCase("symlink") {}
-
- void run()
- {
- FSPath f("fs_path_TEST_dir/new_sym");
- TEST_CHECK(f.symlink("the_target"));
- TEST_CHECK_EQUAL(f.readlink(), "the_target");
- f.unlink();
- }
- } test_fs_symlink;
-
- struct FSPathBaseDirName : TestCase
- {
- FSPathBaseDirName() : TestCase("basename and dirname") {}
-
- void run()
- {
- FSPath a("/foo/bar");
- FSPath b("/moo/went/the/cow");
- FSPath c("/");
- FSPath d(".");
- FSPath e("..");
-
- TEST_CHECK(a.basename() == "bar");
- TEST_CHECK(stringify(a.dirname()) == "/foo");
- TEST_CHECK(b.basename() == "cow");
- TEST_CHECK(stringify(b.dirname()) == "/moo/went/the");
- TEST_CHECK(c.basename() == "/");
- TEST_CHECK(stringify(c.dirname()) == "/");
- TEST_CHECK(d.basename() == ".");
- TEST_CHECK(stringify(d.dirname()) == ".");
- TEST_CHECK(e.basename() == "..");
- TEST_CHECK(stringify(e.dirname()) == "..");
- }
- } test_fs_path_dir_base_name;
-
- struct FSPathStripLeading : TestCase
- {
- FSPathStripLeading() : TestCase("strip_leading") {}
-
- void run()
- {
- FSPath root1("/stairway/to/heaven/");
- FSPath root2("");
- FSPath root3("/");
-
- FSPath a(root1);
- FSPath b(root1 / "usr" / "share");
- FSPath c(root2 / "my" / "directory");
- FSPath d(root3 / "my" / "directory");
-
- TEST_CHECK(stringify(a.strip_leading(root1)) == "/");
- TEST_CHECK(stringify(b.strip_leading(root1)) == "/usr/share");
- TEST_CHECK(stringify(c.strip_leading(root2)) == "/my/directory");
- TEST_CHECK(stringify(d.strip_leading(root3)) == "/my/directory");
- }
- } test_fs_path_strip_leading;
-
- struct FSPathToOstreamOperator : TestCase
- {
- FSPathToOstreamOperator() : TestCase("operator<<") {}
-
- void run()
- {
- std::string n("fs_path_TEST_dir/no_perms");
- std::ostringstream s;
- FSPath a(n);
-
- s << a;
-
- TEST_CHECK_EQUAL(s.str(), n);
- }
- } test_fs_path_to_ostream_operator;
+ FSPath f("fs_path_TEST_dir/symlink_to_dir_a/file_in_a");
+ FSPath r(f.realpath());
+ std::string g("fs_path_TEST_dir/dir_a/file_in_a");
+ EXPECT_EQ(g, stringify(r).substr(stringify(r).length() - g.length()));
+}
+
+TEST(FSPath, Symlink)
+{
+ FSPath f("fs_path_TEST_dir/new_sym");
+ EXPECT_TRUE(f.symlink("the_target"));
+ EXPECT_EQ("the_target", f.readlink());
+ f.unlink();
+}
+
+TEST(FSPath, BaseDirName)
+{
+ FSPath a("/foo/bar");
+ FSPath b("/moo/went/the/cow");
+ FSPath c("/");
+ FSPath d(".");
+ FSPath e("..");
+
+ EXPECT_TRUE(a.basename() == "bar");
+ EXPECT_TRUE(stringify(a.dirname()) == "/foo");
+ EXPECT_TRUE(b.basename() == "cow");
+ EXPECT_TRUE(stringify(b.dirname()) == "/moo/went/the");
+ EXPECT_TRUE(c.basename() == "/");
+ EXPECT_TRUE(stringify(c.dirname()) == "/");
+ EXPECT_TRUE(d.basename() == ".");
+ EXPECT_TRUE(stringify(d.dirname()) == ".");
+ EXPECT_TRUE(e.basename() == "..");
+ EXPECT_TRUE(stringify(e.dirname()) == "..");
+}
+
+TEST(FSPath, StripLeading)
+{
+ FSPath root1("/stairway/to/heaven/");
+ FSPath root2("");
+ FSPath root3("/");
+
+ FSPath a(root1);
+ FSPath b(root1 / "usr" / "share");
+ FSPath c(root2 / "my" / "directory");
+ FSPath d(root3 / "my" / "directory");
+
+ EXPECT_TRUE(stringify(a.strip_leading(root1)) == "/");
+ EXPECT_TRUE(stringify(b.strip_leading(root1)) == "/usr/share");
+ EXPECT_TRUE(stringify(c.strip_leading(root2)) == "/my/directory");
+ EXPECT_TRUE(stringify(d.strip_leading(root3)) == "/my/directory");
+}
+
+TEST(FSPath, OStream)
+{
+ std::string n("fs_path_TEST_dir/no_perms");
+ std::ostringstream s;
+ FSPath a(n);
+
+ s << a;
+
+ EXPECT_EQ(n, s.str());
}