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;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsParserTest, MissingAllOptions) {
|
|
|
|
EXPECT_DEATH(
|
|
|
|
parse({"./myExecutable"}),
|
|
|
|
"Usage:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsParserTest, MissingDir) {
|
|
|
|
EXPECT_DEATH(
|
|
|
|
parse({"./myExecutable", "/home/user/baseDir"}),
|
|
|
|
"Usage:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:39:10 +02:00
|
|
|
TEST_F(ProgramOptionsParserTest, ConfigFileMissing) {
|
|
|
|
EXPECT_DEATH(
|
|
|
|
parse({"./myExecutable", "/home/user/baseDir", "/home/user/mountDir"}),
|
|
|
|
"Usage:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
TEST_F(ProgramOptionsParserTest, HelpLongOption) {
|
|
|
|
EXPECT_DEATH(
|
|
|
|
parse({"./myExecutable", "--help"}),
|
|
|
|
"Usage:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsParserTest, HelpShortOption) {
|
|
|
|
EXPECT_DEATH(
|
|
|
|
parse({"./myExecutable", "-h"}),
|
|
|
|
"Usage:"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsParserTest, NoSpecialOptions) {
|
2015-09-29 14:39:10 +02:00
|
|
|
ProgramOptions options = parse({"./myExecutable", "--config", "/home/user/configFile", "/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());
|
|
|
|
EXPECT_VECTOR_EQ({"./myExecutable", "/home/user/mountDir"}, options.fuseOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsParserTest, FuseOptionGiven) {
|
2015-09-29 14:39:10 +02:00
|
|
|
ProgramOptions options = parse({"./myExecutable", "--config", "/home/user/configFile", "/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());
|
|
|
|
}
|