1*2851c541SNicolas Bonnefon /* 2*2851c541SNicolas Bonnefon * Copyright (C) 2009, 2010 Nicolas Bonnefon and other contributors 3*2851c541SNicolas Bonnefon * 4*2851c541SNicolas Bonnefon * This file is part of glogg. 5*2851c541SNicolas Bonnefon * 6*2851c541SNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7*2851c541SNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8*2851c541SNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9*2851c541SNicolas Bonnefon * (at your option) any later version. 10*2851c541SNicolas Bonnefon * 11*2851c541SNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12*2851c541SNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*2851c541SNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*2851c541SNicolas Bonnefon * GNU General Public License for more details. 15*2851c541SNicolas Bonnefon * 16*2851c541SNicolas Bonnefon * You should have received a copy of the GNU General Public License 17*2851c541SNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18*2851c541SNicolas Bonnefon */ 19*2851c541SNicolas Bonnefon 2062819106SNicolas Bonnefon #include <QSignalSpy> 2162819106SNicolas Bonnefon #include <QMutexLocker> 2262819106SNicolas Bonnefon #include <QFile> 2362819106SNicolas Bonnefon 2462819106SNicolas Bonnefon #include "testlogdata.h" 2562819106SNicolas Bonnefon #include "logdata.h" 2662819106SNicolas Bonnefon 2762819106SNicolas Bonnefon #if QT_VERSION < 0x040500 2862819106SNicolas Bonnefon #define QBENCHMARK 2962819106SNicolas Bonnefon #endif 3062819106SNicolas Bonnefon 3162819106SNicolas Bonnefon #if !defined( TMPDIR ) 3262819106SNicolas Bonnefon #define TMPDIR "/tmp" 3362819106SNicolas Bonnefon #endif 3462819106SNicolas Bonnefon 355f0a91faSNicolas Bonnefon static const qint64 VBL_NB_LINES = 4999999LL; 3662819106SNicolas Bonnefon static const int VBL_LINE_PER_PAGE = 70; 3736c1f171SNicolas Bonnefon static const char* vbl_format="LOGDATA is a part of glogg, we are going to test it thoroughly, this is line\t\t%07d\n"; 3836c1f171SNicolas Bonnefon static const int VBL_LINE_LENGTH = (76+2+7) ; // Without the final '\n' ! 3936c1f171SNicolas Bonnefon static const int VBL_VISIBLE_LINE_LENGTH = (76+8+4+7); // Without the final '\n' ! 4062819106SNicolas Bonnefon 415f0a91faSNicolas Bonnefon static const qint64 SL_NB_LINES = 5000LL; 4262819106SNicolas Bonnefon static const int SL_LINE_PER_PAGE = 70; 4362819106SNicolas Bonnefon static const char* sl_format="LOGDATA is a part of glogg, we are going to test it thoroughly, this is line %06d\n"; 4462819106SNicolas Bonnefon static const int SL_LINE_LENGTH = 83; // Without the final '\n' ! 4562819106SNicolas Bonnefon 46b76c5bcfSNicolas Bonnefon static const char* partial_line_begin = "123... beginning of line."; 47b76c5bcfSNicolas Bonnefon static const char* partial_line_end = " end of line 123.\n"; 48b76c5bcfSNicolas Bonnefon 4962819106SNicolas Bonnefon void TestLogData::initTestCase() 5062819106SNicolas Bonnefon { 5162819106SNicolas Bonnefon QVERIFY( generateDataFiles() ); 5262819106SNicolas Bonnefon } 5362819106SNicolas Bonnefon 5462819106SNicolas Bonnefon void TestLogData::simpleLoad() 5562819106SNicolas Bonnefon { 5662819106SNicolas Bonnefon LogData logData; 5762819106SNicolas Bonnefon QSignalSpy progressSpy( &logData, SIGNAL( loadingProgressed( int ) ) ); 5862819106SNicolas Bonnefon 5962819106SNicolas Bonnefon // Register for notification file is loaded 60cef94aa9SNicolas Bonnefon connect( &logData, SIGNAL( loadingFinished( bool ) ), 6162819106SNicolas Bonnefon this, SLOT( loadingFinished() ) ); 6262819106SNicolas Bonnefon 6362819106SNicolas Bonnefon QBENCHMARK { 645f0a91faSNicolas Bonnefon logData.attachFile( TMPDIR "/verybiglog.txt" ); 6562819106SNicolas Bonnefon // Wait for the loading to be done 6662819106SNicolas Bonnefon { 6762819106SNicolas Bonnefon QApplication::exec(); 6862819106SNicolas Bonnefon } 6962819106SNicolas Bonnefon } 70db1ac0ecSNicolas Bonnefon QCOMPARE( (qint64) progressSpy.count(), logData.getFileSize() / (5LL*1024*1024) + 2 ); 71db1ac0ecSNicolas Bonnefon // Blocks of 5 MiB + 1 for the start notification (0%) 7262819106SNicolas Bonnefon QCOMPARE( logData.getNbLine(), VBL_NB_LINES ); 735fc7617dSNicolas Bonnefon QCOMPARE( logData.getMaxLength(), VBL_VISIBLE_LINE_LENGTH ); 745fc7617dSNicolas Bonnefon QCOMPARE( logData.getLineLength( 123 ), VBL_VISIBLE_LINE_LENGTH ); 7562819106SNicolas Bonnefon QCOMPARE( logData.getFileSize(), VBL_NB_LINES * (VBL_LINE_LENGTH+1LL) ); 7662819106SNicolas Bonnefon 7762819106SNicolas Bonnefon // Disconnect all signals 7862819106SNicolas Bonnefon disconnect( &logData, 0 ); 7962819106SNicolas Bonnefon } 8062819106SNicolas Bonnefon 8162819106SNicolas Bonnefon void TestLogData::multipleLoad() 8262819106SNicolas Bonnefon { 8362819106SNicolas Bonnefon LogData logData; 84cef94aa9SNicolas Bonnefon QSignalSpy finishedSpy( &logData, SIGNAL( loadingFinished( bool ) ) ); 8562819106SNicolas Bonnefon 8662819106SNicolas Bonnefon // Register for notification file is loaded 87cef94aa9SNicolas Bonnefon connect( &logData, SIGNAL( loadingFinished( bool ) ), 8862819106SNicolas Bonnefon this, SLOT( loadingFinished() ) ); 8962819106SNicolas Bonnefon 9062819106SNicolas Bonnefon // Start loading the VBL 915f0a91faSNicolas Bonnefon logData.attachFile( TMPDIR "/verybiglog.txt" ); 9262819106SNicolas Bonnefon 9362819106SNicolas Bonnefon // Immediately interrupt the loading 9462819106SNicolas Bonnefon logData.interruptLoading(); 9562819106SNicolas Bonnefon 9662819106SNicolas Bonnefon // and wait for the signal 9762819106SNicolas Bonnefon QApplication::exec(); 9862819106SNicolas Bonnefon 9962819106SNicolas Bonnefon // Check we have an empty file 10062819106SNicolas Bonnefon QCOMPARE( finishedSpy.count(), 1 ); 101cef94aa9SNicolas Bonnefon // TODO: check loadingFinished arg == false 1025f0a91faSNicolas Bonnefon QCOMPARE( logData.getNbLine(), 0LL ); 10362819106SNicolas Bonnefon QCOMPARE( logData.getMaxLength(), 0 ); 10462819106SNicolas Bonnefon QCOMPARE( logData.getFileSize(), 0LL ); 10562819106SNicolas Bonnefon 10662819106SNicolas Bonnefon // Restart the VBL 1075f0a91faSNicolas Bonnefon logData.attachFile( TMPDIR "/verybiglog.txt" ); 10862819106SNicolas Bonnefon 10962819106SNicolas Bonnefon // Ensure the counting has started 110a5fe2cedSNicolas Bonnefon { 11162819106SNicolas Bonnefon QMutex mutex; 11262819106SNicolas Bonnefon QWaitCondition sleep; 113a5fe2cedSNicolas Bonnefon // sleep.wait( &mutex, 10 ); 114a5fe2cedSNicolas Bonnefon } 11562819106SNicolas Bonnefon 11662819106SNicolas Bonnefon // Load the SL (should block until VBL is fully indexed) 1175f0a91faSNicolas Bonnefon logData.attachFile( TMPDIR "/smalllog.txt" ); 11862819106SNicolas Bonnefon 11962819106SNicolas Bonnefon // and wait for the 2 signals (one for each file) 12062819106SNicolas Bonnefon QApplication::exec(); 12162819106SNicolas Bonnefon QApplication::exec(); 12262819106SNicolas Bonnefon 12362819106SNicolas Bonnefon // Check we have the small log loaded 12462819106SNicolas Bonnefon QCOMPARE( finishedSpy.count(), 3 ); 12562819106SNicolas Bonnefon QCOMPARE( logData.getNbLine(), SL_NB_LINES ); 12662819106SNicolas Bonnefon QCOMPARE( logData.getMaxLength(), SL_LINE_LENGTH ); 12762819106SNicolas Bonnefon QCOMPARE( logData.getFileSize(), SL_NB_LINES * (SL_LINE_LENGTH+1LL) ); 12862819106SNicolas Bonnefon 12962819106SNicolas Bonnefon // Restart the VBL again 1305f0a91faSNicolas Bonnefon logData.attachFile( TMPDIR "/verybiglog.txt" ); 13162819106SNicolas Bonnefon 13262819106SNicolas Bonnefon // Immediately interrupt the loading 13362819106SNicolas Bonnefon logData.interruptLoading(); 13462819106SNicolas Bonnefon 13562819106SNicolas Bonnefon // and wait for the signal 13662819106SNicolas Bonnefon QApplication::exec(); 13762819106SNicolas Bonnefon 13862819106SNicolas Bonnefon // Check the small log has been restored 13962819106SNicolas Bonnefon QCOMPARE( finishedSpy.count(), 4 ); 14062819106SNicolas Bonnefon QCOMPARE( logData.getNbLine(), SL_NB_LINES ); 14162819106SNicolas Bonnefon QCOMPARE( logData.getMaxLength(), SL_LINE_LENGTH ); 14262819106SNicolas Bonnefon QCOMPARE( logData.getFileSize(), SL_NB_LINES * (SL_LINE_LENGTH+1LL) ); 14362819106SNicolas Bonnefon 14462819106SNicolas Bonnefon // Disconnect all signals 14562819106SNicolas Bonnefon disconnect( &logData, 0 ); 14662819106SNicolas Bonnefon } 14762819106SNicolas Bonnefon 14862819106SNicolas Bonnefon void TestLogData::changingFile() 14962819106SNicolas Bonnefon { 15062819106SNicolas Bonnefon char newLine[90]; 15162819106SNicolas Bonnefon LogData logData; 15262819106SNicolas Bonnefon 153cef94aa9SNicolas Bonnefon QSignalSpy finishedSpy( &logData, SIGNAL( loadingFinished( bool ) ) ); 15462819106SNicolas Bonnefon QSignalSpy progressSpy( &logData, SIGNAL( loadingProgressed( int ) ) ); 1553cf2e1a1SNicolas Bonnefon QSignalSpy changedSpy( &logData, 1563cf2e1a1SNicolas Bonnefon SIGNAL( fileChanged( LogData::MonitoredFileStatus ) ) ); 15762819106SNicolas Bonnefon 15862819106SNicolas Bonnefon // Register for notification file is loaded 159cef94aa9SNicolas Bonnefon connect( &logData, SIGNAL( loadingFinished( bool ) ), 16062819106SNicolas Bonnefon this, SLOT( loadingFinished() ) ); 16162819106SNicolas Bonnefon 16262819106SNicolas Bonnefon // Generate a small file 16362819106SNicolas Bonnefon QFile file( TMPDIR "/changingfile.txt" ); 16462819106SNicolas Bonnefon if ( file.open( QIODevice::WriteOnly ) ) { 16562819106SNicolas Bonnefon for (int i = 0; i < 200; i++) { 16662819106SNicolas Bonnefon snprintf(newLine, 89, sl_format, i); 16762819106SNicolas Bonnefon file.write( newLine, qstrlen(newLine) ); 16862819106SNicolas Bonnefon } 16962819106SNicolas Bonnefon } 17062819106SNicolas Bonnefon file.close(); 17162819106SNicolas Bonnefon 17262819106SNicolas Bonnefon // Start loading it 1735f0a91faSNicolas Bonnefon logData.attachFile( TMPDIR "/changingfile.txt" ); 17462819106SNicolas Bonnefon 17562819106SNicolas Bonnefon // and wait for the signal 17662819106SNicolas Bonnefon QApplication::exec(); 17762819106SNicolas Bonnefon 17862819106SNicolas Bonnefon // Check we have the small file 17962819106SNicolas Bonnefon QCOMPARE( finishedSpy.count(), 1 ); 1805f0a91faSNicolas Bonnefon QCOMPARE( logData.getNbLine(), 200LL ); 18162819106SNicolas Bonnefon QCOMPARE( logData.getMaxLength(), SL_LINE_LENGTH ); 18262819106SNicolas Bonnefon QCOMPARE( logData.getFileSize(), 200 * (SL_LINE_LENGTH+1LL) ); 18362819106SNicolas Bonnefon 18462819106SNicolas Bonnefon // Add some data to it 18562819106SNicolas Bonnefon if ( file.open( QIODevice::Append ) ) { 18662819106SNicolas Bonnefon for (int i = 0; i < 200; i++) { 18762819106SNicolas Bonnefon snprintf(newLine, 89, sl_format, i); 18862819106SNicolas Bonnefon file.write( newLine, qstrlen(newLine) ); 18962819106SNicolas Bonnefon } 190b76c5bcfSNicolas Bonnefon // To test the edge case when the final line is not complete 191b76c5bcfSNicolas Bonnefon file.write( partial_line_begin, qstrlen( partial_line_begin ) ); 19262819106SNicolas Bonnefon } 19362819106SNicolas Bonnefon file.close(); 19462819106SNicolas Bonnefon 1953cf2e1a1SNicolas Bonnefon // and wait for the signals 19662819106SNicolas Bonnefon QApplication::exec(); 19762819106SNicolas Bonnefon 19862819106SNicolas Bonnefon // Check we have a bigger file 1993cf2e1a1SNicolas Bonnefon QCOMPARE( changedSpy.count(), 1 ); 20062819106SNicolas Bonnefon QCOMPARE( finishedSpy.count(), 2 ); 201b76c5bcfSNicolas Bonnefon QCOMPARE( logData.getNbLine(), 401LL ); 20262819106SNicolas Bonnefon QCOMPARE( logData.getMaxLength(), SL_LINE_LENGTH ); 203b76c5bcfSNicolas Bonnefon QCOMPARE( logData.getFileSize(), 400 * (SL_LINE_LENGTH+1LL) 204b76c5bcfSNicolas Bonnefon + strlen( partial_line_begin ) ); 205b76c5bcfSNicolas Bonnefon 206b76c5bcfSNicolas Bonnefon // Add a couple more lines, including the end of the unfinished one. 207b76c5bcfSNicolas Bonnefon if ( file.open( QIODevice::Append ) ) { 208b76c5bcfSNicolas Bonnefon file.write( partial_line_end, qstrlen( partial_line_end ) ); 209b76c5bcfSNicolas Bonnefon for (int i = 0; i < 20; i++) { 210b76c5bcfSNicolas Bonnefon snprintf(newLine, 89, sl_format, i); 211b76c5bcfSNicolas Bonnefon file.write( newLine, qstrlen(newLine) ); 212b76c5bcfSNicolas Bonnefon } 213b76c5bcfSNicolas Bonnefon } 214b76c5bcfSNicolas Bonnefon file.close(); 215b76c5bcfSNicolas Bonnefon 216b76c5bcfSNicolas Bonnefon // and wait for the signals 217b76c5bcfSNicolas Bonnefon QApplication::exec(); 218b76c5bcfSNicolas Bonnefon 219b76c5bcfSNicolas Bonnefon // Check we have a bigger file 220b76c5bcfSNicolas Bonnefon QCOMPARE( changedSpy.count(), 2 ); 221b76c5bcfSNicolas Bonnefon QCOMPARE( finishedSpy.count(), 3 ); 222b76c5bcfSNicolas Bonnefon QCOMPARE( logData.getNbLine(), 421LL ); 223b76c5bcfSNicolas Bonnefon QCOMPARE( logData.getMaxLength(), SL_LINE_LENGTH ); 224b76c5bcfSNicolas Bonnefon QCOMPARE( logData.getFileSize(), 420 * (SL_LINE_LENGTH+1LL) 225b76c5bcfSNicolas Bonnefon + strlen( partial_line_begin ) + strlen( partial_line_end ) ); 22662819106SNicolas Bonnefon 22762819106SNicolas Bonnefon // Truncate the file 22862819106SNicolas Bonnefon QVERIFY( file.open( QIODevice::WriteOnly ) ); 22962819106SNicolas Bonnefon file.close(); 23062819106SNicolas Bonnefon 2313cf2e1a1SNicolas Bonnefon // and wait for the signals 23262819106SNicolas Bonnefon QApplication::exec(); 23362819106SNicolas Bonnefon 23462819106SNicolas Bonnefon // Check we have an empty file 235b76c5bcfSNicolas Bonnefon QCOMPARE( changedSpy.count(), 3 ); 236b76c5bcfSNicolas Bonnefon QCOMPARE( finishedSpy.count(), 4 ); 2375f0a91faSNicolas Bonnefon QCOMPARE( logData.getNbLine(), 0LL ); 23862819106SNicolas Bonnefon QCOMPARE( logData.getMaxLength(), 0 ); 23962819106SNicolas Bonnefon QCOMPARE( logData.getFileSize(), 0LL ); 24062819106SNicolas Bonnefon } 24162819106SNicolas Bonnefon 24262819106SNicolas Bonnefon void TestLogData::sequentialRead() 24362819106SNicolas Bonnefon { 244270ea970SNicolas Bonnefon LogData logData; 24562819106SNicolas Bonnefon 246270ea970SNicolas Bonnefon // Register for notification file is loaded 247cef94aa9SNicolas Bonnefon connect( &logData, SIGNAL( loadingFinished( bool ) ), 248270ea970SNicolas Bonnefon this, SLOT( loadingFinished() ) ); 249270ea970SNicolas Bonnefon 2505f0a91faSNicolas Bonnefon logData.attachFile( TMPDIR "/verybiglog.txt" ); 2515b29309eSNicolas Bonnefon 252270ea970SNicolas Bonnefon // Wait for the loading to be done 25362819106SNicolas Bonnefon { 254270ea970SNicolas Bonnefon QApplication::exec(); 25562819106SNicolas Bonnefon } 25662819106SNicolas Bonnefon 25762819106SNicolas Bonnefon // Read all lines sequentially 25862819106SNicolas Bonnefon QString s; 25962819106SNicolas Bonnefon QBENCHMARK { 260270ea970SNicolas Bonnefon for (int i = 0; i < VBL_NB_LINES; i++) { 261270ea970SNicolas Bonnefon s = logData.getLineString(i); 26262819106SNicolas Bonnefon } 263270ea970SNicolas Bonnefon } 264270ea970SNicolas Bonnefon QCOMPARE( s.length(), VBL_LINE_LENGTH ); 26536c1f171SNicolas Bonnefon 26636c1f171SNicolas Bonnefon } 26736c1f171SNicolas Bonnefon 26836c1f171SNicolas Bonnefon void TestLogData::sequentialReadExpanded() 26936c1f171SNicolas Bonnefon { 27036c1f171SNicolas Bonnefon LogData logData; 27136c1f171SNicolas Bonnefon 27236c1f171SNicolas Bonnefon // Register for notification file is loaded 27336c1f171SNicolas Bonnefon connect( &logData, SIGNAL( loadingFinished( bool ) ), 27436c1f171SNicolas Bonnefon this, SLOT( loadingFinished() ) ); 27536c1f171SNicolas Bonnefon 27636c1f171SNicolas Bonnefon logData.attachFile( TMPDIR "/verybiglog.txt" ); 27736c1f171SNicolas Bonnefon 27836c1f171SNicolas Bonnefon // Wait for the loading to be done 27936c1f171SNicolas Bonnefon { 28036c1f171SNicolas Bonnefon QApplication::exec(); 28136c1f171SNicolas Bonnefon } 28236c1f171SNicolas Bonnefon 28336c1f171SNicolas Bonnefon // Read all expanded lines sequentially 28436c1f171SNicolas Bonnefon QString s; 28536c1f171SNicolas Bonnefon QBENCHMARK { 28636c1f171SNicolas Bonnefon for (int i = 0; i < VBL_NB_LINES; i++) { 28736c1f171SNicolas Bonnefon s = logData.getExpandedLineString(i); 28836c1f171SNicolas Bonnefon } 28936c1f171SNicolas Bonnefon } 29036c1f171SNicolas Bonnefon QCOMPARE( s.length(), VBL_VISIBLE_LINE_LENGTH ); 29162819106SNicolas Bonnefon } 29262819106SNicolas Bonnefon 29362819106SNicolas Bonnefon void TestLogData::randomPageRead() 29462819106SNicolas Bonnefon { 2955b29309eSNicolas Bonnefon LogData logData; 29662819106SNicolas Bonnefon 2975b29309eSNicolas Bonnefon // Register for notification file is loaded 2983ab7c5b5SNicolas Bonnefon connect( &logData, SIGNAL( loadingFinished( bool ) ), 2995b29309eSNicolas Bonnefon this, SLOT( loadingFinished() ) ); 3005b29309eSNicolas Bonnefon 3015b29309eSNicolas Bonnefon logData.attachFile( TMPDIR "/verybiglog.txt" ); 3025b29309eSNicolas Bonnefon // Wait for the loading to be done 30362819106SNicolas Bonnefon { 3045b29309eSNicolas Bonnefon QApplication::exec(); 30562819106SNicolas Bonnefon } 30662819106SNicolas Bonnefon 3075b29309eSNicolas Bonnefon QWARN("Starting random page read test"); 3085b29309eSNicolas Bonnefon 3095b29309eSNicolas Bonnefon // Read page by page from the beginning and the end, using the QStringList 3105b29309eSNicolas Bonnefon // function 3115b29309eSNicolas Bonnefon QStringList list; 31262819106SNicolas Bonnefon QBENCHMARK { 3135b29309eSNicolas Bonnefon for (int page = 0; page < (VBL_NB_LINES/VBL_LINE_PER_PAGE)-1; page++) 31462819106SNicolas Bonnefon { 3155b29309eSNicolas Bonnefon list = logData.getLines( page*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE ); 3165b29309eSNicolas Bonnefon QCOMPARE(list.count(), VBL_LINE_PER_PAGE); 3175b29309eSNicolas Bonnefon int page_from_end = (VBL_NB_LINES/VBL_LINE_PER_PAGE) - page - 1; 3185b29309eSNicolas Bonnefon list = logData.getLines( page_from_end*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE ); 3195b29309eSNicolas Bonnefon QCOMPARE(list.count(), VBL_LINE_PER_PAGE); 32062819106SNicolas Bonnefon } 32162819106SNicolas Bonnefon } 32236c1f171SNicolas Bonnefon 32336c1f171SNicolas Bonnefon } 32436c1f171SNicolas Bonnefon 32536c1f171SNicolas Bonnefon void TestLogData::randomPageReadExpanded() 32636c1f171SNicolas Bonnefon { 32736c1f171SNicolas Bonnefon LogData logData; 32836c1f171SNicolas Bonnefon 32936c1f171SNicolas Bonnefon // Register for notification file is loaded 33036c1f171SNicolas Bonnefon connect( &logData, SIGNAL( loadingFinished( bool ) ), 33136c1f171SNicolas Bonnefon this, SLOT( loadingFinished() ) ); 33236c1f171SNicolas Bonnefon 33336c1f171SNicolas Bonnefon logData.attachFile( TMPDIR "/verybiglog.txt" ); 33436c1f171SNicolas Bonnefon // Wait for the loading to be done 33536c1f171SNicolas Bonnefon { 33636c1f171SNicolas Bonnefon QApplication::exec(); 33736c1f171SNicolas Bonnefon } 33836c1f171SNicolas Bonnefon 33936c1f171SNicolas Bonnefon QWARN("Starting random page read test (expanded lines)"); 34036c1f171SNicolas Bonnefon 34136c1f171SNicolas Bonnefon // Read page by page from the beginning and the end, using the QStringList 34236c1f171SNicolas Bonnefon // function 34336c1f171SNicolas Bonnefon QStringList list; 34436c1f171SNicolas Bonnefon QBENCHMARK { 34536c1f171SNicolas Bonnefon for (int page = 0; page < (VBL_NB_LINES/VBL_LINE_PER_PAGE)-1; page++) 34636c1f171SNicolas Bonnefon { 34736c1f171SNicolas Bonnefon list = logData.getExpandedLines( page*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE ); 34836c1f171SNicolas Bonnefon QCOMPARE(list.count(), VBL_LINE_PER_PAGE); 34936c1f171SNicolas Bonnefon int page_from_end = (VBL_NB_LINES/VBL_LINE_PER_PAGE) - page - 1; 35036c1f171SNicolas Bonnefon list = logData.getExpandedLines( page_from_end*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE ); 35136c1f171SNicolas Bonnefon QCOMPARE(list.count(), VBL_LINE_PER_PAGE); 35236c1f171SNicolas Bonnefon } 35336c1f171SNicolas Bonnefon } 35462819106SNicolas Bonnefon } 35562819106SNicolas Bonnefon 35662819106SNicolas Bonnefon // 35762819106SNicolas Bonnefon // Private functions 35862819106SNicolas Bonnefon // 35962819106SNicolas Bonnefon void TestLogData::loadingFinished() 36062819106SNicolas Bonnefon { 36162819106SNicolas Bonnefon QApplication::quit(); 36262819106SNicolas Bonnefon } 36362819106SNicolas Bonnefon 36462819106SNicolas Bonnefon bool TestLogData::generateDataFiles() 36562819106SNicolas Bonnefon { 36662819106SNicolas Bonnefon char newLine[90]; 36762819106SNicolas Bonnefon 36862819106SNicolas Bonnefon QFile file( TMPDIR "/verybiglog.txt" ); 36962819106SNicolas Bonnefon if ( file.open( QIODevice::WriteOnly ) ) { 37062819106SNicolas Bonnefon for (int i = 0; i < VBL_NB_LINES; i++) { 37162819106SNicolas Bonnefon snprintf(newLine, 89, vbl_format, i); 37262819106SNicolas Bonnefon file.write( newLine, qstrlen(newLine) ); 37362819106SNicolas Bonnefon } 37462819106SNicolas Bonnefon } 37562819106SNicolas Bonnefon else { 37662819106SNicolas Bonnefon return false; 37762819106SNicolas Bonnefon } 37862819106SNicolas Bonnefon file.close(); 37962819106SNicolas Bonnefon 38062819106SNicolas Bonnefon file.setFileName( TMPDIR "/smalllog.txt" ); 38162819106SNicolas Bonnefon if ( file.open( QIODevice::WriteOnly ) ) { 38262819106SNicolas Bonnefon for (int i = 0; i < SL_NB_LINES; i++) { 38362819106SNicolas Bonnefon snprintf(newLine, 89, sl_format, i); 38462819106SNicolas Bonnefon file.write( newLine, qstrlen(newLine) ); 38562819106SNicolas Bonnefon } 38662819106SNicolas Bonnefon } 38762819106SNicolas Bonnefon else { 38862819106SNicolas Bonnefon return false; 38962819106SNicolas Bonnefon } 39062819106SNicolas Bonnefon file.close(); 39162819106SNicolas Bonnefon 39262819106SNicolas Bonnefon return true; 39362819106SNicolas Bonnefon } 394