mxmlparser_test.cpp

来自「跨平台C++基础库」· C++ 代码 · 共 79 行

CPP
79
字号

#include "MXMLParser_test.h"
#include "../ENV_test.h"

#include "MCRT/MXMLTree.h"
#include "MCRT/MXMLNode.h"

#include "MCRT/mcommon.h"

// register the fixture into registry
CPPUNIT_TEST_SUITE_REGISTRATION( MXMLParserTest );//register test class in cppunit

void MXMLParserTest::setUp()
{
}

void MXMLParserTest::tearDown()
{
}

void MXMLParserTest::testLoad()
{
    std::string strFilePath =   g_ENVTest.getProjectRoot();
    strFilePath.append( "/test_data/MCRT/MXML_test.xml" );

    MXMLTree    xmlTree;
    xmlTree.Load( strFilePath.c_str() );

    CPPUNIT_ASSERT( xmlTree.m_pDoc != NULL );
}

void MXMLParserTest::testGetRootNode()
{
    std::string strFilePath =   g_ENVTest.getProjectRoot();
    strFilePath.append( "/test_data/MCRT/MXML_test.xml" );

    MXMLTree    xmlTree;
    xmlTree.Load( strFilePath.c_str() );

    MXMLNode    rootNode    =   xmlTree.GetRootNode();

    const char* pRootNodeName   =   rootNode.GetName();
    CPPUNIT_ASSERT( pRootNodeName != NULL );
    if ( pRootNodeName != NULL )
    {
        CPPUNIT_ASSERT( ::strcmp( pRootNodeName, "MenuItem" ) == 0 );
    }
}

void MXMLParserTest::testNodeValue()
{
    std::string strFilePath =   g_ENVTest.getProjectRoot();
    strFilePath.append( "/test_data/MCRT/MXML_test.xml" );

    MXMLTree    xmlTree;
    xmlTree.Load( strFilePath.c_str() );

    MXMLNode    nodeNullValue   =   xmlTree.GetRootNode();

    const char* pNodeValue  =   nodeNullValue.GetValue();
    CPPUNIT_ASSERT( pNodeValue == NULL );
}

void MXMLParserTest::testNodeAttr()
{
    std::string strFilePath =   g_ENVTest.getProjectRoot();
    strFilePath.append( "/test_data/MCRT/MXML_test.xml" );

    MXMLTree    xmlTree;
    xmlTree.Load( strFilePath.c_str() );

    MXMLNode    attrNode    =   xmlTree.GetNode( "/MenuItem/File/File_New" );

    CPPUNIT_ASSERT( ::strcmp( attrNode.GetAttr( "strAttr" ), "File_New_str" ) == 0 );
    CPPUNIT_ASSERT( attrNode.GetIntAttr( "intAttr" ) == 1 );
    CPPUNIT_ASSERT( MCommon::IsEqual( attrNode.GetDoubleAttr( "doubleAttr" ), 3.3 ) );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?