Skip to content

Commit

Permalink
Link CutterTest against Cutter
Browse files Browse the repository at this point in the history
  • Loading branch information
thestr4ng3r authored and yossizap committed Nov 14, 2019
1 parent 49a9f18 commit 8daf438
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 62 deletions.
14 changes: 9 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ project(Cutter VERSION "${CUTTER_VERSION_FULL}")

set(CMAKE_CXX_STANDARD 11)

include_directories(core widgets common plugins)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
Expand Down Expand Up @@ -192,10 +190,13 @@ if(CUTTER_ENABLE_CRASH_REPORTS)
endif()
endif()

target_link_libraries(Cutter Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Svg Qt5::Network)
target_link_libraries(Cutter ${RADARE2_TARGET})
list(REMOVE_ITEM SOURCE_FILES Main.cpp)
add_library(CutterLib OBJECT ${UI_FILES} ${QRC_FILES} ${SOURCE_FILES} ${HEADER_FILES} ${BINDINGS_SOURCE})
target_include_directories(CutterLib PUBLIC . core widgets common plugins)
target_link_libraries(CutterLib Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Svg Qt5::Network)
target_link_libraries(CutterLib ${RADARE2_LIBRARIES})
if(CUTTER_ENABLE_PYTHON)
target_link_libraries(Cutter ${PYTHON_LIBRARIES})
target_link_libraries(CutterLib ${PYTHON_LIBRARIES})
if(CUTTER_ENABLE_PYTHON_BINDINGS)
target_link_libraries(Cutter Shiboken2::libshiboken PySide2::pyside2)

Expand All @@ -220,6 +221,9 @@ if(TARGET KF5::SyntaxHighlighting)
target_compile_definitions(Cutter PRIVATE CUTTER_ENABLE_KSYNTAXHIGHLIGHTING)
endif()

add_executable(Cutter Main.cpp)
target_link_libraries(Cutter CutterLib)

if(CUTTER_ENABLE_TESTS)
add_subdirectory(test)
endif()
74 changes: 38 additions & 36 deletions src/CutterApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <R2GhidraDecompiler.h>
#endif

CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc, argv)
CutterApplication::CutterApplication(int &argc, char **argv, bool test) : QApplication(argc, argv)
{
// Setup application information
setApplicationVersion(CUTTER_VERSION_FULL);
Expand Down Expand Up @@ -162,45 +162,11 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
#if QT_VERSION_CHECK(5, 10, 0) < QT_VERSION
setStyle(new CutterProxyStyle());
#endif // QT_VERSION_CHECK(5, 10, 0) < QT_VERSION

if (args.empty()) {
if (analLevelSpecified) {
printf("%s\n",
QObject::tr("Filename must be specified to start analysis automatically.").toLocal8Bit().constData());
std::exit(1);
}

// check if this is the first execution of Cutter in this computer
// Note: the execution after the preferences benn reset, will be considered as first-execution
if (Config()->isFirstExecution()) {
mainWindow->displayWelcomeDialog();
}
mainWindow->displayNewFileDialog();
} else { // filename specified as positional argument
InitialOptions options;
options.filename = args[0];
if (analLevelSpecified) {
switch (analLevel) {
case 0:
default:
options.analCmd = {};
break;
case 1:
options.analCmd = { {"aaa", "Auto analysis"} };
break;
case 2:
options.analCmd = { {"aaaa", "Auto analysis (experimental)"} };
break;
}
}
options.script = cmd_parser.value(scriptOption);
mainWindow->openNewFile(options, analLevelSpecified);
}

#ifdef CUTTER_APPVEYOR_R2DEC
qputenv("R2DEC_HOME", "radare2\\lib\\plugins\\r2dec-js");
#endif


#ifdef APPIMAGE
{
auto sleighHome = QDir(QCoreApplication::applicationDirPath()); // appdir/bin
Expand All @@ -226,6 +192,42 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
Core()->setConfig("r2ghidra.sleighhome", sleighHome.absolutePath());
}
#endif

if (!test) {
if (args.empty()) {
if (analLevelSpecified) {
printf("%s\n",
QObject::tr("Filename must be specified to start analysis automatically.").toLocal8Bit().constData());
std::exit(1);
}

// check if this is the first execution of Cutter in this computer
// Note: the execution after the preferences benn reset, will be considered as first-execution
if (Config()->isFirstExecution()) {
mainWindow->displayWelcomeDialog();
}
mainWindow->displayNewFileDialog();
} else { // filename specified as positional argument
InitialOptions options;
options.filename = args[0];
if (analLevelSpecified) {
switch (analLevel) {
case 0:
default:
options.analCmd = {};
break;
case 1:
options.analCmd = { {"aaa", "Auto analysis"} };
break;
case 2:
options.analCmd = { {"aaaa", "Auto analysis (experimental)"} };
break;
}
}
options.script = cmd_parser.value(scriptOption);
mainWindow->openNewFile(options, analLevelSpecified);
}
}
}

