Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uses a command line option to specify the kind of exception to create.
- Loading branch information
1 parent
2f63c61
commit fc5a612
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
build-* | ||
example/example.pro.user | ||
test/test.pro.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#include <QApplication> | ||
#include <QDebug> | ||
#include <QMessageBox> | ||
|
||
#include <assert.h> | ||
|
||
#ifdef ASM_CRASH_REPORT | ||
#include "asmCrashReport.h" | ||
#endif | ||
|
||
class crashTest | ||
{ | ||
public: | ||
void crashMe() { function1(); } | ||
|
||
void accessViolation( int val ) | ||
{ | ||
qDebug() << Q_FUNC_INFO; | ||
int * foo = NULL; | ||
*foo = val; | ||
} | ||
|
||
void stackoverflow() | ||
{ | ||
qDebug() << Q_FUNC_INFO; | ||
int foo[10000]; | ||
(void)foo; | ||
stackoverflow(); | ||
} | ||
|
||
void throwError() | ||
{ | ||
qDebug() << Q_FUNC_INFO; | ||
throw "error"; | ||
} | ||
|
||
void outOfBounds() | ||
{ | ||
qDebug() << Q_FUNC_INFO; | ||
std::vector<int> v; | ||
v[0] = 5; | ||
} | ||
|
||
void abort() | ||
{ | ||
qDebug() << Q_FUNC_INFO; | ||
::abort(); | ||
} | ||
|
||
private: | ||
void divideByZero( int val ) | ||
{ | ||
qDebug() << Q_FUNC_INFO << val; | ||
int foo = val / 0; | ||
} | ||
|
||
void function2( int val ) | ||
{ | ||
++val; | ||
|
||
divideByZero( val ); | ||
} | ||
|
||
void function1() | ||
{ | ||
function2( 41 ); | ||
} | ||
}; | ||
|
||
|
||
void myterminate () { | ||
qCritical() << "terminate handler called"; | ||
abort(); // forces abnormal termination | ||
} | ||
|
||
|
||
int main( int argc, char** argv ) | ||
{ | ||
std::set_terminate (myterminate); | ||
|
||
QApplication app( argc, argv ); | ||
|
||
app.setApplicationName( QStringLiteral( "asmCrashReportTest" ) ); | ||
app.setApplicationVersion( QStringLiteral( "1.0.0" ) ); | ||
|
||
#ifdef ASM_CRASH_REPORT | ||
asmCrashReport::setSignalHandler( QString(), [] (const QString &inFileName, bool inSuccess) { | ||
QString message; | ||
|
||
if ( inSuccess ) | ||
{ | ||
message = QStringLiteral( "Sorry, %1 has crashed. A log file was written to:\n\n%2\n\nPlease email this to support@example.com." ).arg( QCoreApplication::applicationName(), inFileName ); | ||
} | ||
else | ||
{ | ||
message = QStringLiteral( "Sorry, %1 has crashed and we could not write a log file to:\n\n%2\n\nPlease contact support@example.com." ).arg( QCoreApplication::applicationName(), inFileName ); | ||
} | ||
|
||
QMessageBox::critical( nullptr, QObject::tr( "%1 Crashed" ).arg( QCoreApplication::applicationName() ), message ); | ||
}); | ||
#endif | ||
|
||
int methode = 0; | ||
if (argc > 1) | ||
{ | ||
methode = QString(argv[1]).toInt(); | ||
} | ||
crashTest ct; | ||
switch (methode) { | ||
case 0: | ||
ct.crashMe(); | ||
break; | ||
case 1: | ||
ct.accessViolation(17); | ||
break; | ||
case 2: | ||
ct.stackoverflow(); | ||
break; | ||
case 3: | ||
ct.throwError(); | ||
break; | ||
case 4: | ||
ct.outOfBounds(); | ||
break; | ||
case 5: | ||
ct.abort(); | ||
break; | ||
default: | ||
qDebug() << "Invalid methode"; | ||
return 1; | ||
} | ||
|
||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
message( "Building test" ) | ||
|
||
TARGET = asmCrashReportTest | ||
TEMPLATE = app | ||
|
||
mac:CONFIG -= app_bundle | ||
CONFIG += c++14 | ||
|
||
QT += widgets | ||
|
||
if ( !include( ../asmCrashReport.pri ) ) { | ||
error( Could not find the asmCrashReport.pri file. ) | ||
} | ||
|
||
SOURCES += \ | ||
main.cpp |