jasmine-headless-webkit/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp

130 lines
3.3 KiB
C++
Raw Permalink Normal View History

2011-08-03 16:26:39 +00:00
#include <QtTest/QtTest>
#include "ConsoleOutput.h"
#include "ConsoleOutput_test.h"
using namespace std;
2011-08-30 19:59:09 +00:00
ConsoleOutputTest::ConsoleOutputTest() : QObject() {}
2011-08-03 16:26:39 +00:00
void ConsoleOutputTest::testPassed() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
2011-08-03 16:26:39 +00:00
2011-08-29 17:35:36 +00:00
output.consoleLogUsed = true;
2011-08-03 16:26:39 +00:00
output.outputIO = &buffer;
output.passed("test");
QVERIFY(buffer.str() == ".");
QVERIFY(output.successes.size() == 1);
QVERIFY(output.failures.size() == 0);
2011-08-29 17:35:36 +00:00
QVERIFY(output.consoleLogUsed == false);
2011-08-03 16:26:39 +00:00
}
void ConsoleOutputTest::testFailed() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
2011-08-03 16:26:39 +00:00
2011-08-29 17:35:36 +00:00
output.consoleLogUsed = true;
2011-08-03 16:26:39 +00:00
output.outputIO = &buffer;
output.failed("test");
QVERIFY(buffer.str() == "F");
QVERIFY(output.successes.size() == 0);
QVERIFY(output.failures.size() == 1);
2011-08-29 17:35:36 +00:00
QVERIFY(output.consoleLogUsed == false);
2011-08-03 16:26:39 +00:00
}
2011-08-26 15:18:04 +00:00
void ConsoleOutputTest::testErrorLog() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
2011-08-26 15:18:04 +00:00
output.outputIO = &buffer;
output.errorLog("message", 1, "source");
QVERIFY(buffer.str() == "[error] source:1 : message\n");
}
2011-08-29 17:35:36 +00:00
void ConsoleOutputTest::testInternalLog() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
2011-08-29 17:35:36 +00:00
output.outputIO = &buffer;
output.internalLog("note", "message");
QVERIFY(buffer.str() == "[note] message\n");
}
void ConsoleOutputTest::testConsoleLog() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
2011-08-29 17:35:36 +00:00
output.consoleLogUsed = false;
output.outputIO = &buffer;
output.consoleLog("log");
QVERIFY(buffer.str() == "\n[console] log\n");
}
void ConsoleOutputTest::testConsoleLogUsed() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
2011-08-29 17:35:36 +00:00
output.consoleLogUsed = true;
output.outputIO = &buffer;
output.consoleLog("log");
QVERIFY(buffer.str() == "[console] log\n");
}
void ConsoleOutputTest::testLogSpecFilename() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
2011-08-29 17:35:36 +00:00
output.outputIO = &buffer;
output.logSpecFilename("whatever");
QVERIFY(buffer.str() == "\n\nwhatever\n");
}
void ConsoleOutputTest::testLogSpecResult() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
output.outputIO = &buffer;
output.logSpecResult("whatever");
QVERIFY(buffer.str() == " whatever\n");
}
void ConsoleOutputTest::testReportResultsFailedSingular() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
output.outputIO = &buffer;
output.reportFailure("1", "1", "1");
QVERIFY(buffer.str() == "\nFAIL: 1 test, 1 failure, 1 sec.\n");
}
void ConsoleOutputTest::testReportResultsFailedPlural() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
output.outputIO = &buffer;
output.reportFailure("2", "2", "2");
QVERIFY(buffer.str() == "\nFAIL: 2 tests, 2 failures, 2 secs.\n");
}
void ConsoleOutputTest::testReportResultsSucceeded() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
output.outputIO = &buffer;
output.reportSuccess("2", "2", "2");
QVERIFY(buffer.str() == "\nPASS: 2 tests, 2 failures, 2 secs.\n");
}
void ConsoleOutputTest::testReportResultsSucceededWithJSErrors() {
stringstream buffer;
2011-08-30 19:59:09 +00:00
ConsoleOutput output;
output.outputIO = &buffer;
output.reportSuccessWithJSErrors("2", "2", "2");
QVERIFY(buffer.str() == "\nPASS with JS errors: 2 tests, 2 failures, 2 secs.\n");
}
2011-08-03 16:26:39 +00:00
2011-08-30 19:59:09 +00:00
QTEST_MAIN(ConsoleOutputTest);
2011-08-03 16:26:39 +00:00