string(REPLACE -O2 "" LLVM_CFLAGS ${LLVM_CFLAGS})
string(REPLACE -fno-exceptions "" LLVM_CFLAGS ${LLVM_CFLAGS})
string(REPLACE -fno-rtti "" LLVM_CFLAGS ${LLVM_CFLAGS})
+string(REPLACE -DNDEBUG "" LLVM_CFLAGS ${LLVM_CFLAGS})
separate_arguments(LLVM_CFLAGS)
add_definitions(${LLVM_CFLAGS})
separate_arguments(LLVM_LIBS)
SET(frida_SOURCES
- src/main.cxx
src/core/InformationManager.cxx
src/core/BasicBlock.cxx
src/core/Function.cxx
src/disassembler/Disassembler.hxx
)
-ADD_EXECUTABLE(frida ${frida_SOURCES} ${frida_HEADERS_MOC})
+ADD_EXECUTABLE(frida src/main.cxx ${frida_SOURCES} ${frida_HEADERS_MOC})
#ADD_LIBRARY(llvm SHARED )
ADD_DEFINITIONS(${QT_DEFINITIONS})
set(fridatest_SOURCES
src/test.cxx
+ src/core/tests/BasicBlockTest.cxx
+ ${frida_SOURCES}
)
add_executable(fridatest ${fridatest_SOURCES})
+
+qt5_use_modules(fridatest Widgets)
+
#ADD_SUBDIRECTORY(/usr/src/gtest gtest)
ADD_SUBDIRECTORY(/usr/src/gmock gmock)
enable_testing()
-target_link_libraries(fridatest gmock gtest gmock_main)
+target_link_libraries(fridatest gmock gtest gmock_main ${QT_LIBRARIES} ${LLVM_LDFLAGS} -lLLVM-3.5 ${LLVM_SYSTEM_LIBS} ${LOG4CXX_LDFLAGS} ${GUILE_LDFLAGS} ${QUAZIP_LIBRARIES})
add_test( fridatest fridatest )
--- /dev/null
+#include <gtest/gtest.h>
+#include <algorithm>
+
+#include "gui/qt.hxx"
+#include "core/InformationManager.hxx"
+#include "core/BasicBlock.hxx"
+
+TEST(BasicBlockTest, deserializeValidInstance) {
+ QFile file("testdata/core/BasicBlock/valid.xml");
+ InformationManager manager;
+ file.open(QFile::ReadOnly | QFile::Text);
+ QXmlStreamReader reader(&file);
+
+ reader.readNextStartElement();
+ BasicBlock* block = BasicBlock::deserialize(reader, &manager);
+
+ ASSERT_NE((void*)NULL, (void*)block);
+ EXPECT_EQ(0x403e50, block->getStartAddress());
+ EXPECT_EQ(0x403e66, block->getEndAddress());
+ EXPECT_EQ(0x403e50, block->getNextBlock(0));
+ EXPECT_EQ(0x403e66, block->getNextBlock(1));
+}
+
+TEST(BasicBlockTest, deserializeInvalidInstance) {
+ QFile file("testdata/core/BasicBlock/invalid.xml");
+ InformationManager manager;
+ file.open(QFile::ReadOnly | QFile::Text);
+ QXmlStreamReader reader(&file);
+
+ reader.readNextStartElement();
+ BasicBlock* block = BasicBlock::deserialize(reader, &manager);
+
+ ASSERT_EQ((void*)NULL, (void*)block);
+}
+
+TEST(BasicBlockTest, deserializeThenSerializeIsIdentity) {
+ QFile infile("testdata/core/BasicBlock/valid.xml");
+ QTemporaryFile outfile;
+
+ InformationManager manager;
+ infile.open(QFile::ReadOnly | QFile::Text);
+ outfile.open();
+ QXmlStreamReader reader(&infile);
+ QXmlStreamWriter writer(&outfile);
+
+ reader.readNextStartElement();
+ BasicBlock* block = BasicBlock::deserialize(reader, &manager);
+ block->serialize(writer);
+
+ infile.seek(0);
+ outfile.seek(0);
+
+ std::string outtext = outfile.readAll().data();
+ outtext.erase(remove_if(outtext.begin(), outtext.end(), isspace),
+ outtext.end());
+
+ std::string intext = infile.readAll().data();
+ intext.erase(remove_if(intext.begin(), intext.end(), isspace),
+ intext.end());
+
+ ASSERT_STREQ(outtext.c_str(), intext.c_str());
+}