* Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
* ubs-engine is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include "test_ubse_node_controller_module.h"
#include <src/framework/ha/ubse_election_module.h>
#include <ubse_timer.h>
#include "ubse_node_controller_module.cpp"
namespace ubse::node_controller::ut {
using namespace ubse::timer;
using namespace election;
using namespace ubse::com;
void TestUbseNodeControllerModule::SetUp()
{
Test::SetUp();
}
void TestUbseNodeControllerModule::TearDown()
{
Test::TearDown();
GlobalMockObject::verify();
}
TEST_F(TestUbseNodeControllerModule, Start)
{
MOCKER_CPP(&UbseNodeControllerAgent::Start).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerMaster::Start).stubs().will(returnValue(UBSE_OK));
UbseNodeControllerModule module{};
EXPECT_EQ(module.Start(), UBSE_OK);
}
TEST_F(TestUbseNodeControllerModule, UnInitialize)
{
MOCKER_CPP(&UbseNodeControllerMaster::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerAgent::UnInitialize).stubs().will(ignoreReturnValue());
UbseNodeControllerModule module{};
EXPECT_NO_THROW(module.UnInitialize());
}
TEST_F(TestUbseNodeControllerModule, Stop)
{
MOCKER(UbseElectionChangeDeAttachHandler).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerMaster::Stop).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerAgent::Stop).stubs().will(ignoreReturnValue());
UbseNodeControllerModule module{};
EXPECT_NO_THROW(module.Stop());
}
TEST_F(TestUbseNodeControllerModule, Initialize_Success)
{
MOCKER(UbseNodeApi::Register).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::Initialize).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerMaster::Initialize).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerMaster::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER(UbseRegRpcService).stubs().will(returnValue(UBSE_OK));
UbseNodeControllerModule module{};
EXPECT_EQ(module.Initialize(), UBSE_OK);
}
TEST_F(TestUbseNodeControllerModule, Initialize_Fail_ApiRegister)
{
MOCKER(UbseNodeApi::Register).stubs().will(returnValue(UBSE_ERROR));
UbseNodeControllerModule module{};
EXPECT_EQ(module.Initialize(), UBSE_ERROR);
}
TEST_F(TestUbseNodeControllerModule, Initialize_Fail_AgentInit)
{
MOCKER(UbseNodeApi::Register).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::Initialize).stubs().will(returnValue(UBSE_ERROR));
UbseNodeControllerModule module{};
EXPECT_EQ(module.Initialize(), UBSE_ERROR);
}
TEST_F(TestUbseNodeControllerModule, Initialize_Fail_MasterInit)
{
MOCKER(UbseNodeApi::Register).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::Initialize).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerMaster::Initialize).stubs().will(returnValue(UBSE_ERROR));
MOCKER(UbseRegRpcService).stubs().will(returnValue(UBSE_OK));
UbseNodeControllerModule module{};
EXPECT_EQ(module.Initialize(), UBSE_ERROR);
}
TEST_F(TestUbseNodeControllerModule, Initialize_Fail_AgentMsgHandler)
{
MOCKER(UbseNodeApi::Register).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::Initialize).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER(UbseRegRpcService).expects(atLeast(1)).will(returnValue(UBSE_ERROR));
UbseNodeControllerModule module{};
EXPECT_EQ(module.Initialize(), UBSE_ERROR);
}
TEST_F(TestUbseNodeControllerModule, Initialize_Fail_MasterMsgHandler)
{
MOCKER(UbseNodeApi::Register).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::Initialize).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerMaster::Initialize).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerMaster::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER(UbseRegRpcService).stubs().will(returnValue(UBSE_ERROR));
UbseNodeControllerModule module{};
EXPECT_EQ(module.Initialize(), UBSE_ERROR);
}
TEST_F(TestUbseNodeControllerModule, Stop_Normal)
{
MOCKER(UbseElectionChangeDeAttachHandler).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerMaster::Stop).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerAgent::Stop).stubs().will(ignoreReturnValue());
UbseNodeControllerModule module{};
EXPECT_NO_THROW(module.Stop());
}
TEST_F(TestUbseNodeControllerModule, Stop_ElectionFail)
{
MOCKER(UbseElectionChangeDeAttachHandler).stubs().will(returnValue(UBSE_ERROR));
MOCKER_CPP(&UbseNodeControllerMaster::Stop).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerAgent::Stop).stubs().will(ignoreReturnValue());
UbseNodeControllerModule module{};
EXPECT_NO_THROW(module.Stop());
}
TEST_F(TestUbseNodeControllerModule, ModuleLifecycle)
{
GTEST_SKIP();
MOCKER(UbseNodeApi::Register).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::Initialize).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerMaster::Initialize).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerMaster::UnInitialize).stubs().will(ignoreReturnValue());
MOCKER(UbseRegRpcService).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerAgent::Start).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerMaster::Start).stubs().will(returnValue(UBSE_OK));
MOCKER(UbseElectionChangeDeAttachHandler).stubs().will(returnValue(UBSE_OK));
MOCKER_CPP(&UbseNodeControllerMaster::Stop).stubs().will(ignoreReturnValue());
MOCKER_CPP(&UbseNodeControllerAgent::Stop).stubs().will(ignoreReturnValue());
UbseNodeControllerModule module{};
EXPECT_EQ(module.Initialize(), UBSE_OK);
EXPECT_EQ(module.Start(), UBSE_OK);
EXPECT_NO_THROW(module.Stop());
EXPECT_NO_THROW(module.UnInitialize());
}
}