mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-07-02 05:35:11 +00:00
38
tests/unit_tests/smart_ifc/CMakeLists.txt
Normal file
38
tests/unit_tests/smart_ifc/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
# Define project
|
||||
project (UnitTest_Smart_Interface VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Find the IDL compiler
|
||||
# REMARKS The compiler can only be found after it has build. Having both the compiler and the unittest project build, causes an
|
||||
# error during the scanning phase of CMake.
|
||||
#find_program(SDVIDL NAMES "sdv_idl_compiler" PATHS "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../../bin/" NO_CACHE)
|
||||
set (SDVIDL "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/../../bin/sdv_idl_compiler")
|
||||
message("Use IDL compiler: ${SDVIDL}")
|
||||
|
||||
# Compile the IDL
|
||||
add_custom_command(
|
||||
OUTPUT ${PROJECT_SOURCE_DIR}/generated/smart_ifc.h
|
||||
DEPENDS sdv_idl_compiler
|
||||
MAIN_DEPENDENCY ${PROJECT_SOURCE_DIR}/smart_ifc.idl
|
||||
COMMENT "Build smart_ifc.idl"
|
||||
COMMAND ${SDVIDL} "${PROJECT_SOURCE_DIR}/smart_ifc.idl" "-I${PROJECT_SOURCE_DIR}/../../../export" "-O${PROJECT_SOURCE_DIR}/generated" --no_ps
|
||||
VERBATIM
|
||||
)
|
||||
set_source_files_properties(smart_ifc.cpp OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/generated/smart_ifc.h)
|
||||
|
||||
# Compile the source code
|
||||
add_executable(UnitTest_Smart_Interface
|
||||
"main.cpp"
|
||||
"smart_ifc.cpp" "ifc_map.cpp" )
|
||||
target_link_libraries(UnitTest_Smart_Interface ${CMAKE_DL_LIBS} GTest::GTest)
|
||||
|
||||
# Add the IDL Compiler unittest
|
||||
add_test(NAME UnitTest_Smart_Interface COMMAND UnitTest_Smart_Interface)
|
||||
|
||||
# Execute the test
|
||||
add_custom_command(TARGET UnitTest_Smart_Interface POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E env TEST_EXECUTION_MODE=CMake "$<TARGET_FILE:UnitTest_Smart_Interface>" --gtest_output=xml:${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/UnitTest_Smart_Interface.xml
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
# Build dependencies
|
||||
add_dependencies(UnitTest_Smart_Interface CompileCoreIDL)
|
||||
512
tests/unit_tests/smart_ifc/ifc_map.cpp
Normal file
512
tests/unit_tests/smart_ifc/ifc_map.cpp
Normal file
@@ -0,0 +1,512 @@
|
||||
#include "../../include/gtest_custom.h"
|
||||
#include "generated/smart_ifc.h"
|
||||
#include <support/interface_ptr.h>
|
||||
|
||||
/**
|
||||
* @brief Member test helper class
|
||||
*/
|
||||
template <typename TInterface>
|
||||
class CMemberHelper : public TInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rnTest Reference to the test call counter.
|
||||
*/
|
||||
CMemberHelper(size_t& rnTest) : m_rnTest(rnTest)
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Test function. Overload of several interface functions.
|
||||
*/
|
||||
virtual void Test() override
|
||||
{
|
||||
m_rnTest++;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t& m_rnTest; ///< Referebce to test call counter.
|
||||
};
|
||||
|
||||
/// Cast helper uses the same class.
|
||||
using CCastHelper = CMemberHelper<IAmbiguousInterface>;
|
||||
|
||||
/**
|
||||
* @brief First class to test resolving the ambiguity cast.
|
||||
*/
|
||||
class CCastHelper1 : public CCastHelper
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rnTest Reference to the test call counter.
|
||||
*/
|
||||
CCastHelper1(size_t& rnTest) : CCastHelper(rnTest)
|
||||
{}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Second class to test resolving the ambiguity cast.
|
||||
*/
|
||||
class CCastHelper2 : public CCastHelper
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rnTest Reference to the test call counter.
|
||||
*/
|
||||
CCastHelper2(size_t& rnTest) : CCastHelper(rnTest)
|
||||
{}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Chain base helper class.
|
||||
*/
|
||||
template <typename TInterface1, typename TInterface2>
|
||||
class CChainHelper : public sdv::IInterfaceAccess, public CMemberHelper<TInterface1>, public CMemberHelper<TInterface2>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] rnTest Reference to the test call counter.
|
||||
*/
|
||||
CChainHelper(size_t& rnTest) : CMemberHelper<TInterface1>(rnTest), CMemberHelper<TInterface2>(rnTest)
|
||||
{}
|
||||
|
||||
// Interface map
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(TInterface1)
|
||||
SDV_INTERFACE_ENTRY(TInterface2)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
};
|
||||
|
||||
/// Chain helper.
|
||||
using TChainHelperBase = CChainHelper<IBaseInterface1, IBaseInterface2>;
|
||||
using TChainHelperMember = CChainHelper<IChainMapMemberInterface1, IChainMapMemberInterface2>;
|
||||
using TChainHelperMemberSmartPointer = CChainHelper<IChainMapMemberSmartPointerInterface1, IChainMapMemberSmartPointerInterface2>;
|
||||
using TChainHelperMemberPointer = CChainHelper<IChainMapMemberPointerInterface1, IChainMapMemberPointerInterface2>;
|
||||
using TChainHelperMemberSharedPointer = CChainHelper<IChainMapMemberSharedPointerInterface1, IChainMapMemberSharedPointerInterface2>;
|
||||
using TChainHelperMemberWeakPointer = CChainHelper<IChainMapMemberWeakPointerInterface1, IChainMapMemberWeakPointerInterface2>;
|
||||
|
||||
/**
|
||||
* @brief Helper class to test the interface map.
|
||||
*/
|
||||
class CInterfaceMapHelper : public NamespaceTest1::INamespaceIfc1, public NamespaceTest2::INamespaceIfc2, public CCastHelper1,
|
||||
public CCastHelper2, public IDeniedInterface, public TChainHelperBase, public IConditionInterface,
|
||||
public IMainSectionInterface1, public IMainSectionInterface2, public ISection0Interface, public ISection1Interface,
|
||||
public ISection2Interface
|
||||
{
|
||||
public:
|
||||
CInterfaceMapHelper() : CCastHelper1(m_nTest), CCastHelper2(m_nTest), TChainHelperBase(m_nTest), m_member(m_nTest),
|
||||
m_memberPointer(m_nTest), m_pMember(&m_memberPointer), m_chainmember(m_nTest), m_chainmemberSmartPointer(m_nTest),
|
||||
m_ptrChainMemberSmartPointer(&m_chainmemberSmartPointer), m_chainmemberPointer(m_nTest),
|
||||
m_pChainMemberPointer(&m_chainmemberPointer)
|
||||
{
|
||||
m_ptrMember = std::make_shared<CMemberHelper<IMemberSharedPointer>>(m_nTest);
|
||||
m_ptrWeakMember = std::make_shared<CMemberHelper<IMemberWeakPointer>>(m_nTest);
|
||||
m_weakMember = m_ptrWeakMember;
|
||||
m_ptrChainMemberSharedPointer = std::make_shared<TChainHelperMemberSharedPointer>(m_nTest);
|
||||
m_ptrMemberWeakPointer = std::make_shared<TChainHelperMemberWeakPointer>(m_nTest);
|
||||
m_weakChainMemberWeakPointer = m_ptrMemberWeakPointer;
|
||||
}
|
||||
|
||||
// Interface map
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(NamespaceTest1::INamespaceIfc1)
|
||||
SDV_INTERFACE_USE_NAMESPACE(NamespaceTest2)
|
||||
SDV_INTERFACE_ENTRY(INamespaceIfc2)
|
||||
SDV_INTERFACE_ENTRY_MEMBER(IMember, m_member)
|
||||
SDV_INTERFACE_ENTRY_MEMBER(IMemberPointerEmpty, m_pEmptyMember)
|
||||
SDV_INTERFACE_ENTRY_MEMBER(IMemberPointer, m_pMember)
|
||||
SDV_INTERFACE_ENTRY_MEMBER(IMemberSharedPointerEmpty, m_ptrEmptyMember)
|
||||
SDV_INTERFACE_ENTRY_MEMBER(IMemberSharedPointer, m_ptrMember)
|
||||
SDV_INTERFACE_ENTRY_MEMBER(IMemberWeakPointerEmpty, m_weakEmptyMember)
|
||||
SDV_INTERFACE_ENTRY_MEMBER(IMemberWeakPointer, m_weakMember)
|
||||
SDV_INTERFACE_ENTRY_INDIRECT(IAmbiguousInterface, CCastHelper2)
|
||||
SDV_INTERFACE_DENY_ENTRY(IDeniedInterface)
|
||||
SDV_INTERFACE_CHAIN_BASE(TChainHelperBase)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_chainmember)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_ptrChainMemberSmartPointerEmpty)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_ptrChainMemberSmartPointer)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_pChainMemberPointerEmpty)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_pChainMemberPointer)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_ptrChainMemberSharedPointerEmpty)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_ptrChainMemberSharedPointer)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_weakChainMemberWeakPointerEmpty)
|
||||
SDV_INTERFACE_CHAIN_MEMBER(m_weakChainMemberWeakPointer)
|
||||
SDV_INTERFACE_SET_SECTION_CONDITION(m_iSection == 0, 0)
|
||||
SDV_INTERFACE_SET_SECTION_CONDITION(m_iSection == 1, 1)
|
||||
SDV_INTERFACE_SET_SECTION_CONDITION(m_iSection == 2, 2)
|
||||
SDV_INTERFACE_SET_SECTION_CONDITION(m_iSection == 3, 3)
|
||||
SDV_INTERFACE_SECTION(0)
|
||||
SDV_INTERFACE_ENTRY(ISection0Interface)
|
||||
SDV_INTERFACE_DEFAULT_SECTION()
|
||||
SDV_INTERFACE_ENTRY(IMainSectionInterface1)
|
||||
SDV_INTERFACE_SECTION(1)
|
||||
SDV_INTERFACE_ENTRY(ISection1Interface)
|
||||
SDV_INTERFACE_SET_SECTION(2)
|
||||
SDV_INTERFACE_SECTION(2)
|
||||
SDV_INTERFACE_ENTRY(ISection2Interface)
|
||||
SDV_INTERFACE_DEFAULT_SECTION()
|
||||
SDV_INTERFACE_ENTRY(IMainSectionInterface2)
|
||||
SDV_INTERFACE_CHECK_CONDITION(m_bConditionEnabled)
|
||||
SDV_INTERFACE_ENTRY(IConditionInterface)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
/**
|
||||
* @brief Test function. Overload of several interface functions.
|
||||
*/
|
||||
virtual void Test() override
|
||||
{
|
||||
m_nTest++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the amount of times the test function has been called.
|
||||
* @return The test call counter.
|
||||
*/
|
||||
size_t GetTestCallCount() const { return m_nTest; }
|
||||
|
||||
/**
|
||||
* @brief When set, the interfaces following the conditional check are accessible.
|
||||
* @param[in] bEnable Flag to enable or disable the conditional check.
|
||||
*/
|
||||
void SetCondition(bool bEnable) { m_bConditionEnabled = bEnable; }
|
||||
|
||||
/**
|
||||
* @brief Set or reset the section to select.
|
||||
* @param[in] iSection The section to select or -1 for the main section.
|
||||
*/
|
||||
void SetSection(int iSection = -1) { m_iSection = iSection; }
|
||||
|
||||
private:
|
||||
bool m_bConditionEnabled = false; ///< Condition flag, enabling conditional interface.
|
||||
int m_iSection = -1; ///< Section selector
|
||||
size_t m_nTest = 0; ///< Test call counter.
|
||||
CMemberHelper<IMember> m_member; ///< Member class.
|
||||
CMemberHelper<IMemberPointer> m_memberPointer; ///< Member for pointer class.
|
||||
CMemberHelper<IMemberPointerEmpty>* m_pEmptyMember = nullptr; ///< Empty member class pointer.
|
||||
CMemberHelper<IMemberPointer>* m_pMember = nullptr; ///< Member class pointer.
|
||||
std::shared_ptr<CMemberHelper<IMemberSharedPointerEmpty>> m_ptrEmptyMember; ///< Empty member class smart pointer.
|
||||
std::shared_ptr<CMemberHelper<IMemberSharedPointer>> m_ptrMember; ///< Member class smart pointer.
|
||||
std::weak_ptr<CMemberHelper<IMemberWeakPointerEmpty>> m_weakEmptyMember; ///< Empty member class weak pointer.
|
||||
std::shared_ptr<CMemberHelper<IMemberWeakPointer>> m_ptrWeakMember; ///< Member class smart pointer.
|
||||
std::weak_ptr<CMemberHelper<IMemberWeakPointer>> m_weakMember; ///< Member class weak pointer.
|
||||
TChainHelperMember m_chainmember; ///< Chain the member.
|
||||
TChainHelperMemberSmartPointer m_chainmemberSmartPointer; ///< Member for smart pointer chaining.
|
||||
sdv::TInterfaceAccessPtr m_ptrChainMemberSmartPointerEmpty; ///< Chain the empty smart pointer.
|
||||
sdv::TInterfaceAccessPtr m_ptrChainMemberSmartPointer; ///< Chain the smart pointer.
|
||||
TChainHelperMemberPointer m_chainmemberPointer; ///< Member for pointer chaining.
|
||||
TChainHelperMemberPointer* m_pChainMemberPointerEmpty = nullptr; ///< Chain the empty pointer.
|
||||
TChainHelperMemberPointer* m_pChainMemberPointer = nullptr; ///< Chain the pointer.
|
||||
std::shared_ptr<TChainHelperMemberSharedPointer> m_ptrChainMemberSharedPointerEmpty; ///< Chain the empty shared pointer.
|
||||
std::shared_ptr<TChainHelperMemberSharedPointer> m_ptrChainMemberSharedPointer; ///< Chain the shared pointer.
|
||||
std::shared_ptr<TChainHelperMemberWeakPointer> m_ptrMemberWeakPointer; ///< Member for weak pointer chaining.
|
||||
std::weak_ptr<TChainHelperMemberWeakPointer> m_weakChainMemberWeakPointerEmpty; ///< Chain the empty weak pointer.
|
||||
std::weak_ptr<TChainHelperMemberWeakPointer> m_weakChainMemberWeakPointer; ///< Chain the weak pointer.
|
||||
};
|
||||
|
||||
TEST(Interface_Map_Test, Namespace)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
NamespaceTest1::INamespaceIfc1* pIfc1 = ptrHelper.GetInterface<NamespaceTest1::INamespaceIfc1>();
|
||||
ASSERT_NE(pIfc1, nullptr);
|
||||
pIfc1->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
|
||||
NamespaceTest2::INamespaceIfc2* pIfc2 = ptrHelper.GetInterface<NamespaceTest2::INamespaceIfc2>();
|
||||
ASSERT_NE(pIfc2, nullptr);
|
||||
pIfc2->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 2ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, Member)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IMember* pMember = ptrHelper.GetInterface<IMember>();
|
||||
ASSERT_NE(pMember, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pMember->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, MemberPointer)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IMemberPointerEmpty* pMemberPointerEmpty = ptrHelper.GetInterface<IMemberPointerEmpty>();
|
||||
IMemberPointer* pMemberPointer = ptrHelper.GetInterface<IMemberPointer>();
|
||||
EXPECT_EQ(pMemberPointerEmpty, nullptr);
|
||||
ASSERT_NE(pMemberPointer, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pMemberPointer->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, MemberSharedPointer)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IMemberSharedPointerEmpty* pMemberPointerEmpty = ptrHelper.GetInterface<IMemberSharedPointerEmpty>();
|
||||
IMemberSharedPointer* pMemberPointer = ptrHelper.GetInterface<IMemberSharedPointer>();
|
||||
EXPECT_EQ(pMemberPointerEmpty, nullptr);
|
||||
ASSERT_NE(pMemberPointer, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pMemberPointer->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, MemberWeakPointer)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IMemberWeakPointerEmpty* pMemberPointerEmpty = ptrHelper.GetInterface<IMemberWeakPointerEmpty>();
|
||||
IMemberWeakPointer* pMemberPointer = ptrHelper.GetInterface<IMemberWeakPointer>();
|
||||
EXPECT_EQ(pMemberPointerEmpty, nullptr);
|
||||
ASSERT_NE(pMemberPointer, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pMemberPointer->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, ResolveInterfaceAmbiguity)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
IAmbiguousInterface* pCastHelper1 = static_cast<CCastHelper1*>(&helper);
|
||||
IAmbiguousInterface* pCastHelper2 = static_cast<CCastHelper2*>(&helper);
|
||||
EXPECT_NE(pCastHelper1, nullptr);
|
||||
EXPECT_NE(pCastHelper2, nullptr);
|
||||
EXPECT_NE(pCastHelper1, pCastHelper2);
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IAmbiguousInterface* pCastedIfc = ptrHelper.GetInterface<IAmbiguousInterface>();
|
||||
ASSERT_NE(pCastedIfc, nullptr);
|
||||
EXPECT_EQ(pCastedIfc, pCastHelper2);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pCastedIfc->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, DenyInterface)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
IDeniedInterface* pDeniedIfc1 = static_cast<IDeniedInterface*>(&helper);
|
||||
EXPECT_NE(pDeniedIfc1, nullptr);
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IDeniedInterface* pDeniedIfc2 = ptrHelper.GetInterface<IDeniedInterface>();
|
||||
EXPECT_EQ(pDeniedIfc2, nullptr);
|
||||
EXPECT_NE(pDeniedIfc1, pDeniedIfc2);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, ChainInterfaceMapBaseClass)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IBaseInterface1* pBaseIfc1 = ptrHelper.GetInterface<IBaseInterface1>();
|
||||
IBaseInterface2* pBaseIfc2 = ptrHelper.GetInterface<IBaseInterface2>();
|
||||
ASSERT_NE(pBaseIfc1, nullptr);
|
||||
ASSERT_NE(pBaseIfc2, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pBaseIfc1->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
pBaseIfc2->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 2ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, ChainInterfaceMapBaseMember)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IChainMapMemberInterface1* pChainMemberIfc1 = ptrHelper.GetInterface<IChainMapMemberInterface1>();
|
||||
IChainMapMemberInterface1* pChainMemberIfc2 = ptrHelper.GetInterface<IChainMapMemberInterface1>();
|
||||
ASSERT_NE(pChainMemberIfc1, nullptr);
|
||||
ASSERT_NE(pChainMemberIfc2, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pChainMemberIfc1->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
pChainMemberIfc2->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 2ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, ChainInterfaceMapBaseMemberSmartPointer)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IChainMapMemberSmartPointerInterface1* pChainMemberIfc1 = ptrHelper.GetInterface<IChainMapMemberSmartPointerInterface1>();
|
||||
IChainMapMemberSmartPointerInterface2* pChainMemberIfc2 = ptrHelper.GetInterface<IChainMapMemberSmartPointerInterface2>();
|
||||
ASSERT_NE(pChainMemberIfc1, nullptr);
|
||||
ASSERT_NE(pChainMemberIfc2, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pChainMemberIfc1->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
pChainMemberIfc2->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 2ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, ChainInterfaceMapBaseMemberPointer)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IChainMapMemberPointerInterface1* pChainMemberIfc1 = ptrHelper.GetInterface<IChainMapMemberPointerInterface1>();
|
||||
IChainMapMemberPointerInterface2* pChainMemberIfc2 = ptrHelper.GetInterface<IChainMapMemberPointerInterface2>();
|
||||
ASSERT_NE(pChainMemberIfc1, nullptr);
|
||||
ASSERT_NE(pChainMemberIfc2, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pChainMemberIfc1->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
pChainMemberIfc2->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 2ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, ChainInterfaceMapBaseMemberSharedPointer)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IChainMapMemberSharedPointerInterface1* pChainMemberIfc1 = ptrHelper.GetInterface<IChainMapMemberSharedPointerInterface1>();
|
||||
IChainMapMemberSharedPointerInterface2* pChainMemberIfc2 = ptrHelper.GetInterface<IChainMapMemberSharedPointerInterface2>();
|
||||
ASSERT_NE(pChainMemberIfc1, nullptr);
|
||||
ASSERT_NE(pChainMemberIfc2, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pChainMemberIfc1->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
pChainMemberIfc2->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 2ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, ChainInterfaceMapBaseMemberWeakPointer)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IChainMapMemberWeakPointerInterface1* pChainMemberIfc1 = ptrHelper.GetInterface<IChainMapMemberWeakPointerInterface1>();
|
||||
IChainMapMemberWeakPointerInterface2* pChainMemberIfc2 = ptrHelper.GetInterface<IChainMapMemberWeakPointerInterface2>();
|
||||
ASSERT_NE(pChainMemberIfc1, nullptr);
|
||||
ASSERT_NE(pChainMemberIfc2, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pChainMemberIfc1->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
pChainMemberIfc2->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 2ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, ConditionalInterface)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
IConditionInterface* pIfc = ptrHelper.GetInterface<IConditionInterface>();
|
||||
EXPECT_EQ(pIfc, nullptr);
|
||||
|
||||
helper.SetCondition(true);
|
||||
pIfc = ptrHelper.GetInterface<IConditionInterface>();
|
||||
ASSERT_NE(pIfc, nullptr);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 0ul);
|
||||
pIfc->Test();
|
||||
EXPECT_EQ(helper.GetTestCallCount(), 1ul);
|
||||
}
|
||||
|
||||
TEST(Interface_Map_Test, SectionTest)
|
||||
{
|
||||
CInterfaceMapHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrHelper = &helper;
|
||||
ASSERT_TRUE(ptrHelper);
|
||||
|
||||
// Check for the interfaces
|
||||
auto fnCheck = [&](bool bExpectMain1, bool bExpectMain2, bool bExpectSection0, bool bExpectSection1, bool bExpectSection2, size_t nExpectCnt)
|
||||
{
|
||||
size_t nTemp = helper.GetTestCallCount();
|
||||
IMainSectionInterface1* pMain1 = ptrHelper.GetInterface<IMainSectionInterface1>();
|
||||
if (pMain1)
|
||||
{
|
||||
EXPECT_TRUE(bExpectMain1);
|
||||
pMain1->Test();
|
||||
} else
|
||||
EXPECT_FALSE(bExpectMain1);
|
||||
|
||||
IMainSectionInterface2* pMain2 = ptrHelper.GetInterface<IMainSectionInterface2>();
|
||||
if (pMain2)
|
||||
{
|
||||
EXPECT_TRUE(bExpectMain2);
|
||||
pMain2->Test();
|
||||
} else
|
||||
EXPECT_FALSE(bExpectMain2);
|
||||
|
||||
ISection0Interface* pSection0 = ptrHelper.GetInterface<ISection0Interface>();
|
||||
if (pSection0)
|
||||
{
|
||||
EXPECT_TRUE(bExpectSection0);
|
||||
pSection0->Test();
|
||||
} else
|
||||
EXPECT_FALSE(bExpectSection0);
|
||||
|
||||
ISection1Interface* pSection1 = ptrHelper.GetInterface<ISection1Interface>();
|
||||
if (pSection1)
|
||||
{
|
||||
EXPECT_TRUE(bExpectSection1);
|
||||
pSection1->Test();
|
||||
} else
|
||||
EXPECT_FALSE(bExpectSection1);
|
||||
|
||||
ISection2Interface* pSection2 = ptrHelper.GetInterface<ISection2Interface>();
|
||||
if (pSection2)
|
||||
{
|
||||
EXPECT_TRUE(bExpectSection2);
|
||||
pSection2->Test();
|
||||
} else
|
||||
EXPECT_FALSE(bExpectSection2);
|
||||
|
||||
EXPECT_EQ(helper.GetTestCallCount(), nTemp + nExpectCnt);
|
||||
};
|
||||
|
||||
// Mains section (-1) is enabled
|
||||
fnCheck(true, true, false, false, false, 2);
|
||||
|
||||
// Enable section 0
|
||||
helper.SetSection(0);
|
||||
fnCheck(true, true, true, false, false, 3);
|
||||
|
||||
// Enable section 1
|
||||
helper.SetSection(1);
|
||||
fnCheck(true, true, false, true, true, 4);
|
||||
|
||||
// Enable section 2
|
||||
helper.SetSection(2);
|
||||
fnCheck(true, true, false, false, true, 3);
|
||||
|
||||
// Enable section 3
|
||||
helper.SetSection(3);
|
||||
fnCheck(true, true, false, false, false, 2);
|
||||
|
||||
// Enable main section
|
||||
helper.SetSection();
|
||||
fnCheck(true, true, false, false, false, 2);
|
||||
}
|
||||
|
||||
19
tests/unit_tests/smart_ifc/main.cpp
Normal file
19
tests/unit_tests/smart_ifc/main.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "../../../global/process_watchdog.h"
|
||||
#include "../../../global/localmemmgr.h"
|
||||
|
||||
/**
|
||||
* @brief Main function
|
||||
*/
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
extern "C" int wmain(int argc, wchar_t* argv[])
|
||||
#else
|
||||
extern "C" int main(int argc, char* argv[])
|
||||
#endif
|
||||
{
|
||||
CProcessWatchdog watchdog;
|
||||
|
||||
CLocalMemMgr memmgr;
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
720
tests/unit_tests/smart_ifc/smart_ifc.cpp
Normal file
720
tests/unit_tests/smart_ifc/smart_ifc.cpp
Normal file
@@ -0,0 +1,720 @@
|
||||
#include "../../include/gtest_custom.h"
|
||||
#include "generated/smart_ifc.h"
|
||||
#include <support/interface_ptr.h>
|
||||
|
||||
/**
|
||||
* @brief Helper class to test the smart pointer classes.
|
||||
*/
|
||||
class CSmartInterfaceHelper : public sdv::IInterfaceAccess, public IOther, public sdv::IObjectDestroy, public sdv::IObjectLifetime
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] bEnableObjectDestroy When set, the sdv::IObjectDestroy interface is exposed through the interface map.
|
||||
* @param[in] bEnableObjectRefCnt Object lifetime interface exposed through the interface map.
|
||||
*/
|
||||
CSmartInterfaceHelper(bool bEnableObjectDestroy = false, bool bEnableObjectRefCnt = false) :
|
||||
m_bEnableObjectDestroy(bEnableObjectDestroy), m_bEnableObjectRefCnt(bEnableObjectRefCnt)
|
||||
{}
|
||||
|
||||
// Interface map
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::IInterfaceAccess)
|
||||
SDV_INTERFACE_ENTRY(IOther)
|
||||
SDV_INTERFACE_SET_SECTION_CONDITION(m_bEnableObjectDestroy, 1)
|
||||
SDV_INTERFACE_SECTION(1)
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectDestroy)
|
||||
SDV_INTERFACE_DEFAULT_SECTION()
|
||||
SDV_INTERFACE_SET_SECTION_CONDITION(m_bEnableObjectRefCnt, 2)
|
||||
SDV_INTERFACE_SECTION(2)
|
||||
SDV_INTERFACE_ENTRY(sdv::IObjectLifetime)
|
||||
SDV_INTERFACE_DEFAULT_SECTION()
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
/**
|
||||
* @brief Destroy the object. Overload of sdv::IObjectDestroy::DestroyObject.
|
||||
* @attention After a call of this function, all exposed interfaces render invalid and should not be used any more.
|
||||
*/
|
||||
virtual void DestroyObject() override
|
||||
{
|
||||
if (m_bDestroyCalled) m_bDestroyCalledTooMany = true;
|
||||
m_bDestroyCalled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Increment the lifetime. Needs to be balanced by a call to Decrement. Overload of IObjectLifetime::Increment.
|
||||
*/
|
||||
virtual void Increment() override
|
||||
{
|
||||
m_iCounter++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decrement the lifetime. If the lifetime reaches zero, the object will be destroyed (through the exposed
|
||||
* IObjectDestroy interface). Overload of IObjectLifetime::Decrement.
|
||||
* @return Returns 'true' if the object was destroyed, false if not.
|
||||
*/
|
||||
virtual bool Decrement() override
|
||||
{
|
||||
m_iCounter--;
|
||||
if (!m_iCounter)
|
||||
{
|
||||
DestroyObject();
|
||||
return true;
|
||||
}
|
||||
if (m_iCounter < 0) m_bDecrementCalledTooMany = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current lifetime count. Overload of IObjectLifetime::GetCount.
|
||||
*/
|
||||
virtual uint32_t GetCount() const override
|
||||
{
|
||||
return static_cast<uint32_t>(m_iCounter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test function. Overload of IOther::Test.
|
||||
*/
|
||||
virtual void Test() override
|
||||
{
|
||||
m_bTest = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return whether destroy was called at least one time.
|
||||
* @return Returns the destroy-object-flag.
|
||||
*/
|
||||
bool IsDestroyCalled() const { return m_bDestroyCalled; }
|
||||
|
||||
/**
|
||||
* @brief Return when destroyed was called twice or more - which is an error.
|
||||
* @return Returns the destroy-object-too-many-times-flag.
|
||||
*/
|
||||
bool IsDestroyCalledTooManyTimes() const { return m_bDestroyCalledTooMany; }
|
||||
|
||||
/**
|
||||
* @brief Return when decrement was called too many times (more than increment) - which is an error.
|
||||
* @return Returns the decrement-object-too-many-times-flag.
|
||||
*/
|
||||
bool IsDecrementCalledTooManyTimes() const { return m_bDecrementCalledTooMany; }
|
||||
|
||||
/**
|
||||
* @brief Hast the test function been called?
|
||||
* @return The test function flag.
|
||||
*/
|
||||
bool TestCalled() const { return m_bTest; }
|
||||
|
||||
private:
|
||||
bool m_bEnableObjectDestroy = false; ///< When enabled, object destroy is exposed.
|
||||
bool m_bEnableObjectRefCnt = false; ///< When ebabled, object reference counting is exposed.
|
||||
bool m_bDestroyCalled = false; ///< Flag set when DestroyObject is called.
|
||||
bool m_bDestroyCalledTooMany = false; ///< Flag set when DestroyObject is called more than once.
|
||||
bool m_bDecrementCalledTooMany = false; ///< Flag set when Decrement is called more than Increment.
|
||||
bool m_bTest = false; ///< Flag set by the a call to the test function.
|
||||
int32_t m_iCounter = 0; ///< Object lifetime counter
|
||||
};
|
||||
|
||||
TEST(Smart_Interface_Test, IInterfaceAccess_Self)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::IInterfaceAccess* pAccess = &helper;
|
||||
ASSERT_NE(pAccess, nullptr);
|
||||
|
||||
sdv::interface_t tInterface = pAccess->GetInterface(sdv::GetInterfaceId<sdv::IInterfaceAccess>());
|
||||
EXPECT_TRUE(tInterface);
|
||||
EXPECT_EQ(tInterface.get<sdv::IInterfaceAccess>(), pAccess);
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, IInterfaceAccess_Other)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::IInterfaceAccess* pAccess = &helper;
|
||||
ASSERT_NE(pAccess, nullptr);
|
||||
|
||||
sdv::interface_t tInterface = pAccess->GetInterface(sdv::GetInterfaceId<IOther>());
|
||||
EXPECT_TRUE(tInterface);
|
||||
ASSERT_NE(tInterface.get<IOther>(), nullptr);
|
||||
EXPECT_EQ(tInterface.get<IOther>(), static_cast<IOther*>(&helper));
|
||||
EXPECT_EQ(tInterface.get<IOther>(), pAccess->GetInterface<IOther>());
|
||||
EXPECT_FALSE(helper.TestCalled());
|
||||
tInterface.get<IOther>()->Test();
|
||||
EXPECT_TRUE(helper.TestCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TInterfaceAccessPtr_Declaration)
|
||||
{
|
||||
sdv::TInterfaceAccessPtr ptrAccess;
|
||||
EXPECT_FALSE(ptrAccess);
|
||||
EXPECT_FALSE(ptrAccess.IsValid());
|
||||
EXPECT_EQ(static_cast<sdv::IInterfaceAccess*>(ptrAccess), nullptr);
|
||||
EXPECT_EQ(ptrAccess.GetInterface<sdv::IInterfaceAccess>(), nullptr);
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TInterfaceAccessPtr_AssignmentConstructor)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrAccess(&helper);
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
EXPECT_TRUE(ptrAccess.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrAccess), nullptr);
|
||||
ASSERT_NE(ptrAccess.GetInterface<IOther>(), nullptr);
|
||||
EXPECT_FALSE(helper.TestCalled());
|
||||
ptrAccess.GetInterface<IOther>()->Test();
|
||||
EXPECT_TRUE(helper.TestCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TInterfaceAccessPtr_CopyConstructor)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrInitial(&helper);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
sdv::TInterfaceAccessPtr ptrAccess(ptrInitial);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
EXPECT_TRUE(ptrAccess.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrAccess), nullptr);
|
||||
ASSERT_NE(ptrAccess.GetInterface<IOther>(), nullptr);
|
||||
EXPECT_FALSE(helper.TestCalled());
|
||||
ptrAccess.GetInterface<IOther>()->Test();
|
||||
EXPECT_TRUE(helper.TestCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TInterfaceAccessPtr_MoveConstructor)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrInitial(&helper);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
sdv::TInterfaceAccessPtr ptrAccess(std::move(ptrInitial));
|
||||
EXPECT_FALSE(ptrInitial);
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
EXPECT_TRUE(ptrAccess.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrAccess), nullptr);
|
||||
ASSERT_NE(ptrAccess.GetInterface<IOther>(), nullptr);
|
||||
EXPECT_FALSE(helper.TestCalled());
|
||||
ptrAccess.GetInterface<IOther>()->Test();
|
||||
EXPECT_TRUE(helper.TestCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TInterfaceAccessPtr_AssignmentOperator)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrAccess;
|
||||
EXPECT_FALSE(ptrAccess);
|
||||
ptrAccess = &helper;
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
EXPECT_TRUE(ptrAccess.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrAccess), nullptr);
|
||||
ASSERT_NE(ptrAccess.GetInterface<IOther>(), nullptr);
|
||||
EXPECT_FALSE(helper.TestCalled());
|
||||
ptrAccess.GetInterface<IOther>()->Test();
|
||||
EXPECT_TRUE(helper.TestCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TInterfaceAccessPtr_CopyOperator)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrInitial(&helper);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
sdv::TInterfaceAccessPtr ptrAccess;
|
||||
EXPECT_FALSE(ptrAccess);
|
||||
ptrAccess = ptrInitial;
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
EXPECT_TRUE(ptrAccess.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrAccess), nullptr);
|
||||
ASSERT_NE(ptrAccess.GetInterface<IOther>(), nullptr);
|
||||
EXPECT_FALSE(helper.TestCalled());
|
||||
ptrAccess.GetInterface<IOther>()->Test();
|
||||
EXPECT_TRUE(helper.TestCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TInterfaceAccessPtr_MoveOperator)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrInitial(&helper);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
sdv::TInterfaceAccessPtr ptrAccess;
|
||||
EXPECT_FALSE(ptrAccess);
|
||||
ptrAccess = std::move(ptrInitial);
|
||||
EXPECT_FALSE(ptrInitial);
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
EXPECT_TRUE(ptrAccess.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrAccess), nullptr);
|
||||
ASSERT_NE(ptrAccess.GetInterface<IOther>(), nullptr);
|
||||
EXPECT_FALSE(helper.TestCalled());
|
||||
ptrAccess.GetInterface<IOther>()->Test();
|
||||
EXPECT_TRUE(helper.TestCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, IObjectDestroy_NoInterface)
|
||||
{
|
||||
CSmartInterfaceHelper helper;
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrAccess(&helper);
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
|
||||
// Get interface
|
||||
sdv::IObjectDestroy* pObjectDestroy = ptrAccess.GetInterface<sdv::IObjectDestroy>();
|
||||
EXPECT_EQ(pObjectDestroy, nullptr);
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, IObjectDestroy)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrAccess(&helper);
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
|
||||
// Get interface
|
||||
sdv::IObjectDestroy* pObjectDestroy = ptrAccess.GetInterface<sdv::IObjectDestroy>();
|
||||
ASSERT_NE(pObjectDestroy, nullptr);
|
||||
|
||||
// Destroy the object
|
||||
pObjectDestroy->DestroyObject();
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Destroy the object (simulates illegal call to pObjectDestroy, which normally would be destroyed with the previous call).
|
||||
pObjectDestroy->DestroyObject();
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_TRUE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, IObjectLifetime)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true, true);
|
||||
|
||||
sdv::TInterfaceAccessPtr ptrAccess(&helper);
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
|
||||
// Get interface
|
||||
sdv::IObjectLifetime* pObjectLifetime = ptrAccess.GetInterface<sdv::IObjectLifetime>();
|
||||
ASSERT_NE(pObjectLifetime, nullptr);
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 0u);
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
|
||||
// Increment
|
||||
pObjectLifetime->Increment();
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 1u);
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
|
||||
// Increment
|
||||
pObjectLifetime->Increment();
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 2u);
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
|
||||
// Decrement
|
||||
pObjectLifetime->Decrement();
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 1u);
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
|
||||
// Decrement - this will destroy the object
|
||||
pObjectLifetime->Decrement();
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 0u);
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
|
||||
// Decrement - one too many
|
||||
pObjectLifetime->Decrement();
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), static_cast<uint32_t>(-1));
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_TRUE(helper.IsDecrementCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, ObjectLifetimeWrapper_CreateEmpty)
|
||||
{
|
||||
sdv::IInterfaceAccess* pObject = sdv::CObjectLifetimeWrapper::CreateWrapper(nullptr);
|
||||
EXPECT_EQ(pObject, nullptr);
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, ObjectLifetimeWrapper_Create)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
sdv::IInterfaceAccess* pObject = sdv::CObjectLifetimeWrapper::CreateWrapper(&helper);
|
||||
ASSERT_NE(pObject, nullptr);
|
||||
|
||||
// Helper class should not expose object lifetime
|
||||
sdv::IObjectLifetime* pObjectLifetime = sdv::CInterfacePtr(&helper).GetInterface<sdv::IObjectLifetime>();
|
||||
EXPECT_EQ(pObjectLifetime, nullptr);
|
||||
|
||||
// Wrapper should expose object lifetime interface
|
||||
pObjectLifetime = sdv::CInterfacePtr(pObject).GetInterface<sdv::IObjectLifetime>();
|
||||
ASSERT_NE(pObjectLifetime, nullptr);
|
||||
|
||||
// Helper class exposes IObjectDestroy
|
||||
sdv::IObjectDestroy* pObjectDestroy = sdv::CInterfacePtr(&helper).GetInterface<sdv::IObjectDestroy>();
|
||||
ASSERT_NE(pObjectDestroy, nullptr);
|
||||
|
||||
// Wrapper should also expose object destroy
|
||||
pObjectDestroy = sdv::CInterfacePtr(pObject).GetInterface<sdv::IObjectDestroy>();
|
||||
EXPECT_NE(pObjectDestroy, nullptr);
|
||||
|
||||
// Status quo
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 1u);
|
||||
|
||||
// Increment
|
||||
pObjectLifetime->Increment();
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 2u);
|
||||
|
||||
// Decrement
|
||||
pObjectLifetime->Decrement();
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 1u);
|
||||
|
||||
// Decrement
|
||||
pObjectLifetime->Decrement();
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, ObjectLifetimeWrapper_DestroyObject)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
sdv::IInterfaceAccess* pObject = sdv::CObjectLifetimeWrapper::CreateWrapper(&helper);
|
||||
ASSERT_NE(pObject, nullptr);
|
||||
|
||||
// Helper class should not expose object lifetime
|
||||
sdv::IObjectLifetime* pObjectLifetime = sdv::CInterfacePtr(&helper).GetInterface<sdv::IObjectLifetime>();
|
||||
EXPECT_EQ(pObjectLifetime, nullptr);
|
||||
|
||||
// Wrapper should expose object lifetime interface
|
||||
pObjectLifetime = sdv::CInterfacePtr(pObject).GetInterface<sdv::IObjectLifetime>();
|
||||
ASSERT_NE(pObjectLifetime, nullptr);
|
||||
|
||||
// Helper class exposes IObjectDestroy
|
||||
sdv::IObjectDestroy* pObjectDestroy = sdv::CInterfacePtr(&helper).GetInterface<sdv::IObjectDestroy>();
|
||||
ASSERT_NE(pObjectDestroy, nullptr);
|
||||
|
||||
// Wrapper should also expose object destroy
|
||||
pObjectDestroy = sdv::CInterfacePtr(pObject).GetInterface<sdv::IObjectDestroy>();
|
||||
EXPECT_NE(pObjectDestroy, nullptr);
|
||||
|
||||
// Status quo
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 1u);
|
||||
|
||||
// Increment
|
||||
pObjectLifetime->Increment();
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 2u);
|
||||
|
||||
// Call object destroy on the wrapper.
|
||||
pObjectDestroy->DestroyObject();
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
EXPECT_EQ(pObjectLifetime->GetCount(), 1u);
|
||||
|
||||
// Call object destroy on the wrapper.
|
||||
pObjectDestroy->DestroyObject();
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDecrementCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_Declaration)
|
||||
{
|
||||
sdv::TObjectPtr ptrObject;
|
||||
EXPECT_FALSE(ptrObject);
|
||||
EXPECT_FALSE(ptrObject.IsValid());
|
||||
EXPECT_EQ(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_EQ(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_AssignmentConstructor)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Use scope
|
||||
{
|
||||
sdv::TObjectPtr ptrObject(&helper);
|
||||
EXPECT_TRUE(ptrObject);
|
||||
EXPECT_TRUE(ptrObject.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_NE(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_CopyConstructor)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Use scope
|
||||
{
|
||||
sdv::TObjectPtr ptrInitial(&helper);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
sdv::TObjectPtr ptrObject(ptrInitial);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
EXPECT_TRUE(ptrObject);
|
||||
EXPECT_TRUE(ptrObject.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_NE(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_MoveConstructor)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Use scope
|
||||
{
|
||||
sdv::TObjectPtr ptrInitial(&helper);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
sdv::TObjectPtr ptrObject(std::move(ptrInitial));
|
||||
EXPECT_FALSE(ptrInitial);
|
||||
EXPECT_TRUE(ptrObject);
|
||||
EXPECT_TRUE(ptrObject.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_NE(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_AssignmentOperator)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Use scope
|
||||
{
|
||||
sdv::TObjectPtr ptrObject;
|
||||
EXPECT_FALSE(ptrObject);
|
||||
ptrObject = &helper;
|
||||
EXPECT_TRUE(ptrObject);
|
||||
EXPECT_TRUE(ptrObject.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_NE(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_CopyOperator)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Use scope
|
||||
{
|
||||
sdv::TObjectPtr ptrInitial(&helper);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
sdv::TObjectPtr ptrObject;
|
||||
EXPECT_FALSE(ptrObject);
|
||||
ptrObject = ptrInitial;
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
EXPECT_TRUE(ptrObject);
|
||||
EXPECT_TRUE(ptrObject.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_NE(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_MoveOperator)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Use scope
|
||||
{
|
||||
sdv::TObjectPtr ptrInitial(&helper);
|
||||
EXPECT_TRUE(ptrInitial);
|
||||
sdv::TObjectPtr ptrObject;
|
||||
EXPECT_FALSE(ptrObject);
|
||||
ptrObject = std::move(ptrInitial);
|
||||
EXPECT_FALSE(ptrInitial);
|
||||
EXPECT_TRUE(ptrObject);
|
||||
EXPECT_TRUE(ptrObject.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_NE(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_Clear)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Use scope
|
||||
{
|
||||
sdv::TObjectPtr ptrObject(&helper);
|
||||
EXPECT_TRUE(ptrObject);
|
||||
EXPECT_TRUE(ptrObject.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_NE(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
ptrObject.Clear();
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_Detach)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Use scope
|
||||
sdv::TInterfaceAccessPtr ptrAccess;
|
||||
{
|
||||
sdv::TObjectPtr ptrObject(&helper);
|
||||
EXPECT_TRUE(ptrObject);
|
||||
EXPECT_TRUE(ptrObject.IsValid());
|
||||
EXPECT_NE(static_cast<sdv::IInterfaceAccess*>(ptrObject), nullptr);
|
||||
EXPECT_NE(ptrObject.GetInterface<sdv::IObjectDestroy>(), nullptr);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
ptrAccess = ptrObject.Detach();
|
||||
EXPECT_TRUE(ptrAccess);
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
// Object is not destroyed yet
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
|
||||
// Explicitly destroy the object
|
||||
sdv::IObjectDestroy* pDestroy = ptrAccess.GetInterface<sdv::IObjectDestroy>();
|
||||
ASSERT_NE(pDestroy, nullptr);
|
||||
pDestroy->DestroyObject();
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_RefCnt)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
EXPECT_EQ(helper.GetCount(), 0u);
|
||||
|
||||
sdv::TObjectPtr ptrObject(&helper);
|
||||
EXPECT_EQ(helper.GetCount(), 0u); // Not exposed by helper and therefore not used
|
||||
|
||||
sdv::IObjectLifetime* pLifetime = ptrObject.GetInterface<sdv::IObjectLifetime>();
|
||||
ASSERT_NE(pLifetime, nullptr);
|
||||
EXPECT_EQ(pLifetime->GetCount(), 1u);
|
||||
|
||||
ptrObject.Clear();
|
||||
EXPECT_EQ(helper.GetCount(), 0u);
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_RefCntTransfer)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
EXPECT_EQ(helper.GetCount(), 0u);
|
||||
|
||||
sdv::TObjectPtr ptrObject(&helper);
|
||||
EXPECT_EQ(helper.GetCount(), 0u); // Not exposed by helper and therefore not used
|
||||
|
||||
sdv::IObjectLifetime* pLifetime = ptrObject.GetInterface<sdv::IObjectLifetime>();
|
||||
ASSERT_NE(pLifetime, nullptr);
|
||||
EXPECT_EQ(pLifetime->GetCount(), 1u);
|
||||
|
||||
sdv::TObjectPtr ptrObject2(static_cast<sdv::IInterfaceAccess*>(ptrObject));
|
||||
EXPECT_EQ(helper.GetCount(), 0u); // Not exposed by helper and therefore not used
|
||||
ASSERT_NE(pLifetime, nullptr);
|
||||
EXPECT_EQ(pLifetime->GetCount(), 2u);
|
||||
|
||||
ptrObject.Clear();
|
||||
EXPECT_EQ(pLifetime->GetCount(), 1u);
|
||||
EXPECT_EQ(helper.GetCount(), 0u);
|
||||
|
||||
ptrObject2.Clear();
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
}
|
||||
|
||||
TEST(Smart_Interface_Test, TObjectPtr_RefCntObject)
|
||||
{
|
||||
CSmartInterfaceHelper helper(true, true);
|
||||
|
||||
EXPECT_FALSE(helper.IsDestroyCalled());
|
||||
EXPECT_FALSE(helper.IsDestroyCalledTooManyTimes());
|
||||
EXPECT_EQ(helper.GetCount(), 0u);
|
||||
|
||||
sdv::TObjectPtr ptrObject(&helper);
|
||||
EXPECT_EQ(helper.GetCount(), 1u);
|
||||
|
||||
sdv::IObjectLifetime* pLifetime = ptrObject.GetInterface<sdv::IObjectLifetime>();
|
||||
ASSERT_NE(pLifetime, nullptr);
|
||||
EXPECT_EQ(pLifetime->GetCount(), 1u);
|
||||
|
||||
sdv::TObjectPtr ptrObject2(static_cast<sdv::IInterfaceAccess*>(ptrObject));
|
||||
EXPECT_EQ(helper.GetCount(), 2u);
|
||||
ASSERT_NE(pLifetime, nullptr);
|
||||
EXPECT_EQ(pLifetime->GetCount(), 2u);
|
||||
|
||||
ptrObject.Clear();
|
||||
EXPECT_EQ(pLifetime->GetCount(), 1u);
|
||||
EXPECT_EQ(helper.GetCount(), 1u);
|
||||
|
||||
ptrObject2.Clear();
|
||||
EXPECT_TRUE(helper.IsDestroyCalled());
|
||||
EXPECT_EQ(helper.GetCount(), 0u);
|
||||
}
|
||||
344
tests/unit_tests/smart_ifc/smart_ifc.idl
Normal file
344
tests/unit_tests/smart_ifc/smart_ifc.idl
Normal file
@@ -0,0 +1,344 @@
|
||||
#include <interfaces/core.idl>
|
||||
|
||||
/**
|
||||
* @brief Other interface (test for sdv::TInterfaceAccessPtr and sdv::TObjectPtr).
|
||||
*/
|
||||
interface IOther
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Module to test namespaces.
|
||||
*/
|
||||
module NamespaceTest1
|
||||
{
|
||||
/**
|
||||
* @brief Interface in first namespace.
|
||||
*/
|
||||
interface INamespaceIfc1
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Module to test namespaces.
|
||||
*/
|
||||
module NamespaceTest2
|
||||
{
|
||||
/**
|
||||
* @brief Interface in first namespace.
|
||||
*/
|
||||
interface INamespaceIfc2
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for member testing
|
||||
*/
|
||||
interface IMember
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for member testing
|
||||
*/
|
||||
interface IMemberPointerEmpty
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for member testing
|
||||
*/
|
||||
interface IMemberPointer
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for member testing
|
||||
*/
|
||||
interface IMemberSharedPointerEmpty
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for member testing
|
||||
*/
|
||||
interface IMemberSharedPointer
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for member testing
|
||||
*/
|
||||
interface IMemberWeakPointerEmpty
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for member testing
|
||||
*/
|
||||
interface IMemberWeakPointer
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for ambiguity testing.
|
||||
*/
|
||||
interface IAmbiguousInterface
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for denial testing.
|
||||
*/
|
||||
interface IDeniedInterface
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map base class testing.
|
||||
*/
|
||||
interface IBaseInterface1
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map base class testing.
|
||||
*/
|
||||
interface IBaseInterface2
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map member class testing.
|
||||
*/
|
||||
interface IChainMapMemberInterface1
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map base class testing.
|
||||
*/
|
||||
interface IChainMapMemberInterface2
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map member class testing.
|
||||
*/
|
||||
interface IChainMapMemberSmartPointerInterface1
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map base class testing.
|
||||
*/
|
||||
interface IChainMapMemberSmartPointerInterface2
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map member class testing.
|
||||
*/
|
||||
interface IChainMapMemberPointerInterface1
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map base class testing.
|
||||
*/
|
||||
interface IChainMapMemberPointerInterface2
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map member class testing.
|
||||
*/
|
||||
interface IChainMapMemberSharedPointerInterface1
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map base class testing.
|
||||
*/
|
||||
interface IChainMapMemberSharedPointerInterface2
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map member class testing.
|
||||
*/
|
||||
interface IChainMapMemberWeakPointerInterface1
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for chain map base class testing.
|
||||
*/
|
||||
interface IChainMapMemberWeakPointerInterface2
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for condition testing.
|
||||
*/
|
||||
interface IConditionInterface
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for section testing.
|
||||
*/
|
||||
interface IMainSectionInterface1
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for section testing.
|
||||
*/
|
||||
interface IMainSectionInterface2
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for section testing.
|
||||
*/
|
||||
interface ISection0Interface
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for section testing.
|
||||
*/
|
||||
interface ISection1Interface
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface for section testing.
|
||||
*/
|
||||
interface ISection2Interface
|
||||
{
|
||||
/**
|
||||
* @brief Test function.
|
||||
*/
|
||||
void Test();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user