You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
181 lines
4.4 KiB
181 lines
4.4 KiB
15 years ago
|
/*
|
||
|
This file is or will be part of KDE desktop environment
|
||
|
|
||
|
(c) 2006 Dirk Mueller <mueller@kde.org>
|
||
|
|
||
|
It is licensed under GPL version 2.
|
||
|
|
||
|
If it is part of KDE libraries than this file is licensed under
|
||
|
LGPL version 2.
|
||
|
*/
|
||
|
|
||
|
#include <unistd.h>
|
||
|
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqdir.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
#include "kdirwatchunittest.h"
|
||
|
|
||
|
void KDirWatchTest::VERIFY_NOTHING()
|
||
|
{
|
||
|
unsigned m_s[3];
|
||
|
for(int i = 0; i < 3; ++i)
|
||
|
m_s[i] = m_signals[i];
|
||
|
|
||
|
for (int i = 0; i < 20; ++i) {
|
||
|
usleep(100*1000);
|
||
14 years ago
|
tqApp->processEvents();
|
||
15 years ago
|
}
|
||
|
|
||
|
bool nothing_failed = true;
|
||
|
for (int i = 0; i < 3; ++i)
|
||
|
if (m_s[i] != m_signals[i])
|
||
|
nothing_failed = false;
|
||
|
|
||
|
KDirWatch::statistics();
|
||
|
|
||
|
VERIFY (nothing_failed);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KDirWatchTest::VERIFY_DIRTY(const TQString& alert)
|
||
15 years ago
|
{
|
||
|
unsigned m_s[3];
|
||
|
for(int i = 0; i < 3; ++i)
|
||
|
m_s[i] = m_signals[i];
|
||
|
|
||
|
for (int i = 0; i < 20; ++i) {
|
||
|
usleep(100*1000);
|
||
14 years ago
|
tqApp->processEvents();
|
||
15 years ago
|
}
|
||
|
|
||
|
VERIFY (m_s[sigCreated] == m_signals[sigCreated] &&
|
||
|
m_s[sigDeleted] == m_signals[sigDeleted] &&
|
||
|
m_s[sigDirty] + 1 == m_signals[sigDirty] &&
|
||
|
m_lastSignal == alert);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KDirWatchTest::VERIFY_CREATED(const TQString& alert)
|
||
15 years ago
|
{
|
||
|
unsigned m_s[3];
|
||
|
for(int i = 0; i < 3; ++i)
|
||
|
m_s[i] = m_signals[i];
|
||
|
|
||
|
for (int i = 0; i < 20; ++i) {
|
||
|
usleep(100*1000);
|
||
14 years ago
|
tqApp->processEvents();
|
||
15 years ago
|
}
|
||
|
|
||
|
VERIFY (m_s[sigDirty] == m_signals[sigDirty] &&
|
||
|
m_s[sigDeleted] == m_signals[sigDeleted] &&
|
||
|
m_s[sigCreated] + 1 == m_signals[sigCreated] &&
|
||
|
m_lastSignal == alert);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KDirWatchTest::VERIFY_DELETED(const TQString& alert)
|
||
15 years ago
|
{
|
||
|
unsigned m_s[3];
|
||
|
for(int i = 0; i < 3; ++i)
|
||
|
m_s[i] = m_signals[i];
|
||
|
|
||
|
for (int i = 0; i < 20; ++i) {
|
||
|
usleep(100*1000);
|
||
14 years ago
|
tqApp->processEvents();
|
||
15 years ago
|
}
|
||
|
|
||
|
VERIFY (m_s[sigDirty] == m_signals[sigDirty] &&
|
||
|
m_s[sigCreated] == m_signals[sigCreated] &&
|
||
|
m_s[sigDeleted] + 1 == m_signals[sigDeleted] &&
|
||
|
m_lastSignal == alert);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KDirWatchTest::remove_file (const TQString& file)
|
||
15 years ago
|
{
|
||
15 years ago
|
::unlink (TQFile::encodeName(file));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KDirWatchTest::touch_file (const TQString& file)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQFile f(file);
|
||
15 years ago
|
f.open(IO_WriteOnly);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KDirWatchTest::rename_file(const TQString& from, const TQString& to)
|
||
15 years ago
|
{
|
||
15 years ago
|
::rename(TQFile::encodeName(from), TQFile::encodeName(to));
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
KUNITTEST_MODULE ( tdeunittest_kdirwatch, "KDirWatchTest" )
|
||
15 years ago
|
KUNITTEST_MODULE_REGISTER_TESTER (KDirWatchTest)
|
||
|
|
||
15 years ago
|
#define SLEEP() TQApplication::processEvents();
|
||
15 years ago
|
|
||
|
void KDirWatchTest::allTests()
|
||
|
{
|
||
|
for(int loop=0; loop<3; ++loop) {
|
||
|
d = new KDirWatch;
|
||
|
VERIFY (d != 0);
|
||
|
|
||
15 years ago
|
TQDir* dir = new TQDir(m_workingDir);
|
||
15 years ago
|
VERIFY (dir != 0);
|
||
|
|
||
15 years ago
|
connect(d, TQT_SIGNAL (dirty( const TQString &)), TQT_SLOT( slotDirty( const TQString &)) );
|
||
|
connect(d, TQT_SIGNAL (created( const TQString &)), TQT_SLOT( slotCreated( const TQString &)) );
|
||
|
connect(d, TQT_SIGNAL (deleted( const TQString &)), TQT_SLOT( slotDeleted( const TQString &)) );
|
||
15 years ago
|
|
||
|
VERIFY (dir->mkdir (m_workingDir));
|
||
|
|
||
|
d->addDir (m_workingDir);
|
||
|
VERIFY_NOTHING();
|
||
|
dir->mkdir ("does");
|
||
|
VERIFY_DIRTY (m_workingDir);
|
||
|
touch_file (m_workingDir + "/file");
|
||
|
VERIFY_DIRTY (m_workingDir);
|
||
|
VERIFY_NOTHING ();
|
||
|
remove_file (m_workingDir + "/file");
|
||
|
d->addDir (m_workingDir + "/does/not/exist");
|
||
|
d->removeDir (m_workingDir);
|
||
|
VERIFY_NOTHING();
|
||
|
|
||
|
dir->mkdir ("does/not");
|
||
|
VERIFY_NOTHING();
|
||
|
dir->mkdir ("does/not/exist");
|
||
|
VERIFY_CREATED (m_workingDir + "/does/not/exist");
|
||
|
|
||
|
dir->rmdir ("does/not/exist");
|
||
|
VERIFY_DELETED (m_workingDir + "/does/not/exist");
|
||
|
dir->rmdir ("does/not");
|
||
|
VERIFY_NOTHING();
|
||
|
dir->rmdir ("does");
|
||
|
VERIFY_NOTHING();
|
||
|
|
||
|
d->addFile(m_workingDir + "/a");
|
||
|
touch_file(m_workingDir + "/a");
|
||
|
VERIFY_CREATED (m_workingDir + "/a");
|
||
|
|
||
|
rename_file (m_workingDir + "/a", m_workingDir + "/b");
|
||
|
VERIFY_DELETED (m_workingDir + "/a");
|
||
|
VERIFY_NOTHING();
|
||
|
|
||
|
touch_file (m_workingDir + "/a");
|
||
|
VERIFY_CREATED (m_workingDir + "/a");
|
||
|
VERIFY_NOTHING();
|
||
|
|
||
|
touch_file (m_workingDir + "/a");
|
||
|
VERIFY_DIRTY (m_workingDir + "/a");
|
||
|
|
||
|
remove_file (m_workingDir + "/b");
|
||
|
VERIFY_NOTHING();
|
||
|
|
||
|
d->removeFile(m_workingDir + "/a");
|
||
|
|
||
|
remove_file(m_workingDir + "/a");
|
||
|
|
||
|
VERIFY (dir->rmdir (m_workingDir));
|
||
|
delete d;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#include "kdirwatchunittest.moc"
|