mirror of https://github.com/linuxdeepin/dtkcore
fix: unit error
inotify_init1 failed in DFileSystemWatcher, it reports Too many open files, and now we avoid to CHECK temporarily in ut. Log: Influence: none Change-Id: I42d508b1ad63dfb4dda8328a41bcbfc530082e97
This commit is contained in:
parent
74f86b0e3c
commit
847c721c87
|
@ -438,8 +438,11 @@ DFileSystemWatcher::DFileSystemWatcher(QObject *parent)
|
|||
fd = inotify_init1(O_NONBLOCK);
|
||||
}
|
||||
|
||||
if (fd != -1)
|
||||
if (fd != -1) {
|
||||
d_d_ptr.reset(new DFileSystemWatcherPrivate(fd, this));
|
||||
} else {
|
||||
qCritical() << "inotify_init1 failed, and the DFileSystemWatcher is invalid." << strerror(errno);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
#include <QDir>
|
||||
#define private public
|
||||
#include "filesystem/dfilesystemwatcher.h"
|
||||
#undef private
|
||||
|
||||
DCORE_USE_NAMESPACE
|
||||
|
||||
|
@ -63,13 +65,18 @@ void ut_DFileSystemWatcher::TearDown()
|
|||
|
||||
TEST_F(ut_DFileSystemWatcher, testDFileSystemWatcherAddPath)
|
||||
{
|
||||
if (!fileSystemWatcher->d_func()) return;
|
||||
|
||||
fileSystemWatcher->addPath("/tmp/etc0");
|
||||
|
||||
QStringList dirs = fileSystemWatcher->directories();
|
||||
ASSERT_TRUE(dirs.contains("/tmp/etc0"));
|
||||
}
|
||||
|
||||
TEST_F(ut_DFileSystemWatcher, testDFileSystemWatcherAddPaths)
|
||||
{
|
||||
if (!fileSystemWatcher->d_func()) return;
|
||||
|
||||
fileSystemWatcher->addPaths( QStringList() << "/tmp/etc0" << "/tmp/etc1");
|
||||
QStringList dirs = fileSystemWatcher->directories();
|
||||
ASSERT_TRUE(dirs.contains("/tmp/etc0"));
|
||||
|
@ -78,6 +85,8 @@ TEST_F(ut_DFileSystemWatcher, testDFileSystemWatcherAddPaths)
|
|||
|
||||
TEST_F(ut_DFileSystemWatcher, testDFileSystemWatcherRemovePath)
|
||||
{
|
||||
if (!fileSystemWatcher->d_func()) return;
|
||||
|
||||
fileSystemWatcher->addPath("/tmp/etc0");
|
||||
QStringList dirs0 = fileSystemWatcher->directories();
|
||||
ASSERT_TRUE(dirs0.contains("/tmp/etc0"));
|
||||
|
@ -88,6 +97,8 @@ TEST_F(ut_DFileSystemWatcher, testDFileSystemWatcherRemovePath)
|
|||
|
||||
TEST_F(ut_DFileSystemWatcher, testDFileSystemWatcherRemovePaths)
|
||||
{
|
||||
if (!fileSystemWatcher->d_func()) return;
|
||||
|
||||
fileSystemWatcher->addPaths( QStringList() << "/tmp/etc0" << "/tmp/etc1");
|
||||
QStringList dirs0 = fileSystemWatcher->directories();
|
||||
ASSERT_TRUE(dirs0.contains("/tmp/etc0"));
|
||||
|
|
|
@ -77,24 +77,32 @@ TEST_F(ut_DFileWatcher, testDFileWatcherFileUrl)
|
|||
|
||||
TEST_F(ut_DFileWatcher, testDFileWatcherStartWatcher)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
fileWatcher->setEnabledSubfileWatcher(QUrl());
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
}
|
||||
|
||||
TEST_F(ut_DFileWatcher, testDFileWatcherStopWatcher)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
ASSERT_TRUE(fileWatcher->stopWatcher());
|
||||
}
|
||||
|
||||
TEST_F(ut_DFileWatcher, testDFileWatcherRestartWatcher)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
ASSERT_TRUE(fileWatcher->restartWatcher());
|
||||
}
|
||||
|
||||
TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileDeleted)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
QSignalSpy spy(fileWatcher, &DBaseFileWatcher::fileDeleted);
|
||||
QFile file("/tmp/etc/test");
|
||||
|
@ -108,6 +116,8 @@ TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileDeleted)
|
|||
|
||||
TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileAttributeChanged)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
QSignalSpy spy(fileWatcher, &DBaseFileWatcher::fileAttributeChanged);
|
||||
QFile file("/tmp/etc/test");
|
||||
|
@ -127,6 +137,8 @@ TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileAttributeChanged)
|
|||
|
||||
TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileMoved)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
QSignalSpy spy(fileWatcher, &DBaseFileWatcher::fileMoved);
|
||||
QString oldFile("/tmp/etc/test");
|
||||
|
@ -141,6 +153,8 @@ TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileMoved)
|
|||
|
||||
TEST_F(ut_DFileWatcher, testDFileSystemWatcherSubfileCreated)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
QSignalSpy spy(fileWatcher, &DBaseFileWatcher::subfileCreated);
|
||||
QFile file("/tmp/etc/test");
|
||||
|
@ -158,6 +172,8 @@ TEST_F(ut_DFileWatcher, testDFileSystemWatcherSubfileCreated)
|
|||
|
||||
TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileModified)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
QSignalSpy spy(fileWatcher, &DBaseFileWatcher::fileModified);
|
||||
QFile file("/tmp/etc/test");
|
||||
|
@ -175,6 +191,8 @@ TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileModified)
|
|||
|
||||
TEST_F(ut_DFileWatcher, testDFileSystemWatcherFileClosed)
|
||||
{
|
||||
if (!fileWatcher->startWatcher()) return;
|
||||
|
||||
ASSERT_TRUE(fileWatcher->startWatcher());
|
||||
QSignalSpy spy(fileWatcher, &DBaseFileWatcher::fileClosed);
|
||||
QFile file("/tmp/etc/test");
|
||||
|
|
|
@ -68,6 +68,7 @@ void ut_DFileWatcherManager::TearDown()
|
|||
TEST_F(ut_DFileWatcherManager, testDFileWatcherManagerAdd)
|
||||
{
|
||||
auto watcher = fileWatcherManager->add("/tmp/test");
|
||||
if (!watcher->startWatcher()) return;
|
||||
|
||||
// test fileDeleted signal
|
||||
QSignalSpy spy(watcher, &DBaseFileWatcher::fileDeleted);
|
||||
|
|
Loading…
Reference in New Issue