actually turn the dptr test into a test
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 13 Nov 2010 20:55:06 +0000 (20:55 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 13 Nov 2010 20:55:06 +0000 (20:55 +0000)
git-svn-id: https://silmor.de/svn/softmagic/elam/trunk@625 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

tests/dptr/dptrpriv.cpp
tests/dptr/dptrtest.cpp
tests/dptr/dptrtest.h

index c3466ba..4e3dc91 100644 (file)
@@ -3,21 +3,12 @@
 
 #include <QtCore>
 
-class DPTR_CLASS_NAME(ClassWithDptr)
+class DPTR_CLASS_NAME(ClassWithDptr):public DPtr
 {
        public:
-               static int cnt;
                int num;
-               Private(){num=cnt++;qDebug()<<"creates dptr"<<num;}
-               Private(const Private&p){num=p.num;qDebug()<<"copyconst dptr"<<num;}
-               ~Private(){qDebug()<<"delete dptr"<<num;}
-               Private& operator=(const Private&p){
-                       qDebug()<<"copy dptr"<<p.num<<"onto"<<num;
-                       num=p.num;
-                       return *this;
-               }
+               Private(){num=0;}
 };
-int ClassWithDptr::Private::cnt=0;
 DEFINE_DPTR(ClassWithDptr)
 
 
@@ -25,25 +16,20 @@ 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:
-               static int cnt;
                int num;
-               Private(){num=cnt++;qDebug()<<"creates dptr"<<num;}
-               Private(const Private&p){num=p.num;qDebug()<<"copyconst dptr"<<num;}
-               ~Private(){qDebug()<<"delete dptr"<<num;}
-               Private& operator=(const Private&p){
-                       qDebug()<<"copy dptr"<<p.num<<"onto"<<num;
-                       num=p.num;
-                       return *this;
-               }
+               Private(){num=0;}
 };
-int ClassWithSDptr::Private::cnt=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;}
index a2f5a68..273106c 100644 (file)
@@ -7,30 +7,39 @@
 
 void DPtrTest::simpleDP()
 {
-       qDebug()<<"dynamic"<<ClassWithDptr().toString();
-       qDebug()<<"dynamic"<<ClassWithDptr().toString();
-       ClassWithDptr so;
-       qDebug()<<"static"<<so.toString();
-       ClassWithDptr co(so);
-       qDebug()<<"static copy"<<co.toString();
-       qDebug()<<"dynamic copy"<<ClassWithDptr(so).toString();
-       co=ClassWithDptr();
-       qDebug()<<"overwritten"<<co.toString();
+       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()
 {
-       qDebug()<<"dynamic"<<ClassWithSDptr().toString();
-       qDebug()<<"dynamic"<<ClassWithSDptr().toString();
-       ClassWithSDptr so;
-       qDebug()<<"static"<<so.toString();
-       ClassWithSDptr co(so);
-       qDebug()<<"static copy"<<co.toString();
-       qDebug()<<"dynamic copy"<<ClassWithSDptr(so).toString();
-       co=ClassWithSDptr();
-       qDebug()<<"overwritten"<<co.toString();
-       so=co;
-       qDebug()<<"overwritten"<<so.toString();
+       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);
 }
 
 
index 0b5a30b..8c821d8 100644 (file)
@@ -7,6 +7,8 @@ class ClassWithDptr
        DECLARE_DPTR(d)
        public:
                QString toString()const;
+               int num()const;
+               void setNum(int);
 };
 
 class ClassWithSDptr
@@ -14,6 +16,8 @@ class ClassWithSDptr
        DECLARE_SHARED_DPTR(d)
        public:
                QString toString()const;
+               int num()const;
+               void setNum(int);
 };