aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 15:02:03 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-20 16:20:41 +0000
commit52997c9040bba0f5b1c2be9a3897e7ef0fcfd1e0 (patch)
treed4563cffad05303271931ff213bbf0be24d46387
parente8dac41ca05d6ab1fc40ecb94f49f0e1ea07afa5 (diff)
downloadpaludis-52997c9040bba0f5b1c2be9a3897e7ef0fcfd1e0.tar.gz
paludis-52997c9040bba0f5b1c2be9a3897e7ef0fcfd1e0.tar.xz
gtest more
-rw-r--r--paludis/util/files.m42
-rw-r--r--paludis/util/safe_ifstream_TEST.cc126
2 files changed, 49 insertions, 79 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4
index 214e1e6..a47b7e1 100644
--- a/paludis/util/files.m4
+++ b/paludis/util/files.m4
@@ -69,7 +69,7 @@ add(`realpath', `hh', `cc', `test', `testscript')
add(`remove_shared_ptr', `hh')
add(`return_literal_function', `hh', `cc', `fwd', `test')
add(`rmd160', `hh', `cc', `test')
-add(`safe_ifstream', `hh', `cc', `fwd', `test', `testscript')
+add(`safe_ifstream', `hh', `cc', `fwd', `gtest', `testscript')
add(`safe_ofstream', `hh', `cc', `gtest', `testscript')
add(`save', `hh', `gtest')
add(`sequence', `hh', `fwd', `impl', `cc')
diff --git a/paludis/util/safe_ifstream_TEST.cc b/paludis/util/safe_ifstream_TEST.cc
index c22b1fd..9750aaf 100644
--- a/paludis/util/safe_ifstream_TEST.cc
+++ b/paludis/util/safe_ifstream_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2009, 2010 Ciaran McCreesh
+ * Copyright (c) 2009, 2010, 2011 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -19,93 +19,63 @@
#include <paludis/util/safe_ifstream.hh>
#include <paludis/util/fs_path.hh>
-#include <test/test_runner.hh>
-#include <test/test_framework.hh>
+
#include <unistd.h>
#include <sys/types.h>
-using namespace test;
+#include <gtest/gtest.h>
+
using namespace paludis;
-namespace test_cases
+TEST(SafeIFStream, Existing)
{
- struct ExistingTest : TestCase
- {
- ExistingTest() : TestCase("existing file") { }
-
- void run()
- {
- SafeIFStream s(FSPath::cwd() / "safe_ifstream_TEST_dir" / "existing");
- TEST_CHECK(s);
- std::string t;
- s >> t;
- TEST_CHECK(s);
- TEST_CHECK_EQUAL(t, "first");
- s >> t;
- TEST_CHECK_EQUAL(t, std::string(1000, 'x'));
-
- s.clear();
- s.seekg(0, std::ios::beg);
-
- TEST_CHECK(s);
- s >> t;
- TEST_CHECK(s);
- TEST_CHECK_EQUAL(t, "first");
- s >> t;
- TEST_CHECK_EQUAL(t, std::string(1000, 'x'));
- }
- } test_existing;
-
- struct ExistingSymTest : TestCase
- {
- ExistingSymTest() : TestCase("existing sym") { }
-
- void run()
- {
- SafeIFStream s(FSPath::cwd() / "safe_ifstream_TEST_dir" / "existing");
- TEST_CHECK(s);
- std::string t;
- s >> t;
- TEST_CHECK(s);
- TEST_CHECK_EQUAL(t, "first");
- s >> t;
- TEST_CHECK_EQUAL(t, std::string(1000, 'x'));
- }
- } test_existing_sym;
-
- struct ExistingDirTest : TestCase
- {
- ExistingDirTest() : TestCase("existing dir") { }
-
- void run()
- {
- TEST_CHECK_THROWS(SafeIFStream(FSPath::cwd() / "safe_ifstream_TEST_dir" / "existing_dir"), SafeIFStreamError);
- }
- } test_existing_dir;
-
- struct ExistingPermTest : TestCase
- {
- ExistingPermTest() : TestCase("existing unreadable file") { }
+ SafeIFStream s(FSPath::cwd() / "safe_ifstream_TEST_dir" / "existing");
+ ASSERT_TRUE(s);
+ std::string t;
+ s >> t;
+ ASSERT_TRUE(s);
+ EXPECT_EQ("first", t);
+ s >> t;
+ EXPECT_EQ(std::string(1000, 'x'), t);
+
+ s.clear();
+ s.seekg(0, std::ios::beg);
+
+ ASSERT_TRUE(s);
+ s >> t;
+ ASSERT_TRUE(s);
+ EXPECT_EQ("first", t);
+ s >> t;
+ EXPECT_EQ(std::string(1000, 'x'), t);
+}
- bool skip() const
- {
- return 0 == getuid();
- }
+TEST(SafeIFStream, ExistingSym)
+{
+ SafeIFStream s(FSPath::cwd() / "safe_ifstream_TEST_dir" / "existing");
+ ASSERT_TRUE(s);
+ std::string t;
+ s >> t;
+ ASSERT_TRUE(s);
+ EXPECT_EQ("first", t);
+ s >> t;
+ EXPECT_EQ(std::string(1000, 'x'), t);
+}
- void run()
- {
- TEST_CHECK_THROWS(SafeIFStream(FSPath::cwd() / "safe_ifstream_TEST_dir" / "existing_perm"), SafeIFStreamError);
- }
- } test_existing_perm;
+TEST(SafeIFStream, ExistingDir)
+{
+ EXPECT_THROW(SafeIFStream(FSPath::cwd() / "safe_ifstream_TEST_dir" / "existing_dir"), SafeIFStreamError);
+}
- struct ExistingNoentTest : TestCase
+TEST(SafeIFStream, ExistingPerm)
+{
+ if (0 != getuid())
{
- ExistingNoentTest() : TestCase("no such file") { }
+ EXPECT_THROW(SafeIFStream(FSPath::cwd() / "safe_ifstream_TEST_dir" / "existing_perm"), SafeIFStreamError);
+ }
+}
- void run()
- {
- TEST_CHECK_THROWS(SafeIFStream(FSPath::cwd() / "safe_ofstream_TEST_dir" / "noent"), SafeIFStreamError);
- }
- } test_existing_noent;
+TEST(SafeIFStream, ExistingNoEnt)
+{
+ EXPECT_THROW(SafeIFStream(FSPath::cwd() / "safe_ofstream_TEST_dir" / "noent"), SafeIFStreamError);
}