2015-10-22 18:48:04 +02:00
|
|
|
#pragma once
|
|
|
|
#ifndef MESSMER_CRYFS_TEST_TESTUTILS_MOCKCONSOLE_H
|
|
|
|
#define MESSMER_CRYFS_TEST_TESTUTILS_MOCKCONSOLE_H
|
|
|
|
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <cpp-utils/io/Console.h>
|
|
|
|
#include <gmock/gmock.h>
|
2015-10-22 18:48:04 +02:00
|
|
|
|
|
|
|
class MockConsole: public cpputils::Console {
|
|
|
|
public:
|
2019-10-13 17:49:57 +02:00
|
|
|
MOCK_METHOD(void, print, (const std::string&), (override));
|
|
|
|
MOCK_METHOD(unsigned int, ask, (const std::string&, const std::vector<std::string>&), (override));
|
|
|
|
MOCK_METHOD(bool, askYesNo, (const std::string&, bool), (override));
|
|
|
|
MOCK_METHOD(std::string, askPassword, (const std::string&), (override));
|
2015-10-22 18:48:04 +02:00
|
|
|
};
|
|
|
|
|
2015-10-23 12:16:23 +02:00
|
|
|
ACTION_P(ChooseCipher, cipherName) {
|
|
|
|
return std::find(arg1.begin(), arg1.end(), cipherName) - arg1.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ChooseAnyCipher() ChooseCipher("aes-256-gcm")
|
|
|
|
|
|
|
|
class TestWithMockConsole {
|
|
|
|
public:
|
|
|
|
// Return a console that chooses a valid cryfs setting
|
2016-01-17 14:57:40 +01:00
|
|
|
static std::shared_ptr<MockConsole> mockConsole() {
|
2018-10-19 20:34:51 +02:00
|
|
|
auto console = std::make_shared<::testing::NiceMock<MockConsole>>();
|
2015-10-23 12:16:23 +02:00
|
|
|
EXPECT_CALL(*console, ask(::testing::_, ::testing::_)).WillRepeatedly(ChooseCipher("aes-256-gcm"));
|
2016-09-25 02:50:28 +02:00
|
|
|
EXPECT_CALL(*console, askYesNo(::testing::_, ::testing::_)).WillRepeatedly(::testing::Return(true));
|
2015-10-23 12:16:23 +02:00
|
|
|
return console;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-22 18:48:04 +02:00
|
|
|
#endif
|