69 lines
2.8 KiB
C++
69 lines
2.8 KiB
C++
/*
|
|
* 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 "LedControlMock.h"
|
|
#include "ILog.h"
|
|
LedControlTest::LedControlTest(const std::string &ledName) : mLedName(ledName)
|
|
{
|
|
//
|
|
}
|
|
LedControlMock::LedControlMock(const std::string &ledName) : LedControlTest(ledName)
|
|
{
|
|
//
|
|
}
|
|
StatusCode LedControlTest::SetLedState(const LedState &state)
|
|
{
|
|
LogInfo("SetLedState mLedName = %s, state = %s\n", mLedName.c_str(), PrintLedState(state));
|
|
StatusCode code = SetLedStateTrace(state);
|
|
if (StatusCodeEqual(code, "STATUS_CODE_VIRTUAL_FUNCTION")) {
|
|
// return SetLedState(state);
|
|
}
|
|
return code;
|
|
}
|
|
StatusCode LedControlTest::SetLedStateTrace(const LedState &state)
|
|
{
|
|
return CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION);
|
|
}
|
|
void LedControlMock::SetLedStateMock(std::shared_ptr<VLedHal> &vMock, const LedState &state,
|
|
const unsigned int &aliveTimeMs, const unsigned int &blinkTimeMs)
|
|
{
|
|
LogInfo("LedControlMock::SetLedState\n");
|
|
std::shared_ptr<LedControlMock> mock = std::dynamic_pointer_cast<LedControlMock>(vMock);
|
|
if (!mock) {
|
|
LogError("Can't set led state, led not found.\n");
|
|
return;
|
|
}
|
|
constexpr int SOMEBODY_CONTROL_LED = 1;
|
|
EXPECT_CALL(*mock.get(), SetLedStateTrace(_))
|
|
.WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
|
auto defaultExpectations = [=, &vMock]() {
|
|
// std::shared_ptr<LedControlMock> mock = std::dynamic_pointer_cast<LedControlMock>(vMock);
|
|
// if (!mock) {
|
|
// LogError("Can't set led state, led not found.\n");
|
|
// return;
|
|
// }
|
|
// EXPECT_CALL(*mock.get(), SetLedStateTrace(state))
|
|
// .WillRepeatedly(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
|
};
|
|
if (blinkTimeMs == LED_NOT_BLINK) {
|
|
EXPECT_CALL(*mock.get(), SetLedStateTrace(state))
|
|
.Times(SOMEBODY_CONTROL_LED)
|
|
.WillRepeatedly(DoAll(Invoke(defaultExpectations), Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
|
}
|
|
else {
|
|
EXPECT_CALL(*mock.get(), SetLedStateTrace(state))
|
|
.Times(AtLeast(SOMEBODY_CONTROL_LED))
|
|
.WillRepeatedly(DoAll(Invoke(defaultExpectations), Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
|
|
}
|
|
} |