|
From: <net...@us...> - 2003-04-28 20:38:32
|
Update of /cvsroot/cpptool/rfta/src/rftaparser
In directory sc8-pr-cvs1:/tmp/cvs-serv25925/src/rftaparser
Modified Files:
UnparsedDeclarationListMutatorTest.h
UnparsedDeclarationListMutatorTest.cpp
Log Message:
-- additional test for class body declaration list parsing
Index: UnparsedDeclarationListMutatorTest.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/UnparsedDeclarationListMutatorTest.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** UnparsedDeclarationListMutatorTest.h 15 Apr 2003 19:04:20 -0000 1.1
--- UnparsedDeclarationListMutatorTest.h 28 Apr 2003 20:38:27 -0000 1.2
***************
*** 19,22 ****
--- 19,23 ----
CPPUNIT_TEST_SUITE( UnparsedDeclarationListMutatorTest );
CPPUNIT_TEST( testMutate );
+ CPPUNIT_TEST( testClassParse );
CPPUNIT_TEST_SUITE_END();
***************
*** 33,36 ****
--- 34,38 ----
void testMutate();
+ void testClassParse();
private:
Index: UnparsedDeclarationListMutatorTest.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftaparser/UnparsedDeclarationListMutatorTest.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** UnparsedDeclarationListMutatorTest.cpp 15 Apr 2003 19:04:20 -0000 1.1
--- UnparsedDeclarationListMutatorTest.cpp 28 Apr 2003 20:38:28 -0000 1.2
***************
*** 7,11 ****
--- 7,14 ----
#include "stdafx.h"
#include "UnparsedDeclarationListMutator.h"
+ #include "UnparsedDeclarationMutator.h"
#include "NamespaceParser.h"
+ #include "KeyedString.h"
+ #include <rfta/parser/DeclarationParser.h>
#include "UnparsedDeclarationListMutatorTest.h"
#include <rfta/parser/ASTNode.h>
***************
*** 78,81 ****
--- 81,164 ----
29);
RFTA_ASSERT_EQUAL( 2, namespaceNode->getProperty(ASTNodeProperties::namespaceBodyProperty)->getChildCount() );
+
+ }
+
+ void
+ UnparsedDeclarationListMutatorTest::testClassParse()
+ {
+ /* precreate a AST with a unparsed declaration list: */
+
+ Testing::KeyedString source;
+ source << "class y {";
+ source.setKeyStart("CLASS-BODY") << " ";
+ source.addKeyed("MEMBER", "int x;") << " ";
+ source << "public: ";
+ source.addKeyed("MEMBER", "virtual int func(int) = 0;") << " ";
+ source << "private: ";
+ source.addKeyed("MEMBER", "int fc2() { return 0; }") << " ";
+ source << "protected: signal:";
+ source.setKeyEnd("CLASS-BODY");
+ source << "};";
+
+ SourceASTNodePtr sourceNode = SourceASTNode::create( source, source );
+
+ // parse declaration:
+ ParseContext context(sourceNode);
+ DeclarationParser parser(context, sourceNode->getBlankedSourceStart(), sourceNode->getBlankedSourceEnd());
+ parser.tryParse();
+
+ // mutate declaration:
+ ASTNodePtr classNode = sourceNode->getChildAt(0);
+
+ // do variable declaration parsing
+ UnparsedDeclarationMutator mutator( context,
+ classNode,
+ sourceNode );
+
+ CppUnit::Message message( "mutator failed",
+ "Source:\n" + source.asString() );
+ CppUnit::Asserter::failIf( !mutator.tryMutate(), message, CPPUNIT_SOURCELINE() );
+
+
+ // check precondition for test:
+ RFTA_ASSERT_NODE_PROPERTY_HAS( classNode,
+ ASTNodeProperties::declarationSpecifiersProperty,
+ ASTNodeTypes::declarationSpecifierList,
+ 0,
+ source.length()-1 );
+
+ ASTNodePtr specifierList = classNode->getProperty(ASTNodeProperties::declarationSpecifiersProperty);
+ ASTNodePtr classSpecifier = specifierList->getChildAt(0);
+
+ RFTA_ASSERT_NODE_PROPERTY_HAS( classSpecifier,
+ ASTNodeProperties::classBodyProperty,
+ ASTNodeTypes::unparsedDeclarationList,
+ source.getKeyedIndex("CLASS-BODY",0),
+ source.getKeyedLen("CLASS-BODY",0) );
+
+ ASTNodePtr classBody = classSpecifier->getProperty( ASTNodeProperties::classBodyProperty );
+
+ // execute mutator test:
+ UnparsedDeclarationListMutator listmutator;
+ listmutator.mutate( classBody, sourceNode );
+
+ // check parsing results:
+ // check post condition:
+ RFTA_ASSERT_NODE_TYPE( classBody, ASTNodeTypes::declarationList );
+ RFTA_ASSERT_EQUAL( 3, classBody->getChildCount() );
+
+ RFTA_ASSERT_NODE_HAS( classBody->getChildAt(0),
+ ASTNodeTypes::unparsedDeclaration,
+ source.getKeyedIndex("MEMBER",0),
+ source.getKeyedLen("MEMBER",0) );
+ RFTA_ASSERT_NODE_HAS( classBody->getChildAt(1),
+ ASTNodeTypes::unparsedDeclaration,
+ source.getKeyedIndex("MEMBER",1),
+ source.getKeyedLen("MEMBER",1) );
+ RFTA_ASSERT_NODE_HAS( classBody->getChildAt(2),
+ ASTNodeTypes::functionImplementation,
+ source.getKeyedIndex("MEMBER",2),
+ source.getKeyedLen("MEMBER",2) );
+
}
|