diff --git a/hal/src/SdCardHal.cpp b/hal/src/SdCardHal.cpp index 01c3191b..349b4971 100644 --- a/hal/src/SdCardHal.cpp +++ b/hal/src/SdCardHal.cpp @@ -55,7 +55,7 @@ void SdCardHal::DevDetectingThread(void) const char *dev = SD_CARD_DEV; mThreadRuning = true; while (mThreadRuning) { - fd = open(dev, O_RDONLY); + fd = fx_open(dev, O_RDONLY); if (fd < 0) { LogInfo("sdCardHal: %s open failed.\n", dev); if (SdCardHalStatus::PULL_OUT != status) { diff --git a/test/hal/CMakeLists.txt b/test/hal/CMakeLists.txt index d0e591af..c5ccbcc6 100644 --- a/test/hal/CMakeLists.txt +++ b/test/hal/CMakeLists.txt @@ -23,7 +23,7 @@ aux_source_directory(./src SRC_FILES) set(TARGET_NAME HalTest) add_executable(${TARGET_NAME} ${SRC_FILES}) -target_link_libraries(${TARGET_NAME} gtest gmock pthread Hal) +target_link_libraries(${TARGET_NAME} HalTestTool gtest gmock pthread) if(${TEST_COVERAGE} MATCHES "true") target_link_libraries(${TARGET_NAME} gcov) endif() diff --git a/test/hal/tool/CMakeLists.txt b/test/hal/tool/CMakeLists.txt index 9752e2e2..46a6cde1 100644 --- a/test/hal/tool/CMakeLists.txt +++ b/test/hal/tool/CMakeLists.txt @@ -19,7 +19,7 @@ include_directories( aux_source_directory(./src TEST_TOOL_SRC_FILES) set(TEST_TOOL_TARGET HalTestTool) add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES}) -target_link_libraries(${TEST_TOOL_TARGET} KeyControl LedControl Log) +target_link_libraries(${TEST_TOOL_TARGET} Hal KeyControl LedControl LinuxApiMock Log) if ("${COMPILE_IMPROVE_SUPPORT}" MATCHES "true") add_custom_target( diff --git a/test/hal/tool/src/KeyControlMock.cpp b/test/hal/tool/src/KeyControlMock.cpp index c6f22e54..fa7c18b5 100644 --- a/test/hal/tool/src/KeyControlMock.cpp +++ b/test/hal/tool/src/KeyControlMock.cpp @@ -14,6 +14,10 @@ */ #include "KeyControlMock.h" #include "ILog.h" +unsigned int KeyControlTest::GetStatusCheckPeriodMs(void) +{ + return PERIPHERAL_CHECK_PERIOD_MS; +} KeyControlTest::KeyControlTest(const std::string &keyName) : mKeyName(keyName) { } @@ -36,6 +40,15 @@ void KeyControlTest::KeyEventTrigger(const std::string &keyName, const KeyEvent } monitor->KeyEventHappened(keyName, static_cast(event), timeMs); } +const std::string KeyControlTest::GetKeyName(void) +{ + return mKeyName; +} +StatusCode KeyControlTest::KeyEventTriggerTrace(const std::string &keyName, const KeyEvent &event, + const unsigned int &timeMs) +{ + return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); +} KeyControlMock::KeyControlMock(const std::string &keyName) : KeyControlTest(keyName) { } diff --git a/test/hal/tool/src/KeyControlMock.h b/test/hal/tool/src/KeyControlMock.h index c6b4b180..31800119 100644 --- a/test/hal/tool/src/KeyControlMock.h +++ b/test/hal/tool/src/KeyControlMock.h @@ -23,24 +23,15 @@ class KeyControlTest : public KeyControl, public VKeyHal public: KeyControlTest(const std::string &keyName); virtual ~KeyControlTest() = default; - unsigned int GetStatusCheckPeriodMs(void) override - { - return PERIPHERAL_CHECK_PERIOD_MS; - } + unsigned int GetStatusCheckPeriodMs(void) override; void SetKeyMonitor(std::shared_ptr &monitor) override; void CheckKeyStatus(void) override; void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs) override; - const std::string GetKeyName(void) override - { - return mKeyName; - } + const std::string GetKeyName(void) override; private: virtual StatusCode KeyEventTriggerTrace(const std::string &keyName, const KeyEvent &event, - const unsigned int &timeMs) - { - return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION); - } + const unsigned int &timeMs); private: const std::string mKeyName; @@ -51,7 +42,6 @@ class KeyControlMock : public KeyControlTest public: KeyControlMock(const std::string &keyName); virtual ~KeyControlMock() = default; - // void KeyEventTrigger(const std::string &keyName, const KeyEvent &event, const unsigned int &timeMs) override; void SetKeyEvent(const KeyHalEvent &event); bool MockKeyClick(const unsigned int &pressingTimeMs = 200); MOCK_METHOD3(KeyEventTriggerTrace, StatusCode(const std::string &, const KeyEvent &, const unsigned int &)); diff --git a/test/hal/tool/src/SdCardHalMock.cpp b/test/hal/tool/src/SdCardHalMock.cpp new file mode 100644 index 00000000..2574bc3c --- /dev/null +++ b/test/hal/tool/src/SdCardHalMock.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "SdCardHalMock.h" \ No newline at end of file diff --git a/test/hal/tool/src/SdCardHalMock.h b/test/hal/tool/src/SdCardHalMock.h new file mode 100644 index 00000000..ab97d630 --- /dev/null +++ b/test/hal/tool/src/SdCardHalMock.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 Fancy Code. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SD_CARD_HAL_MOCK_H +#define SD_CARD_HAL_MOCK_H +#include "IHalCpp.h" +#include "SdCardHal.h" +class SdCardHalMock : public SdCardHal +{ +public: + SdCardHalMock() = default; + virtual ~SdCardHalMock() = default; +}; +#endif \ No newline at end of file diff --git a/test/utils/LinuxApiMock/CMakeLists.txt b/test/utils/LinuxApiMock/CMakeLists.txt index 425cd51a..f921bacb 100644 --- a/test/utils/LinuxApiMock/CMakeLists.txt +++ b/test/utils/LinuxApiMock/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories( ./src ./include ${UTILS_SOURCE_PATH}/Log/include + ${TEST_SOURCE_PATH} ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include ) @@ -13,8 +14,6 @@ include_directories( # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs # ) - - aux_source_directory(./src SRC_FILES) set(TARGET_NAME LinuxApiMock) diff --git a/test/utils/LinuxApiMock/include/LinuxApiMock.h b/test/utils/LinuxApiMock/include/LinuxApiMock.h index 37a37c81..25596af1 100644 --- a/test/utils/LinuxApiMock/include/LinuxApiMock.h +++ b/test/utils/LinuxApiMock/include/LinuxApiMock.h @@ -14,36 +14,8 @@ */ #ifndef LINUX_API_MOCK_H #define LINUX_API_MOCK_H -#include -#include +#include "GtestUsing.h" #include -using ::testing::_; -using ::testing::Action; -using ::testing::ActionInterface; -using ::testing::Assign; -using ::testing::ByMove; -using ::testing::ByRef; -using ::testing::DefaultValue; -using ::testing::DoAll; -using ::testing::DoDefault; -using ::testing::IgnoreResult; -using ::testing::Invoke; -using ::testing::InvokeWithoutArgs; -using ::testing::MakePolymorphicAction; -using ::testing::PolymorphicAction; -using ::testing::Return; -using ::testing::ReturnNew; -using ::testing::ReturnNull; -using ::testing::ReturnPointee; -using ::testing::ReturnRef; -using ::testing::ReturnRefOfCopy; -using ::testing::ReturnRoundRobin; -using ::testing::SaveArg; -using ::testing::SetArgPointee; -using ::testing::SetArgumentPointee; -using ::testing::Unused; -using ::testing::WithArgs; -using ::testing::internal::BuiltInDefaultValue; constexpr int INVALID_HANDLE = -1; constexpr int MOCK_SELECT_TIME_OUT = 0; class LinuxApiMock diff --git a/test/utils/McuProtocol/tool/CMakeLists.txt b/test/utils/McuProtocol/tool/CMakeLists.txt index 47d68d20..a72de19c 100644 --- a/test/utils/McuProtocol/tool/CMakeLists.txt +++ b/test/utils/McuProtocol/tool/CMakeLists.txt @@ -10,6 +10,7 @@ include_directories( ${UTILS_SOURCE_PATH}/UartDevice/include ${UTILS_SOURCE_PATH}/ModBusCRC16/include ${UTILS_SOURCE_PATH}/McuProtocol/src + ${TEST_SOURCE_PATH} ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include ${TEST_SOURCE_PATH}/utils/UartDevice/tool/include ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include @@ -19,8 +20,6 @@ include_directories( # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs # ) - - aux_source_directory(./src TEST_TOOL_SRC_FILES) set(TEST_TOOL_TARGET McuProtocolTestTool) add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES}) diff --git a/test/utils/UartDevice/CMakeLists.txt b/test/utils/UartDevice/CMakeLists.txt index 57956873..f442586f 100644 --- a/test/utils/UartDevice/CMakeLists.txt +++ b/test/utils/UartDevice/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories( ${UTILS_SOURCE_PATH}/StatusCode/include ${UTILS_SOURCE_PATH}/Log/include ${UTILS_SOURCE_PATH}/UartDevice/include + ${TEST_SOURCE_PATH} ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include ${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include diff --git a/test/utils/UartDevice/tool/CMakeLists.txt b/test/utils/UartDevice/tool/CMakeLists.txt index f31e830f..a3cea16a 100644 --- a/test/utils/UartDevice/tool/CMakeLists.txt +++ b/test/utils/UartDevice/tool/CMakeLists.txt @@ -8,13 +8,12 @@ include_directories( ${UTILS_SOURCE_PATH}/StatusCode/include ${UTILS_SOURCE_PATH}/Log/include ${TEST_SOURCE_PATH}/utils/LinuxApiMock/include + ${TEST_SOURCE_PATH} ) # link_directories( # ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs # ) - - aux_source_directory(./src TEST_TOOL_SRC_FILES) set(TEST_TOOL_TARGET UartDeviceTestTool) add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})