2015-10-29 19:34:36 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef MESSMER_CRYFS_TEST_CLI_TESTUTILS_CLITEST_H
|
|
|
|
#define MESSMER_CRYFS_TEST_CLI_TESTUTILS_CLITEST_H
|
|
|
|
|
|
|
|
#include <google/gtest/gtest.h>
|
|
|
|
#include <messmer/cpp-utils/tempfile/TempDir.h>
|
|
|
|
#include <messmer/cpp-utils/tempfile/TempFile.h>
|
|
|
|
#include "../../../src/Cli.h"
|
2015-10-30 19:53:15 +01:00
|
|
|
#include <messmer/cpp-utils/logging/logging.h>
|
2015-10-29 19:34:36 +01:00
|
|
|
|
|
|
|
class CliTest : public ::testing::Test {
|
|
|
|
public:
|
2015-10-30 17:23:08 +01:00
|
|
|
CliTest(): _basedir(), _mountdir(), basedir(_basedir.path()), mountdir(_mountdir.path()), logfile(), configfile(false) {}
|
2015-10-29 19:34:36 +01:00
|
|
|
|
2015-10-30 17:23:08 +01:00
|
|
|
cpputils::TempDir _basedir;
|
|
|
|
cpputils::TempDir _mountdir;
|
|
|
|
boost::filesystem::path basedir;
|
|
|
|
boost::filesystem::path mountdir;
|
2015-10-29 19:34:36 +01:00
|
|
|
cpputils::TempFile logfile;
|
|
|
|
cpputils::TempFile configfile;
|
|
|
|
|
2015-10-29 19:55:26 +01:00
|
|
|
void run(std::vector<const char*> args) {
|
2015-10-29 19:34:36 +01:00
|
|
|
std::vector<char*> _args;
|
|
|
|
_args.reserve(args.size()+1);
|
|
|
|
_args.push_back(const_cast<char*>("cryfs"));
|
|
|
|
for (const char *arg : args) {
|
|
|
|
_args.push_back(const_cast<char*>(arg));
|
|
|
|
}
|
|
|
|
cryfs::Cli().main(_args.size(), _args.data());
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:55:26 +01:00
|
|
|
void EXPECT_EXIT_WITH_HELP_MESSAGE(std::vector<const char*> args) {
|
2015-10-29 19:34:36 +01:00
|
|
|
EXPECT_RUN_ERROR(args, "Usage");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:55:26 +01:00
|
|
|
void EXPECT_RUN_ERROR(std::vector<const char*> args, const char *message) {
|
2015-10-29 19:34:36 +01:00
|
|
|
EXPECT_EXIT(
|
|
|
|
run(args),
|
|
|
|
::testing::ExitedWithCode(1),
|
|
|
|
message
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:53:15 +01:00
|
|
|
class _UnmountFilesystemInDestructor final {
|
|
|
|
public:
|
|
|
|
_UnmountFilesystemInDestructor(const boost::filesystem::path &baseDir) :_baseDir(baseDir) {}
|
|
|
|
~_UnmountFilesystemInDestructor() {
|
|
|
|
if (0 != system((std::string("fusermount -u ")+_baseDir.c_str()).c_str()), "Could not unmount cryfs") {
|
|
|
|
cpputils::logging::LOG(cpputils::logging::ERROR) << "Could not unmount cryfs";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
boost::filesystem::path _baseDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
void EXPECT_RUN_SUCCESS(std::vector<const char*> args, const boost::filesystem::path &baseDir) {
|
|
|
|
/*_UnmountFilesystemInDestructor raii(baseDir);
|
|
|
|
EXPECT_EXIT(
|
2015-10-29 19:34:36 +01:00
|
|
|
run(args),
|
|
|
|
::testing::ExitedWithCode(0),
|
|
|
|
"Filesystem is running"
|
|
|
|
);*/
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|