Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv30424/src/rftaparser
Added Files:
CPPParserTest.cpp CPPParserTest.h
Log Message:
* added
--- NEW FILE: CPPParserTest.cpp ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/04/29
// //////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CPPParserTest.h"
#include <rfta/parser/CPPParser.h>
namespace Refactoring
{
CPPUNIT_TEST_SUITE_REGISTRATION( CPPParserTest );
CPPParserTest::CPPParserTest()
: functionKey_( "Function" )
, selectionKey_( "Selection" )
{
}
CPPParserTest::~CPPParserTest()
{
}
void
CPPParserTest::setUp()
{
}
void
CPPParserTest::tearDown()
{
}
void
CPPParserTest::checkParseFunctionAt( const Testing::KeyedString &source )
{
CPPParser parser( source );
int selectionIndex = source.getKeyedIndex( selectionKey_, 0 );
ASTNodePtr functionNode = parser.parseForFunctionBodyAt( selectionIndex );
CPPUNIT_ASSERT_MESSAGE( "Failed to find function implementation node", functionNode );
CPPUNIT_ASSERT( functionNode->getRange().contains( SourceRange( selectionIndex, 0 ) ) );
CPPUNIT_ASSERT( functionNode->getRange() == source.getKeyedRange( functionKey_, 0 ) );
}
void
CPPParserTest::addFunctionImplementation( Testing::KeyedString &source )
{
source.setKeyStart( functionKey_ );
source << "int function() {\n";
source << "return ";
source.addKeyed( selectionKey_, "10" );
source << ";\n}";
source.setKeyEnd( functionKey_ );
}
void
CPPParserTest::testParseFunction()
{
Testing::KeyedString source;
source << "// source\n";
addFunctionImplementation( source );
source << " ";
checkParseFunctionAt( source );
}
void
CPPParserTest::testParseFunctionInNamespace()
{
Testing::KeyedString source;
source << "// source\n"
<< "namespace Source {";
addFunctionImplementation( source );
source << " } // namespace Source ";
checkParseFunctionAt( source );
}
void
CPPParserTest::testParseFunctionInNestedNamespace()
{
Testing::KeyedString source;
source << "// source\n"
<< "namespace Source {\n"
<< "namespace Nested { ";
addFunctionImplementation( source );
source << " } // namespace Nested\n";
source << " } // namespace Source\n";
checkParseFunctionAt( source );
}
void
CPPParserTest::testParseFunctionInClassDeclaration()
{
}
} // namespace Refactoring
--- NEW FILE: CPPParserTest.h ---
// //////////////////////////////////////////////////////////////////////////
// (c)Copyright 2002, Baptiste Lepilleur.
// Created: 2003/04/29
// //////////////////////////////////////////////////////////////////////////
#ifndef RFTA_CPPPARSERTEST_H
#define RFTA_CPPPARSERTEST_H
#include "UnitTesting.h"
#include "KeyedString.h"
namespace Refactoring
{
/// Unit tests for CPPParserTest
class CPPParserTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( CPPParserTest );
CPPUNIT_TEST( testParseFunction );
CPPUNIT_TEST( testParseFunctionInNamespace );
CPPUNIT_TEST( testParseFunctionInNestedNamespace );
CPPUNIT_TEST( testParseFunctionInClassDeclaration );
CPPUNIT_TEST_SUITE_END();
public:
/*! Constructs a CPPParserTest object.
*/
CPPParserTest();
/// Destructor.
virtual ~CPPParserTest();
void setUp();
void tearDown();
void testParseFunction();
void testParseFunctionInNamespace();
void testParseFunctionInNestedNamespace();
void testParseFunctionInClassDeclaration();
private:
void checkParseFunctionAt( const Testing::KeyedString &source );
void addFunctionImplementation( Testing::KeyedString &source );
const std::string functionKey_;
const std::string selectionKey_;
};
// Inlines methods for CPPParserTest:
// ----------------------------------
} // namespace Refactoring
#endif // RFTA_CPPPARSERTEST_H
|