File indexing completed on 2024-11-10 04:40:15
0001 /* 0002 SPDX-FileCopyrightText: 2010 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "../sharedvaluepool_p.h" 0008 #include <QTest> 0009 0010 #include <QList> 0011 #include <QSet> 0012 #include <set> 0013 #include <utility> 0014 #include <vector> 0015 0016 using namespace Akonadi; 0017 0018 class SharedValuePoolTest : public QObject 0019 { 0020 Q_OBJECT 0021 private Q_SLOTS: 0022 void testQVector_data() 0023 { 0024 QTest::addColumn<int>("size"); 0025 QTest::newRow("10") << 10; 0026 QTest::newRow("100") << 100; 0027 } 0028 0029 void testQVector() 0030 { 0031 QFETCH(int, size); 0032 QList<QByteArray> data; 0033 Internal::SharedValuePool<QByteArray, QList> pool; 0034 0035 for (int i = 0; i < size; ++i) { 0036 QByteArray b(10, static_cast<char>(i)); 0037 data.push_back(b); 0038 QCOMPARE(pool.sharedValue(b), b); 0039 QCOMPARE(pool.sharedValue(b), b); 0040 } 0041 0042 QBENCHMARK { 0043 for (const QByteArray &b : std::as_const(data)) { 0044 pool.sharedValue(b); 0045 } 0046 } 0047 } 0048 0049 /*void testQSet_data() 0050 { 0051 QTest::addColumn<int>( "size" ); 0052 QTest::newRow( "10" ) << 10; 0053 QTest::newRow( "100" ) << 100; 0054 } 0055 0056 void testQSet() 0057 { 0058 QFETCH( int, size ); 0059 QList<QByteArray> data; 0060 Internal::SharedValuePool<QByteArray, QSet> pool; 0061 0062 for ( int i = 0; i < size; ++i ) { 0063 QByteArray b( 10, (char)i ); 0064 data.push_back( b ); 0065 QCOMPARE( pool.sharedValue( b ), b ); 0066 QCOMPARE( pool.sharedValue( b ), b ); 0067 } 0068 0069 QBENCHMARK { 0070 foreach ( const QByteArray &b, data ) 0071 pool.sharedValue( b ); 0072 } 0073 }*/ 0074 }; 0075 0076 QTEST_MAIN(SharedValuePoolTest) 0077 0078 #include "sharedvaluepooltest.moc"