From 732caa94408c263f14bae486a12883dc11d88450 Mon Sep 17 00:00:00 2001 From: Fancy code <258828110.@qq.com> Date: Sat, 20 Jul 2024 22:01:08 +0800 Subject: [PATCH] Improve:sd card mock function. --- test/utils/LinuxApiMock/include/LinuxApiMock.h | 16 ++++++++++++++++ test/utils/LinuxApiMock/src/LinuxApiMock.cpp | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/test/utils/LinuxApiMock/include/LinuxApiMock.h b/test/utils/LinuxApiMock/include/LinuxApiMock.h index f14c54c..2909ebe 100644 --- a/test/utils/LinuxApiMock/include/LinuxApiMock.h +++ b/test/utils/LinuxApiMock/include/LinuxApiMock.h @@ -18,6 +18,8 @@ #include 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 &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 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 &mock, const std::string &command, const int &result); }; #endif \ No newline at end of file diff --git a/test/utils/LinuxApiMock/src/LinuxApiMock.cpp b/test/utils/LinuxApiMock/src/LinuxApiMock.cpp index 52c0f59..b5db393 100644 --- a/test/utils/LinuxApiMock/src/LinuxApiMock.cpp +++ b/test/utils/LinuxApiMock/src/LinuxApiMock.cpp @@ -86,10 +86,17 @@ int LinuxApiMock::fx_system(const char *command) { return __real_fx_system(command); } +void LinuxTest::InitSDCardDefaultStatus(std::shared_ptr &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::CreateLinuxTest(void) { std::shared_ptr test = std::make_shared(); LinuxTestImpl::ApiInit(test); + InitSDCardDefaultStatus(test); return test; } void LinuxTest::SetSystemCommandResult(std::shared_ptr &mock, const std::string &command, const int &result)