Link CutterTest against Cutter

This commit is contained in:
Florian Märkl 2019-03-20 18:30:37 +01:00
parent 2d191ad17f
commit 45ec96129e
7 changed files with 63 additions and 22 deletions

View File

@ -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()

View File

@ -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; }

View File

@ -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);

View File

@ -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)

View File

@ -1,9 +0,0 @@
QT += widgets testlib
HEADERS = AutoTest.h \
CutterTest.h
SOURCES = main.cpp \
TestHexdumpWidget.cpp \
CutterTest.cpp

View File

@ -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()
@ -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"

View File

@ -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);
}