hunting/test/utils/UartDevice/src_mock/UartDevice_Mock_Test.cpp
2024-01-25 12:01:03 -08:00

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