From 2d191ad17f1b00c17faaf44fd1ee044506e3184a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Fri, 13 Apr 2018 18:02:28 +0200 Subject: [PATCH 01/17] Add basic Test Suite --- src/test/AutoTest.h | 73 ++++++++++++++++++++++++++++++++++ src/test/CMakeLists.txt | 15 +++++++ src/test/CutterTest.cpp | 13 ++++++ src/test/CutterTest.h | 16 ++++++++ src/test/CutterTest.pro | 9 +++++ src/test/TestHexdumpWidget.cpp | 28 +++++++++++++ src/test/main.cpp | 8 ++++ 7 files changed, 162 insertions(+) create mode 100644 src/test/AutoTest.h create mode 100644 src/test/CMakeLists.txt create mode 100644 src/test/CutterTest.cpp create mode 100644 src/test/CutterTest.h create mode 100644 src/test/CutterTest.pro create mode 100644 src/test/TestHexdumpWidget.cpp create mode 100644 src/test/main.cpp diff --git a/src/test/AutoTest.h b/src/test/AutoTest.h new file mode 100644 index 000000000..e7c46761c --- /dev/null +++ b/src/test/AutoTest.h @@ -0,0 +1,73 @@ + +#ifndef AUTOTEST_H +#define AUTOTEST_H + +// see http://qtcreator.blogspot.de/2009/10/running-multiple-unit-tests.html + +#include +#include +#include +#include + +namespace AutoTest +{ +typedef QList TestList; + +inline TestList &testList() +{ + static TestList list; + return list; +} + +inline bool findObject(QObject *object) +{ + TestList &list = testList(); + if (list.contains(object)) { + return true; + } + + for (QObject *test : list) { + if (test->objectName() == object->objectName()) { + return true; + } + } + return false; +} + +inline void addTest(QObject *object) +{ + TestList &list = testList(); + if (!findObject(object)) { + list.append(object); + } +} + +inline int run(int argc, char *argv[]) +{ + int ret = 0; + + for (QObject *test : testList()) { + ret += QTest::qExec(test, argc, argv); + } + + return ret; +} +} + +template +class Test +{ +public: + QSharedPointer child; + + Test(const QString &name) + : child(new T) + { + child->setObjectName(name); + AutoTest::addTest(child.data()); + } +}; + +#define DECLARE_TEST(className) static Test t(#className); + +#endif //AUTOTEST_H diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt new file mode 100644 index 000000000..cd37a1261 --- /dev/null +++ b/src/test/CMakeLists.txt @@ -0,0 +1,15 @@ + +find_package(Qt5 REQUIRED COMPONENTS Core Widgets Gui 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}) + +message(STATUS "sources from CutterTest.pro: ${TEST_SOURCE_FILES}") +message(STATUS "headers from CutterTest.pro: ${TEST_HEADER_FILES}") + +add_executable(CutterTest ${TEST_SOURCE_FILES} ${TEST_HEADER_FILES}) +qt5_use_modules(CutterTest Core Widgets Gui Test) diff --git a/src/test/CutterTest.cpp b/src/test/CutterTest.cpp new file mode 100644 index 000000000..3384b3ca5 --- /dev/null +++ b/src/test/CutterTest.cpp @@ -0,0 +1,13 @@ + +#include "CutterTest.h" + +void CutterTest::initTestCase() +{ + qDebug("CutterTest::initTestCase()"); +} + +void CutterTest::cleanupTestCase() +{ + qDebug("CutterTest::cleanupTestCase()"); +} + diff --git a/src/test/CutterTest.h b/src/test/CutterTest.h new file mode 100644 index 000000000..d1519cc43 --- /dev/null +++ b/src/test/CutterTest.h @@ -0,0 +1,16 @@ + +#ifndef CUTTERTEST_H +#define CUTTERTEST_H + +#include + +class CutterTest: public QObject +{ + Q_OBJECT + +protected slots: + virtual void initTestCase(); + virtual void cleanupTestCase(); +}; + +#endif //CUTTERTEST_H diff --git a/src/test/CutterTest.pro b/src/test/CutterTest.pro new file mode 100644 index 000000000..c8f1dcd4b --- /dev/null +++ b/src/test/CutterTest.pro @@ -0,0 +1,9 @@ + +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 new file mode 100644 index 000000000..7cf97c008 --- /dev/null +++ b/src/test/TestHexdumpWidget.cpp @@ -0,0 +1,28 @@ + +#include + +#include "AutoTest.h" +#include "CutterTest.h" + +class TestHexdumpWidget: public CutterTest +{ + Q_OBJECT +private slots: + void initTestCase() override; + void toUpper(); +}; + +void TestHexdumpWidget::initTestCase() +{ + qDebug("TestHexdumpWidget::initTestCase()"); +} + +void TestHexdumpWidget::toUpper() +{ + QString str = "Hello"; + QCOMPARE(str.toUpper(), QString("HELLO")); +} + +DECLARE_TEST(TestHexdumpWidget) +#include "TestHexdumpWidget.moc" + diff --git a/src/test/main.cpp b/src/test/main.cpp new file mode 100644 index 000000000..35d674277 --- /dev/null +++ b/src/test/main.cpp @@ -0,0 +1,8 @@ + +#include "AutoTest.h" + +int main(int argc, char *argv[]) +{ + return AutoTest::run(argc, argv); +} + 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 02/17] 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 2dccd1562..864f1aec1 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 f8dc01e39..0a333bf95 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 e7c46761c..50f448bec 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 cd37a1261..5d425e12f 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 c8f1dcd4b..000000000 --- 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 7cf97c008..13377f744 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 35d674277..f639c1cbd 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); } From 5200845fd0b335ad3e1332a571a995f07fcff5b4 Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 15 Nov 2019 15:16:20 +0000 Subject: [PATCH 03/17] Fixed issues after rebase --- src/CutterApplication.cpp | 2 +- src/core/MainWindow.cpp | 10 ++++++++-- src/core/MainWindow.h | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index 864f1aec1..1c231304a 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -135,7 +135,7 @@ CutterApplication::CutterApplication(int &argc, char **argv, bool test) : QAppli plugin->registerDecompilers(); } - mainWindow = new MainWindow(); + mainWindow = new MainWindow(nullptr, test); installEventFilter(mainWindow); // set up context menu shortcut display fix diff --git a/src/core/MainWindow.cpp b/src/core/MainWindow.cpp index 6e796a8c3..f0ac6a2ee 100644 --- a/src/core/MainWindow.cpp +++ b/src/core/MainWindow.cpp @@ -125,12 +125,18 @@ T *getNewInstance(MainWindow *m) using namespace Cutter; -MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), core(Core()), ui(new Ui::MainWindow) +MainWindow::MainWindow(QWidget *parent, bool testMode) : + QMainWindow(parent), + core(Core()), + testMode(testMode), + ui(new Ui::MainWindow) { tabsOnTop = false; configuration = Config(); - initUI(); + if (!testMode) { + initUI(); + } } MainWindow::~MainWindow() {} diff --git a/src/core/MainWindow.h b/src/core/MainWindow.h index ce1bdceb5..45d9a6ff6 100644 --- a/src/core/MainWindow.h +++ b/src/core/MainWindow.h @@ -213,6 +213,8 @@ private slots: private: CutterCore *core; + bool testMode; + bool tabsOnTop; ut64 hexdumpTopOffset; ut64 hexdumpBottomOffset; From e9994fab288ff21c6c6e4efa8cd79692dd787939 Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 15 Nov 2019 20:30:25 +0000 Subject: [PATCH 04/17] Fix travis --- src/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 47357c696..46ad126b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -516,6 +516,10 @@ if(CUTTER_ENABLE_PYTHON) endif() endforeach() +<<<<<<< HEAD +======= + get_target_property(BINDINGS_INCLUDE_DIRS CutterLib INCLUDE_DIRECTORIES) +>>>>>>> Fix travis if(APPLE AND _qt5Core_install_prefix) list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include") list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtCore") @@ -595,3 +599,7 @@ if(UNIX AND NOT APPLE) DESTINATION "share/applications" COMPONENT Devel) endif() + +if(CUTTER_ENABLE_TESTS) + add_subdirectory(test) +endif() From 14f8a13cc59ea68e676691c9a699cff966a15623 Mon Sep 17 00:00:00 2001 From: yossizap Date: Tue, 15 Dec 2020 19:42:44 +0000 Subject: [PATCH 05/17] Fix rebase --- src/CMakeLists.txt | 49 +++++++++++++++++++++------------------ src/CutterApplication.cpp | 40 ++------------------------------ src/core/MainWindow.h | 2 +- src/test/CMakeLists.txt | 1 - 4 files changed, 29 insertions(+), 63 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46ad126b1..4c9093970 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -425,8 +425,8 @@ endif() if (TARGET Graphviz::GVC) - list(APPEND SOURCES widgets/GraphvizLayout.cpp) - list(APPEND HEADER_FILES widgets/GraphvizLayout.h) + list(APPEND SOURCE_FILES ${CUTTER_PRO_GRAPHVIZ_SOURCES}) + list(APPEND HEADER_FILES ${CUTTER_PRO_GRAPHVIZ_HEADERS}) endif() if (WIN32) @@ -442,8 +442,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" set_source_files_properties(${BINDINGS_SOURCE} PROPERTIES COMPILE_FLAGS -w) endif() - -add_executable(Cutter ${OPTIONS} ${UI_FILES} ${QRC_FILES} ${PLATFORM_RESOURCES} ${SOURCES} ${HEADER_FILES} ${BINDINGS_SOURCE}) +list(REMOVE_ITEM SOURCES Main.cpp) +add_library(CutterLib OBJECT ${UI_FILES} ${QRC_FILES} ${PLATFORM_RESOURCES} ${SOURCES} ${HEADER_FILES} ${BINDINGS_SOURCE}) +add_executable(Cutter ${OPTIONS} Main.cpp) set_target_properties(Cutter PROPERTIES OUTPUT_NAME cutter RUNTIME_OUTPUT_DIRECTORY .. @@ -458,33 +459,39 @@ foreach(_dir ${CUTTER_INCLUDE_DIRECTORIES}) $ $ ) + target_include_directories(CutterLib PUBLIC + $ + $ + ) endforeach() +target_link_libraries(Cutter CutterLib) if (TARGET Graphviz::GVC) - target_link_libraries(Cutter PRIVATE Graphviz::GVC) - target_compile_definitions(Cutter PRIVATE CUTTER_ENABLE_GRAPHVIZ) + target_link_libraries(CutterLib PRIVATE Graphviz::GVC) + target_compile_definitions(CutterLib PRIVATE CUTTER_ENABLE_GRAPHVIZ) endif() if(CUTTER_ENABLE_CRASH_REPORTS) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) - target_link_libraries(Cutter PRIVATE Threads::Threads) + target_link_libraries(CutterLib PRIVATE Threads::Threads) add_definitions(-DCUTTER_ENABLE_CRASH_REPORTS) if (NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ") endif() find_package(Breakpad REQUIRED) - target_link_libraries(Cutter PRIVATE Breakpad::client) + target_link_libraries(CutterLib PRIVATE Breakpad::client) endif() -target_link_libraries(Cutter PUBLIC ${QT_PREFIX}::Core ${QT_PREFIX}::Widgets ${QT_PREFIX}::Gui PRIVATE ${QT_PREFIX}::Svg ${QT_PREFIX}::Network) +target_link_libraries(CutterLib PUBLIC ${QT_PREFIX}::Core ${QT_PREFIX}::Widgets ${QT_PREFIX}::Gui PRIVATE ${QT_PREFIX}::Svg ${QT_PREFIX}::Network) if (CUTTER_QT6) - target_link_libraries(Cutter PUBLIC Qt6::Core5Compat Qt6::SvgWidgets) - target_link_libraries(Cutter PRIVATE Qt6::OpenGLWidgets) + target_link_libraries(CutterLib PUBLIC Qt6::Core5Compat Qt6::SvgWidgets) + target_link_libraries(CutterLib PRIVATE Qt6::OpenGLWidgets) endif() -target_link_libraries(Cutter PUBLIC ${RIZIN_TARGET}) +target_link_libraries(CutterLib PUBLIC ${RIZIN_TARGET}) + if(CUTTER_ENABLE_PYTHON) if (WIN32) # On windows some of the Python STABLE API functions are in seperate library @@ -494,15 +501,15 @@ if(CUTTER_ENABLE_PYTHON) if((NOT _PYTHON_LIBRARY STREQUAL "optimized") AND (NOT _PYTHON_LIBRARY STREQUAL "debug")) get_filename_component(_PYTHON_LIB_DIR ${_PYTHON_LIBRARY} DIRECTORY) message(STATUS "Add extra library dir for Python: ${_PYTHON_LIB_DIR}") - target_link_directories(Cutter PRIVATE ${_PYTHON_LIB_DIR}) + target_link_directories(CutterLib PRIVATE ${_PYTHON_LIB_DIR}) endif() endforeach() endif() - target_link_libraries(Cutter PRIVATE ${PYTHON_LIBRARIES}) + target_link_libraries(CutterLib PRIVATE ${PYTHON_LIBRARIES}) if(CUTTER_ENABLE_PYTHON_BINDINGS) - target_link_libraries(Cutter PRIVATE Shiboken2::libshiboken PySide2::pyside2) + target_link_libraries(CutterLib PRIVATE Shiboken2::libshiboken PySide2::pyside2) - get_target_property(RAW_BINDINGS_INCLUDE_DIRS Cutter INCLUDE_DIRECTORIES) + get_target_property(RAW_BINDINGS_INCLUDE_DIRS CutterLib INCLUDE_DIRECTORIES) if(NOT CUTTER_USE_BUNDLED_RIZIN) get_target_property(RAW_RIZIN_INCLUDE_DIRS ${RIZIN_TARGET} INTERFACE_INCLUDE_DIRECTORIES) list(APPEND RAW_BINDINGS_INCLUDE_DIRS "${RAW_RIZIN_INCLUDE_DIRS}") @@ -516,10 +523,6 @@ if(CUTTER_ENABLE_PYTHON) endif() endforeach() -<<<<<<< HEAD -======= - get_target_property(BINDINGS_INCLUDE_DIRS CutterLib INCLUDE_DIRECTORIES) ->>>>>>> Fix travis if(APPLE AND _qt5Core_install_prefix) list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include") list(APPEND BINDINGS_INCLUDE_DIRS "${_qt5Core_install_prefix}/include/QtCore") @@ -539,8 +542,8 @@ if(CUTTER_ENABLE_PYTHON) endif() if(TARGET KF5::SyntaxHighlighting) - target_link_libraries(Cutter PRIVATE KF5::SyntaxHighlighting) - target_compile_definitions(Cutter PRIVATE CUTTER_ENABLE_KSYNTAXHIGHLIGHTING) + target_link_libraries(CutterLib PRIVATE KF5::SyntaxHighlighting) + target_compile_definitions(CutterLib PRIVATE CUTTER_ENABLE_KSYNTAXHIGHLIGHTING) endif() if (CUTTER_APPIMAGE_BUILD) @@ -562,7 +565,7 @@ endif() include(Translations) # Install files -install(TARGETS Cutter +install(TARGETS Cutter CutterLib EXPORT CutterTargets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" BUNDLE DESTINATION "." # needs to be tested diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index 1c231304a..9f9ee7f5b 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -143,7 +143,7 @@ CutterApplication::CutterApplication(int &argc, char **argv, bool test) : QAppli setStyle(new CutterProxyStyle()); #endif // QT_VERSION_CHECK(5, 10, 0) < QT_VERSION - if (clOptions.args.empty() && clOptions.fileOpenOptions.projectFile.isEmpty()) { + if (clOptions.args.empty() && clOptions.fileOpenOptions.projectFile.isEmpty() && !test) { // check if this is the first execution of Cutter in this computer // Note: the execution after the preferences been reset, will be considered as // first-execution @@ -151,7 +151,7 @@ CutterApplication::CutterApplication(int &argc, char **argv, bool test) : QAppli mainWindow->displayWelcomeDialog(); } mainWindow->displayNewFileDialog(); - } else { // filename specified as positional argument + } else if (!test) { // filename specified as positional argument bool askOptions = (clOptions.analysisLevel != AutomaticAnalysisLevel::Ask) || !clOptions.fileOpenOptions.projectFile.isEmpty(); mainWindow->openNewFile(clOptions.fileOpenOptions, askOptions); @@ -193,42 +193,6 @@ CutterApplication::CutterApplication(int &argc, char **argv, bool test) : QAppli 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/core/MainWindow.h b/src/core/MainWindow.h index 45d9a6ff6..9b815f412 100644 --- a/src/core/MainWindow.h +++ b/src/core/MainWindow.h @@ -67,7 +67,7 @@ class CUTTER_EXPORT MainWindow : public QMainWindow public: bool responsive; - explicit MainWindow(QWidget *parent = nullptr); + explicit MainWindow(QWidget *parent = nullptr, bool testMode = false); ~MainWindow() override; void openNewFile(InitialOptions &options, bool skipOptionsDialog = false); diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 5d425e12f..218120e49 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,4 +1,3 @@ - find_package(Qt5 REQUIRED COMPONENTS Test) set(TEST_HEADER_FILES From f9665513875efd4d5b295d12fd52d80cbf81a662 Mon Sep 17 00:00:00 2001 From: yossizap Date: Tue, 15 Dec 2020 19:44:32 +0000 Subject: [PATCH 06/17] Update CI --- .appveyor.yml | 2 ++ .github/workflows/ccpp.yml | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 4f0866ae5..0ad11549e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -49,12 +49,14 @@ build_script: -DCUTTER_PACKAGE_JSDEC=ON -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON -DCUTTER_ENABLE_CRASH_REPORTS=ON + -DCUTTER_ENABLE_TESTS=ON -DCMAKE_PREFIX_PATH=%CUTTER_DEPS%\\pyside -DCPACK_PACKAGE_FILE_NAME=%PACKAGE_NAME% -G Ninja .." - cmd: cmake --build . --config Release - cmd: cmake --build . --config Release --target package + - cmd: src/test/CutterTest # Tests test: off diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 64a3f7f65..3b40b76f0 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -117,6 +117,7 @@ jobs: -DCUTTER_ENABLE_PYTHON_BINDINGS=ON \ -DCUTTER_ENABLE_GRAPHVIZ=OFF \ -DCUTTER_ENABLE_CRASH_REPORTS=ON \ + -DCUTTER_ENABLE_TESTS=ON \ -DCUTTER_USE_BUNDLED_RIZIN=ON \ -DCUTTER_APPIMAGE_BUILD=ON \ -DCUTTER_ENABLE_PACKAGING=ON \ @@ -131,9 +132,11 @@ jobs: -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DCUTTER_USE_BUNDLED_RIZIN=ON \ + -DCUTTER_ENABLE_TESTS=ON \ .. fi ninja + ./src/test/CutterTest if [[ "${{ matrix.package || false }}" = "true" ]] then export CUTTER_VERSION=$(python ../scripts/get_version.py) @@ -185,6 +188,7 @@ jobs: -DCUTTER_ENABLE_CRASH_REPORTS=ON \ -DCUTTER_USE_BUNDLED_RIZIN=ON \ -DCUTTER_ENABLE_PACKAGING=ON \ + -DCUTTER_ENABLE_TESTS=ON \ -DCUTTER_PACKAGE_DEPENDENCIES=ON \ -DCUTTER_ENABLE_DEPENDENCY_DOWNLOADS=ON \ -DCUTTER_PACKAGE_RZ_GHIDRA=ON \ @@ -198,7 +202,8 @@ jobs: make package export CUTTER_VERSION=$(python3 ../scripts/get_version.py) echo PACKAGE_NAME=${PACKAGE_NAME}.dmg >> $GITHUB_ENV - echo UPLOAD_ASSET_TYPE=application/x-apple-diskimage >> $GITHUB_ENV + echo UPLOAD_ASSET_TYPE=application/x-apple-diskimage >> $GITHUB_ENVV + ./src/test/CutterTest; - name: windows dependencies if: contains(matrix.os, 'windows') shell: bash @@ -222,6 +227,7 @@ jobs: cmake ^ -DCMAKE_BUILD_TYPE=Release ^ -DCUTTER_USE_BUNDLED_RIZIN=ON ^ + -DCUTTER_ENABLE_TESTS=ON \ -DCUTTER_ENABLE_PYTHON=ON ^ -DCUTTER_ENABLE_PYTHON_BINDINGS=ON ^ -DCUTTER_ENABLE_PACKAGING=ON ^ @@ -237,6 +243,7 @@ jobs: .. cmake --build . --config Release cmake --build . --config Release --target package + ./src/test/CutterTest echo PACKAGE_NAME=%PACKAGE_NAME%.zip >> %GITHUB_ENV% echo UPLOAD_ASSET_TYPE=application/zip >> %GITHUB_ENV% - uses: actions/upload-artifact@v2 From 9f32c57f1c224950b11fce1c166518f82c80d770 Mon Sep 17 00:00:00 2001 From: yossizap Date: Tue, 15 Dec 2020 20:45:15 +0000 Subject: [PATCH 07/17] Attempt to fix gh --- .github/workflows/ccpp.yml | 4 +++- CMakeLists.txt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 3b40b76f0..bd193d855 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -101,7 +101,9 @@ jobs: fi source scripts/prepare_breakpad_linux.sh - export PKG_CONFIG_PATH="$CUSTOM_BREAKPAD_PREFIX/lib/pkgconfig:${PKG_CONFIG_PATH:-}" # + export PKG_CONFIG_PATH="$CUSTOM_BREAKPAD_PREFIX/lib/pkgconfig:${PKG_CONFIG_PATH:-}" + export QT_QPA_PLATFORM=minimal + export LD_LIBRARY_PATH=./Rizin-prefix/lib:$LD_LIBRARY_PATH mkdir build cd build cmake --version diff --git a/CMakeLists.txt b/CMakeLists.txt index 991368ec7..ef398b442 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ option(CUTTER_PACKAGE_DEPENDENCIES "During install step include the third party option(CUTTER_PACKAGE_RZ_GHIDRA "Compile and install rz-ghidra during install step." OFF) option(CUTTER_PACKAGE_RZ_LIBSWIFT, "Compile and install rz-libswift demangler during the install step." OFF) option(CUTTER_PACKAGE_JSDEC "Compile and install jsdec during install step." OFF) +option(CUTTER_ENABLE_TESTS "Build QtTest tests" OFF) OPTION(CUTTER_QT6 "Use QT6" OFF) if(NOT CUTTER_ENABLE_PYTHON) From 17ad717c06d18b14d4b2b4e02e96c92fb93462ed Mon Sep 17 00:00:00 2001 From: yossizap Date: Sat, 19 Dec 2020 16:18:25 +0000 Subject: [PATCH 08/17] Fix rebase --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index bd193d855..83f6fd543 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -138,7 +138,7 @@ jobs: .. fi ninja - ./src/test/CutterTest + ./src/test/CutterTest if [[ "${{ matrix.package || false }}" = "true" ]] then export CUTTER_VERSION=$(python ../scripts/get_version.py) From 628f19cd211bfd81d681766bea8f49e938304acb Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 5 Feb 2021 21:24:07 +0000 Subject: [PATCH 09/17] Fix windows relative path --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 83f6fd543..59e2b7678 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -245,7 +245,7 @@ jobs: .. cmake --build . --config Release cmake --build . --config Release --target package - ./src/test/CutterTest + src/test/CutterTest echo PACKAGE_NAME=%PACKAGE_NAME%.zip >> %GITHUB_ENV% echo UPLOAD_ASSET_TYPE=application/zip >> %GITHUB_ENV% - uses: actions/upload-artifact@v2 From 6cfd37b812d631c20aa70149955a0941ce9d8bf8 Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 5 Feb 2021 21:33:42 +0000 Subject: [PATCH 10/17] Fix graphivz paths --- src/CMakeLists.txt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4c9093970..6cb45849a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -425,10 +425,8 @@ endif() if (TARGET Graphviz::GVC) - list(APPEND SOURCE_FILES ${CUTTER_PRO_GRAPHVIZ_SOURCES}) - list(APPEND HEADER_FILES ${CUTTER_PRO_GRAPHVIZ_HEADERS}) -endif() - + list(APPEND SOURCES widgets/GraphvizLayout.cpp) + list(APPEND HEADER_FILES widgets/GraphvizLayout.h) if (WIN32) set(PLATFORM_RESOURCES "img/cutter.rc") set(OPTIONS WIN32) From dd2afa1c3c5ec5bea0b1257c6525f2f8df9f7184 Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 5 Feb 2021 21:35:09 +0000 Subject: [PATCH 11/17] remove unneeded exports --- .github/workflows/ccpp.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 59e2b7678..fb8f23130 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -101,9 +101,6 @@ jobs: fi source scripts/prepare_breakpad_linux.sh - export PKG_CONFIG_PATH="$CUSTOM_BREAKPAD_PREFIX/lib/pkgconfig:${PKG_CONFIG_PATH:-}" - export QT_QPA_PLATFORM=minimal - export LD_LIBRARY_PATH=./Rizin-prefix/lib:$LD_LIBRARY_PATH mkdir build cd build cmake --version @@ -138,6 +135,7 @@ jobs: .. fi ninja + export QT_QPA_PLATFORM=minimal ./src/test/CutterTest if [[ "${{ matrix.package || false }}" = "true" ]] then From 2c17e8785c96ca1a1fbbf6204753aab599ede8dd Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 5 Feb 2021 21:36:07 +0000 Subject: [PATCH 12/17] Fix windows cmake flags --- .github/workflows/ccpp.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index fb8f23130..c7d660c69 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -227,7 +227,7 @@ jobs: cmake ^ -DCMAKE_BUILD_TYPE=Release ^ -DCUTTER_USE_BUNDLED_RIZIN=ON ^ - -DCUTTER_ENABLE_TESTS=ON \ + -DCUTTER_ENABLE_TESTS=ON ^ -DCUTTER_ENABLE_PYTHON=ON ^ -DCUTTER_ENABLE_PYTHON_BINDINGS=ON ^ -DCUTTER_ENABLE_PACKAGING=ON ^ From 87d2e5e156b0caf22c636db1dd32edee44e344d6 Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 5 Feb 2021 21:47:11 +0000 Subject: [PATCH 13/17] Graphivz fix --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6cb45849a..398ce7c27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -427,6 +427,8 @@ endif() if (TARGET Graphviz::GVC) list(APPEND SOURCES widgets/GraphvizLayout.cpp) list(APPEND HEADER_FILES widgets/GraphvizLayout.h) +endif() + if (WIN32) set(PLATFORM_RESOURCES "img/cutter.rc") set(OPTIONS WIN32) From 652c5343f971c23dc83c770eb8863718d360363e Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 5 Feb 2021 21:50:14 +0000 Subject: [PATCH 14/17] Readd breakpad pkg config --- .github/workflows/ccpp.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index c7d660c69..778e66f5c 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -101,6 +101,7 @@ jobs: fi source scripts/prepare_breakpad_linux.sh + export PKG_CONFIG_PATH="$CUSTOM_BREAKPAD_PREFIX/lib/pkgconfig:${PKG_CONFIG_PATH:-}" # mkdir build cd build cmake --version From dfa5f3db49cdf370d1eb4e451affc2a07e0fcafa Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 5 Feb 2021 22:11:14 +0000 Subject: [PATCH 15/17] Change cutterlib to static --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 398ce7c27..84dff4f55 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -443,7 +443,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" endif() list(REMOVE_ITEM SOURCES Main.cpp) -add_library(CutterLib OBJECT ${UI_FILES} ${QRC_FILES} ${PLATFORM_RESOURCES} ${SOURCES} ${HEADER_FILES} ${BINDINGS_SOURCE}) +add_library(CutterLib STATIC ${UI_FILES} ${QRC_FILES} ${PLATFORM_RESOURCES} ${SOURCES} ${HEADER_FILES} ${BINDINGS_SOURCE}) add_executable(Cutter ${OPTIONS} Main.cpp) set_target_properties(Cutter PROPERTIES OUTPUT_NAME cutter From ee9d2f04b7edfb22d57f3ef418cc6acea0ddc5b1 Mon Sep 17 00:00:00 2001 From: yossizap Date: Fri, 5 Feb 2021 23:09:52 +0000 Subject: [PATCH 16/17] Move tests to test/ --- .github/workflows/ccpp.yml | 6 +++--- CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 4 ---- {src/test => test}/AutoTest.h | 0 {src/test => test}/CMakeLists.txt | 0 {src/test => test}/CutterTest.cpp | 0 {src/test => test}/CutterTest.h | 0 {src/test => test}/TestHexdumpWidget.cpp | 0 {src/test => test}/main.cpp | 0 9 files changed, 7 insertions(+), 7 deletions(-) rename {src/test => test}/AutoTest.h (100%) rename {src/test => test}/CMakeLists.txt (100%) rename {src/test => test}/CutterTest.cpp (100%) rename {src/test => test}/CutterTest.h (100%) rename {src/test => test}/TestHexdumpWidget.cpp (100%) rename {src/test => test}/main.cpp (100%) diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index 778e66f5c..06dcb702c 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -137,7 +137,7 @@ jobs: fi ninja export QT_QPA_PLATFORM=minimal - ./src/test/CutterTest + ./test/CutterTest if [[ "${{ matrix.package || false }}" = "true" ]] then export CUTTER_VERSION=$(python ../scripts/get_version.py) @@ -204,7 +204,7 @@ jobs: export CUTTER_VERSION=$(python3 ../scripts/get_version.py) echo PACKAGE_NAME=${PACKAGE_NAME}.dmg >> $GITHUB_ENV echo UPLOAD_ASSET_TYPE=application/x-apple-diskimage >> $GITHUB_ENVV - ./src/test/CutterTest; + ./test/CutterTest; - name: windows dependencies if: contains(matrix.os, 'windows') shell: bash @@ -244,7 +244,7 @@ jobs: .. cmake --build . --config Release cmake --build . --config Release --target package - src/test/CutterTest + cd test; CutterTest echo PACKAGE_NAME=%PACKAGE_NAME%.zip >> %GITHUB_ENV% echo UPLOAD_ASSET_TYPE=application/zip >> %GITHUB_ENV% - uses: actions/upload-artifact@v2 diff --git a/CMakeLists.txt b/CMakeLists.txt index ef398b442..73acd49f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,3 +136,7 @@ add_subdirectory(src) if(CUTTER_ENABLE_PACKAGING) add_subdirectory(dist) endif() + +if(CUTTER_ENABLE_TESTS) + add_subdirectory(test) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 84dff4f55..468c957ca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -602,7 +602,3 @@ if(UNIX AND NOT APPLE) DESTINATION "share/applications" COMPONENT Devel) endif() - -if(CUTTER_ENABLE_TESTS) - add_subdirectory(test) -endif() diff --git a/src/test/AutoTest.h b/test/AutoTest.h similarity index 100% rename from src/test/AutoTest.h rename to test/AutoTest.h diff --git a/src/test/CMakeLists.txt b/test/CMakeLists.txt similarity index 100% rename from src/test/CMakeLists.txt rename to test/CMakeLists.txt diff --git a/src/test/CutterTest.cpp b/test/CutterTest.cpp similarity index 100% rename from src/test/CutterTest.cpp rename to test/CutterTest.cpp diff --git a/src/test/CutterTest.h b/test/CutterTest.h similarity index 100% rename from src/test/CutterTest.h rename to test/CutterTest.h diff --git a/src/test/TestHexdumpWidget.cpp b/test/TestHexdumpWidget.cpp similarity index 100% rename from src/test/TestHexdumpWidget.cpp rename to test/TestHexdumpWidget.cpp diff --git a/src/test/main.cpp b/test/main.cpp similarity index 100% rename from src/test/main.cpp rename to test/main.cpp From be74bc3e5e06d7be2b3e7bbe477b575426d40d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 31 May 2022 14:50:16 +0200 Subject: [PATCH 17/17] Fix test command --- test/TestHexdumpWidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/TestHexdumpWidget.cpp b/test/TestHexdumpWidget.cpp index 13377f744..76eaa250f 100644 --- a/test/TestHexdumpWidget.cpp +++ b/test/TestHexdumpWidget.cpp @@ -28,8 +28,8 @@ void TestHexdumpWidget::toUpper() void TestHexdumpWidget::something() { - QString a = Core()->cmd("fo"); - qDebug() << "r2 returned:" << a; + QString a = Core()->cmd("fortune"); + qDebug() << "rz returned:" << a; } DECLARE_TEST(TestHexdumpWidget)