This commit is contained in:
Fancy code 2024-04-28 14:55:38 +08:00
parent d8f7e2c076
commit 6610558788
12 changed files with 64 additions and 51 deletions

View File

@ -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) {

View File

@ -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()

View File

@ -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(

View File

@ -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<VirtualKeyEvent>(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)
{
}

View File

@ -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<VKeyHalMonitor> &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 &));

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -14,36 +14,8 @@
*/
#ifndef LINUX_API_MOCK_H
#define LINUX_API_MOCK_H
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "GtestUsing.h"
#include <memory>
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

View File

@ -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})

View File

@ -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

View File

@ -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})