Changeset View
Changeset View
Standalone View
Standalone View
debuggers/gdb/unittests/test_gdb.cpp
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Line(s) | |||||
249 | 249 | | |||
250 | #define WAIT_FOR(session, condition) \ | 250 | #define WAIT_FOR(session, condition) \ | ||
251 | do { \ | 251 | do { \ | ||
252 | TestWaiter w((session), #condition, __FILE__, __LINE__); \ | 252 | TestWaiter w((session), #condition, __FILE__, __LINE__); \ | ||
253 | while (w.waitUnless((condition))) /* nothing */ ; \ | 253 | while (w.waitUnless((condition))) /* nothing */ ; \ | ||
254 | } while(0) | 254 | } while(0) | ||
255 | 255 | | |||
256 | #define COMPARE_DATA(index, expected) \ | 256 | #define COMPARE_DATA(index, expected) \ | ||
257 | compareData((index), (expected), __FILE__, __LINE__) | 257 | do { if(!compareData((index), (expected), __FILE__, __LINE__)) return; } while (0) | ||
258 | 258 | | |||
259 | void compareData(QModelIndex index, QString expected, const char *file, int line) | 259 | bool compareData(QModelIndex index, QString expected, const char *file, int line) | ||
260 | { | 260 | { | ||
261 | QString s = index.model()->data(index, Qt::DisplayRole).toString(); | 261 | QString s = index.model()->data(index, Qt::DisplayRole).toString(); | ||
262 | if (s != expected) { | 262 | if (s != expected) { | ||
263 | QFAIL(qPrintable(QString("'%0' didn't match expected '%1' in %2:%3").arg(s).arg(expected).arg(file).arg(line))); | 263 | QTest::qFail(qPrintable(QString("'%0' didn't match expected '%1' in %2:%3") | ||
264 | .arg(s).arg(expected).arg(file).arg(line)), | ||||
265 | file, line); | ||||
266 | return false; | ||||
264 | } | 267 | } | ||
268 | return true; | ||||
265 | } | 269 | } | ||
266 | 270 | | |||
267 | static const QString debugeeFileName = findSourceFile("debugee.cpp"); | 271 | static const QString debugeeFileName = findSourceFile("debugee.cpp"); | ||
268 | 272 | | |||
269 | KDevelop::BreakpointModel* breakpoints() | 273 | KDevelop::BreakpointModel* breakpoints() | ||
270 | { | 274 | { | ||
271 | return KDevelop::ICore::self()->debugController()->breakpointModel(); | 275 | return KDevelop::ICore::self()->debugController()->breakpointModel(); | ||
272 | } | 276 | } | ||
▲ Show 20 Lines • Show All 1719 Lines • ▼ Show 20 Line(s) | 1985 | #ifdef HAVE_PATH_WITH_SPACES_TEST | |||
1992 | session->run(); | 1996 | session->run(); | ||
1993 | WAIT_FOR_STATE(session, DebugSession::EndedState); | 1997 | WAIT_FOR_STATE(session, DebugSession::EndedState); | ||
1994 | #endif | 1998 | #endif | ||
1995 | } | 1999 | } | ||
1996 | 2000 | | |||
1997 | bool GdbTest::waitForState(DebugSession *session, DebugSession::DebuggerState state, | 2001 | bool GdbTest::waitForState(DebugSession *session, DebugSession::DebuggerState state, | ||
1998 | const char *file, int line, bool waitForIdle) | 2002 | const char *file, int line, bool waitForIdle) | ||
1999 | { | 2003 | { | ||
2000 | QPointer<DebugSession> s(session); //session can get deleted in DebugController | 2004 | QPointer<MIDebugSession> s(session); //session can get deleted in DebugController | ||
2001 | QTime stopWatch; | 2005 | QTime stopWatch; | ||
2002 | stopWatch.start(); | 2006 | stopWatch.start(); | ||
2003 | while (s.data()->state() != state || (waitForIdle && s->debuggerStateIsOn(s_dbgBusy))) { | 2007 | | ||
2008 | // legacy behavior for tests that implicitly may require waiting for idle, | ||||
2009 | // but which were written before waitForIdle was added | ||||
2010 | waitForIdle = waitForIdle || state != MIDebugSession::EndedState; | ||||
2011 | | ||||
2012 | while (s && (s->state() != state || (waitForIdle && s->debuggerStateIsOn(s_dbgBusy)))) { | ||||
2004 | if (stopWatch.elapsed() > 5000) { | 2013 | if (stopWatch.elapsed() > 5000) { | ||
2005 | qWarning() << "current state" << s.data()->state() << "waiting for" << state; | 2014 | qWarning() << "current state" << s->state() << "waiting for" << state; | ||
2006 | QTest::qFail(qPrintable(QString("Timeout before reaching state %0").arg(state)), | 2015 | QTest::qFail(qPrintable(QString("Timeout before reaching state %0").arg(state)), | ||
2007 | file, line); | 2016 | file, line); | ||
2008 | return false; | 2017 | return false; | ||
2009 | } | 2018 | } | ||
2010 | QTest::qWait(20); | 2019 | QTest::qWait(20); | ||
2011 | if (!s) { | 2020 | } | ||
2012 | if (state == DebugSession::EndedState) | 2021 | | ||
2013 | break; | 2022 | // NOTE: don't wait anymore after leaving the loop. Waiting re-enters event loop and | ||
2023 | // may change session state. | ||||
2024 | | ||||
2025 | if (!s && state != MIDebugSession::EndedState) { | ||||
2014 | QTest::qFail(qPrintable(QString("Session ended before reaching state %0").arg(state)), | 2026 | QTest::qFail(qPrintable(QString("Session ended before reaching state %0").arg(state)), | ||
2015 | file, line); | 2027 | file, line); | ||
2016 | return false; | 2028 | return false; | ||
2017 | } | 2029 | } | ||
2018 | } | | |||
2019 | if (!waitForIdle && state != DebugSession::EndedState) { | | |||
2020 | // legacy behavior for tests that implicitly may require waiting for idle, | | |||
2021 | // but which were written before waitForIdle was added | | |||
2022 | QTest::qWait(100); | | |||
2023 | } | | |||
2024 | 2030 | | |||
2025 | qDebug() << "Reached state " << state << " in " << file << ':' << line; | 2031 | qDebug() << "Reached state " << state << " in " << file << ':' << line; | ||
2026 | return true; | 2032 | return true; | ||
2027 | } | 2033 | } | ||
2028 | } // end of namespace GDB | 2034 | } // end of namespace GDB | ||
2029 | } // end of namespace KDevMI | 2035 | } // end of namespace KDevMI | ||
2030 | 2036 | | |||
2031 | QTEST_MAIN(KDevMI::GDB::GdbTest) | 2037 | QTEST_MAIN(KDevMI::GDB::GdbTest) | ||
2032 | 2038 | | |||
2033 | 2039 | | |||
2034 | #include "test_gdb.moc" | 2040 | #include "test_gdb.moc" | ||
2035 | #include "moc_test_gdb.cpp" | 2041 | #include "moc_test_gdb.cpp" | ||
2036 | 2042 | |