diff options
Diffstat (limited to 'paludis/util/safe_ifstream_TEST.cc')
-rw-r--r-- | paludis/util/safe_ifstream_TEST.cc | 126 |
1 files changed, 48 insertions, 78 deletions
diff --git a/paludis/util/safe_ifstream_TEST.cc b/paludis/util/safe_ifstream_TEST.cc index c22b1fd87..9750aaf42 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); } |