From a9e2dea97e289ff1b269225646546124fde6210b Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Thu, 6 Sep 2018 22:44:23 -0700 Subject: [PATCH] Fix argument string ownership --- test/cryfs-cli/CliTest_IntegrityCheck.cpp | 4 ++-- test/cryfs-cli/CliTest_WrongEnvironment.cpp | 8 ++++---- test/cryfs-cli/testutils/CliTest.h | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/cryfs-cli/CliTest_IntegrityCheck.cpp b/test/cryfs-cli/CliTest_IntegrityCheck.cpp index 729d4ba9..a15015f0 100644 --- a/test/cryfs-cli/CliTest_IntegrityCheck.cpp +++ b/test/cryfs-cli/CliTest_IntegrityCheck.cpp @@ -24,7 +24,7 @@ public: }; TEST_F(CliTest_IntegrityCheck, givenIncorrectFilesystemId_thenFails) { - vector args {basedir.string().c_str(), mountdir.string().c_str(), "--cipher", "aes-256-gcm", "-f"}; + vector args {basedir.string().c_str(), mountdir.string().c_str(), "--cipher", "aes-256-gcm", "-f"}; //TODO Remove "-f" parameter, once EXPECT_RUN_SUCCESS can handle that EXPECT_RUN_SUCCESS(args, mountdir); modifyFilesystemId(); @@ -36,7 +36,7 @@ TEST_F(CliTest_IntegrityCheck, givenIncorrectFilesystemId_thenFails) { } TEST_F(CliTest_IntegrityCheck, givenIncorrectFilesystemKey_thenFails) { - vector args {basedir.string().c_str(), mountdir.string().c_str(), "--cipher", "aes-256-gcm", "-f"}; + vector args {basedir.string().c_str(), mountdir.string().c_str(), "--cipher", "aes-256-gcm", "-f"}; //TODO Remove "-f" parameter, once EXPECT_RUN_SUCCESS can handle that EXPECT_RUN_SUCCESS(args, mountdir); modifyFilesystemKey(); diff --git a/test/cryfs-cli/CliTest_WrongEnvironment.cpp b/test/cryfs-cli/CliTest_WrongEnvironment.cpp index 40a72b18..660e282b 100644 --- a/test/cryfs-cli/CliTest_WrongEnvironment.cpp +++ b/test/cryfs-cli/CliTest_WrongEnvironment.cpp @@ -52,15 +52,15 @@ public: ); } - vector args() { - vector result = {basedir.string().c_str(), mountdir.string().c_str()}; + vector args() { + vector result = {basedir.string(), mountdir.string()}; if (GetParam().externalConfigfile) { result.push_back("--config"); - result.push_back(configfile.path().string().c_str()); + result.push_back(configfile.path().string()); } if (GetParam().logIsNotStderr) { result.push_back("--logfile"); - result.push_back(logfile.path().string().c_str()); + result.push_back(logfile.path().string()); } if (GetParam().runningInForeground) { result.push_back("-f"); diff --git a/test/cryfs-cli/testutils/CliTest.h b/test/cryfs-cli/testutils/CliTest.h index b1563c58..bea20d6f 100644 --- a/test/cryfs-cli/testutils/CliTest.h +++ b/test/cryfs-cli/testutils/CliTest.h @@ -41,13 +41,13 @@ public: return std::move(httpClient); } - int run(std::vector args) { - std::vector _args; - _args.reserve(args.size()+1); - _args.push_back("cryfs"); - for (const char *arg : args) { - _args.push_back(arg); - } + int run(const std::vector& args) { + std::vector _args; + _args.reserve(args.size() + 1); + _args.emplace_back("cryfs"); + for (const std::string& arg : args) { + _args.emplace_back(arg.c_str()); + } auto &keyGenerator = cpputils::Random::PseudoRandom(); ON_CALL(*console, askPassword(testing::StrEq("Password: "))).WillByDefault(testing::Return("pass")); ON_CALL(*console, askPassword(testing::StrEq("Confirm Password: "))).WillByDefault(testing::Return("pass")); @@ -55,18 +55,18 @@ public: return cryfs::Cli(keyGenerator, cpputils::SCrypt::TestSettings, console).main(_args.size(), _args.data(), _httpClient()); } - void EXPECT_EXIT_WITH_HELP_MESSAGE(std::vector args, const std::string &message, cryfs::ErrorCode errorCode) { + void EXPECT_EXIT_WITH_HELP_MESSAGE(const std::vector& args, const std::string &message, cryfs::ErrorCode errorCode) { EXPECT_RUN_ERROR(args, (".*Usage:.*"+message).c_str(), errorCode); } - void EXPECT_RUN_ERROR(std::vector args, const char* message, cryfs::ErrorCode errorCode) { + void EXPECT_RUN_ERROR(const std::vector& args, const char* message, cryfs::ErrorCode errorCode) { cpputils::CaptureStderrRAII capturedStderr; int exit_code = run(args); capturedStderr.EXPECT_MATCHES(message); EXPECT_EQ(exitCode(errorCode), exit_code); } - void EXPECT_RUN_SUCCESS(std::vector args, const boost::filesystem::path &mountDir) { + void EXPECT_RUN_SUCCESS(const std::vector& args, const boost::filesystem::path &mountDir) { //TODO Make this work when run in background ASSERT(std::find(args.begin(), args.end(), string("-f")) != args.end(), "Currently only works if run in foreground"); bool unmount_success = false;