Improve:sd card mock function.
This commit is contained in:
parent
280afb79c5
commit
732caa9440
|
@ -18,6 +18,8 @@
|
|||
#include <memory>
|
||||
constexpr int INVALID_HANDLE = -1;
|
||||
constexpr int MOCK_SELECT_TIME_OUT = 0;
|
||||
constexpr int MOCK_SYSTEM_RESULT_SUCCESS = 0;
|
||||
constexpr int MOCK_SYSTEM_RESULT_FAILURE = -1;
|
||||
class LinuxApiMock
|
||||
{
|
||||
public:
|
||||
|
@ -67,12 +69,26 @@ public:
|
|||
*/
|
||||
virtual int GetHandleForMock(void);
|
||||
|
||||
private:
|
||||
static void InitSDCardDefaultStatus(std::shared_ptr<LinuxTest> &mock);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief The functions from here on are all used in the simulator under the Ubuntu system. When cross-compiling, it
|
||||
* is forbidden to use the following functions directly.
|
||||
*/
|
||||
/**
|
||||
* @brief Create an instance of the LinuxTest class. The LinuxTest class instance can only be created through this
|
||||
* function.
|
||||
*/
|
||||
static std::shared_ptr<LinuxTest> CreateLinuxTest(void);
|
||||
/**
|
||||
* @brief Controls the return value when the system function executes a shell command. This function can only simply
|
||||
* control the return value and cannot capture and analyze the parameters of the shell command.
|
||||
* @param mock
|
||||
* @param command shell command
|
||||
* @param result return value of system function
|
||||
*/
|
||||
static void SetSystemCommandResult(std::shared_ptr<LinuxTest> &mock, const std::string &command, const int &result);
|
||||
};
|
||||
#endif
|
|
@ -86,10 +86,17 @@ int LinuxApiMock::fx_system(const char *command)
|
|||
{
|
||||
return __real_fx_system(command);
|
||||
}
|
||||
void LinuxTest::InitSDCardDefaultStatus(std::shared_ptr<LinuxTest> &mock)
|
||||
{
|
||||
LinuxTest::SetSystemCommandResult(mock, "mkfs.vfat", MOCK_SYSTEM_RESULT_SUCCESS);
|
||||
LinuxTest::SetSystemCommandResult(mock, "mount", MOCK_SYSTEM_RESULT_SUCCESS);
|
||||
LinuxTest::SetSystemCommandResult(mock, "umount", MOCK_SYSTEM_RESULT_SUCCESS);
|
||||
}
|
||||
std::shared_ptr<LinuxTest> LinuxTest::CreateLinuxTest(void)
|
||||
{
|
||||
std::shared_ptr<LinuxTest> test = std::make_shared<LinuxTestImpl>();
|
||||
LinuxTestImpl::ApiInit(test);
|
||||
InitSDCardDefaultStatus(test);
|
||||
return test;
|
||||
}
|
||||
void LinuxTest::SetSystemCommandResult(std::shared_ptr<LinuxTest> &mock, const std::string &command, const int &result)
|
||||
|
|
Loading…
Reference in New Issue
Block a user