hunting/test/utils/UartDevice/src_mock/UartDevice_Mock_Test.cpp
2024-01-24 08:20:47 -08:00

67 lines
2.0 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 "ILog.h"
#include "LinuxApiMock.h"
#include "UartDevice.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace UartDeviceMockTest
{
class LinuxApiMockTest : public LinuxApiMock
{
public:
LinuxApiMockTest() = default;
virtual ~LinuxApiMockTest() = default;
MOCK_METHOD2(fx_open, int(const char *, int));
};
class UartDeviceMockTest : public testing::Test
{
public:
UartDeviceMockTest() {}
virtual ~UartDeviceMockTest() {}
static void SetUpTestCase()
{
CreateLogModule();
ILogInit(LOG_INSTANCE_TYPE_END);
}
static void TearDownTestCase() { ILogUnInit(); }
virtual void SetUp() {}
virtual void TearDown() {}
};
// ../output_files/test/bin/UartDeviceTest --gtest_filter=UartDeviceMockTest.Demo
TEST_F(UartDeviceMockTest, Demo)
{
const char *deviceName = "dev/s1";
uart_info device = {
deviceName,
1152000,
'N',
8,
1,
'N',
};
std::shared_ptr<LinuxApiMockTest> tmp = std::make_shared<LinuxApiMockTest>();
std::shared_ptr<LinuxApiMock> test = tmp;
LinuxApiMock::GetInstance(&test);
EXPECT_CALL(*tmp.get(), fx_open(deviceName, ::testing::_))
.WillRepeatedly(::testing::DoAll((::testing::Return(1000000000))));
void *object = CreateUartDevice(device);
IUartOpen(object);
// IUartSend(object, nullptr, 0);
// IUartRecv(object, nullptr, 0, 0);
// IUartTcflush(object);
IUartDeviceFree(object);
}
} // namespace UartDeviceMockTest