From 1a6e626b9c76f45fc1c330231d3c449305f32db9 Mon Sep 17 00:00:00 2001 From: konrad Date: Tue, 28 Dec 2010 19:41:20 +0000 Subject: [PATCH] move tests to dptr git-svn-id: https://silmor.de/svn/softmagic/chester/trunk@691 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- tests/dptrpriv.cpp | 35 +++++++++++++++++++++++++++++++++++ tests/dptrtest.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/dptrtest.h | 32 ++++++++++++++++++++++++++++++++ tests/dptrtest.pro | 7 +++++++ 4 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 tests/dptrpriv.cpp create mode 100644 tests/dptrtest.cpp create mode 100644 tests/dptrtest.h create mode 100644 tests/dptrtest.pro diff --git a/tests/dptrpriv.cpp b/tests/dptrpriv.cpp new file mode 100644 index 0000000..4e3dc91 --- /dev/null +++ b/tests/dptrpriv.cpp @@ -0,0 +1,35 @@ + +#include "dptrtest.h" + +#include + +class DPTR_CLASS_NAME(ClassWithDptr):public DPtr +{ + public: + int num; + Private(){num=0;} +}; +DEFINE_DPTR(ClassWithDptr) + + +QString ClassWithDptr::toString()const +{ + return QString("class with dptr %1").arg(d->num); +} +int ClassWithDptr::num()const{return d->num;} +void ClassWithDptr::setNum(int n){d->num=n;} + +class DPTR_CLASS_NAME(ClassWithSDptr):public SharedDPtr +{ + public: + int num; + Private(){num=0;} +}; +DEFINE_SHARED_DPTR(ClassWithSDptr) + +QString ClassWithSDptr::toString()const +{ + return QString("class with shared dptr %1").arg(d->num); +} +int ClassWithSDptr::num()const{return d->num;} +void ClassWithSDptr::setNum(int n){d->num=n;} diff --git a/tests/dptrtest.cpp b/tests/dptrtest.cpp new file mode 100644 index 0000000..273106c --- /dev/null +++ b/tests/dptrtest.cpp @@ -0,0 +1,46 @@ + +#include "dptrtest.h" + +#include +#include +#include + +void DPtrTest::simpleDP() +{ + QCOMPARE(ClassWithDptr().num(),0); + ClassWithDptr o1;o1.setNum(1); + QCOMPARE(o1.num(),1); + ClassWithDptr o2;o2.setNum(2); + ClassWithDptr o3(o1); + QCOMPARE(o1.num(),1); + QCOMPARE(o2.num(),2); + QCOMPARE(o3.num(),1); + o1=o2; + QCOMPARE(o1.num(),2); + o2.setNum(3); + QCOMPARE(o1.num(),2); + QCOMPARE(o2.num(),3); +} + +void DPtrTest::sharedDP() +{ + QCOMPARE(ClassWithSDptr().num(),0); + ClassWithSDptr o1;o1.setNum(1); + QCOMPARE(o1.num(),1); + ClassWithSDptr o2;o2.setNum(2); + ClassWithSDptr o3(o1); + QCOMPARE(o1.num(),1); + QCOMPARE(o2.num(),2); + QCOMPARE(o3.num(),1); + o1.setNum(4); + QCOMPARE(o1.num(),4); + QCOMPARE(o2.num(),2); + QCOMPARE(o3.num(),4); + o2=o1;o2.setNum(5); + QCOMPARE(o1.num(),5); + QCOMPARE(o2.num(),5); + QCOMPARE(o3.num(),5); +} + + +QTEST_MAIN(DPtrTest) \ No newline at end of file diff --git a/tests/dptrtest.h b/tests/dptrtest.h new file mode 100644 index 0000000..8c821d8 --- /dev/null +++ b/tests/dptrtest.h @@ -0,0 +1,32 @@ +#include "../../src/dptr.h" + +#include + +class ClassWithDptr +{ + DECLARE_DPTR(d) + public: + QString toString()const; + int num()const; + void setNum(int); +}; + +class ClassWithSDptr +{ + DECLARE_SHARED_DPTR(d) + public: + QString toString()const; + int num()const; + void setNum(int); +}; + + +#include + +class DPtrTest:public QObject +{ + Q_OBJECT + private slots: + void simpleDP(); + void sharedDP(); +}; diff --git a/tests/dptrtest.pro b/tests/dptrtest.pro new file mode 100644 index 0000000..7abdab0 --- /dev/null +++ b/tests/dptrtest.pro @@ -0,0 +1,7 @@ +TEMPLATE = app +TARGET = dptrtest +QT -= gui +CONFIG += qtestlib debug + +SOURCES += dptrtest.cpp dptrpriv.cpp +HEADERS += dptrtest.h \ No newline at end of file -- 1.7.2.5