3 #include <QCoreApplication>
11 #include "threadtestcontroller.h"
12 #include "HelperClass.h"
18 - open the same file twice
19 - lock fileregion with readlock (handle 1)
20 - try to lock the same region with a read lock -> should work
21 - try to lock the same region with a write lock -> should fail
23 - create a writelock on handle 1
24 - create a writelock on handle 2 ->>fail
25 - try to lock totally different regions --> should work
27 2. multiple threadstest:
29 - open the same file twice
30 - let thread 1 lock (READLOCK) a region of a file
31 - let thread 2 do the same lock ---> should work
32 - let thread 1 upgrade its lock to a WRITELOCK -->should fail (because thread 2 holds the readlock)
34 - try to lock totally different regions of the file -> should work
37 int main(int argc, char *argv[])
39 QCoreApplication app(argc, argv);
43 QFile file1("lock.file");
44 QFile file2("lock.file");
46 if(file1.open(QIODevice::ReadWrite) && file2.open(QIODevice::ReadWrite))
51 qDebug()<<"----Starting first test----";
52 qDebug()<<"Trying to create some locks without collison";
54 QxtFileLock lock1(&file1,0x10,20,QxtFileLock::WriteLock);
56 qDebug()<<"---- Write Lock Test passed----";
58 qDebug()<<"---- Write Lock Test failed----";
62 QxtFileLock lock2(&file2,0x10,20,QxtFileLock::ReadLock);
64 qDebug()<<"---- Read Lock Test passed----";
66 qDebug()<<"---- Read Lock Test failed----";
74 qDebug()<<"----Starting next test-----";
75 qDebug()<<"Trying to readlock the same region with DIFFERENT handles ";
76 QxtFileLock *lock1 = new QxtFileLock(&file1,0x10,20,QxtFileLock::ReadLock);
77 QxtFileLock *lock2 = new QxtFileLock(&file2,0x10,20,QxtFileLock::ReadLock);
79 if(lock1->lock() && lock2->lock())
80 qDebug()<<"----Test passed----";
82 qDebug()<<"----Test failed----";
90 qDebug()<<"----Starting next test-----";
91 qDebug()<<"Trying to lock the same region with DIFFERENT handles and different locks";
92 QxtFileLock *lock1 = new QxtFileLock(&file1,0x10,20,QxtFileLock::ReadLock);
93 QxtFileLock *lock2 = new QxtFileLock(&file2,0x10,20,QxtFileLock::WriteLock);
95 if(lock1->lock() && !lock2->lock())
96 qDebug()<<"----Test passed----";
98 qDebug()<<"----Test failed----";
106 qDebug()<<"----Starting next test-----";
107 qDebug()<<"Trying to writelock the same region with DIFFERENT handles";
108 QxtFileLock *lock1 = new QxtFileLock(&file1,0x10,20,QxtFileLock::WriteLock);
109 QxtFileLock *lock2 = new QxtFileLock(&file2,0x10,20,QxtFileLock::WriteLock);
111 if(lock1->lock() && !lock2->lock())
112 qDebug()<<"----Test passed----";
114 qDebug()<<"----Test failed----";
122 qDebug()<<"----Starting next test-----";
123 qDebug()<<"Trying to writelock the different regions with DIFFERENT handles";
124 QxtFileLock *lock1 = new QxtFileLock(&file1,0x10,20,QxtFileLock::WriteLock);
125 QxtFileLock *lock2 = new QxtFileLock(&file2,0x10+21,20,QxtFileLock::WriteLock);
127 if(lock1->lock() && lock2->lock())
128 qDebug()<<"----Test passed----";
130 qDebug()<<"----Test failed----";
138 qDebug()<<"All base tests are finished, now starting the threaded tests";
140 ThreadTestController controller;
142 if(controller.startTests())
144 HelperClass *testClient = new HelperClass();