From 23d1522f8ba1446d0b91a324e32638a8b022ccac Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 19 Jul 2016 20:33:23 +0100 Subject: [PATCH] Replace loot_write_minimal_list_test test Don't test what happens what happens when loot_write_minimal_list() is given an invalid path, it turns out that's very sensitive and non-portable. Instead test that the same error gets returned for trying to write to a read-only file (which occurs in the same place). --- src/tests/api/loot_write_minimal_list_test.h | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/tests/api/loot_write_minimal_list_test.h b/src/tests/api/loot_write_minimal_list_test.h index 5d2ac055..9f87562e 100644 --- a/src/tests/api/loot_write_minimal_list_test.h +++ b/src/tests/api/loot_write_minimal_list_test.h @@ -43,6 +43,12 @@ protected: } void TearDown() { + if (boost::filesystem::exists(outputPath)) { + boost::filesystem::permissions(outputPath, + boost::filesystem::perms::add_perms + | boost::filesystem::perms::owner_write); + } + ApiGameOperationsTest::TearDown(); ASSERT_NO_THROW(boost::filesystem::remove(outputPath)); @@ -87,10 +93,6 @@ TEST_P(loot_write_minimal_list_test, shouldReturnAnInvalidArgsErrorIfAPointerArg EXPECT_EQ(loot_error_invalid_args, loot_write_minimal_list(db_, NULL, false)); } -TEST_P(loot_write_minimal_list_test, shouldReturnAFileWriteErrorIfThePathGivenIsInvalid) { - EXPECT_EQ(loot_error_file_write_fail, loot_write_minimal_list(db_, "/:?*", false)); -} - TEST_P(loot_write_minimal_list_test, shouldReturnOkAndWriteToFileIfArgumentsGivenAreValid) { EXPECT_EQ(loot_ok, loot_write_minimal_list(db_, outputPath.string().c_str(), false)); EXPECT_TRUE(boost::filesystem::exists(outputPath)); @@ -115,6 +117,17 @@ TEST_P(loot_write_minimal_list_test, shouldReturnOkIfTheFileAlreadyExistsAndTheO EXPECT_EQ(loot_ok, loot_write_minimal_list(db_, outputPath.string().c_str(), true)); } +TEST_P(loot_write_minimal_list_test, shouldReturnAFileWriteErrorIfPathGivenExistsAndIsReadOnly) { + ASSERT_EQ(loot_ok, loot_write_minimal_list(db_, outputPath.string().c_str(), false)); + ASSERT_TRUE(boost::filesystem::exists(outputPath)); + + boost::filesystem::permissions(outputPath, + boost::filesystem::perms::remove_perms + | boost::filesystem::perms::owner_write); + + EXPECT_EQ(loot_error_file_write_fail, loot_write_minimal_list(db_, outputPath.string().c_str(), true)); +} + TEST_P(loot_write_minimal_list_test, shouldWriteOnlyBashTagsAndDirtyInfo) { ASSERT_NO_THROW(GenerateMasterlist()); ASSERT_EQ(loot_ok, loot_load_lists(db_, masterlistPath.string().c_str(), NULL));