| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). |
| 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 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 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" |