CutterApplication::~CutterApplication()
Expand Down
2 changes: 1 addition & 1 deletion src/CutterApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CutterApplication : public QApplication
Q_OBJECT

public:
CutterApplication(int &argc, char **argv);
CutterApplication(int &argc, char **argv, bool test = false);
~CutterApplication();

MainWindow *getMainWindow()
Expand Down
2 changes: 1 addition & 1 deletion src/test/AutoTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Test
public:
QSharedPointer<T> child;

Test(const QString &name)
explicit Test(const QString &name)
: child(new T)
{
child->setObjectName(name);
Expand Down
19 changes: 9 additions & 10 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui Test)
find_package(Qt5 REQUIRED COMPONENTS Test)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/CutterTest.pro"
"${CMAKE_CURRENT_BINARY_DIR}/CutterTest.pro"
COPYONLY) # trigger reconfigure if CutterTest.pro changes
parse_qmake_pro("${CMAKE_CURRENT_BINARY_DIR}/CutterTest.pro" CUTTER_TEST_PRO)
set(TEST_SOURCE_FILES ${CUTTER_TEST_PRO_SOURCES})
set(TEST_HEADER_FILES ${CUTTER_TEST_PRO_HEADERS})
set(TEST_HEADER_FILES
AutoTest.h
CutterTest.h)

message(STATUS "sources from CutterTest.pro: ${TEST_SOURCE_FILES}")
message(STATUS "headers from CutterTest.pro: ${TEST_HEADER_FILES}")
set(TEST_SOURCE_FILES
main.cpp
CutterTest.cpp
TestHexdumpWidget.cpp)

add_executable(CutterTest ${TEST_SOURCE_FILES} ${TEST_HEADER_FILES})
qt5_use_modules(CutterTest Core Widgets Gui Test)
target_link_libraries(CutterTest CutterLib Qt5::Test)
9 changes: 0 additions & 9 deletions src/test/CutterTest.pro

This file was deleted.

9 changes: 9 additions & 0 deletions src/test/TestHexdumpWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
#include "AutoTest.h"
#include "CutterTest.h"

#include <Cutter.h>

class TestHexdumpWidget: public CutterTest
{
Q_OBJECT
private slots:
void initTestCase() override;
void toUpper();
void something();
};

void TestHexdumpWidget::initTestCase()
Expand All @@ -23,6 +26,12 @@ void TestHexdumpWidget::toUpper()
QCOMPARE(str.toUpper(), QString("HELLO"));
}

void TestHexdumpWidget::something()
{
QString a = Core()->cmd("fo");
qDebug() << "r2 returned:" << a;
}

DECLARE_TEST(TestHexdumpWidget)
#include "TestHexdumpWidget.moc"

6 changes: 6 additions & 0 deletions src/test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@

#include "AutoTest.h"

#include "CutterApplication.h"

int main(int argc, char *argv[])
{
int argcApp = 1;
char *argvApp[] = { strdup("./Cutter") };
CutterApplication app(argcApp, argvApp, true);

return AutoTest::run(argc, argv);
}

0 comments on commit 8daf438

Please sign in to comment.