libcryfs/test/testutils/MockConsole.h
Sebastian Messmer 20b0034ab1 - Refactor main()
- Added CryConfigLoaderTest
2015-10-23 12:16:23 +02:00

33 lines
1.1 KiB
C++

#pragma once
#ifndef MESSMER_CRYFS_TEST_TESTUTILS_MOCKCONSOLE_H
#define MESSMER_CRYFS_TEST_TESTUTILS_MOCKCONSOLE_H
#include <messmer/cpp-utils/io/Console.h>
#include <google/gmock/gmock.h>
class MockConsole: public cpputils::Console {
public:
MOCK_METHOD1(print, void(const std::string&));
MOCK_METHOD2(ask, unsigned int(const std::string&, const std::vector<std::string>&));
MOCK_METHOD1(askYesNo, bool(const std::string&));
};
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
static cpputils::unique_ref<MockConsole> mockConsole() {
auto console = cpputils::make_unique_ref<MockConsole>();
EXPECT_CALL(*console, ask(::testing::_, ::testing::_)).WillRepeatedly(ChooseCipher("aes-256-gcm"));
EXPECT_CALL(*console, askYesNo(::testing::_)).WillRepeatedly(::testing::Return(true));
return console;
}
};
#endif