2015-09-29 14:29:10 +02:00
|
|
|
#include "testutils/ProgramOptionsTestBase.h"
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <cryfs/cli/program_options/ProgramOptions.h>
|
|
|
|
#include <cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
|
2015-09-29 14:29:10 +02:00
|
|
|
|
|
|
|
using namespace cryfs::program_options;
|
|
|
|
using std::vector;
|
2015-10-17 19:38:24 +02:00
|
|
|
using boost::none;
|
2015-11-18 11:01:48 +01:00
|
|
|
using boost::optional;
|
|
|
|
using std::ostream;
|
2015-10-17 19:38:24 +02:00
|
|
|
using std::string;
|
2015-11-18 11:01:48 +01:00
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
|
|
|
// This is needed for google test to work with boost::optional<boost::filesystem::path>
|
|
|
|
namespace boost {
|
|
|
|
template<> ostream& operator<< <char, std::char_traits<char>, bf::path>(ostream &stream, const optional<bf::path> &path) {
|
|
|
|
if (path == none) {
|
|
|
|
return stream << "none";
|
|
|
|
}
|
|
|
|
return stream << *path;
|
|
|
|
}
|
|
|
|
}
|
2015-09-29 14:29:10 +02:00
|
|
|
|
|
|
|
class ProgramOptionsTest: public ProgramOptionsTestBase {};
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, BaseDir) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("/home/user/mydir", "", none, false, none, none, none, options({"./myExecutable"}));
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_EQ("/home/user/mydir", testobj.baseDir());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, MountDir) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "/home/user/mydir", none, false, none, none, none, options({"./myExecutable"}));
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_EQ("/home/user/mydir", testobj.mountDir());
|
|
|
|
}
|
|
|
|
|
2015-10-24 19:56:05 +02:00
|
|
|
TEST_F(ProgramOptionsTest, ConfigfileNone) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, true, none, none, none, options({"./myExecutable"}));
|
2015-10-24 19:56:05 +02:00
|
|
|
EXPECT_EQ(none, testobj.configFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, ConfigfileSome) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", bf::path("/home/user/configfile"), true, none, none, none, options({"./myExecutable"}));
|
2015-10-24 19:56:05 +02:00
|
|
|
EXPECT_EQ("/home/user/configfile", testobj.configFile().get());
|
2015-09-29 14:39:10 +02:00
|
|
|
}
|
|
|
|
|
2015-10-15 05:26:05 +02:00
|
|
|
TEST_F(ProgramOptionsTest, ForegroundFalse) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, false, none, none, none, options({"./myExecutable"}));
|
2015-10-15 05:26:05 +02:00
|
|
|
EXPECT_FALSE(testobj.foreground());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, ForegroundTrue) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, true, none, none, none, options({"./myExecutable"}));
|
2015-10-15 05:26:05 +02:00
|
|
|
EXPECT_TRUE(testobj.foreground());
|
|
|
|
}
|
|
|
|
|
2015-10-17 19:38:24 +02:00
|
|
|
TEST_F(ProgramOptionsTest, LogfileNone) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, true, none, none, none, options({"./myExecutable"}));
|
2015-10-17 19:38:24 +02:00
|
|
|
EXPECT_EQ(none, testobj.logFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, LogfileSome) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, true, none, bf::path("logfile"), none, options({"./myExecutable"}));
|
2015-10-17 19:38:24 +02:00
|
|
|
EXPECT_EQ("logfile", testobj.logFile().get());
|
|
|
|
}
|
|
|
|
|
2015-11-12 20:43:11 +01:00
|
|
|
TEST_F(ProgramOptionsTest, UnmountAfterIdleMinutesNone) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, true, none, none, none, options({"./myExecutable"}));
|
2015-11-12 20:43:11 +01:00
|
|
|
EXPECT_EQ(none, testobj.unmountAfterIdleMinutes());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, UnmountAfterIdleMinutesSome) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, true, 10, none, none, options({"./myExecutable"}));
|
2015-11-12 20:43:11 +01:00
|
|
|
EXPECT_EQ(10, testobj.unmountAfterIdleMinutes().get());
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:53:15 +01:00
|
|
|
TEST_F(ProgramOptionsTest, CipherNone) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, true, none, none, none, options({"./myExecutable"}));
|
2015-10-30 19:53:15 +01:00
|
|
|
EXPECT_EQ(none, testobj.cipher());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, CipherSome) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("", "", none, true, none, none, string("aes-256-gcm"), options({"./myExecutable"}));
|
2015-10-30 19:53:15 +01:00
|
|
|
EXPECT_EQ("aes-256-gcm", testobj.cipher().get());
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
TEST_F(ProgramOptionsTest, EmptyFuseOptions) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("/rootDir", "/home/user/mydir", none, false, none, none, none, options({"./myExecutable"}));
|
2015-09-29 14:29:10 +02:00
|
|
|
//Fuse should have the mount dir as first parameter
|
|
|
|
EXPECT_VECTOR_EQ({"./myExecutable", "/home/user/mydir"}, testobj.fuseOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, SomeFuseOptions) {
|
2016-02-13 11:38:56 +01:00
|
|
|
ProgramOptions testobj("/rootDir", "/home/user/mydir", none, false, none, none, none, options({"./myExecutable", "-f", "--longoption"}));
|
2015-09-29 14:29:10 +02:00
|
|
|
//Fuse should have the mount dir as first parameter
|
|
|
|
EXPECT_VECTOR_EQ({"./myExecutable", "/home/user/mydir", "-f", "--longoption"}, testobj.fuseOptions());
|
|
|
|
}
|