From 45ec96129ebfaba01b0d043fda6e3216e2305e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Wed, 20 Mar 2019 18:30:37 +0100 Subject: [PATCH] Link CutterTest against Cutter --- src/CutterApplication.cpp | 38 +++++++++++++++++++++++++++++++++- src/CutterApplication.h | 2 +- src/test/AutoTest.h | 2 +- src/test/CMakeLists.txt | 19 ++++++++--------- src/test/CutterTest.pro | 9 -------- src/test/TestHexdumpWidget.cpp | 9 ++++++++ src/test/main.cpp | 6 ++++++ 7 files changed, 63 insertions(+), 22 deletions(-) delete mode 100644 src/test/CutterTest.pro diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index 2dccd156..864f1aec 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -39,7 +39,7 @@ #define CUTTER_COMPILE_TIME_RZ_VERSION "" RZ_VERSION #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); @@ -193,6 +193,42 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc Core()->setConfig("ghidra.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() diff --git a/src/CutterApplication.h b/src/CutterApplication.h index f8dc01e3..0a333bf9 100644 --- a/src/CutterApplication.h +++ b/src/CutterApplication.h @@ -26,7 +26,7 @@ class CutterApplication : public QApplication Q_OBJECT public: - CutterApplication(int &argc, char **argv); + CutterApplication(int &argc, char **argv, bool test = false); ~CutterApplication(); MainWindow *getMainWindow() { return mainWindow; } diff --git a/src/test/AutoTest.h b/src/test/AutoTest.h index e7c46761..50f448be 100644 --- a/src/test/AutoTest.h +++ b/src/test/AutoTest.h @@ -60,7 +60,7 @@ class Test public: QSharedPointer child; - Test(const QString &name) + explicit Test(const QString &name) : child(new T) { child->setObjectName(name); diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index cd37a126..5d425e12 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -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) diff --git a/src/test/CutterTest.pro b/src/test/CutterTest.pro deleted file mode 100644 index c8f1dcd4..00000000 --- a/src/test/CutterTest.pro +++ /dev/null @@ -1,9 +0,0 @@ - -QT += widgets testlib - -HEADERS = AutoTest.h \ - CutterTest.h - -SOURCES = main.cpp \ - TestHexdumpWidget.cpp \ - CutterTest.cpp diff --git a/src/test/TestHexdumpWidget.cpp b/src/test/TestHexdumpWidget.cpp index 7cf97c00..13377f74 100644 --- a/src/test/TestHexdumpWidget.cpp +++ b/src/test/TestHexdumpWidget.cpp @@ -4,12 +4,15 @@ #include "AutoTest.h" #include "CutterTest.h" +#include + class TestHexdumpWidget: public CutterTest { Q_OBJECT private slots: void initTestCase() override; void toUpper(); + void something(); }; void TestHexdumpWidget::initTestCase() @@ -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" diff --git a/src/test/main.cpp b/src/test/main.cpp index 35d67427..f639c1cb 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -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); }