mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
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");
|
||||
return;
|
||||
}
|
||||
mStartMission = IDeviceManager::GetInstance()->GetIpcMission();
|
||||
RunStateMachine(mStartMission);
|
||||
// mStartMission = IDeviceManager::GetInstance()->GetIpcMission();
|
||||
// RunStateMachine(mStartMission);
|
||||
}
|
||||
void MissionStateMachine::UnInit(void)
|
||||
{
|
||||
}
|
||||
void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||
{
|
||||
LogInfo("Make all states and start the state machine.\n");
|
||||
mStateTree[MissionState::TOP_STATE] = MissionManagerMakeImpl::GetInstance()->CreateTopState();
|
||||
mStateMachine->SetTopState(mStateTree[MissionState::TOP_STATE].get());
|
||||
}
|
||||
// void MissionStateMachine::RunStateMachine(const IpcMission &mission)
|
||||
// {
|
||||
// LogInfo("Make all states and start the state machine.\n");
|
||||
// mStateTree[MissionState::TOP_STATE] = MissionManagerMakeImpl::GetInstance()->CreateTopState();
|
||||
// mStateMachine->SetTopState(mStateTree[MissionState::TOP_STATE].get());
|
||||
// }
|
||||
|
|
|
@ -33,11 +33,11 @@ public:
|
|||
void UnInit(void);
|
||||
|
||||
private:
|
||||
void RunStateMachine(const IpcMission &mission);
|
||||
// void RunStateMachine(const IpcMission &mission);
|
||||
|
||||
private:
|
||||
std::shared_ptr<VStateMachineHandle> mStateMachine;
|
||||
std::map<MissionState, std::shared_ptr<State>> mStateTree;
|
||||
IpcMission mStartMission;
|
||||
// IpcMission mStartMission;
|
||||
};
|
||||
#endif
|
|
@ -31,7 +31,7 @@ StatusCode CreateHalModule(void)
|
|||
auto instance = std::make_shared<IHalCpp>();
|
||||
StatusCode code2 = HalMakePtr::GetInstance()->CreateHalSharePtr(instance);
|
||||
if (IsCodeOK(code2)) {
|
||||
LogInfo("IHal manager instance is ok.\n");
|
||||
LogInfo("Hal instance is ok.\n");
|
||||
IHalCpp::GetInstance(&instance);
|
||||
}
|
||||
return code2;
|
||||
|
@ -46,7 +46,7 @@ void CreateHalCppModule(void)
|
|||
auto instance = std::make_shared<IHalCpp>();
|
||||
StatusCode code2 = HalMakePtr::GetInstance()->CreateHalSharePtr(instance);
|
||||
if (IsCodeOK(code2)) {
|
||||
LogInfo("IHal manager instance is ok.\n");
|
||||
LogInfo("Hal instance is ok.\n");
|
||||
IHalCpp::GetInstance(&instance);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,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 HalTestTool)
|
||||
add_library(${TEST_TOOL_TARGET} STATIC ${TEST_TOOL_SRC_FILES})
|
||||
|
|
|
@ -15,16 +15,63 @@
|
|||
#ifndef HAL_TEST_TOOL_H
|
||||
#define HAL_TEST_TOOL_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
|
||||
{
|
||||
public:
|
||||
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
|
||||
{
|
||||
public:
|
||||
HalTestTool() = default;
|
||||
virtual ~HalTestTool() = default;
|
||||
void Init(void);
|
||||
void UnInit(void);
|
||||
|
||||
private:
|
||||
std::shared_ptr<HalCppMock> mHalMock;
|
||||
};
|
||||
#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
|
||||
* 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}/UartDevice/include
|
||||
${UTILS_SOURCE_PATH}/McuProtocol/include
|
||||
${HAL_SOURCE_PATH}/include
|
||||
${HAL_SOURCE_PATH}/src
|
||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/include
|
||||
${MIDDLEWARE_SOURCE_PATH}/DeviceManager/src
|
||||
${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
|
||||
${TEST_SOURCE_PATH}/utils/LinuxApiMock/include
|
||||
${TEST_SOURCE_PATH}/utils/UartDevice/tool/include
|
||||
${TEST_SOURCE_PATH}/utils/McuProtocol/tool/include
|
||||
${TEST_SOURCE_PATH}/middleware/McuAskBase/tool/include
|
||||
${TEST_SOURCE_PATH}/hal/tool/include
|
||||
# ${TEST_SOURCE_PATH}/utils/UartDevice/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/googlemock/include
|
||||
)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "HalTestTool.h"
|
||||
#include "IDeviceManager.h"
|
||||
#include "ILog.h"
|
||||
#include <gmock/gmock.h>
|
||||
|
@ -19,7 +20,7 @@
|
|||
#include <thread>
|
||||
namespace DeviceManagerTest
|
||||
{
|
||||
class DeviceManagerTest : public testing::Test
|
||||
class DeviceManagerTest : public testing::Test, public HalTestTool
|
||||
{
|
||||
public:
|
||||
DeviceManagerTest() {}
|
||||
|
@ -32,12 +33,13 @@ public:
|
|||
static void TearDownTestCase() { ILogUnInit(); }
|
||||
virtual void SetUp()
|
||||
{
|
||||
CreateDeviceManagerModule();
|
||||
// mLinuxTest = LinuxTest::CreateLinuxTest();
|
||||
// std::shared_ptr<LinuxApiMock> test = mLinuxTest;
|
||||
// LinuxApiMock::GetInstance(&test);
|
||||
// LinuxApiMock::GetInstance()->Init();
|
||||
// McuManagerTestTool::Init(mLinuxTest);
|
||||
HalTestTool::Init();
|
||||
CreateHalCppModule();
|
||||
CreateDeviceManagerModule();
|
||||
// CreateMcuManager();
|
||||
}
|
||||
virtual void TearDown()
|
||||
|
@ -46,7 +48,7 @@ public:
|
|||
// mLinuxTest = std::make_shared<LinuxTest>();
|
||||
// std::shared_ptr<LinuxApiMock> test = std::make_shared<LinuxApiMock>();
|
||||
// LinuxApiMock::GetInstance(&test);
|
||||
// McuManagerTestTool::UnInit();
|
||||
HalTestTool::UnInit();
|
||||
// DestroyMcuManager();
|
||||
DestroyDeviceManagerModule();
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ void McuManagerTestTool::Init(std::shared_ptr<LinuxTest> &mock)
|
|||
{
|
||||
LogInfo("McuManagerTestTool::Init\n");
|
||||
mMcuManagerMock = std::make_shared<McuManagerImplTest>();
|
||||
// EXPECT_CALL(*mMcuManagerMock.get(), DeleteMcuAsk(_)).Times(500);
|
||||
OverrideMcuManagerMakePtrObject();
|
||||
std::shared_ptr<McuManagerMakePtr> tmp = McuManagerMakePtr::GetInstance();
|
||||
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/googlemock/include
|
||||
)
|
||||
message("=========================================${EXTERNAL_LIBS_OUTPUT_PATH}")
|
||||
link_directories(
|
||||
${LIBS_OUTPUT_PATH}
|
||||
${EXTERNAL_LIBS_OUTPUT_PATH}
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
aux_source_directory(. SRC_FILES)
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
|
|
|
@ -9,12 +9,11 @@ include_directories(
|
|||
${UTILS_SOURCE_PATH}/StatusCode/include
|
||||
${UTILS_SOURCE_PATH}/Log/include
|
||||
)
|
||||
|
||||
#do not rely on any other library
|
||||
#link_directories(
|
||||
#)
|
||||
|
||||
|
||||
|
||||
aux_source_directory(./src SRC_FILES)
|
||||
|
||||
set(TARGET_NAME StatusCode)
|
||||
|
@ -33,11 +32,21 @@ add_custom_target(
|
|||
-p ${PLATFORM_PATH}/cmake-shell
|
||||
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(
|
||||
TARGET ${TARGET_NAME}
|
||||
PRE_BUILD
|
||||
COMMAND make StatusCode_code_check
|
||||
COMMAND make StatusCode_code_format
|
||||
WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
|
||||
)
|
||||
endif()
|
||||
|
||||
define_file_name(${TARGET_NAME})
|
|
@ -3,9 +3,9 @@
|
|||
* 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.
|
||||
|
@ -16,38 +16,28 @@
|
|||
#define STATUSCODE_H
|
||||
#include <stdbool.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
enum STATUS_CODE
|
||||
{
|
||||
STATUS_CODE_OK = 0,
|
||||
STATUS_CODE_NOT_OK,
|
||||
STATUS_CODE_VIRTUAL_FUNCTION,
|
||||
STATUS_CODE_INVALID_PARAMENTER,
|
||||
STATUS_CODE_MAKE_SHARED_PTR_FAILED,
|
||||
STATUS_CODE_END
|
||||
};
|
||||
typedef struct status_code StatusCode;
|
||||
typedef struct status_code
|
||||
{
|
||||
const char *(*mPrintStringCode)(const StatusCode);
|
||||
const bool (*mCodeEqual)(const StatusCode, const char *);
|
||||
const long int mStatusCode;
|
||||
} StatusCode;
|
||||
const StatusCode CreateStatusCode(const long int 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;
|
||||
}
|
||||
static inline bool StatusCodeEqual(const StatusCode code, const char *value)
|
||||
{
|
||||
return code.mCodeEqual(code, value);
|
||||
}
|
||||
enum STATUS_CODE
|
||||
{
|
||||
STATUS_CODE_OK = 0,
|
||||
STATUS_CODE_NOT_OK,
|
||||
STATUS_CODE_VIRTUAL_FUNCTION,
|
||||
STATUS_CODE_INVALID_PARAMENTER,
|
||||
STATUS_CODE_MAKE_SHARED_PTR_FAILED,
|
||||
STATUS_CODE_END
|
||||
};
|
||||
typedef struct status_code StatusCode;
|
||||
typedef struct status_code
|
||||
{
|
||||
const char *(*mPrintStringCode)(const StatusCode);
|
||||
const bool (*mCodeEqual)(const StatusCode, const char *);
|
||||
const long int mStatusCode;
|
||||
} StatusCode;
|
||||
const StatusCode CreateStatusCode(const long int 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; }
|
||||
static inline bool StatusCodeEqual(const StatusCode code, const char *value) { return code.mCodeEqual(code, value); }
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
* 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.
|
||||
|
@ -17,14 +17,10 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
static const char *StatusCodeString[STATUS_CODE_END + 1] = {
|
||||
"STATUS_CODE_OK",
|
||||
"STATUS_CODE_NOT_OK",
|
||||
"STATUS_CODE_INVALID_PARAMENTER",
|
||||
"STATUS_CODE_END"};
|
||||
"STATUS_CODE_OK", "STATUS_CODE_NOT_OK", "STATUS_CODE_INVALID_PARAMENTER", "STATUS_CODE_END"};
|
||||
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]);
|
||||
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)
|
||||
{
|
||||
if (STATUS_CODE_OK >= code.mStatusCode || code.mStatusCode >= STATUS_CODE_END)
|
||||
{
|
||||
if (STATUS_CODE_OK >= code.mStatusCode || code.mStatusCode >= STATUS_CODE_END) {
|
||||
return false;
|
||||
}
|
||||
if (strlen(value) != strlen(StatusCodeString[code.mStatusCode]))
|
||||
{
|
||||
if (strlen(value) != strlen(StatusCodeString[code.mStatusCode])) {
|
||||
return false;
|
||||
}
|
||||
if (memcmp(value, StatusCodeString[code.mStatusCode], strlen(value)) == 0)
|
||||
{
|
||||
if (memcmp(value, StatusCodeString[code.mStatusCode], strlen(value)) == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static StatusCode NewStatusCode(const long int code)
|
||||
{
|
||||
StatusCode result = {
|
||||
_PrintStringCode_,
|
||||
CodeEqual,
|
||||
code};
|
||||
StatusCode result = {_PrintStringCode_, CodeEqual, code};
|
||||
return result;
|
||||
}
|
||||
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);
|
||||
}
|
||||
LogError("undefined code.\n");
|
||||
|
|
Loading…
Reference in New Issue
Block a user