/*============================================================================== * FUNCTION: ProcTest::testName * OVERVIEW: Test setting and reading name, constructor, native address *============================================================================*/ void ProcTest::testName () { Prog* prog = new Prog(); BinaryFile *pBF = new BinaryFileStub(); CPPUNIT_ASSERT(pBF != 0); std::string nm("default name"); BinaryFileFactory bff; pBF = bff.Load(HELLO_PENTIUM); FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff); CPPUNIT_ASSERT(pFE != 0); prog->setFrontEnd(pFE); CPPUNIT_ASSERT(prog); pFE->readLibraryCatalog(); // Since we are not decoding m_proc = new UserProc(prog, nm, 20000); // Will print in decimal if error std::string actual(m_proc->getName()); CPPUNIT_ASSERT_EQUAL(std::string("default name"), actual); std::string name("printf"); LibProc lp(prog, name, 30000); actual = lp.getName(); CPPUNIT_ASSERT_EQUAL(name, actual); ADDRESS a = lp.getNativeAddress(); ADDRESS expected = 30000; CPPUNIT_ASSERT_EQUAL(expected, a); a = m_proc->getNativeAddress(); expected = 20000; CPPUNIT_ASSERT_EQUAL(expected, a); delete prog; delete m_proc; // delete pFE; // No! Deleting the prog deletes the pFE already (which deletes the BinaryFileFactory) }
/*============================================================================== * FUNCTION: TypeTest::testNotEqual * OVERVIEW: Test type inequality *============================================================================*/ void TypeTest::testCompound() { BinaryFileFactory bff; BinaryFile *pBF = bff.Load(HELLO_WINDOWS); FrontEnd *pFE = new PentiumFrontEnd(pBF, new Prog, &bff); Boomerang::get()->setLogger(new FileLogger()); // May try to output some messages to LOG pFE->readLibraryCatalog(); // Read definitions Signature* paintSig = pFE->getLibSignature("BeginPaint"); // Second argument should be an LPPAINTSTRUCT Type* ty = paintSig->getParamType(1); const char* p = ty->getCtype(); std::string expected("LPPAINTSTRUCT"); std::string actual(p); CPPUNIT_ASSERT_EQUAL(expected, actual); // Get the type pointed to ty = ty->asPointer()->getPointsTo(); p = ty->getCtype(); expected = "PAINTSTRUCT"; actual = p; CPPUNIT_ASSERT_EQUAL(expected, actual); // Offset 8 should have a RECT Type* subTy = ty->asCompound()->getTypeAtOffset(8*8); p = subTy->getCtype(); expected = "RECT"; actual = p; CPPUNIT_ASSERT_EQUAL(expected, actual); // Name at offset C should be bottom p = subTy->asCompound()->getNameAtOffset(0x0C*8); expected = "bottom"; actual = p; CPPUNIT_ASSERT_EQUAL(expected, actual); // Now figure out the name at offset 8+C p = ty->asCompound()->getNameAtOffset((8 + 0x0C)*8); expected = "rcPaint"; actual = p; CPPUNIT_ASSERT_EQUAL(expected, actual); // Also at offset 8 p = ty->asCompound()->getNameAtOffset((8 + 0)*8); actual = p; CPPUNIT_ASSERT_EQUAL(expected, actual); // Also at offset 8+4 p = ty->asCompound()->getNameAtOffset((8 + 4)*8); actual = p; CPPUNIT_ASSERT_EQUAL(expected, actual); // And at offset 8+8 p = ty->asCompound()->getNameAtOffset((8 + 8)*8); actual = p; CPPUNIT_ASSERT_EQUAL(expected, actual); delete pFE; }