author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
#include <q3dict.h> |
|
46 |
||
47 |
//TESTED_CLASS= |
|
48 |
//TESTED_FILES= |
|
49 |
||
50 |
class tst_Q3Dict : public QObject |
|
51 |
{ |
|
52 |
Q_OBJECT |
|
53 |
||
54 |
public: |
|
55 |
tst_Q3Dict(); |
|
56 |
virtual ~tst_Q3Dict(); |
|
57 |
||
58 |
||
59 |
public slots: |
|
60 |
void init(); |
|
61 |
void cleanup(); |
|
62 |
private slots: |
|
63 |
void resize(); |
|
64 |
void acc_01_data(); |
|
65 |
void acc_01(); |
|
66 |
}; |
|
67 |
||
68 |
tst_Q3Dict::tst_Q3Dict() |
|
69 |
{ |
|
70 |
} |
|
71 |
||
72 |
tst_Q3Dict::~tst_Q3Dict() |
|
73 |
{ |
|
74 |
} |
|
75 |
||
76 |
void tst_Q3Dict::init() |
|
77 |
{ |
|
78 |
// TODO: Add initialization code here. |
|
79 |
// This will be executed immediately before each test is run. |
|
80 |
} |
|
81 |
||
82 |
void tst_Q3Dict::cleanup() |
|
83 |
{ |
|
84 |
// TODO: Add cleanup code here. |
|
85 |
// This will be executed immediately after each test is run. |
|
86 |
} |
|
87 |
||
88 |
#include <qstring.h> |
|
89 |
#include <qdatetime.h> |
|
90 |
#include <stdlib.h> |
|
91 |
||
92 |
QString keyFor( int i ) |
|
93 |
{ |
|
94 |
QString key; |
|
95 |
key.sprintf("KEY%05d",i); |
|
96 |
return key; |
|
97 |
} |
|
98 |
#include <qapplication.h> |
|
99 |
||
100 |
void tst_Q3Dict::acc_01_data() |
|
101 |
{ |
|
102 |
QTest::addColumn<int>("nins"); |
|
103 |
||
104 |
//next we fill it with data |
|
105 |
QTest::newRow( "data0" ) << 5; |
|
106 |
} |
|
107 |
||
108 |
void tst_Q3Dict::acc_01() |
|
109 |
{ |
|
110 |
QFETCH(int,nins); |
|
111 |
||
112 |
Q3Dict<int> dict(7); |
|
113 |
dict.setAutoDelete( TRUE ); |
|
114 |
||
115 |
for ( int i=0; i<nins; i++ ) { |
|
116 |
int* d = new int; |
|
117 |
*d = i; |
|
118 |
dict.insert(keyFor(i),d); |
|
119 |
} |
|
120 |
||
121 |
QTime timer; |
|
122 |
int start = nins/500; |
|
123 |
if (start == 0) |
|
124 |
start = 1; |
|
125 |
for ( int j=start; j<1000000; j+=1+j/10 ) {// don't want to use 0 here because that crashes |
|
126 |
||
127 |
timer.start(); |
|
128 |
dict.resize( j ); |
|
129 |
// int ms_r = timer.elapsed(); |
|
130 |
||
131 |
int n=0; |
|
132 |
timer.start(); |
|
133 |
for ( Q3DictIterator<int> it(dict); it.current(); ++it ) { |
|
134 |
n++; |
|
135 |
QVERIFY( keyFor( *it.current() ) == it.currentKey() ); // Wrong key if it isn't |
|
136 |
} |
|
137 |
QVERIFY( !(n != nins) ); //qFatal("Too few"); |
|
138 |
// int ms_i = timer.elapsed(); |
|
139 |
||
140 |
timer.start(); |
|
141 |
for ( int i = 0; i<nins; i++ ) { |
|
142 |
dict.find( keyFor(i) ); |
|
143 |
} |
|
144 |
// int ms_f = timer.elapsed(); |
|
145 |
// qDebug("resize(%d) took %dms, iteration took %dms, find took %0.1f\265s", j, ms_r, ms_i, 1000.0*ms_f/nins); |
|
146 |
} |
|
147 |
||
148 |
dict.resize( 10 ); |
|
149 |
} |
|
150 |
||
151 |
void tst_Q3Dict::resize() |
|
152 |
{ |
|
153 |
Q3Dict<int> dict(7); |
|
154 |
QVERIFY( dict.size() == 7 ); |
|
155 |
||
156 |
int i; |
|
157 |
for ( i=0; i<7; i++ ) { |
|
158 |
int* d = new int(i); |
|
159 |
dict.insert(keyFor(i),d); |
|
160 |
} |
|
161 |
||
162 |
QVERIFY(dict.size() == 7); |
|
163 |
||
164 |
for (i = 0; i < 7; ++i) |
|
165 |
delete dict.take(keyFor(i)); |
|
166 |
} |
|
167 |
||
168 |
QTEST_APPLESS_MAIN(tst_Q3Dict) |
|
169 |
#include "tst_q3dict.moc" |