00001 /*============================================================================== 00002 * FILE: ProgTest.cc 00003 * OVERVIEW: Provides the implementation for the ProgTest class, which 00004 * tests the Exp and derived classes 00005 *============================================================================*/ 00006 /* 00007 * $Revision: 1.9 $ 00008 * 00009 * 18 Apr 02 - Mike: Created 00010 * 18 Jul 02 - Mike: Set up prog.pFE before calling readLibParams 00011 */ 00012 00013 #define HELLO_PENTIUM "test/pentium/hello" 00014 00015 #include "ProgTest.h" 00016 #include "BinaryFile.h" 00017 #include "pentiumfrontend.h" 00018 #include <map> 00019 #include <sstream> 00020 00021 /*============================================================================== 00022 * FUNCTION: ProgTest::registerTests 00023 * OVERVIEW: Register the test functions in the given suite 00024 * PARAMETERS: Pointer to the test suite 00025 * RETURNS: <nothing> 00026 *============================================================================*/ 00027 #define MYTEST(name) \ 00028 suite->addTest(new CppUnit::TestCaller<ProgTest> ("ProgTest", \ 00029 &ProgTest::name, *this)) 00030 00031 void ProgTest::registerTests(CppUnit::TestSuite* suite) { 00032 MYTEST(testName); 00033 } 00034 00035 int ProgTest::countTestCases () const 00036 { return 2; } // ? What's this for? 00037 00038 /*============================================================================== 00039 * FUNCTION: ProgTest::setUp 00040 * OVERVIEW: Set up some expressions for use with all the tests 00041 * NOTE: Called before any tests 00042 * PARAMETERS: <none> 00043 * RETURNS: <nothing> 00044 *============================================================================*/ 00045 void ProgTest::setUp () { 00046 //prog.setName("default name"); 00047 } 00048 00049 /*============================================================================== 00050 * FUNCTION: ProgTest::tearDown 00051 * OVERVIEW: Delete expressions created in setUp 00052 * NOTE: Called after all tests 00053 * PARAMETERS: <none> 00054 * RETURNS: <nothing> 00055 *============================================================================*/ 00056 void ProgTest::tearDown () { 00057 } 00058 00059 /*============================================================================== 00060 * FUNCTION: ProgTest::testName 00061 * OVERVIEW: Test setting and reading name 00062 *============================================================================*/ 00063 void ProgTest::testName () { 00064 BinaryFileFactory bff; 00065 BinaryFile *pBF = bff.Load(HELLO_PENTIUM); // Don't actually use it 00066 Prog* prog = new Prog(); 00067 FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff); 00068 // We need a Prog object with a pBF (for getEarlyParamExp()) 00069 prog->setFrontEnd(pFE); 00070 std::string actual(prog->getName()); 00071 std::string expected(HELLO_PENTIUM); 00072 CPPUNIT_ASSERT_EQUAL(expected, actual); 00073 std::string name("Happy prog"); 00074 prog->setName(name.c_str()); 00075 actual = prog->getName(); 00076 CPPUNIT_ASSERT_EQUAL(name, actual); 00077 delete pFE; 00078 } 00079 00080 // Pathetic: the second test we had (for readLibraryParams) is now obsolete; 00081 // the front end does this now.