X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcontrib%2Flibqxt-2007-10-24%2Ftests%2FQxtFileLock%2Fsrc%2Flocktestclient.cpp;fp=src%2Fcontrib%2Flibqxt-2007-10-24%2Ftests%2FQxtFileLock%2Fsrc%2Flocktestclient.cpp;h=bc2f800f90a0681b1618efd137611ed259d46b04;hp=0000000000000000000000000000000000000000;hb=a634acadbcf6017474f68a3eaf7cb632660e9e49;hpb=cd122ca8e0d2c0ffc5397e0a813c75d791a7e6e3 diff --git a/src/contrib/libqxt-2007-10-24/tests/QxtFileLock/src/locktestclient.cpp b/src/contrib/libqxt-2007-10-24/tests/QxtFileLock/src/locktestclient.cpp new file mode 100644 index 00000000..bc2f800f --- /dev/null +++ b/src/contrib/libqxt-2007-10-24/tests/QxtFileLock/src/locktestclient.cpp @@ -0,0 +1,104 @@ +#include "locktestclient.h" +#include +#include +#include +#include +#include + +LockTestClient::LockTestClient(QObject *parent) + : QObject(parent) +{ +} + + +LockTestClient::~LockTestClient() +{ +} + +void LockTestClient::startTests() +{ + QTcpSocket socket; + socket.connectToHost ( "localhost", 55555); + char control; + + #define GetNextCommand() if(socket.waitForReadyRead (-1) )\ + {\ + if(socket.bytesAvailable() > 1)\ + qDebug()<<"Something is wrong here";\ + socket.getChar(&control);\ + if(control == 'a')\ + {\ + socket.disconnectFromHost();\ + return;\ + }\ + if(control != 'n')\ + { \ + qDebug()<<"Wrong control command";\ + }\ + } + + if(socket.waitForConnected (-1)) + { + QFile file("lock.file"); + + if(!file.open(QIODevice::ReadWrite)) + { + qDebug()<<"Could not open lockfile"; + return; + } + + if(1) + { + GetNextCommand(); + //Trying to readlock the same region + QxtFileLock lock(&file,0x10,20,QxtFileLock::ReadLock); + if(lock.lock()) + socket.putChar('s'); //s for success f for fail + else + socket.putChar('f'); + socket.waitForBytesWritten(-1); + } + + if(1) + { + GetNextCommand(); + //Trying to lock the same region with different locks + QxtFileLock lock(&file,0x10,20,QxtFileLock::WriteLock); + + if(!lock.lock()) + socket.putChar('s'); //s for success f for fail + else + socket.putChar('f'); + socket.waitForBytesWritten(-1); + } + + if(1) + { + GetNextCommand(); + //Trying to writelock the same region + QxtFileLock lock(&file,0x10,20,QxtFileLock::WriteLock); + + if(!lock.lock()) + socket.putChar('s'); //s for success f for fail + else + socket.putChar('f'); + socket.waitForBytesWritten(-1); + } + + if(1) + { + GetNextCommand(); + //Trying to writelock different regions + QxtFileLock lock(&file,0x10+21,20,QxtFileLock::WriteLock); + + if(lock.lock()) + socket.putChar('s'); //s for success f for fail + else + socket.putChar('f'); + socket.waitForBytesWritten(-1); + } + + } +} + +