ParserTest.cpp

Go to the documentation of this file.
00001 /*==============================================================================
00002  * FILE:       ParserTest.cc
00003  * OVERVIEW:   Provides the implementation for the ParserTest class, which
00004  *              tests the sslparser.y etc
00005  *============================================================================*/
00006 /*
00007  * $Revision: 1.7 $
00008  *
00009  * 13 May 02 - Mike: Created
00010  */
00011 
00012 #define SPARC_SSL       "frontend/machine/sparc/sparc.ssl"
00013 
00014 #include "ParserTest.h"
00015 #include "sslparser.h"
00016 
00017 #include <sstream>
00018 
00019 /*==============================================================================
00020  * FUNCTION:        ParserTest::registerTests
00021  * OVERVIEW:        Register the test functions in the given suite
00022  * PARAMETERS:      Pointer to the test suite
00023  * RETURNS:         <nothing>
00024  *============================================================================*/
00025 #define MYTEST(name) \
00026 suite->addTest(new CppUnit::TestCaller<ParserTest> ("ParserTest", \
00027     &ParserTest::name, *this))
00028 
00029 void ParserTest::registerTests(CppUnit::TestSuite* suite) {
00030     MYTEST(testRead);
00031     MYTEST(testExp);
00032 }
00033 
00034 int ParserTest::countTestCases () const
00035 { return 2; }   // ? What's this for?
00036 
00037 /*==============================================================================
00038  * FUNCTION:        ParserTest::setUp
00039  * OVERVIEW:        Set up some expressions for use with all the tests
00040  * NOTE:            Called before any tests
00041  * PARAMETERS:      <none>
00042  * RETURNS:         <nothing>
00043  *============================================================================*/
00044 void ParserTest::setUp () {
00045 }
00046 
00047 /*==============================================================================
00048  * FUNCTION:        ParserTest::tearDown
00049  * OVERVIEW:        Delete expressions created in setUp
00050  * NOTE:            Called after all tests
00051  * PARAMETERS:      <none>
00052  * RETURNS:         <nothing>
00053  *============================================================================*/
00054 void ParserTest::tearDown () {
00055 }
00056 
00057 /*==============================================================================
00058  * FUNCTION:        ParserTest::testRead
00059  * OVERVIEW:        Test reading the SSL file
00060  *============================================================================*/
00061 void ParserTest::testRead () {
00062     RTLInstDict d;
00063     CPPUNIT_ASSERT(d.readSSLFile(SPARC_SSL));
00064 }
00065 
00066 /*==============================================================================
00067  * FUNCTION:        ParserTest::testExp
00068  * OVERVIEW:        Test parsing an expression
00069  *============================================================================*/
00070 void ParserTest::testExp () {
00071     std::string s("*i32* r0 := 5 + 6");
00072     Statement *a = SSLParser::parseExp(s.c_str());
00073     CPPUNIT_ASSERT(a);
00074     std::ostringstream ost;
00075     a->print(ost);
00076     CPPUNIT_ASSERT_EQUAL ("   0 "+s, std::string(ost.str()));
00077     std::string s2 = "*i32* r[0] := 5 + 6";
00078     a = SSLParser::parseExp(s2.c_str());
00079     CPPUNIT_ASSERT(a);
00080     std::ostringstream ost2;
00081     a->print(ost2);
00082     // Still should print to string s, not s2
00083     CPPUNIT_ASSERT_EQUAL ("   0 "+s, std::string(ost2.str()));
00084 }
00085 

Generated on Tue Sep 19 21:18:25 2006 for Boomerang by  doxygen 1.4.6