ProcTest.cpp

Go to the documentation of this file.
00001 /*==============================================================================
00002  * FILE:       ProcTest.cc
00003  * OVERVIEW:   Provides the implementation for the ProcTest class, which
00004  *              tests the Proc class
00005  *============================================================================*/
00006 /*
00007  * $Revision: 1.10 $
00008  *
00009  * 23 Apr 02 - Mike: Created
00010  * 10 Mar 03 - Mike: Mods to not use Prog::pBF (no longer public)
00011  */
00012 
00013 #define HELLO_PENTIUM       "test/pentium/hello"
00014 
00015 #include "ProcTest.h"
00016 #include "BinaryFile.h"
00017 #include "BinaryFileStub.h"
00018 #include "pentiumfrontend.h"
00019 
00020 #include <sstream>
00021 #include <map>
00022 
00023 /*==============================================================================
00024  * FUNCTION:        ProcTest::registerTests
00025  * OVERVIEW:        Register the test functions in the given suite
00026  * PARAMETERS:      Pointer to the test suite
00027  * RETURNS:         <nothing>
00028  *============================================================================*/
00029 #define MYTEST(name) \
00030 suite->addTest(new CppUnit::TestCaller<ProcTest> ("testProc", \
00031     &ProcTest::name, *this))
00032 
00033 void ProcTest::registerTests(CppUnit::TestSuite* suite) {
00034 
00035     MYTEST(testName);
00036 }
00037 
00038 int ProcTest::countTestCases () const
00039 { return 2; }   // ? What's this for?
00040 
00041 /*==============================================================================
00042  * FUNCTION:        ProcTest::setUp
00043  * OVERVIEW:        Set up some expressions for use with all the tests
00044  * NOTE:            Called before any tests
00045  * PARAMETERS:      <none>
00046  * RETURNS:         <nothing>
00047  *============================================================================*/
00048 void ProcTest::setUp () {
00049 }
00050 
00051 /*==============================================================================
00052  * FUNCTION:        ProcTest::tearDown
00053  * OVERVIEW:        Delete expressions created in setUp
00054  * NOTE:            Called after all tests
00055  * PARAMETERS:      <none>
00056  * RETURNS:         <nothing>
00057  *============================================================================*/
00058 void ProcTest::tearDown () {
00059     delete m_proc;
00060 }
00061 
00062 /*==============================================================================
00063  * FUNCTION:        ProcTest::testName
00064  * OVERVIEW:        Test setting and reading name, constructor, native address
00065  *============================================================================*/
00066 void ProcTest::testName () {
00067     Prog* prog = new Prog();
00068     BinaryFile *pBF = new BinaryFileStub();
00069     CPPUNIT_ASSERT(pBF != 0);
00070     std::string nm("default name");
00071     BinaryFileFactory bff;
00072     pBF = bff.Load(HELLO_PENTIUM);
00073     FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
00074     CPPUNIT_ASSERT(pFE != 0);
00075     prog->setFrontEnd(pFE);
00076     CPPUNIT_ASSERT(prog);
00077     pFE->readLibraryCatalog();              // Since we are not decoding
00078     m_proc = new UserProc(prog, nm, 20000); // Will print in decimal if error
00079     std::string actual(m_proc->getName());
00080     CPPUNIT_ASSERT_EQUAL(std::string("default name"), actual);
00081 
00082     std::string name("printf");
00083     LibProc lp(prog, name, 30000);
00084     actual =  lp.getName();
00085     CPPUNIT_ASSERT_EQUAL(name, actual);
00086 
00087     ADDRESS a = lp.getNativeAddress();
00088     ADDRESS expected = 30000;
00089     CPPUNIT_ASSERT_EQUAL(expected, a);
00090     a = m_proc->getNativeAddress();
00091     expected = 20000;
00092     CPPUNIT_ASSERT_EQUAL(expected, a);
00093 
00094     delete prog;
00095     // delete pFE;      // No! Deleting the prog deletes the pFE already (which deletes the BinaryFileFactory)
00096 }
00097 

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