2015-09-29 14:29:10 +02:00
|
|
|
#include "testutils/ProgramOptionsTestBase.h"
|
|
|
|
#include "../../src/program_options/Parser.h"
|
|
|
|
|
|
|
|
using namespace cryfs::program_options;
|
|
|
|
using std::vector;
|
2015-10-24 19:56:05 +02:00
|
|
|
using boost::none;
|
2015-09-29 14:29:10 +02:00
|
|
|
|
|
|
|
class ProgramOptionsParserTest: public ProgramOptionsTestBase {
|
|
|
|
public:
|
|
|
|
ProgramOptions parse(std::initializer_list<const char*> options) {
|
|
|
|
vector<char*> _options = ProgramOptionsTestBase::options(options);
|
|
|
|
return Parser(_options.size(), _options.data()).parse();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-28 15:27:30 +01:00
|
|
|
TEST_F(ProgramOptionsParserTest, MissingAllOptions) {
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_DEATH(
|
2015-10-16 04:06:00 +02:00
|
|
|
parse({"./myExecutable"}),
|
|
|
|
"Usage:"
|
2015-09-29 14:29:10 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-28 15:27:30 +01:00
|
|
|
TEST_F(ProgramOptionsParserTest, MissingDir) {
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_DEATH(
|
|
|
|
parse({"./myExecutable", "/home/user/baseDir"}),
|
|
|
|
"Usage:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-28 15:27:30 +01:00
|
|
|
TEST_F(ProgramOptionsParserTest, HelpLongOption) {
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_DEATH(
|
|
|
|
parse({"./myExecutable", "--help"}),
|
|
|
|
"Usage:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-28 15:27:30 +01:00
|
|
|
TEST_F(ProgramOptionsParserTest, HelpShortOption) {
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_DEATH(
|
|
|
|
parse({"./myExecutable", "-h"}),
|
|
|
|
"Usage:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsParserTest, NoSpecialOptions) {
|
2015-10-24 19:56:05 +02:00
|
|
|
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"});
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_EQ("/home/user/baseDir", options.baseDir());
|
|
|
|
EXPECT_EQ("/home/user/mountDir", options.mountDir());
|
2015-10-24 19:56:05 +02:00
|
|
|
EXPECT_EQ(none, options.logFile());
|
|
|
|
EXPECT_EQ(none, options.configFile());
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_VECTOR_EQ({"./myExecutable", "/home/user/mountDir"}, options.fuseOptions());
|
|
|
|
}
|
|
|
|
|
2015-10-24 19:56:05 +02:00
|
|
|
TEST_F(ProgramOptionsParserTest, LogfileGiven) {
|
2015-10-24 20:00:54 +02:00
|
|
|
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--logfile", "/home/user/mylogfile", "/home/user/mountDir"});
|
2015-10-24 19:56:05 +02:00
|
|
|
EXPECT_EQ("/home/user/mylogfile", options.logFile().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsParserTest, ConfigfileGiven) {
|
2015-10-24 20:00:54 +02:00
|
|
|
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--config", "/home/user/myconfigfile", "/home/user/mountDir"});
|
2015-10-24 19:56:05 +02:00
|
|
|
EXPECT_EQ("/home/user/myconfigfile", options.configFile().value());
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
TEST_F(ProgramOptionsParserTest, FuseOptionGiven) {
|
2015-10-24 19:56:05 +02:00
|
|
|
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir", "--", "-f"});
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_EQ("/home/user/baseDir", options.baseDir());
|
|
|
|
EXPECT_EQ("/home/user/mountDir", options.mountDir());
|
|
|
|
EXPECT_VECTOR_EQ({"./myExecutable", "/home/user/mountDir", "-f"}, options.fuseOptions());
|
|
|
|
}
|