77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
#include <ebcl/SyntaxTree.hh>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
using namespace ebcl;
|
|
|
|
class SyntaxTreeTest : public CppUnit::TestFixture
|
|
{
|
|
CPPUNIT_TEST_SUITE( SyntaxTreeTest );
|
|
CPPUNIT_TEST( testEmpty );
|
|
CPPUNIT_TEST( testSetData );
|
|
CPPUNIT_TEST( testUpdateData );
|
|
CPPUNIT_TEST( testAddChildren );
|
|
CPPUNIT_TEST_SUITE_END( );
|
|
|
|
public:
|
|
void testEmpty( );
|
|
void testSetData( );
|
|
void testUpdateData( );
|
|
void testAddChildren( );
|
|
};
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SyntaxTreeTest );
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
enum class E_TestNode_
|
|
{
|
|
ROOT ,
|
|
ADD ,
|
|
VALUE
|
|
};
|
|
|
|
using T_Test_ = T_SyntaxTree< E_TestNode_ >;
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
void SyntaxTreeTest::testEmpty( )
|
|
{
|
|
T_Test_ st{ E_TestNode_::ROOT };
|
|
CPPUNIT_ASSERT( E_TestNode_::ROOT == st.typeOf( 0 ) );
|
|
CPPUNIT_ASSERT( st.childrenOf( 0 ).empty( ) );
|
|
CPPUNIT_ASSERT_EQUAL( 0u , st.parentOf( 0 ) );
|
|
CPPUNIT_ASSERT( !st.hasData( 0 ) );
|
|
}
|
|
|
|
void SyntaxTreeTest::testSetData( )
|
|
{
|
|
T_Test_ st{ E_TestNode_::ROOT };
|
|
CPPUNIT_ASSERT( E_TestNode_::ROOT == st.typeOf( 0 ) );
|
|
CPPUNIT_ASSERT( !st.hasData( 0 ) );
|
|
CPPUNIT_ASSERT_EQUAL( 12u , st.newData< uint32_t >( 0 , 12 ) );
|
|
CPPUNIT_ASSERT( st.hasData( 0 ) );
|
|
CPPUNIT_ASSERT_EQUAL( 12u , st.dataOf< uint32_t>( 0 ) );
|
|
}
|
|
|
|
void SyntaxTreeTest::testUpdateData( )
|
|
{
|
|
T_Test_ st{ E_TestNode_::ROOT };
|
|
st.newData< uint32_t >( 0 , 12 );
|
|
st.dataOf< uint32_t>( 0 ) = 42u;
|
|
CPPUNIT_ASSERT_EQUAL( 42u , st.dataOf< uint32_t>( 0 ) );
|
|
}
|
|
|
|
void SyntaxTreeTest::testAddChildren( )
|
|
{
|
|
T_Test_ st{ E_TestNode_::ROOT };
|
|
const auto rc{ st.addChild( 0 , E_TestNode_::ADD ) };
|
|
CPPUNIT_ASSERT_EQUAL( 1u , rc );
|
|
CPPUNIT_ASSERT_EQUAL( 1u , st.childrenOf( 0 ).size( ) );
|
|
CPPUNIT_ASSERT_EQUAL( rc , st.childrenOf( 0 )[ 0 ] );
|
|
CPPUNIT_ASSERT_EQUAL( 0u , st.parentOf( rc ) );
|
|
CPPUNIT_ASSERT( E_TestNode_::ADD == st.typeOf( rc ) );
|
|
|
|
const auto cc{ st.addChild( rc , E_TestNode_::VALUE ) };
|
|
CPPUNIT_ASSERT_EQUAL( 2u , cc );
|
|
CPPUNIT_ASSERT_EQUAL( 1u , st.childrenOf( rc ).size( ) );
|
|
CPPUNIT_ASSERT_EQUAL( cc , st.childrenOf( rc )[ 0 ] );
|
|
CPPUNIT_ASSERT( E_TestNode_::VALUE == st.typeOf( cc ) );
|
|
}
|