2
Copyright (C) 2010 by Vishesh Handa <handa.vish@gmail.com>
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License or (at your option) version 3 or any later version
8
accepted by the membership of KDE e.V. (or its successor approved
9
by the membership of KDE e.V.), which shall act as a proxy
10
defined in Section 14 of version 3 of the license.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include "filesystemtreetest.h"
25
#include <KStandardDirs>
26
#include <qtest_kde.h>
29
#include <QTextStream>
36
void FileSystemTreeTest::testAdditions()
39
FileSystemTreeItem * item, *p;
41
tree.add( new FileSystemTreeItem( "/a/b/c" ) );
42
QVERIFY( tree.toList() == QList<QString>() << "/a/b/c" );
44
tree.add( new FileSystemTreeItem( "/a/b/" ) );
45
QVERIFY( tree.toList() == QList<QString>() << "/a/b/" << "/a/b/c" );
46
item = tree.find( "/a/b/c" );
48
p = tree.find( "/a/b/" );
50
QVERIFY( item->parent() == p );
52
tree.add( new FileSystemTreeItem( "/a/" ) );
53
QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/" << "/a/b/c" );
55
tree.add( new FileSystemTreeItem( "/a/ba" ) );
56
QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/" << "/a/b/c" << "/a/ba" );
58
tree.add( new FileSystemTreeItem( "/a/bb" ) );
59
QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/" << "/a/b/c" << "/a/ba" << "/a/bb" );
61
tree.add( new FileSystemTreeItem( "/a/b/d" ) );
62
QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/" << "/a/b/c" << "/a/b/d" << "/a/ba" << "/a/bb" );
64
int size = tree.size();
65
tree.add( new FileSystemTreeItem("/a/b/d") );
66
QVERIFY( tree.size() == size );
69
tree.add( new FileSystemTreeItem( "/b" ) );
70
QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/" << "/a/b/c" << "/a/b/d" << "/a/ba" << "/a/bb" << "/b" );
72
kDebug() << tree.toList();
75
item = tree.find("/a/b/d");
77
QVERIFY( item->url() == "/a/b/d" );
84
checkPointers( tree );
86
kDebug() << "Old : " << size << " New : "<< tree.size();
87
QVERIFY( size == (tree.size() +1) );
89
kDebug() << "To list..";
90
kDebug() << "LIST :::: " << tree.toList();
91
QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/c" << "/a/b/d" << "/a/ba" << "/a/bb" << "/b" );
93
item = tree.find("/a/b/c");
95
FileSystemTreeItem * parent = tree.find("/a/");
96
QVERIFY( parent != 0 );
97
QVERIFY( item->parent() == parent );
101
QVERIFY( size == tree.size() + 1 );
102
QVERIFY( tree.toList() == QList<QString>() << "/a/b/c" << "/a/b/d" << "/a/ba" << "/a/bb" << "/b" );
104
tree.add( new FileSystemTreeItem("/a/") );
105
QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/c" << "/a/b/d" << "/a/ba" << "/a/bb" << "/b" );
108
void FileSystemTreeTest::checkPointers(const FileSystemTree& tree)
110
foreach( FileSystemTreeItem * p, tree.rootNodes() ) {
115
void FileSystemTreeTest::check( FileSystemTreeItem* child, FileSystemTreeItem* parent)
117
kDebug() << "Checking with child ";
118
kDebug() << child->url();
119
kDebug() << " and parent ";
121
kDebug() << parent->url();
126
QVERIFY( child->parent() == parent );
128
QVERIFY( parent->children().indexOf( child ) != -1 );
131
void FileSystemTreeTest::checkAll( FileSystemTreeItem* c, FileSystemTreeItem* p)
134
foreach( FileSystemTreeItem * ch, c->children() ) {
140
QTEST_KDEMAIN_CORE(FileSystemTreeTest)