~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to nepomuk/services/backupsync/gui/test/filesystemtreetest.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
   Copyright (C) 2010 by Vishesh Handa <handa.vish@gmail.com>
3
 
 
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.
11
 
 
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.
16
 
 
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/>.
19
 
 */
20
 
 
21
 
#include "filesystemtreetest.h"
22
 
 
23
 
#include <KTempDir>
24
 
#include <KRandom>
25
 
#include <KStandardDirs>
26
 
#include <qtest_kde.h>
27
 
 
28
 
#include <QtTest>
29
 
#include <QTextStream>
30
 
#include <QFile>
31
 
#include <QSignalSpy>
32
 
#include <QEventLoop>
33
 
#include <QTimer>
34
 
#include <QDir>
35
 
 
36
 
void FileSystemTreeTest::testAdditions()
37
 
{
38
 
    FileSystemTree tree;
39
 
    FileSystemTreeItem * item, *p;
40
 
 
41
 
    tree.add( new FileSystemTreeItem( "/a/b/c" ) );
42
 
    QVERIFY( tree.toList() == QList<QString>() << "/a/b/c" );
43
 
   
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" );
47
 
    QVERIFY( item != 0 );
48
 
    p = tree.find( "/a/b/" );
49
 
    QVERIFY( p != 0 );
50
 
    QVERIFY( item->parent() == p );
51
 
    
52
 
    tree.add( new FileSystemTreeItem( "/a/" ) );
53
 
    QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/" << "/a/b/c" );
54
 
    
55
 
    tree.add( new FileSystemTreeItem( "/a/ba" ) );
56
 
    QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/" << "/a/b/c" << "/a/ba" );
57
 
    
58
 
    tree.add( new FileSystemTreeItem( "/a/bb" ) );
59
 
    QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/" << "/a/b/c" << "/a/ba" << "/a/bb" );
60
 
    
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" );
63
 
 
64
 
    int size = tree.size();
65
 
    tree.add( new FileSystemTreeItem("/a/b/d") );
66
 
    QVERIFY( tree.size() == size );
67
 
 
68
 
    
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" );
71
 
 
72
 
    kDebug() << tree.toList();
73
 
    
74
 
    // Find tests
75
 
    item = tree.find("/a/b/d");
76
 
    QVERIFY( item != 0 );
77
 
    QVERIFY( item->url() == "/a/b/d" );
78
 
    kDebug() << "?";
79
 
 
80
 
    size = tree.size();
81
 
    tree.remove("/a/b");
82
 
 
83
 
    // Check all pointers
84
 
    checkPointers( tree );
85
 
    
86
 
    kDebug() << "Old : " << size << " New : "<< tree.size();
87
 
    QVERIFY( size == (tree.size() +1) );
88
 
 
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" );
92
 
 
93
 
    item = tree.find("/a/b/c");
94
 
    QVERIFY( item != 0 );
95
 
    FileSystemTreeItem * parent = tree.find("/a/");
96
 
    QVERIFY( parent != 0 );
97
 
    QVERIFY( item->parent() == parent );
98
 
 
99
 
    size = tree.size();
100
 
    tree.remove( "/a" );
101
 
    QVERIFY( size == tree.size() + 1 );
102
 
    QVERIFY( tree.toList() == QList<QString>() << "/a/b/c" << "/a/b/d" << "/a/ba" << "/a/bb" << "/b" );
103
 
 
104
 
    tree.add( new FileSystemTreeItem("/a/") );
105
 
    QVERIFY( tree.toList() == QList<QString>() << "/a/" << "/a/b/c" << "/a/b/d" << "/a/ba" << "/a/bb" << "/b" );
106
 
}
107
 
 
108
 
void FileSystemTreeTest::checkPointers(const FileSystemTree& tree)
109
 
{
110
 
    foreach( FileSystemTreeItem * p, tree.rootNodes() ) {
111
 
        checkAll( p, 0 );
112
 
    }
113
 
}
114
 
 
115
 
void FileSystemTreeTest::check( FileSystemTreeItem* child, FileSystemTreeItem* parent)
116
 
{
117
 
    kDebug() << "Checking with child ";
118
 
    kDebug() << child->url();
119
 
    kDebug() << " and parent ";
120
 
    if( parent )
121
 
        kDebug() << parent->url();
122
 
    else
123
 
        kDebug() << " NULL";
124
 
    
125
 
    if( child )
126
 
        QVERIFY( child->parent() == parent );
127
 
    if( parent )
128
 
        QVERIFY( parent->children().indexOf( child ) != -1 );
129
 
}
130
 
 
131
 
void FileSystemTreeTest::checkAll( FileSystemTreeItem* c, FileSystemTreeItem* p)
132
 
{
133
 
    check( c, p );
134
 
    foreach( FileSystemTreeItem * ch, c->children() ) {
135
 
        check( ch, c );
136
 
    }
137
 
}
138
 
 
139
 
 
140
 
QTEST_KDEMAIN_CORE(FileSystemTreeTest)