Fix paths for Windows tests

This commit is contained in:
Sebastian Messmer 2018-09-07 05:00:47 -07:00
parent 9b990b4fd1
commit de3095a4d4
3 changed files with 72 additions and 47 deletions

View File

@ -9,6 +9,12 @@ using std::string;
using boost::optional; using boost::optional;
using boost::none; using boost::none;
#if defined(_MSC_VER)
constexpr const char* some_local_state_dir = "C:/my/local/state/dir";
#else
constexpr const char* some_local_state_dir = "/my/local/state/dir";
#endif
namespace bf = boost::filesystem; namespace bf = boost::filesystem;
class EnvironmentTest : public ::testing::Test { class EnvironmentTest : public ::testing::Test {
@ -72,8 +78,8 @@ TEST_F(EnvironmentTest, LocalStateDir_NotSet) {
} }
TEST_F(EnvironmentTest, LocalStateDir_Set) { TEST_F(EnvironmentTest, LocalStateDir_Set) {
WithEnv env("CRYFS_LOCAL_STATE_DIR", "/my/local/state/dir"); WithEnv env("CRYFS_LOCAL_STATE_DIR", some_local_state_dir);
EXPECT_EQ("/my/local/state/dir", Environment::localStateDir().string()); EXPECT_EQ(some_local_state_dir, Environment::localStateDir().string());
} }
TEST_F(EnvironmentTest, LocalStateDir_ConvertsRelativeToAbsolutePath_WithDot) { TEST_F(EnvironmentTest, LocalStateDir_ConvertsRelativeToAbsolutePath_WithDot) {

View File

@ -14,6 +14,18 @@ using boost::none;
namespace bf = boost::filesystem; namespace bf = boost::filesystem;
using cpputils::CaptureStderrRAII; using cpputils::CaptureStderrRAII;
#if !defined(_MSC_VER)
constexpr const char *basedir = "/home/user/baseDir";
constexpr const char *mountdir = "/home/user/mountDir";
constexpr const char *logfile = "/home/user/logfile";
constexpr const char *configfile = "/home/user/configfile";
#else
constexpr const char *basedir = "C:\\basedir";
constexpr const char *mountdir = "C:\\mountdir";
constexpr const char *logfile = "C:\\logfile";
constexpr const char *configfile = "C:\\configfile";
#endif
class ProgramOptionsParserTest: public ProgramOptionsTestBase { class ProgramOptionsParserTest: public ProgramOptionsTestBase {
public: public:
ProgramOptions parse(std::initializer_list<const char*> options) { ProgramOptions parse(std::initializer_list<const char*> options) {
@ -36,7 +48,7 @@ TEST_F(ProgramOptionsParserTest, MissingAllOptions) {
TEST_F(ProgramOptionsParserTest, MissingDir) { TEST_F(ProgramOptionsParserTest, MissingDir) {
CaptureStderrRAII captureStderr; CaptureStderrRAII captureStderr;
try { try {
parse({"./myExecutable", "/home/user/baseDir"}); parse({"./myExecutable", basedir});
EXPECT_TRUE(false); // expect throw EXPECT_TRUE(false); // expect throw
} catch (const CryfsException& e) { } catch (const CryfsException& e) {
EXPECT_EQ(ErrorCode::InvalidArguments, e.errorCode()); EXPECT_EQ(ErrorCode::InvalidArguments, e.errorCode());
@ -78,88 +90,88 @@ TEST_F(ProgramOptionsParserTest, ShowCiphers) {
} }
TEST_F(ProgramOptionsParserTest, BaseDir_Absolute) { TEST_F(ProgramOptionsParserTest, BaseDir_Absolute) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ("/home/user/baseDir", options.baseDir()); EXPECT_EQ(basedir, options.baseDir());
} }
TEST_F(ProgramOptionsParserTest, Basedir_Relative) { TEST_F(ProgramOptionsParserTest, Basedir_Relative) {
ProgramOptions options = parse({"./myExecutable", "baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", "baseDir", mountdir});
EXPECT_EQ(bf::current_path() / "baseDir", options.baseDir()); EXPECT_EQ(bf::current_path() / "baseDir", options.baseDir());
} }
TEST_F(ProgramOptionsParserTest, MountDir_Absolute) { TEST_F(ProgramOptionsParserTest, MountDir_Absolute) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ("/home/user/mountDir", options.mountDir()); EXPECT_EQ(mountdir, options.mountDir());
} }
TEST_F(ProgramOptionsParserTest, MountDir_Relative) { TEST_F(ProgramOptionsParserTest, MountDir_Relative) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "mountDir"});
EXPECT_EQ(bf::current_path() / "mountDir", options.mountDir()); EXPECT_EQ(bf::current_path() / "mountDir", options.mountDir());
} }
TEST_F(ProgramOptionsParserTest, Foreground_False) { TEST_F(ProgramOptionsParserTest, Foreground_False) {
ProgramOptions options = parse({"./myExecutable", "/home/user/basedir", "mountdir"}); ProgramOptions options = parse({"./myExecutable", basedir, "mountdir"});
EXPECT_FALSE(options.foreground()); EXPECT_FALSE(options.foreground());
} }
TEST_F(ProgramOptionsParserTest, Foreground_True) { TEST_F(ProgramOptionsParserTest, Foreground_True) {
ProgramOptions options = parse({"./myExecutable", "-f", "/home/user/basedir", "mountdir"}); ProgramOptions options = parse({"./myExecutable", "-f", basedir, "mountdir"});
EXPECT_TRUE(options.foreground()); EXPECT_TRUE(options.foreground());
} }
TEST_F(ProgramOptionsParserTest, AllowFilesystemUpgrade_False) { TEST_F(ProgramOptionsParserTest, AllowFilesystemUpgrade_False) {
ProgramOptions options = parse({"./myExecutable", "/home/user/basedir", "mountdir"}); ProgramOptions options = parse({"./myExecutable", basedir, "mountdir"});
EXPECT_FALSE(options.allowFilesystemUpgrade()); EXPECT_FALSE(options.allowFilesystemUpgrade());
} }
TEST_F(ProgramOptionsParserTest, AllowFilesystemUpgrade_True) { TEST_F(ProgramOptionsParserTest, AllowFilesystemUpgrade_True) {
ProgramOptions options = parse({"./myExecutable", "--allow-filesystem-upgrade", "/home/user/basedir", "mountdir"}); ProgramOptions options = parse({"./myExecutable", "--allow-filesystem-upgrade", basedir, "mountdir"});
EXPECT_TRUE(options.allowFilesystemUpgrade()); EXPECT_TRUE(options.allowFilesystemUpgrade());
} }
TEST_F(ProgramOptionsParserTest, LogfileGiven) { TEST_F(ProgramOptionsParserTest, LogfileGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--logfile", "/home/user/mylogfile", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--logfile", logfile, mountdir});
EXPECT_EQ("/home/user/mylogfile", options.logFile().value()); EXPECT_EQ(logfile, options.logFile().value());
} }
TEST_F(ProgramOptionsParserTest, LogfileGiven_RelativePath) { TEST_F(ProgramOptionsParserTest, LogfileGiven_RelativePath) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--logfile", "mylogfile", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--logfile", "mylogfile", mountdir});
EXPECT_EQ(bf::current_path() / "mylogfile", options.logFile().value()); EXPECT_EQ(bf::current_path() / "mylogfile", options.logFile().value());
} }
TEST_F(ProgramOptionsParserTest, LogfileNotGiven) { TEST_F(ProgramOptionsParserTest, LogfileNotGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ(none, options.logFile()); EXPECT_EQ(none, options.logFile());
} }
TEST_F(ProgramOptionsParserTest, ConfigfileGiven) { TEST_F(ProgramOptionsParserTest, ConfigfileGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--config", "/home/user/myconfigfile", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--config", configfile, mountdir});
EXPECT_EQ("/home/user/myconfigfile", options.configFile().value()); EXPECT_EQ(configfile, options.configFile().value());
} }
TEST_F(ProgramOptionsParserTest, ConfigfileGiven_RelativePath) { TEST_F(ProgramOptionsParserTest, ConfigfileGiven_RelativePath) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--config", "myconfigfile", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--config", "myconfigfile", mountdir});
EXPECT_EQ(bf::current_path() / "myconfigfile", options.configFile().value()); EXPECT_EQ(bf::current_path() / "myconfigfile", options.configFile().value());
} }
TEST_F(ProgramOptionsParserTest, ConfigfileNotGiven) { TEST_F(ProgramOptionsParserTest, ConfigfileNotGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ(none, options.configFile()); EXPECT_EQ(none, options.configFile());
} }
TEST_F(ProgramOptionsParserTest, CipherGiven) { TEST_F(ProgramOptionsParserTest, CipherGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--cipher", "aes-256-gcm", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--cipher", "aes-256-gcm", mountdir});
EXPECT_EQ("aes-256-gcm", options.cipher().value()); EXPECT_EQ("aes-256-gcm", options.cipher().value());
} }
TEST_F(ProgramOptionsParserTest, CipherNotGiven) { TEST_F(ProgramOptionsParserTest, CipherNotGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ(none, options.cipher()); EXPECT_EQ(none, options.cipher());
} }
TEST_F(ProgramOptionsParserTest, InvalidCipher) { TEST_F(ProgramOptionsParserTest, InvalidCipher) {
try { try {
parse({"./myExecutable", "/home/user/baseDir", "--cipher", "invalid-cipher", "/home/user/mountDir"}); parse({"./myExecutable", basedir, "--cipher", "invalid-cipher", mountdir});
EXPECT_TRUE(false); // expect throw EXPECT_TRUE(false); // expect throw
} catch (const CryfsException& e) { } catch (const CryfsException& e) {
EXPECT_EQ(ErrorCode::InvalidArguments, e.errorCode()); EXPECT_EQ(ErrorCode::InvalidArguments, e.errorCode());
@ -168,92 +180,92 @@ TEST_F(ProgramOptionsParserTest, InvalidCipher) {
} }
TEST_F(ProgramOptionsParserTest, UnmountAfterIdleMinutesGiven) { TEST_F(ProgramOptionsParserTest, UnmountAfterIdleMinutesGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--unmount-idle", "10", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--unmount-idle", "10", mountdir});
EXPECT_EQ(10, options.unmountAfterIdleMinutes().value()); EXPECT_EQ(10, options.unmountAfterIdleMinutes().value());
} }
TEST_F(ProgramOptionsParserTest, UnmountAfterIdleMinutesGiven_Float) { TEST_F(ProgramOptionsParserTest, UnmountAfterIdleMinutesGiven_Float) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--unmount-idle", "0.5", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--unmount-idle", "0.5", mountdir});
EXPECT_EQ(0.5, options.unmountAfterIdleMinutes().value()); EXPECT_EQ(0.5, options.unmountAfterIdleMinutes().value());
} }
TEST_F(ProgramOptionsParserTest, UnmountAfterIdleMinutesNotGiven) { TEST_F(ProgramOptionsParserTest, UnmountAfterIdleMinutesNotGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ(none, options.unmountAfterIdleMinutes()); EXPECT_EQ(none, options.unmountAfterIdleMinutes());
} }
TEST_F(ProgramOptionsParserTest, BlocksizeGiven) { TEST_F(ProgramOptionsParserTest, BlocksizeGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--blocksize", "10240", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--blocksize", "10240", mountdir});
EXPECT_EQ(10240u, options.blocksizeBytes().value()); EXPECT_EQ(10240u, options.blocksizeBytes().value());
} }
TEST_F(ProgramOptionsParserTest, BlocksizeNotGiven) { TEST_F(ProgramOptionsParserTest, BlocksizeNotGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ(none, options.blocksizeBytes()); EXPECT_EQ(none, options.blocksizeBytes());
} }
TEST_F(ProgramOptionsParserTest, MissingBlockIsIntegrityViolationGiven_True) { TEST_F(ProgramOptionsParserTest, MissingBlockIsIntegrityViolationGiven_True) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--missing-block-is-integrity-violation", "true", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--missing-block-is-integrity-violation", "true", mountdir});
EXPECT_TRUE(options.missingBlockIsIntegrityViolation().value()); EXPECT_TRUE(options.missingBlockIsIntegrityViolation().value());
} }
TEST_F(ProgramOptionsParserTest, MissingBlockIsIntegrityViolationGiven_False) { TEST_F(ProgramOptionsParserTest, MissingBlockIsIntegrityViolationGiven_False) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--missing-block-is-integrity-violation", "false", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--missing-block-is-integrity-violation", "false", mountdir});
EXPECT_FALSE(options.missingBlockIsIntegrityViolation().value()); EXPECT_FALSE(options.missingBlockIsIntegrityViolation().value());
} }
TEST_F(ProgramOptionsParserTest, AllowIntegrityViolations_True) { TEST_F(ProgramOptionsParserTest, AllowIntegrityViolations_True) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--allow-integrity-violations", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, "--allow-integrity-violations", mountdir});
EXPECT_TRUE(options.allowIntegrityViolations()); EXPECT_TRUE(options.allowIntegrityViolations());
} }
TEST_F(ProgramOptionsParserTest, AllowIntegrityViolations_False) { TEST_F(ProgramOptionsParserTest, AllowIntegrityViolations_False) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_FALSE(options.allowIntegrityViolations()); EXPECT_FALSE(options.allowIntegrityViolations());
} }
TEST_F(ProgramOptionsParserTest, MissingBlockIsIntegrityViolationNotGiven) { TEST_F(ProgramOptionsParserTest, MissingBlockIsIntegrityViolationNotGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ(none, options.missingBlockIsIntegrityViolation()); EXPECT_EQ(none, options.missingBlockIsIntegrityViolation());
} }
TEST_F(ProgramOptionsParserTest, FuseOptionGiven) { TEST_F(ProgramOptionsParserTest, FuseOptionGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir", "--", "-f"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir, "--", "-f"});
EXPECT_EQ("/home/user/baseDir", options.baseDir()); EXPECT_EQ(basedir, options.baseDir());
EXPECT_EQ("/home/user/mountDir", options.mountDir()); EXPECT_EQ(mountdir, options.mountDir());
EXPECT_VECTOR_EQ({"-f"}, options.fuseOptions()); EXPECT_VECTOR_EQ({"-f"}, options.fuseOptions());
} }
TEST_F(ProgramOptionsParserTest, FuseOptionGiven_Empty) { TEST_F(ProgramOptionsParserTest, FuseOptionGiven_Empty) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir", "--"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir, "--"});
EXPECT_EQ("/home/user/baseDir", options.baseDir()); EXPECT_EQ(basedir, options.baseDir());
EXPECT_EQ("/home/user/mountDir", options.mountDir()); EXPECT_EQ(mountdir, options.mountDir());
EXPECT_VECTOR_EQ({}, options.fuseOptions()); EXPECT_VECTOR_EQ({}, options.fuseOptions());
} }
TEST_F(ProgramOptionsParserTest, FuseOptionNotGiven) { TEST_F(ProgramOptionsParserTest, FuseOptionNotGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir});
EXPECT_EQ("/home/user/baseDir", options.baseDir()); EXPECT_EQ(basedir, options.baseDir());
EXPECT_EQ("/home/user/mountDir", options.mountDir()); EXPECT_EQ(mountdir, options.mountDir());
EXPECT_VECTOR_EQ({}, options.fuseOptions()); EXPECT_VECTOR_EQ({}, options.fuseOptions());
} }
TEST_F(ProgramOptionsParserTest, DirectFuseOptionsGiven_AfterPositionalOptions) { TEST_F(ProgramOptionsParserTest, DirectFuseOptionsGiven_AfterPositionalOptions) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir", "-o", "my_opt"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir, "-o", "my_opt"});
EXPECT_VECTOR_EQ({"-o", "my_opt"}, options.fuseOptions()); EXPECT_VECTOR_EQ({"-o", "my_opt"}, options.fuseOptions());
} }
TEST_F(ProgramOptionsParserTest, DirectFuseOptionsGiven_BeforePositionalOptions) { TEST_F(ProgramOptionsParserTest, DirectFuseOptionsGiven_BeforePositionalOptions) {
ProgramOptions options = parse({"./myExecutable", "-o", "my_opt", "/home/user/baseDir", "/home/user/mountDir"}); ProgramOptions options = parse({"./myExecutable", "-o", "my_opt", basedir, mountdir});
EXPECT_VECTOR_EQ({"-o", "my_opt"}, options.fuseOptions()); EXPECT_VECTOR_EQ({"-o", "my_opt"}, options.fuseOptions());
} }
TEST_F(ProgramOptionsParserTest, DirectFuseOptionsGiven_BeforeAndAfterPositionalOptions) { TEST_F(ProgramOptionsParserTest, DirectFuseOptionsGiven_BeforeAndAfterPositionalOptions) {
ProgramOptions options = parse({"./myExecutable", "-o", "first", "-o", "second", "/home/user/baseDir", "-o", "third", "-o", "fourth", "/home/user/mountDir", "-o", "fifth", "-o", "sixth"}); ProgramOptions options = parse({"./myExecutable", "-o", "first", "-o", "second", basedir, "-o", "third", "-o", "fourth", mountdir, "-o", "fifth", "-o", "sixth"});
EXPECT_VECTOR_EQ({"-o", "first", "-o", "second", "-o", "third", "-o", "fourth", "-o", "fifth", "-o", "sixth"}, options.fuseOptions()); EXPECT_VECTOR_EQ({"-o", "first", "-o", "second", "-o", "third", "-o", "fourth", "-o", "fifth", "-o", "sixth"}, options.fuseOptions());
} }
TEST_F(ProgramOptionsParserTest, DirectAndIndirectFuseOptionsGiven) { TEST_F(ProgramOptionsParserTest, DirectAndIndirectFuseOptionsGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir", "-o", "my_opt", "--", "-o", "other_opt"}); ProgramOptions options = parse({"./myExecutable", basedir, mountdir, "-o", "my_opt", "--", "-o", "other_opt"});
EXPECT_VECTOR_EQ({"-o", "other_opt", "-o", "my_opt"}, options.fuseOptions()); EXPECT_VECTOR_EQ({"-o", "other_opt", "-o", "my_opt"}, options.fuseOptions());
} }

View File

@ -2,6 +2,11 @@
#ifndef MESSMER_CRYFS_TEST_CLI_TESTUTILS_CLITEST_H #ifndef MESSMER_CRYFS_TEST_CLI_TESTUTILS_CLITEST_H
#define MESSMER_CRYFS_TEST_CLI_TESTUTILS_CLITEST_H #define MESSMER_CRYFS_TEST_CLI_TESTUTILS_CLITEST_H
#if defined(_MSC_VER)
#include <codecvt>
#include <dokan/dokan.h>
#endif
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <cpp-utils/tempfile/TempDir.h> #include <cpp-utils/tempfile/TempDir.h>
@ -15,6 +20,8 @@
#include "../../cryfs/testutils/TestWithFakeHomeDirectory.h" #include "../../cryfs/testutils/TestWithFakeHomeDirectory.h"
#include <cryfs/ErrorCodes.h> #include <cryfs/ErrorCodes.h>
#include <cpp-utils/testutils/CaptureStderrRAII.h> #include <cpp-utils/testutils/CaptureStderrRAII.h>
#include <regex>
#include <string>
class CliTest : public ::testing::Test, TestWithFakeHomeDirectory { class CliTest : public ::testing::Test, TestWithFakeHomeDirectory {
public: public: