mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
Update QsLog to 2.1 snapshot 46b643d5bcbc
This commit is contained in:
31
third_party/QsLog/unittest/QtTestUtil/QtTestUtil.h
vendored
Normal file
31
third_party/QsLog/unittest/QtTestUtil/QtTestUtil.h
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Remko Troncon
|
||||
* Licensed under the MIT license.
|
||||
* See COPYING for license details.
|
||||
*/
|
||||
|
||||
#ifndef QtTestUtil_H
|
||||
#define QtTestUtil_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtTest/QtTest>
|
||||
#include "QtTestUtil/TestRegistration.h"
|
||||
|
||||
/**
|
||||
* A macro to register a test class.
|
||||
*
|
||||
* This macro will create a static variable which registers the
|
||||
* testclass with the TestRegistry, and creates an instance of the
|
||||
* test class.
|
||||
*
|
||||
* Execute this macro in the body of your unit test's .cpp file, e.g.
|
||||
* class MyTest {
|
||||
* ...
|
||||
* };
|
||||
*
|
||||
* QTTESTUTIL_REGISTER_TEST(MyTest)
|
||||
*/
|
||||
#define QTTESTUTIL_REGISTER_TEST(TestClass) \
|
||||
static QtTestUtil::TestRegistration<TestClass> TestClass##Registration
|
||||
|
||||
#endif
|
17
third_party/QsLog/unittest/QtTestUtil/SimpleChecker.cpp
vendored
Normal file
17
third_party/QsLog/unittest/QtTestUtil/SimpleChecker.cpp
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Remko Troncon
|
||||
* Licensed under the MIT license.
|
||||
* See COPYING for license details.
|
||||
*/
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "QtTestUtil/TestRegistry.h"
|
||||
|
||||
/**
|
||||
* Runs all tests registered with the QtTestUtil registry.
|
||||
*/
|
||||
int main(int argc, char* argv[]) {
|
||||
QCoreApplication application(argc, argv);
|
||||
return QtTestUtil::TestRegistry::getInstance()->runTests(argc, argv);
|
||||
}
|
38
third_party/QsLog/unittest/QtTestUtil/TestRegistration.h
vendored
Normal file
38
third_party/QsLog/unittest/QtTestUtil/TestRegistration.h
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Remko Troncon
|
||||
* Licensed under the MIT license.
|
||||
* See COPYING for license details.
|
||||
*/
|
||||
|
||||
#ifndef QtTestUtil_TestRegistration_H
|
||||
#define QtTestUtil_TestRegistration_H
|
||||
|
||||
#include "QtTestUtil/TestRegistry.h"
|
||||
|
||||
namespace QtTestUtil {
|
||||
|
||||
/**
|
||||
* A wrapper class around a test to manage registration and static
|
||||
* creation of an instance of the test class.
|
||||
* This class is used by QTTESTUTIL_REGISTER_TEST(), and you should not
|
||||
* use this class directly.
|
||||
*/
|
||||
template<typename TestClass>
|
||||
class TestRegistration {
|
||||
public:
|
||||
TestRegistration() {
|
||||
test_ = new TestClass();
|
||||
TestRegistry::getInstance()->registerTest(test_);
|
||||
}
|
||||
|
||||
~TestRegistration() {
|
||||
delete test_;
|
||||
}
|
||||
|
||||
private:
|
||||
TestClass* test_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
30
third_party/QsLog/unittest/QtTestUtil/TestRegistry.cpp
vendored
Normal file
30
third_party/QsLog/unittest/QtTestUtil/TestRegistry.cpp
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Remko Troncon
|
||||
* Licensed under the MIT license.
|
||||
* See COPYING for license details.
|
||||
*/
|
||||
|
||||
#include "QtTestUtil/TestRegistry.h"
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
namespace QtTestUtil {
|
||||
|
||||
TestRegistry* TestRegistry::getInstance() {
|
||||
static TestRegistry registry;
|
||||
return ®istry;
|
||||
}
|
||||
|
||||
void TestRegistry::registerTest(QObject* test) {
|
||||
tests_ += test;
|
||||
}
|
||||
|
||||
int TestRegistry::runTests(int argc, char* argv[]) {
|
||||
int result = 0;
|
||||
foreach(QObject* test, tests_) {
|
||||
result |= QTest::qExec(test, argc, argv);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
49
third_party/QsLog/unittest/QtTestUtil/TestRegistry.h
vendored
Normal file
49
third_party/QsLog/unittest/QtTestUtil/TestRegistry.h
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Remko Troncon
|
||||
* Licensed under the MIT license.
|
||||
* See COPYING for license details.
|
||||
*/
|
||||
|
||||
#ifndef QtTestUtil_TestRegistry_H
|
||||
#define QtTestUtil_TestRegistry_H
|
||||
|
||||
#include <QList>
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace QtTestUtil {
|
||||
|
||||
/**
|
||||
* A registry of QtTest test classes.
|
||||
* All test classes registered with QTTESTUTIL_REGISTER_TEST add
|
||||
* themselves to this registry. All registered tests can then be run at
|
||||
* once using runTests().
|
||||
*/
|
||||
class TestRegistry {
|
||||
public:
|
||||
/**
|
||||
* Retrieve the single instance of the registry.
|
||||
*/
|
||||
static TestRegistry* getInstance();
|
||||
|
||||
/**
|
||||
* Register a QtTest test.
|
||||
* This method is called by QTTESTUTIL_REGISTER_TEST, and you should
|
||||
* not use this method directly.
|
||||
*/
|
||||
void registerTest(QObject*);
|
||||
|
||||
/**
|
||||
* Run all registered tests using QTest::qExec()
|
||||
*/
|
||||
int runTests(int argc, char* argv[]);
|
||||
|
||||
private:
|
||||
TestRegistry() {}
|
||||
|
||||
private:
|
||||
QList<QObject*> tests_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user