Backup:DeivceManager test code.
This commit is contained in:
parent
ce3da311a6
commit
c81a611f66
|
@ -38,15 +38,15 @@ void MissionStateMachine::Init(void)
|
||||||
LogError("State machine init failed.\n");
|
LogError("State machine init failed.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mStartMission = IDeviceManager::GetInstance()->GetIpcMission();
|
// mStartMission = IDeviceManager::GetInstance()->GetIpcMission();
|
||||||
RunStateMachine(mStartMission);
|
// RunStateMachine(mStartMission);
|
||||||
}
|
}
|
||||||
void MissionStateMachine::UnInit(void)
|
void MissionStateMachine::UnInit(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
// void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||||
{
|
// {
|
||||||
LogInfo("Make all states and start the state machine.\n");
|
// LogInfo("Make all states and start the state machine.\n");
|
||||||
mStateTree[MissionState::TOP_STATE] = MissionManagerMakeImpl::GetInstance()->CreateTopState();
|
// mStateTree[MissionState::TOP_STATE] = MissionManagerMakeImpl::GetInstance()->CreateTopState();
|
||||||
mStateMachine->SetTopState(mStateTree[MissionState::TOP_STATE].get());
|
// mStateMachine->SetTopState(mStateTree[MissionState::TOP_STATE].get());
|
||||||
}
|
// }
|
||||||
|
|
|
@ -33,11 +33,11 @@ public:
|
||||||
void UnInit(void);
|
void UnInit(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void RunStateMachine(const IpcMission &mission);
|
// void RunStateMachine(const IpcMission &mission);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<VStateMachineHandle> mStateMachine;
|
std::shared_ptr<VStateMachineHandle> mStateMachine;
|
||||||
std::map<MissionState, std::shared_ptr<State>> mStateTree;
|
std::map<MissionState, std::shared_ptr<State>> mStateTree;
|
||||||
IpcMission mStartMission;
|
// IpcMission mStartMission;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
|
@ -31,7 +31,7 @@ StatusCode CreateHalModule(void)
|
||||||
auto instance = std::make_shared<IHalCpp>();
|
auto instance = std::make_shared<IHalCpp>();
|
||||||
StatusCode code2 = HalMakePtr::GetInstance()->CreateHalSharePtr(instance);
|
StatusCode code2 = HalMakePtr::GetInstance()->CreateHalSharePtr(instance);
|
||||||
if (IsCodeOK(code2)) {
|
if (IsCodeOK(code2)) {
|
||||||
LogInfo("IHal manager instance is ok.\n");
|
LogInfo("Hal instance is ok.\n");
|
||||||
IHalCpp::GetInstance(&instance);
|
IHalCpp::GetInstance(&instance);
|
||||||
}
|
}
|
||||||
return code2;
|
return code2;
|
||||||
|
@ -46,7 +46,7 @@ void CreateHalCppModule(void)
|
||||||
auto instance = std::make_shared<IHalCpp>();
|
auto instance = std::make_shared<IHalCpp>();
|
||||||
StatusCode code2 = HalMakePtr::GetInstance()->CreateHalSharePtr(instance);
|
StatusCode code2 = HalMakePtr::GetInstance()->CreateHalSharePtr(instance);
|
||||||
if (IsCodeOK(code2)) {
|
if (IsCodeOK(code2)) {
|
||||||
LogInfo("IHal manager instance is ok.\n");
|
LogInfo("Hal instance is ok.\n");
|
||||||
IHalCpp::GetInstance(&instance);
|
IHalCpp::GetInstance(&instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@ include_directories(
|
||||||
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
# ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
aux_source_directory(./src TEST_TOOL_SRC_FILES)
|
||||||
set(TEST_TOOL_TARGET HalTestTool)
|
set(TEST_TOOL_TARGET HalTestTool)
|
||||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||||
|
|
|
@ -15,16 +15,63 @@
|
||||||
#ifndef HAL_TEST_TOOL_H
|
#ifndef HAL_TEST_TOOL_H
|
||||||
#define HAL_TEST_TOOL_H
|
#define HAL_TEST_TOOL_H
|
||||||
#include "HalCpp.h"
|
#include "HalCpp.h"
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
using ::testing::_;
|
||||||
|
using ::testing::Action;
|
||||||
|
using ::testing::ActionInterface;
|
||||||
|
using ::testing::AnyNumber;
|
||||||
|
using ::testing::Assign;
|
||||||
|
using ::testing::AtLeast;
|
||||||
|
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;
|
||||||
class HalCppTest : public HalCpp
|
class HalCppTest : public HalCpp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HalCppTest() = default;
|
HalCppTest() = default;
|
||||||
virtual ~HalCppTest() = default;
|
virtual ~HalCppTest() = default;
|
||||||
|
StatusCode GetLedHals(std::vector<std::shared_ptr<VLedHal>> &ledHals) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual StatusCode GetLedHalsTrace(std::vector<std::shared_ptr<VLedHal>> &ledHals);
|
||||||
|
};
|
||||||
|
class HalCppMock : public HalCppTest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HalCppMock() = default;
|
||||||
|
virtual ~HalCppMock() = default;
|
||||||
|
MOCK_METHOD1(GetLedHalsTrace, StatusCode(std::vector<std::shared_ptr<VLedHal>> &));
|
||||||
};
|
};
|
||||||
class HalTestTool
|
class HalTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
HalTestTool() = default;
|
HalTestTool() = default;
|
||||||
virtual ~HalTestTool() = default;
|
virtual ~HalTestTool() = default;
|
||||||
|
void Init(void);
|
||||||
|
void UnInit(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<HalCppMock> mHalMock;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
55
test/hal/tool/src/HalMakePtrTest.cpp
Normal file
55
test/hal/tool/src/HalMakePtrTest.cpp
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* 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 "HalMakePtrTest.h"
|
||||||
|
#include "ILog.h"
|
||||||
|
void OverrideHalMakePtrObject(std::shared_ptr<HalCppMock> &halMock)
|
||||||
|
{
|
||||||
|
std::shared_ptr<HalMakePtr> impl = std::make_shared<HalMakePtrTest>();
|
||||||
|
std::shared_ptr<HalMakePtrTest> test = std::dynamic_pointer_cast<HalMakePtrTest>(impl);
|
||||||
|
if (test) {
|
||||||
|
test->mHalCppMock = halMock;
|
||||||
|
}
|
||||||
|
HalMakePtr::GetInstance(&impl);
|
||||||
|
}
|
||||||
|
void CancelOverrideHalMakePtrObject(void)
|
||||||
|
{
|
||||||
|
std::shared_ptr<HalMakePtr> tmp = HalMakePtr::GetInstance();
|
||||||
|
std::shared_ptr<HalMakePtrTest> test = std::dynamic_pointer_cast<HalMakePtrTest>(tmp);
|
||||||
|
if (test) {
|
||||||
|
test->mHalCppMock.reset();
|
||||||
|
}
|
||||||
|
std::shared_ptr<HalMakePtr> impl = std::make_shared<HalMakePtrTest>();
|
||||||
|
HalMakePtr::GetInstance(&impl);
|
||||||
|
}
|
||||||
|
HalMakePtrTest::HalMakePtrTest()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
HalMakePtrTest::~HalMakePtrTest()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
mHalCppMock.reset();
|
||||||
|
}
|
||||||
|
StatusCode HalMakePtrTest::CreateHalSharePtr(std::shared_ptr<IHalCpp> &impl)
|
||||||
|
{
|
||||||
|
if (mHalCppMock) {
|
||||||
|
LogInfo("CreateHalSharePtr mHalCppMock\n");
|
||||||
|
impl = mHalCppMock;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogWarning("CreateMcuManager failed:mHalCppMock is nullptr.\n");
|
||||||
|
}
|
||||||
|
return CreateStatusCode(STATUS_CODE_OK);
|
||||||
|
}
|
31
test/hal/tool/src/HalMakePtrTest.h
Normal file
31
test/hal/tool/src/HalMakePtrTest.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/*
|
||||||
|
* 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 HAL_MAKE_PTR_TEST_H
|
||||||
|
#define HAL_MAKE_PTR_TEST_H
|
||||||
|
#include "HalMakePtr.h"
|
||||||
|
#include "HalTestTool.h"
|
||||||
|
void OverrideHalMakePtrObject(std::shared_ptr<HalCppMock> &halMock);
|
||||||
|
void CancelOverrideHalMakePtrObject(void);
|
||||||
|
class HalMakePtrTest : public HalMakePtr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HalMakePtrTest();
|
||||||
|
virtual ~HalMakePtrTest();
|
||||||
|
StatusCode CreateHalSharePtr(std::shared_ptr<IHalCpp> &impl) override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::shared_ptr<HalCppMock> mHalCppMock;
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -12,4 +12,35 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "HalTestTool.h"
|
#include "HalTestTool.h"
|
||||||
|
#include "HalMakePtrTest.h"
|
||||||
|
#include "ILog.h"
|
||||||
|
StatusCode HalCppTest::GetLedHals(std::vector<std::shared_ptr<VLedHal>> &ledHals)
|
||||||
|
{
|
||||||
|
LogInfo("HalCppTest::GetLedHals\n");
|
||||||
|
StatusCode code = GetLedHalsTrace(ledHals);
|
||||||
|
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
||||||
|
return HalCpp::GetLedHals(ledHals);
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
StatusCode HalCppTest::GetLedHalsTrace(std::vector<std::shared_ptr<VLedHal>> &ledHals)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
LogInfo("HalCppTest::GetLedHalsTrace\n");
|
||||||
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
||||||
|
}
|
||||||
|
void HalTestTool::Init(void)
|
||||||
|
{
|
||||||
|
mHalMock = std::make_shared<HalCppMock>();
|
||||||
|
EXPECT_CALL(*mHalMock.get(), GetLedHalsTrace(_))
|
||||||
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
||||||
|
OverrideHalMakePtrObject(mHalMock);
|
||||||
|
}
|
||||||
|
void HalTestTool::UnInit(void)
|
||||||
|
{
|
||||||
|
// std::shared_ptr<IHalCpp> impl = std::make_shared<IHalCpp>();
|
||||||
|
// IHalCpp::GetInstance(&impl);
|
||||||
|
mHalMock.reset();
|
||||||
|
CancelOverrideHalMakePtrObject();
|
||||||
|
}
|
|
@ -10,13 +10,16 @@ include_directories(
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
${UTILS_SOURCE_PATH}/UartDevice/include
|
${UTILS_SOURCE_PATH}/UartDevice/include
|
||||||
${UTILS_SOURCE_PATH}/McuProtocol/include
|
${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||||
|
${HAL_SOURCE_PATH}/include
|
||||||
|
${HAL_SOURCE_PATH}/src
|
||||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
||||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
||||||
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
||||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||||
${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
|
${TEST_SOURCE_PATH}/hal/tool/include
|
||||||
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
# ${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
|
||||||
${TEST_SOURCE_PATH}/middleware/McuAskBase/tool/include
|
# ${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
||||||
|
# ${TEST_SOURCE_PATH}/middleware/McuAskBase/tool/include
|
||||||
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
|
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
|
||||||
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
|
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include "HalTestTool.h"
|
||||||
#include "IDeviceManager.h"
|
#include "IDeviceManager.h"
|
||||||
#include "ILog.h"
|
#include "ILog.h"
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
@ -19,7 +20,7 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
namespace DeviceManagerTest
|
namespace DeviceManagerTest
|
||||||
{
|
{
|
||||||
class DeviceManagerTest : public testing::Test
|
class DeviceManagerTest : public testing::Test, public HalTestTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeviceManagerTest() {}
|
DeviceManagerTest() {}
|
||||||
|
@ -32,12 +33,13 @@ public:
|
||||||
static void TearDownTestCase() { ILogUnInit(); }
|
static void TearDownTestCase() { ILogUnInit(); }
|
||||||
virtual void SetUp()
|
virtual void SetUp()
|
||||||
{
|
{
|
||||||
CreateDeviceManagerModule();
|
|
||||||
// mLinuxTest = LinuxTest::CreateLinuxTest();
|
// mLinuxTest = LinuxTest::CreateLinuxTest();
|
||||||
// std::shared_ptr<LinuxApiMock> test = mLinuxTest;
|
// std::shared_ptr<LinuxApiMock> test = mLinuxTest;
|
||||||
// LinuxApiMock::GetInstance(&test);
|
// LinuxApiMock::GetInstance(&test);
|
||||||
// LinuxApiMock::GetInstance()->Init();
|
// LinuxApiMock::GetInstance()->Init();
|
||||||
// McuManagerTestTool::Init(mLinuxTest);
|
HalTestTool::Init();
|
||||||
|
CreateHalCppModule();
|
||||||
|
CreateDeviceManagerModule();
|
||||||
// CreateMcuManager();
|
// CreateMcuManager();
|
||||||
}
|
}
|
||||||
virtual void TearDown()
|
virtual void TearDown()
|
||||||
|
@ -46,7 +48,7 @@ public:
|
||||||
// mLinuxTest = std::make_shared<LinuxTest>();
|
// mLinuxTest = std::make_shared<LinuxTest>();
|
||||||
// std::shared_ptr<LinuxApiMock> test = std::make_shared<LinuxApiMock>();
|
// std::shared_ptr<LinuxApiMock> test = std::make_shared<LinuxApiMock>();
|
||||||
// LinuxApiMock::GetInstance(&test);
|
// LinuxApiMock::GetInstance(&test);
|
||||||
// McuManagerTestTool::UnInit();
|
HalTestTool::UnInit();
|
||||||
// DestroyMcuManager();
|
// DestroyMcuManager();
|
||||||
DestroyDeviceManagerModule();
|
DestroyDeviceManagerModule();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ void McuManagerTestTool::Init(std::shared_ptr<LinuxTest> &mock)
|
||||||
{
|
{
|
||||||
LogInfo("McuManagerTestTool::Init\n");
|
LogInfo("McuManagerTestTool::Init\n");
|
||||||
mMcuManagerMock = std::make_shared<McuManagerImplTest>();
|
mMcuManagerMock = std::make_shared<McuManagerImplTest>();
|
||||||
// EXPECT_CALL(*mMcuManagerMock.get(), DeleteMcuAsk(_)).Times(500);
|
|
||||||
OverrideMcuManagerMakePtrObject();
|
OverrideMcuManagerMakePtrObject();
|
||||||
std::shared_ptr<McuManagerMakePtr> tmp = McuManagerMakePtr::GetInstance();
|
std::shared_ptr<McuManagerMakePtr> tmp = McuManagerMakePtr::GetInstance();
|
||||||
std::shared_ptr<McuManagerMakePtrTest> test = std::dynamic_pointer_cast<McuManagerMakePtrTest>(tmp);
|
std::shared_ptr<McuManagerMakePtrTest> test = std::dynamic_pointer_cast<McuManagerMakePtrTest>(tmp);
|
||||||
|
|
|
@ -12,16 +12,11 @@ include_directories(
|
||||||
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
|
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googletest/include
|
||||||
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
|
${EXTERNAL_SOURCE_PATH}/gtest/googletest-release-1.11.0/googlemock/include
|
||||||
)
|
)
|
||||||
message("=========================================${EXTERNAL_LIBS_OUTPUT_PATH}")
|
|
||||||
link_directories(
|
link_directories(
|
||||||
${LIBS_OUTPUT_PATH}
|
${LIBS_OUTPUT_PATH}
|
||||||
${EXTERNAL_LIBS_OUTPUT_PATH}
|
${EXTERNAL_LIBS_OUTPUT_PATH}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
aux_source_directory(. SRC_FILES)
|
aux_source_directory(. SRC_FILES)
|
||||||
aux_source_directory(./src SRC_FILES)
|
aux_source_directory(./src SRC_FILES)
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,11 @@ include_directories(
|
||||||
${UTILS_SOURCE_PATH}/StatusCode/include
|
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||||
${UTILS_SOURCE_PATH}/Log/include
|
${UTILS_SOURCE_PATH}/Log/include
|
||||||
)
|
)
|
||||||
|
|
||||||
#do not rely on any other library
|
#do not rely on any other library
|
||||||
#link_directories(
|
#link_directories(
|
||||||
#)
|
#)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
aux_source_directory(./src SRC_FILES)
|
aux_source_directory(./src SRC_FILES)
|
||||||
|
|
||||||
set(TARGET_NAME StatusCode)
|
set(TARGET_NAME StatusCode)
|
||||||
|
@ -33,11 +32,21 @@ add_custom_target(
|
||||||
-p ${PLATFORM_PATH}/cmake-shell
|
-p ${PLATFORM_PATH}/cmake-shell
|
||||||
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/StatusCode
|
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/StatusCode
|
||||||
)
|
)
|
||||||
|
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||||
|
add_custom_target(
|
||||||
|
StatusCode_code_format
|
||||||
|
COMMAND ${CLANG_FORMAT_EXE}
|
||||||
|
-style=file
|
||||||
|
-i ${SRC_FILES} ${HEADER_FILES}
|
||||||
|
WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/StatusCode
|
||||||
|
)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET ${TARGET_NAME}
|
TARGET ${TARGET_NAME}
|
||||||
PRE_BUILD
|
PRE_BUILD
|
||||||
COMMAND make StatusCode_code_check
|
COMMAND make StatusCode_code_check
|
||||||
|
COMMAND make StatusCode_code_format
|
||||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
define_file_name(${TARGET_NAME})
|
define_file_name(${TARGET_NAME})
|
|
@ -3,9 +3,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -16,38 +16,28 @@
|
||||||
#define STATUSCODE_H
|
#define STATUSCODE_H
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
enum STATUS_CODE
|
enum STATUS_CODE
|
||||||
{
|
{
|
||||||
STATUS_CODE_OK = 0,
|
STATUS_CODE_OK = 0,
|
||||||
STATUS_CODE_NOT_OK,
|
STATUS_CODE_NOT_OK,
|
||||||
STATUS_CODE_VIRTUAL_FUNCTION,
|
STATUS_CODE_VIRTUAL_FUNCTION,
|
||||||
STATUS_CODE_INVALID_PARAMENTER,
|
STATUS_CODE_INVALID_PARAMENTER,
|
||||||
STATUS_CODE_MAKE_SHARED_PTR_FAILED,
|
STATUS_CODE_MAKE_SHARED_PTR_FAILED,
|
||||||
STATUS_CODE_END
|
STATUS_CODE_END
|
||||||
};
|
};
|
||||||
typedef struct status_code StatusCode;
|
typedef struct status_code StatusCode;
|
||||||
typedef struct status_code
|
typedef struct status_code
|
||||||
{
|
{
|
||||||
const char *(*mPrintStringCode)(const StatusCode);
|
const char *(*mPrintStringCode)(const StatusCode);
|
||||||
const bool (*mCodeEqual)(const StatusCode, const char *);
|
const bool (*mCodeEqual)(const StatusCode, const char *);
|
||||||
const long int mStatusCode;
|
const long int mStatusCode;
|
||||||
} StatusCode;
|
} StatusCode;
|
||||||
const StatusCode CreateStatusCode(const long int code);
|
const StatusCode CreateStatusCode(const long int code);
|
||||||
static inline const char *PrintStringCode(const StatusCode code)
|
static inline const char *PrintStringCode(const StatusCode code) { return code.mPrintStringCode(code); }
|
||||||
{
|
static inline bool IsCodeOK(const StatusCode code) { return STATUS_CODE_OK == code.mStatusCode ? true : false; }
|
||||||
return code.mPrintStringCode(code);
|
static inline bool StatusCodeEqual(const StatusCode code, const char *value) { return code.mCodeEqual(code, value); }
|
||||||
}
|
|
||||||
static inline bool IsCodeOK(const StatusCode code)
|
|
||||||
{
|
|
||||||
return STATUS_CODE_OK == code.mStatusCode ? true : false;
|
|
||||||
}
|
|
||||||
static inline bool StatusCodeEqual(const StatusCode code, const char *value)
|
|
||||||
{
|
|
||||||
return code.mCodeEqual(code, value);
|
|
||||||
}
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -17,14 +17,10 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
static const char *StatusCodeString[STATUS_CODE_END + 1] = {
|
static const char *StatusCodeString[STATUS_CODE_END + 1] = {
|
||||||
"STATUS_CODE_OK",
|
"STATUS_CODE_OK", "STATUS_CODE_NOT_OK", "STATUS_CODE_INVALID_PARAMENTER", "STATUS_CODE_END"};
|
||||||
"STATUS_CODE_NOT_OK",
|
|
||||||
"STATUS_CODE_INVALID_PARAMENTER",
|
|
||||||
"STATUS_CODE_END"};
|
|
||||||
static const char *_PrintStringCode_(const StatusCode this)
|
static const char *_PrintStringCode_(const StatusCode this)
|
||||||
{
|
{
|
||||||
if (STATUS_CODE_OK <= this.mStatusCode && this.mStatusCode <= STATUS_CODE_END)
|
if (STATUS_CODE_OK <= this.mStatusCode && this.mStatusCode <= STATUS_CODE_END) {
|
||||||
{
|
|
||||||
LogInfo("Status code = [ %s ]\n", StatusCodeString[this.mStatusCode]);
|
LogInfo("Status code = [ %s ]\n", StatusCodeString[this.mStatusCode]);
|
||||||
return StatusCodeString[this.mStatusCode];
|
return StatusCodeString[this.mStatusCode];
|
||||||
}
|
}
|
||||||
|
@ -33,32 +29,25 @@ static const char *_PrintStringCode_(const StatusCode this)
|
||||||
}
|
}
|
||||||
static const bool CodeEqual(const StatusCode code, const char *value)
|
static const bool CodeEqual(const StatusCode code, const char *value)
|
||||||
{
|
{
|
||||||
if (STATUS_CODE_OK >= code.mStatusCode || code.mStatusCode >= STATUS_CODE_END)
|
if (STATUS_CODE_OK >= code.mStatusCode || code.mStatusCode >= STATUS_CODE_END) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strlen(value) != strlen(StatusCodeString[code.mStatusCode]))
|
if (strlen(value) != strlen(StatusCodeString[code.mStatusCode])) {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (memcmp(value, StatusCodeString[code.mStatusCode], strlen(value)) == 0)
|
if (memcmp(value, StatusCodeString[code.mStatusCode], strlen(value)) == 0) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static StatusCode NewStatusCode(const long int code)
|
static StatusCode NewStatusCode(const long int code)
|
||||||
{
|
{
|
||||||
StatusCode result = {
|
StatusCode result = {_PrintStringCode_, CodeEqual, code};
|
||||||
_PrintStringCode_,
|
|
||||||
CodeEqual,
|
|
||||||
code};
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
const StatusCode CreateStatusCode(const long int code)
|
const StatusCode CreateStatusCode(const long int code)
|
||||||
{
|
{
|
||||||
if (STATUS_CODE_OK <= code && code <= STATUS_CODE_END)
|
if (STATUS_CODE_OK <= code && code <= STATUS_CODE_END) {
|
||||||
{
|
|
||||||
return NewStatusCode(code);
|
return NewStatusCode(code);
|
||||||
}
|
}
|
||||||
LogError("undefined code.\n");
|
LogError("undefined code.\n");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user