本文整理汇总了C++中QTEST_ASSERT函数的典型用法代码示例。如果您正苦于以下问题:C++ QTEST_ASSERT函数的具体用法?C++ QTEST_ASSERT怎么用?C++ QTEST_ASSERT使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QTEST_ASSERT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printMessage
static void printMessage(const char *type, const char *msg, const char *file = 0, int line = 0)
{
QTEST_ASSERT(type);
QTEST_ASSERT(msg);
char buf[1024];
const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction()
: "UnknownTestFunc";
const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : "";
const char *gtag = QTestResult::currentGlobalDataTag()
? QTestResult::currentGlobalDataTag()
: "";
const char *filler = (tag[0] && gtag[0]) ? ":" : "";
if (file) {
QTest::qt_snprintf(buf, sizeof(buf), "%s: %s::%s(%s%s%s)%s%s\n"
#ifdef Q_OS_WIN
"%s(%d) : failure location\n"
#else
" Loc: [%s(%d)]\n"
#endif
, type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag,
msg[0] ? " " : "", msg, file, line);
} else {
QTest::qt_snprintf(buf, sizeof(buf), "%s: %s::%s(%s%s%s)%s%s\n",
type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag,
msg[0] ? " " : "", msg);
}
memcpy(buf, type, strlen(type));
outputMessage(buf);
}
示例2: QTEST_ASSERT
void QTestTable::addColumn(int type, const char *name)
{
QTEST_ASSERT(type);
QTEST_ASSERT(name);
d->append(type, name);
}
示例3: QTEST_ASSERT
void QTestBasicStreamer::startStreaming()
{
QTEST_ASSERT(!QTest::stream);
const char *out = QTestLog::outputFileName();
if (!out) {
QTest::stream = stdout;
return;
}
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE)
if (::fopen_s(&QTest::stream, out, "wt")) {
#else
QTest::stream = ::fopen(out, "wt");
if (!QTest::stream) {
#endif
printf("Unable to open file for logging: %s", out);
::exit(1);
}
}
bool QTestBasicStreamer::isTtyOutput()
{
QTEST_ASSERT(QTest::stream);
#if defined(Q_OS_WIN) || defined(Q_OS_INTEGRITY)
return true;
#else
static bool ttyoutput = isatty(fileno(QTest::stream));
return ttyoutput;
#endif
}
示例4: QTEST_ASSERT
void QTestLog::addPass(const char *msg)
{
QTEST_ASSERT(QTest::testLogger);
QTEST_ASSERT(msg);
QTest::testLogger->addIncident(QAbstractTestLogger::Pass, msg);
}
示例5: printMessage
static void printMessage(const char *type, const char *msg, const char *file = 0, int line = 0)
{
QTEST_ASSERT(type);
QTEST_ASSERT(msg);
QTestCharBuffer buf;
const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction()
: "UnknownTestFunc";
const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : "";
const char *gtag = QTestResult::currentGlobalDataTag()
? QTestResult::currentGlobalDataTag()
: "";
const char *filler = (tag[0] && gtag[0]) ? ":" : "";
if (file) {
QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n"
#ifdef Q_OS_WIN
"%s(%d) : failure location\n"
#else
" Loc: [%s(%d)]\n"
#endif
, type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag,
msg[0] ? " " : "", msg, file, line);
} else {
QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n",
type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag,
msg[0] ? " " : "", msg);
}
// In colored mode, printf above stripped our nonprintable control characters.
// Put them back.
memcpy(buf.data(), type, strlen(type));
outputMessage(buf.data());
}
示例6: QTEST_ASSERT
void QAbstractTestLogger::startLogging()
{
QTEST_ASSERT(!QTest::stream);
const char *out = QTestLog::outputFileName();
if (!out) {
QTest::stream = stdout;
return;
}
#if defined(_MSC_VER) && _MSC_VER >= 1400
if (::fopen_s(&QTest::stream, out, "wt")) {
#else
QTest::stream = ::fopen(out, "wt");
if (!QTest::stream) {
#endif
printf("Unable to open file for logging: %s", out);
::exit(1);
}
}
void QAbstractTestLogger::stopLogging()
{
QTEST_ASSERT(QTest::stream);
if (QTest::stream != stdout)
fclose(QTest::stream);
QTest::stream = 0;
}
示例7: mouseWheel
static void mouseWheel(QWindow* window, QObject* item, Qt::MouseButtons buttons,
Qt::KeyboardModifiers stateKey,
QPointF _pos, int xDelta, int yDelta, int delay = -1)
{
QTEST_ASSERT(window);
QTEST_ASSERT(item);
if (delay == -1 || delay < QTest::defaultMouseDelay())
delay = QTest::defaultMouseDelay();
if (delay > 0)
QTest::qWait(delay);
QPoint pos;
QQuickItem *sgitem = qobject_cast<QQuickItem *>(item);
if (sgitem)
pos = sgitem->mapToScene(_pos).toPoint();
QTEST_ASSERT(buttons == Qt::NoButton || buttons & Qt::MouseButtonMask);
QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
QWheelEvent we(pos, window->mapToGlobal(pos), QPoint(0, 0), QPoint(xDelta, yDelta), 0, Qt::Vertical, buttons, stateKey);
QSpontaneKeyEvent::setSpontaneous(&we); // hmmmm
if (!qApp->notify(window, &we))
QTest::qWarn("Wheel event not accepted by receiving window");
}
示例8: QTEST_ASSERT
bool QTestResult::compare(bool success, const char *failureMsg,
char *val1, char *val2,
const char *actual, const char *expected,
const char *file, int line)
{
QTEST_ASSERT(expected);
QTEST_ASSERT(actual);
char msg[1024];
if (QTestLog::verboseLevel() >= 2) {
qsnprintf(msg, 1024, "QCOMPARE(%s, %s)", actual, expected);
QTestLog::info(msg, file, line);
}
if (!failureMsg)
failureMsg = "Compared values are not the same";
if (success && QTest::expectFailMode) {
qsnprintf(msg, 1024, "QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected);
} else if (val1 || val2) {
qsnprintf(msg, 1024, "%s\n Actual (%s): %s\n Expected (%s): %s",
failureMsg,
actual, val1 ? val1 : "<null>",
expected, val2 ? val2 : "<null>");
} else
qsnprintf(msg, 1024, "%s", failureMsg);
delete [] val1;
delete [] val2;
return checkStatement(success, msg, file, line);
}
示例9: QTEST_ASSERT
void QAbstractTestLogger::startLogging()
{
QTEST_ASSERT(!QTest::stream);
const char *out = QTestLog::outputFileName();
if (!out) {
QTest::stream = stdout;
return;
}
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE)
if (::fopen_s(&QTest::stream, out, "wt")) {
#else
QTest::stream = ::fopen(out, "wt");
if (!QTest::stream) {
#endif
printf("Unable to open file for logging: %s", out);
::exit(1);
}
}
void QAbstractTestLogger::stopLogging()
{
QTEST_ASSERT(QTest::stream);
if (QTest::stream != stdout) {
fclose(QTest::stream);
} else {
#ifdef Q_OS_SYMBIAN
// Convenience sleep for Symbian and TRK. Without this sleep depending on the timing the
// user would not see the complete output because it is still pending in any of the buffers
// before arriving via the USB port on the development PC
User::AfterHighRes(2*1000*1000);
#endif
}
QTest::stream = 0;
}
示例10: QTEST_ASSERT
QTestData::QTestData(const char *tag, QTestTable *parent)
{
QTEST_ASSERT(tag);
QTEST_ASSERT(parent);
d = new QTestDataPrivate;
d->tag = qstrdup(tag);
d->parent = parent;
d->data = new void *[parent->elementCount()];
memset(d->data, 0, parent->elementCount() * sizeof(void*));
}
示例11: QTEST_ASSERT
void QAbstractTestLogger::outputString(const char *msg)
{
QTEST_ASSERT(stream);
QTEST_ASSERT(msg);
char *filtered = new char[strlen(msg) + 1];
strcpy(filtered, msg);
filterUnprintable(filtered);
::fputs(filtered, stream);
::fflush(stream);
delete [] filtered;
}
示例12: FROM
void MainTest::deletePost()
{
auto count = FROM(db.posts())
WHERE(Post::idField() == postId)
DELETE();
QTEST_ASSERT(count == 1);
count = FROM(db.posts())
WHERE(Post::idField() == postId)
COUNT();
QTEST_ASSERT(count == 0);
}
示例13: messageHandler
static void messageHandler(QtMsgType type, const char *msg)
{
static QBasicAtomicInt counter = Q_BASIC_ATOMIC_INITIALIZER(QTest::maxWarnings);
if (!msg || !QTest::testLogger) {
// if this goes wrong, something is seriously broken.
qInstallMsgHandler(oldMessageHandler);
QTEST_ASSERT(msg);
QTEST_ASSERT(QTest::testLogger);
}
if (handleIgnoredMessage(type, msg))
// the message is expected, so just swallow it.
return;
if (type != QtFatalMsg) {
if (counter <= 0)
return;
if (!counter.deref()) {
QTest::testLogger->addMessage(QAbstractTestLogger::QSystem,
"Maximum amount of warnings exceeded.");
return;
}
}
switch (type) {
case QtDebugMsg:
QTest::testLogger->addMessage(QAbstractTestLogger::QDebug, msg);
break;
case QtCriticalMsg:
QTest::testLogger->addMessage(QAbstractTestLogger::QSystem, msg);
break;
case QtWarningMsg:
QTest::testLogger->addMessage(QAbstractTestLogger::QWarning, msg);
break;
case QtFatalMsg:
QTest::testLogger->addMessage(QAbstractTestLogger::QFatal, msg);
/* Right now, we're inside the custom message handler and we're
* being qt_message_output in qglobal.cpp. After we return from
* this function, it will proceed with calling exit() and abort()
* and hence crash. Therefore, we call these logging functions such
* that we wrap up nicely, and in particular produce well-formed XML. */
QTestResult::addFailure("Received a fatal error.", "Unknown file", 0);
QTestLog::leaveTestFunction();
QTestLog::stopLogging();
break;
}
}
示例14: testLogger
QT_BEGIN_NAMESPACE
QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger)
: testLogger(logger)
{
QTEST_ASSERT(testLogger);
}
示例15: QTEST_ASSERT
void QTestXunitStreamer::output(QTestElement *element) const
{
QTEST_ASSERT(element);
outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
outputElements(element);
}