diff options
author | 2011-03-20 14:54:40 +0000 | |
---|---|---|
committer | 2011-03-20 16:20:41 +0000 | |
commit | e8dac41ca05d6ab1fc40ecb94f49f0e1ea07afa5 (patch) | |
tree | 9c86740f2c1974b569670459eb99ba19edfc0a9d | |
parent | 9f3df893fd9f9cd52995b2f2d7a430eb912a4361 (diff) | |
download | paludis-e8dac41ca05d6ab1fc40ecb94f49f0e1ea07afa5.tar.gz paludis-e8dac41ca05d6ab1fc40ecb94f49f0e1ea07afa5.tar.xz |
gtest more
-rw-r--r-- | paludis/util/files.m4 | 2 | ||||
-rw-r--r-- | paludis/util/safe_ofstream_TEST.cc | 159 |
2 files changed, 48 insertions, 113 deletions
diff --git a/paludis/util/files.m4 b/paludis/util/files.m4 index 43baca696..214e1e66d 100644 --- a/paludis/util/files.m4 +++ b/paludis/util/files.m4 @@ -70,7 +70,7 @@ 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_ofstream', `hh', `cc', `test', `testscript') +add(`safe_ofstream', `hh', `cc', `gtest', `testscript') add(`save', `hh', `gtest') add(`sequence', `hh', `fwd', `impl', `cc') add(`set', `hh', `fwd', `impl', `cc') diff --git a/paludis/util/safe_ofstream_TEST.cc b/paludis/util/safe_ofstream_TEST.cc index 5bb598668..a33002b88 100644 --- a/paludis/util/safe_ofstream_TEST.cc +++ b/paludis/util/safe_ofstream_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,131 +19,66 @@ #include <paludis/util/safe_ofstream.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(SafeOFStream, New) { - struct NewTest : TestCase - { - NewTest() : TestCase("new file") { } - - void run() - { - SafeOFStream s(FSPath::cwd() / "safe_ofstream_TEST_dir" / "new", -1, false); - TEST_CHECK(s); - s << "foo"; - TEST_CHECK(s); - } - - bool repeatable() const - { - return false; - } - } test_new; - - struct ExistingTest : TestCase - { - ExistingTest() : TestCase("existing file") { } - - void run() - { - SafeOFStream s(FSPath::cwd() / "safe_ofstream_TEST_dir" / "existing", -1, false); - TEST_CHECK(s); - s << "foo"; - TEST_CHECK(s); - } - - bool repeatable() const - { - return false; - } - } test_existing; + SafeOFStream s(FSPath::cwd() / "safe_ofstream_TEST_dir" / "new", -1, false); + ASSERT_TRUE(s); + s << "foo"; + ASSERT_TRUE(s); +} - struct ExistingSymTest : TestCase - { - ExistingSymTest() : TestCase("existing sym") { } +TEST(SafeOFStream, Existing) +{ + SafeOFStream s(FSPath::cwd() / "safe_ofstream_TEST_dir" / "existing", -1, false); + ASSERT_TRUE(s); + s << "foo"; + ASSERT_TRUE(s); +} - void run() - { - SafeOFStream s(FSPath::cwd() / "safe_ofstream_TEST_dir" / "existing_sym", -1, false); - TEST_CHECK(s); - s << "foo"; - TEST_CHECK(s); - } +TEST(SafeOFStream, ExistingSym) +{ + SafeOFStream s(FSPath::cwd() / "safe_ofstream_TEST_dir" / "existing_sym", -1, false); + ASSERT_TRUE(s); + s << "foo"; + ASSERT_TRUE(s); +} - bool repeatable() const - { - return false; - } - } test_existing_sym; +TEST(SafeOFStream, ExistingDir) +{ + EXPECT_THROW(SafeOFStream(FSPath::cwd() / "safe_ofstream_TEST_dir" / "existing_dir", -1, false), SafeOFStreamError); +} - struct ExistingDirTest : TestCase +TEST(SafeOFStream, ExistingPerm) +{ + if (0 != getuid()) { - ExistingDirTest() : TestCase("existing dir") { } - - void run() - { - TEST_CHECK_THROWS(SafeOFStream(FSPath::cwd() / "safe_ofstream_TEST_dir" / "existing_dir", -1, false), SafeOFStreamError); - } - - bool repeatable() const - { - return false; - } - } test_existing_dir; + EXPECT_THROW(SafeOFStream(FSPath::cwd() / "safe_ofstream_TEST_dir" / "existing_perm", -1, false), SafeOFStreamError); + } +} - struct ExistingPermTest : TestCase +TEST(SafeOFStream, WriteFailure) +{ + bool threw(false); + try { - ExistingPermTest() : TestCase("existing unwriteable file") { } - - void run() - { - TEST_CHECK_THROWS(SafeOFStream(FSPath::cwd() / "safe_ofstream_TEST_dir" / "existing_perm", -1, false), SafeOFStreamError); - } - - bool skip() const - { - return 0 == getuid(); - } - - bool repeatable() const - { - return false; - } - } test_existing_perm; - - struct WriteFailTest : TestCase + SafeOFStream s(FSPath("/dev/full"), -1, false); + ASSERT_TRUE(s); + s << "foo"; + ASSERT_TRUE(! s); + } + catch (const SafeOFStreamError &) { - WriteFailTest() : TestCase("write fail") { } - - void run() - { - bool threw(false); - try - { - SafeOFStream s(FSPath("/dev/full"), -1, false); - TEST_CHECK(s); - s << "foo"; - TEST_CHECK(! s); - } - catch (const SafeOFStreamError &) - { - threw = true; - } - - TEST_CHECK(threw); - } + threw = true; + } - bool repeatable() const - { - return false; - } - } test_existing_write_fail; + ASSERT_TRUE(threw); } |