xref: /glogg/tests/testlogfiltereddata.cpp (revision 4fb0346e73d7caa82d42531c8c8681b5eb607728) !
12851c541SNicolas Bonnefon /*
264c49544SNicolas Bonnefon  * Copyright (C) 2009, 2010, 2011 Nicolas Bonnefon and other contributors
32851c541SNicolas Bonnefon  *
42851c541SNicolas Bonnefon  * This file is part of glogg.
52851c541SNicolas Bonnefon  *
62851c541SNicolas Bonnefon  * glogg is free software: you can redistribute it and/or modify
72851c541SNicolas Bonnefon  * it under the terms of the GNU General Public License as published by
82851c541SNicolas Bonnefon  * the Free Software Foundation, either version 3 of the License, or
92851c541SNicolas Bonnefon  * (at your option) any later version.
102851c541SNicolas Bonnefon  *
112851c541SNicolas Bonnefon  * glogg is distributed in the hope that it will be useful,
122851c541SNicolas Bonnefon  * but WITHOUT ANY WARRANTY; without even the implied warranty of
132851c541SNicolas Bonnefon  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
142851c541SNicolas Bonnefon  * GNU General Public License for more details.
152851c541SNicolas Bonnefon  *
162851c541SNicolas Bonnefon  * You should have received a copy of the GNU General Public License
172851c541SNicolas Bonnefon  * along with glogg.  If not, see <http://www.gnu.org/licenses/>.
182851c541SNicolas Bonnefon  */
192851c541SNicolas Bonnefon 
20f35c72b9SNicolas Bonnefon #include <QSignalSpy>
21f35c72b9SNicolas Bonnefon #include <QMutexLocker>
22f35c72b9SNicolas Bonnefon #include <QFile>
23f35c72b9SNicolas Bonnefon 
24f35c72b9SNicolas Bonnefon #include "testlogfiltereddata.h"
25f35c72b9SNicolas Bonnefon #include "logdata.h"
2620ec540aSNicolas Bonnefon #include "logfiltereddata.h"
27f35c72b9SNicolas Bonnefon 
28f35c72b9SNicolas Bonnefon #if !defined( TMPDIR )
29f35c72b9SNicolas Bonnefon #define TMPDIR "/tmp"
30f35c72b9SNicolas Bonnefon #endif
31f35c72b9SNicolas Bonnefon 
325f0a91faSNicolas Bonnefon static const qint64 ML_NB_LINES = 15000LL;
335fc7617dSNicolas Bonnefon static const char* ml_format="LOGDATA is a part of glogg, we are going to test it thoroughly, this is line\t\t%06d\n";
345fc7617dSNicolas Bonnefon static const int ML_VISIBLE_LINE_LENGTH = (76+8+4+6); // Without the final '\n' !
35f35c72b9SNicolas Bonnefon 
365f0a91faSNicolas Bonnefon static const qint64 SL_NB_LINES = 2000LL;
37f35c72b9SNicolas Bonnefon static const char* sl_format="LOGDATA is a part of glogg, we are going to test it thoroughly, this is line %06d\n";
38f35c72b9SNicolas Bonnefon 
397ab70cd2SNicolas Bonnefon static const char* partial_line_begin = "123... beginning of line.";
407ab70cd2SNicolas Bonnefon static const char* partial_line_end = " end of line 123.\n";
417ab70cd2SNicolas Bonnefon 
427ab70cd2SNicolas Bonnefon static const char* partial_nonmatching_line_begin = "Beginning of line.";
437ab70cd2SNicolas Bonnefon 
TestLogFilteredData()440b28d87cSNicolas Bonnefon TestLogFilteredData::TestLogFilteredData() : QObject(),
450b28d87cSNicolas Bonnefon     loadingFinishedMutex_(),
460b28d87cSNicolas Bonnefon     searchProgressedMutex_(),
470b28d87cSNicolas Bonnefon     loadingFinishedCondition_(),
480b28d87cSNicolas Bonnefon     searchProgressedCondition_()
490b28d87cSNicolas Bonnefon {
500b28d87cSNicolas Bonnefon     loadingFinished_received_  = false;
510b28d87cSNicolas Bonnefon     loadingFinished_read_      = false;
520b28d87cSNicolas Bonnefon     searchProgressed_received_ = false;
530b28d87cSNicolas Bonnefon     searchProgressed_read_     = false;
540b28d87cSNicolas Bonnefon }
550b28d87cSNicolas Bonnefon 
initTestCase()56f35c72b9SNicolas Bonnefon void TestLogFilteredData::initTestCase()
57f35c72b9SNicolas Bonnefon {
58f35c72b9SNicolas Bonnefon     QVERIFY( generateDataFiles() );
59f35c72b9SNicolas Bonnefon }
60f35c72b9SNicolas Bonnefon 
simpleSearch()61f35c72b9SNicolas Bonnefon void TestLogFilteredData::simpleSearch()
62f35c72b9SNicolas Bonnefon {
630b28d87cSNicolas Bonnefon     logData_ = new LogData();
64f35c72b9SNicolas Bonnefon 
65f35c72b9SNicolas Bonnefon     // Register for notification file is loaded
660b28d87cSNicolas Bonnefon     connect( logData_, SIGNAL( loadingFinished( bool ) ),
67f35c72b9SNicolas Bonnefon             this, SLOT( loadingFinished() ) );
68f35c72b9SNicolas Bonnefon 
690b28d87cSNicolas Bonnefon     filteredData_ = logData_->getNewFilteredData();
700b28d87cSNicolas Bonnefon     connect( filteredData_, SIGNAL( searchProgressed( int, int ) ),
71f35c72b9SNicolas Bonnefon             this, SLOT( searchProgressed( int, int ) ) );
72f35c72b9SNicolas Bonnefon 
730b28d87cSNicolas Bonnefon     QFuture<void> future = QtConcurrent::run(this, &TestLogFilteredData::simpleSearchTest);
74f35c72b9SNicolas Bonnefon 
750b28d87cSNicolas Bonnefon     QApplication::exec();
760b28d87cSNicolas Bonnefon 
770b28d87cSNicolas Bonnefon     disconnect( filteredData_, 0 );
780b28d87cSNicolas Bonnefon     disconnect( logData_, 0 );
790b28d87cSNicolas Bonnefon 
800b28d87cSNicolas Bonnefon     delete filteredData_;
810b28d87cSNicolas Bonnefon     delete logData_;
820b28d87cSNicolas Bonnefon }
830b28d87cSNicolas Bonnefon 
simpleSearchTest()840b28d87cSNicolas Bonnefon void TestLogFilteredData::simpleSearchTest()
850b28d87cSNicolas Bonnefon {
860b28d87cSNicolas Bonnefon     // First load the tests file
870b28d87cSNicolas Bonnefon     logData_->attachFile( TMPDIR "/mediumlog.txt" );
880b28d87cSNicolas Bonnefon     // Wait for the loading to be done
890b28d87cSNicolas Bonnefon     waitLoadingFinished();
900b28d87cSNicolas Bonnefon     QCOMPARE( logData_->getNbLine(), ML_NB_LINES );
910b28d87cSNicolas Bonnefon     signalLoadingFinishedRead();
920b28d87cSNicolas Bonnefon 
930b28d87cSNicolas Bonnefon     // Now perform a simple search
945f0a91faSNicolas Bonnefon     qint64 matches[] = { 0, 15, 20, 135 };
950ed63e59SNicolas Bonnefon     QBENCHMARK {
96f35c72b9SNicolas Bonnefon         // Start the search
97*4fb0346eSAnton Filimonov         filteredData_->runSearch( QRegularExpression( "123" ) );
98f35c72b9SNicolas Bonnefon 
99f35c72b9SNicolas Bonnefon         // And check we receive data in 4 chunks (the first being empty)
100f35c72b9SNicolas Bonnefon         for ( int i = 0; i < 4; i++ ) {
1010b28d87cSNicolas Bonnefon             std::pair<int,int> progress = waitSearchProgressed();
1025f12ccbaSNicolas Bonnefon             // FIXME: The test for this is unfortunately not reliable
1035f12ccbaSNicolas Bonnefon             // (race conditions)
1045f12ccbaSNicolas Bonnefon             // QCOMPARE( (qint64) progress.first, matches[i] );
1050b28d87cSNicolas Bonnefon             signalSearchProgressedRead();
106f35c72b9SNicolas Bonnefon         }
1070ed63e59SNicolas Bonnefon     }
1080ed63e59SNicolas Bonnefon 
1090b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), matches[3] );
110f35c72b9SNicolas Bonnefon     // Check the search
1110b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->isLineInMatchingList( 123 ), true );
1120b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->isLineInMatchingList( 124 ), false );
1130b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getMaxLength(), ML_VISIBLE_LINE_LENGTH );
1140b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getLineLength( 12 ), ML_VISIBLE_LINE_LENGTH );
1150b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 135LL );
116f35c72b9SNicolas Bonnefon     // Line beyond limit
1170b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->isLineInMatchingList( 60000 ), false );
1180b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getMatchingLineNumber( 0 ), 123LL );
119f35c72b9SNicolas Bonnefon 
1200ed63e59SNicolas Bonnefon     // Now let's try interrupting a search
121*4fb0346eSAnton Filimonov     filteredData_->runSearch( QRegularExpression( "123" ) );
1220ed63e59SNicolas Bonnefon     // ... wait for two chunks.
1230b28d87cSNicolas Bonnefon     waitSearchProgressed();
1240b28d87cSNicolas Bonnefon     signalSearchProgressedRead();
1250ed63e59SNicolas Bonnefon     // and interrupt!
1260b28d87cSNicolas Bonnefon     filteredData_->interruptSearch();
1275f12ccbaSNicolas Bonnefon 
1285f12ccbaSNicolas Bonnefon     {
1295f12ccbaSNicolas Bonnefon         std::pair<int,int> progress;
1305f12ccbaSNicolas Bonnefon         do {
1315f12ccbaSNicolas Bonnefon             progress = waitSearchProgressed();
1320b28d87cSNicolas Bonnefon             signalSearchProgressedRead();
1335f12ccbaSNicolas Bonnefon         } while ( progress.second < 100 );
1340ed63e59SNicolas Bonnefon 
1350ed63e59SNicolas Bonnefon         // (because there is no guarantee when the search is
1360ed63e59SNicolas Bonnefon         // interrupted, we are not sure how many chunk of result
1370ed63e59SNicolas Bonnefon         // we will get.)
1385f12ccbaSNicolas Bonnefon     }
1390ed63e59SNicolas Bonnefon 
1400b28d87cSNicolas Bonnefon     QApplication::quit();
141f35c72b9SNicolas Bonnefon }
142f35c72b9SNicolas Bonnefon 
multipleSearch()143f35c72b9SNicolas Bonnefon void TestLogFilteredData::multipleSearch()
144f35c72b9SNicolas Bonnefon {
1450b28d87cSNicolas Bonnefon     logData_ = new LogData();
146f35c72b9SNicolas Bonnefon 
147f35c72b9SNicolas Bonnefon     // Register for notification file is loaded
1480b28d87cSNicolas Bonnefon     connect( logData_, SIGNAL( loadingFinished( bool ) ),
149f35c72b9SNicolas Bonnefon             this, SLOT( loadingFinished() ) );
150f35c72b9SNicolas Bonnefon 
1510b28d87cSNicolas Bonnefon     filteredData_ = logData_->getNewFilteredData();
1520b28d87cSNicolas Bonnefon     connect( filteredData_, SIGNAL( searchProgressed( int, int ) ),
153f35c72b9SNicolas Bonnefon             this, SLOT( searchProgressed( int, int ) ) );
154f35c72b9SNicolas Bonnefon 
1550b28d87cSNicolas Bonnefon     QFuture<void> future = QtConcurrent::run(this, &TestLogFilteredData::multipleSearchTest);
1560b28d87cSNicolas Bonnefon 
1570b28d87cSNicolas Bonnefon     QApplication::exec();
1580b28d87cSNicolas Bonnefon 
1590b28d87cSNicolas Bonnefon     disconnect( filteredData_, 0 );
1600b28d87cSNicolas Bonnefon     disconnect( logData_, 0 );
1610b28d87cSNicolas Bonnefon 
1620b28d87cSNicolas Bonnefon     delete filteredData_;
1630b28d87cSNicolas Bonnefon     delete logData_;
1640b28d87cSNicolas Bonnefon }
1650b28d87cSNicolas Bonnefon 
multipleSearchTest()1660b28d87cSNicolas Bonnefon void TestLogFilteredData::multipleSearchTest()
1670b28d87cSNicolas Bonnefon {
1680b28d87cSNicolas Bonnefon     // First load the tests file
1690b28d87cSNicolas Bonnefon     logData_->attachFile( TMPDIR "/smalllog.txt" );
1700b28d87cSNicolas Bonnefon     // Wait for the loading to be done
1710b28d87cSNicolas Bonnefon     waitLoadingFinished();
1720b28d87cSNicolas Bonnefon     QCOMPARE( logData_->getNbLine(), SL_NB_LINES );
1730b28d87cSNicolas Bonnefon     signalLoadingFinishedRead();
1740b28d87cSNicolas Bonnefon 
1750b28d87cSNicolas Bonnefon     // Performs two searches in a row
176f35c72b9SNicolas Bonnefon     // Start the search, and immediately another one
1770ed63e59SNicolas Bonnefon     // (the second call should block until the first search is done)
178*4fb0346eSAnton Filimonov     filteredData_->runSearch( QRegularExpression( "1234" ) );
179*4fb0346eSAnton Filimonov     filteredData_->runSearch( QRegularExpression( "123" ) );
180f35c72b9SNicolas Bonnefon 
1810b28d87cSNicolas Bonnefon     for ( int i = 0; i < 3; i++ ) {
1820b28d87cSNicolas Bonnefon         waitSearchProgressed();
1830b28d87cSNicolas Bonnefon         signalSearchProgressedRead();
1840b28d87cSNicolas Bonnefon     }
185f35c72b9SNicolas Bonnefon 
1860b28d87cSNicolas Bonnefon     // We should have the result for the 2nd search after the last chunk
1870b28d87cSNicolas Bonnefon     waitSearchProgressed();
1880b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 12LL );
1890b28d87cSNicolas Bonnefon     signalSearchProgressedRead();
1900ed63e59SNicolas Bonnefon 
1910ed63e59SNicolas Bonnefon     // Now a tricky one: we run a search and immediately attach a new file
1925f12ccbaSNicolas Bonnefon     /* FIXME: sometimes we receive loadingFinished before searchProgressed
1935f12ccbaSNicolas Bonnefon      * -> deadlock in the test.
194*4fb0346eSAnton Filimonov     filteredData_->runSearch( QRegularExpression( "123" ) );
1950b28d87cSNicolas Bonnefon     waitSearchProgressed();
1960b28d87cSNicolas Bonnefon     signalSearchProgressedRead();
1970b28d87cSNicolas Bonnefon     logData_->attachFile( TMPDIR "/mediumlog.txt" );
1980ed63e59SNicolas Bonnefon 
1990ed63e59SNicolas Bonnefon     // We don't expect meaningful results but it should not crash!
2000b28d87cSNicolas Bonnefon     for ( int i = 0; i < 1; i++ ) {
2010b28d87cSNicolas Bonnefon         waitSearchProgressed();
2020b28d87cSNicolas Bonnefon         signalSearchProgressedRead();
2030b28d87cSNicolas Bonnefon     }
2045f12ccbaSNicolas Bonnefon     */
2055f12ccbaSNicolas Bonnefon 
2065f12ccbaSNicolas Bonnefon     sleep(10);
2070ed63e59SNicolas Bonnefon 
2080b28d87cSNicolas Bonnefon     QApplication::quit();
209f35c72b9SNicolas Bonnefon }
210f35c72b9SNicolas Bonnefon 
updateSearch()211ba40a297SNicolas Bonnefon void TestLogFilteredData::updateSearch()
212ba40a297SNicolas Bonnefon {
2130b28d87cSNicolas Bonnefon     logData_ = new LogData();
214ba40a297SNicolas Bonnefon 
215ba40a297SNicolas Bonnefon     // Register for notification file is loaded
2160b28d87cSNicolas Bonnefon     connect( logData_, SIGNAL( loadingFinished( bool ) ),
217ba40a297SNicolas Bonnefon             this, SLOT( loadingFinished() ) );
218ba40a297SNicolas Bonnefon 
2190b28d87cSNicolas Bonnefon     filteredData_ = logData_->getNewFilteredData();
2200b28d87cSNicolas Bonnefon     connect( filteredData_, SIGNAL( searchProgressed( int, int ) ),
221ba40a297SNicolas Bonnefon             this, SLOT( searchProgressed( int, int ) ) );
222ba40a297SNicolas Bonnefon 
2230b28d87cSNicolas Bonnefon     QFuture<void> future = QtConcurrent::run(this, &TestLogFilteredData::updateSearchTest);
224ba40a297SNicolas Bonnefon 
225ba40a297SNicolas Bonnefon     QApplication::exec();
226ba40a297SNicolas Bonnefon 
2270b28d87cSNicolas Bonnefon     disconnect( filteredData_, 0 );
2280b28d87cSNicolas Bonnefon     disconnect( logData_, 0 );
2290b28d87cSNicolas Bonnefon 
2300b28d87cSNicolas Bonnefon     delete filteredData_;
2310b28d87cSNicolas Bonnefon     delete logData_;
2320b28d87cSNicolas Bonnefon }
2330b28d87cSNicolas Bonnefon 
updateSearchTest()2340b28d87cSNicolas Bonnefon void TestLogFilteredData::updateSearchTest()
2350b28d87cSNicolas Bonnefon {
2360b28d87cSNicolas Bonnefon     // First load the tests file
2370b28d87cSNicolas Bonnefon     logData_->attachFile( TMPDIR "/smalllog.txt" );
2380b28d87cSNicolas Bonnefon     // Wait for the loading to be done
2390b28d87cSNicolas Bonnefon     waitLoadingFinished();
2400b28d87cSNicolas Bonnefon     QCOMPARE( logData_->getNbLine(), SL_NB_LINES );
2410b28d87cSNicolas Bonnefon     signalLoadingFinishedRead();
2420b28d87cSNicolas Bonnefon 
2430b28d87cSNicolas Bonnefon     // Perform a first search
244*4fb0346eSAnton Filimonov     filteredData_->runSearch( QRegularExpression( "123" ) );
2450b28d87cSNicolas Bonnefon 
2460b28d87cSNicolas Bonnefon     for ( int i = 0; i < 2; i++ ) {
2470b28d87cSNicolas Bonnefon         waitSearchProgressed();
2480b28d87cSNicolas Bonnefon         signalSearchProgressedRead();
2490b28d87cSNicolas Bonnefon     }
2500b28d87cSNicolas Bonnefon 
251ba40a297SNicolas Bonnefon     // Check the result
2520b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 12LL );
253ba40a297SNicolas Bonnefon 
2545f12ccbaSNicolas Bonnefon     sleep(1);
2555f12ccbaSNicolas Bonnefon 
2567d862d7eSNicolas Bonnefon     QWARN("Starting stage 2");
2577d862d7eSNicolas Bonnefon 
258ba40a297SNicolas Bonnefon     // Add some data to the file
259ba40a297SNicolas Bonnefon     char newLine[90];
260ba40a297SNicolas Bonnefon     QFile file( TMPDIR "/smalllog.txt" );
261ba40a297SNicolas Bonnefon     if ( file.open( QIODevice::Append ) ) {
262ba40a297SNicolas Bonnefon         for (int i = 0; i < 3000; i++) {
263ba40a297SNicolas Bonnefon             snprintf(newLine, 89, sl_format, i);
264ba40a297SNicolas Bonnefon             file.write( newLine, qstrlen(newLine) );
265ba40a297SNicolas Bonnefon         }
2667ab70cd2SNicolas Bonnefon         // To test the edge case when the final line is not complete and matching
2677ab70cd2SNicolas Bonnefon         file.write( partial_line_begin, qstrlen( partial_line_begin ) );
268ba40a297SNicolas Bonnefon     }
269ba40a297SNicolas Bonnefon     file.close();
270ba40a297SNicolas Bonnefon 
2715f12ccbaSNicolas Bonnefon     // Let the system do the update (there might be several ones)
2725f12ccbaSNicolas Bonnefon     do {
2730b28d87cSNicolas Bonnefon         waitLoadingFinished();
2740b28d87cSNicolas Bonnefon         signalLoadingFinishedRead();
2755f12ccbaSNicolas Bonnefon     } while ( logData_->getNbLine() < 5001LL );
2765f12ccbaSNicolas Bonnefon 
2775f12ccbaSNicolas Bonnefon     sleep(1);
2785db60fd3SNicolas Bonnefon 
279ba40a297SNicolas Bonnefon     // Start an update search
2800b28d87cSNicolas Bonnefon     filteredData_->updateSearch();
281ba40a297SNicolas Bonnefon 
2820b28d87cSNicolas Bonnefon     for ( int i = 0; i < 2; i++ ) {
2830b28d87cSNicolas Bonnefon         waitSearchProgressed();
2840b28d87cSNicolas Bonnefon         signalSearchProgressedRead();
2850b28d87cSNicolas Bonnefon     }
286ba40a297SNicolas Bonnefon 
287ba40a297SNicolas Bonnefon     // Check the result
2880b28d87cSNicolas Bonnefon     QCOMPARE( logData_->getNbLine(), 5001LL );
2890b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 26LL );
2907ab70cd2SNicolas Bonnefon 
2917d862d7eSNicolas Bonnefon     QWARN("Starting stage 3");
2927d862d7eSNicolas Bonnefon 
2937ab70cd2SNicolas Bonnefon     // Add a couple more lines, including the end of the unfinished one.
2947ab70cd2SNicolas Bonnefon     if ( file.open( QIODevice::Append ) ) {
2957ab70cd2SNicolas Bonnefon         file.write( partial_line_end, qstrlen( partial_line_end ) );
2967ab70cd2SNicolas Bonnefon         for (int i = 0; i < 20; i++) {
2977ab70cd2SNicolas Bonnefon             snprintf(newLine, 89, sl_format, i);
2987ab70cd2SNicolas Bonnefon             file.write( newLine, qstrlen(newLine) );
2997ab70cd2SNicolas Bonnefon         }
3007ab70cd2SNicolas Bonnefon         // To test the edge case when the final line is not complete and not matching
3017ab70cd2SNicolas Bonnefon         file.write( partial_nonmatching_line_begin,
3027ab70cd2SNicolas Bonnefon                 qstrlen( partial_nonmatching_line_begin ) );
3037ab70cd2SNicolas Bonnefon     }
3047ab70cd2SNicolas Bonnefon     file.close();
3057ab70cd2SNicolas Bonnefon 
3060b28d87cSNicolas Bonnefon     // Let the system do the update
3070b28d87cSNicolas Bonnefon     waitLoadingFinished();
3080b28d87cSNicolas Bonnefon     signalLoadingFinishedRead();
3097ab70cd2SNicolas Bonnefon 
3100b28d87cSNicolas Bonnefon     // Start an update search
3110b28d87cSNicolas Bonnefon     filteredData_->updateSearch();
3120b28d87cSNicolas Bonnefon 
3130b28d87cSNicolas Bonnefon     for ( int i = 0; i < 2; i++ ) {
3140b28d87cSNicolas Bonnefon         waitSearchProgressed();
3150b28d87cSNicolas Bonnefon         signalSearchProgressedRead();
3160b28d87cSNicolas Bonnefon     }
3177ab70cd2SNicolas Bonnefon 
3187ab70cd2SNicolas Bonnefon     // Check the result
3190b28d87cSNicolas Bonnefon     QCOMPARE( logData_->getNbLine(), 5022LL );
3200b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 26LL );
3217ab70cd2SNicolas Bonnefon 
3227d862d7eSNicolas Bonnefon     QWARN("Starting stage 4");
3237d862d7eSNicolas Bonnefon 
3247ab70cd2SNicolas Bonnefon     // Now test the case where a match is found at the end of an updated line.
3257ab70cd2SNicolas Bonnefon     if ( file.open( QIODevice::Append ) ) {
3267ab70cd2SNicolas Bonnefon         file.write( partial_line_end, qstrlen( partial_line_end ) );
3277ab70cd2SNicolas Bonnefon         for (int i = 0; i < 20; i++) {
3287ab70cd2SNicolas Bonnefon             snprintf(newLine, 89, sl_format, i);
3297ab70cd2SNicolas Bonnefon             file.write( newLine, qstrlen(newLine) );
3307ab70cd2SNicolas Bonnefon         }
3317ab70cd2SNicolas Bonnefon     }
3327ab70cd2SNicolas Bonnefon     file.close();
3337ab70cd2SNicolas Bonnefon 
3340b28d87cSNicolas Bonnefon     // Let the system do the update
3350b28d87cSNicolas Bonnefon     waitLoadingFinished();
3360b28d87cSNicolas Bonnefon     signalLoadingFinishedRead();
3377ab70cd2SNicolas Bonnefon 
3380b28d87cSNicolas Bonnefon     // Start an update search
3390b28d87cSNicolas Bonnefon     filteredData_->updateSearch();
3400b28d87cSNicolas Bonnefon 
3410b28d87cSNicolas Bonnefon     for ( int i = 0; i < 2; i++ ) {
3420b28d87cSNicolas Bonnefon         waitSearchProgressed();
3430b28d87cSNicolas Bonnefon         signalSearchProgressedRead();
3440b28d87cSNicolas Bonnefon     }
3457ab70cd2SNicolas Bonnefon 
3467ab70cd2SNicolas Bonnefon     // Check the result
3470b28d87cSNicolas Bonnefon     QCOMPARE( logData_->getNbLine(), 5042LL );
3480b28d87cSNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 27LL );
3490b28d87cSNicolas Bonnefon 
3500b28d87cSNicolas Bonnefon     QApplication::quit();
351ba40a297SNicolas Bonnefon }
352ba40a297SNicolas Bonnefon 
marks()35364c49544SNicolas Bonnefon void TestLogFilteredData::marks()
35464c49544SNicolas Bonnefon {
35564c49544SNicolas Bonnefon     logData_ = new LogData();
35664c49544SNicolas Bonnefon 
35764c49544SNicolas Bonnefon     // Register for notification file is loaded
35864c49544SNicolas Bonnefon     connect( logData_, SIGNAL( loadingFinished( bool ) ),
35964c49544SNicolas Bonnefon             this, SLOT( loadingFinished() ) );
36064c49544SNicolas Bonnefon 
36164c49544SNicolas Bonnefon     filteredData_ = logData_->getNewFilteredData();
36264c49544SNicolas Bonnefon     connect( filteredData_, SIGNAL( searchProgressed( int, int ) ),
36364c49544SNicolas Bonnefon             this, SLOT( searchProgressed( int, int ) ) );
36464c49544SNicolas Bonnefon 
36564c49544SNicolas Bonnefon     QFuture<void> future = QtConcurrent::run(this, &TestLogFilteredData::marksTest);
36664c49544SNicolas Bonnefon 
36764c49544SNicolas Bonnefon     QApplication::exec();
36864c49544SNicolas Bonnefon 
36964c49544SNicolas Bonnefon     disconnect( filteredData_, 0 );
37064c49544SNicolas Bonnefon     disconnect( logData_, 0 );
37164c49544SNicolas Bonnefon 
37264c49544SNicolas Bonnefon     delete filteredData_;
37364c49544SNicolas Bonnefon     delete logData_;
37464c49544SNicolas Bonnefon }
37564c49544SNicolas Bonnefon 
marksTest()37664c49544SNicolas Bonnefon void TestLogFilteredData::marksTest()
37764c49544SNicolas Bonnefon {
37864c49544SNicolas Bonnefon     // First load the tests file
37964c49544SNicolas Bonnefon     logData_->attachFile( TMPDIR "/smalllog.txt" );
38064c49544SNicolas Bonnefon     // Wait for the loading to be done
38164c49544SNicolas Bonnefon     waitLoadingFinished();
38264c49544SNicolas Bonnefon     QCOMPARE( logData_->getNbLine(), SL_NB_LINES );
38364c49544SNicolas Bonnefon     signalLoadingFinishedRead();
38464c49544SNicolas Bonnefon 
38564c49544SNicolas Bonnefon     // First check no line is marked
38664c49544SNicolas Bonnefon     for ( int i = 0; i < SL_NB_LINES; i++ )
38764c49544SNicolas Bonnefon         QVERIFY( filteredData_->isLineMarked( i ) == false );
38864c49544SNicolas Bonnefon 
38964c49544SNicolas Bonnefon     // Try to create some "out of limit" marks
39064c49544SNicolas Bonnefon     filteredData_->addMark( -10 );
39164c49544SNicolas Bonnefon     filteredData_->addMark( SL_NB_LINES + 25 );
39264c49544SNicolas Bonnefon 
39364c49544SNicolas Bonnefon     // Check no line is marked still
39464c49544SNicolas Bonnefon     for ( int i = 0; i < SL_NB_LINES; i++ )
39564c49544SNicolas Bonnefon         QVERIFY( filteredData_->isLineMarked( i ) == false );
39664c49544SNicolas Bonnefon 
39764c49544SNicolas Bonnefon     // Create a couple of unnamed marks
39864c49544SNicolas Bonnefon     filteredData_->addMark( 10 );
399a1e4ce92SNicolas Bonnefon     filteredData_->addMark( 44 );  // This one will also be a match
40064c49544SNicolas Bonnefon     filteredData_->addMark( 25 );
40164c49544SNicolas Bonnefon 
40264c49544SNicolas Bonnefon     // Check they are marked
40364c49544SNicolas Bonnefon     QVERIFY( filteredData_->isLineMarked( 10 ) );
40464c49544SNicolas Bonnefon     QVERIFY( filteredData_->isLineMarked( 25 ) );
405a1e4ce92SNicolas Bonnefon     QVERIFY( filteredData_->isLineMarked( 44 ) );
40664c49544SNicolas Bonnefon 
40764c49544SNicolas Bonnefon     // But others are not
40864c49544SNicolas Bonnefon     QVERIFY( filteredData_->isLineMarked( 15 ) == false );
40964c49544SNicolas Bonnefon     QVERIFY( filteredData_->isLineMarked( 20 ) == false );
41064c49544SNicolas Bonnefon 
411a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 3LL );
41264c49544SNicolas Bonnefon 
41364c49544SNicolas Bonnefon     // Performs a search
41464c49544SNicolas Bonnefon     QSignalSpy progressSpy( filteredData_,
41564c49544SNicolas Bonnefon             SIGNAL( searchProgressed( int, int ) ) );
416*4fb0346eSAnton Filimonov     filteredData_->runSearch( QRegularExpression( "0000.4" ) );
41764c49544SNicolas Bonnefon 
41864c49544SNicolas Bonnefon     for ( int i = 0; i < 1; i++ ) {
41964c49544SNicolas Bonnefon         waitSearchProgressed();
42064c49544SNicolas Bonnefon         signalSearchProgressedRead();
42164c49544SNicolas Bonnefon     }
42264c49544SNicolas Bonnefon 
42364c49544SNicolas Bonnefon     // We should have the result of the search and the marks
42464c49544SNicolas Bonnefon     waitSearchProgressed();
42564c49544SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 12LL );
42664c49544SNicolas Bonnefon     signalSearchProgressedRead();
42764c49544SNicolas Bonnefon 
428a1e4ce92SNicolas Bonnefon     QString startline = "LOGDATA is a part of glogg, we are going to test it thoroughly, this is line ";
429a1e4ce92SNicolas Bonnefon 
430a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(0), startline + "000004" );
431a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(1), startline + "000010" );
432a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(2), startline + "000014" );
433a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(3), startline + "000024" );
434a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(4), startline + "000025" );
435a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(5), startline + "000034" );
436a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(6), startline + "000044" );
437a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(7), startline + "000054" );
438a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(8), startline + "000064" );
439a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(9), startline + "000074" );
440a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(10), startline + "000084" );
441a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(11), startline + "000094" );
442a1e4ce92SNicolas Bonnefon 
443a1e4ce92SNicolas Bonnefon     filteredData_->setVisibility( LogFilteredData::MatchesOnly );
444a1e4ce92SNicolas Bonnefon 
445a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 10LL );
446a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(0), startline + "000004" );
447a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(1), startline + "000014" );
448a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(2), startline + "000024" );
449a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(3), startline + "000034" );
450a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(4), startline + "000044" );
451a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(5), startline + "000054" );
452a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(6), startline + "000064" );
453a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(7), startline + "000074" );
454a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(8), startline + "000084" );
455a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(9), startline + "000094" );
456a1e4ce92SNicolas Bonnefon 
457a1e4ce92SNicolas Bonnefon     filteredData_->setVisibility( LogFilteredData::MarksOnly );
458a1e4ce92SNicolas Bonnefon 
459a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 3LL );
460a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(0), startline + "000010" );
461a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(1), startline + "000025" );
462a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getLineString(2), startline + "000044" );
463a1e4ce92SNicolas Bonnefon 
4644bf9c5f5SNicolas Bonnefon     // Another test with marks only
4654bf9c5f5SNicolas Bonnefon     filteredData_->clearSearch();
4664bf9c5f5SNicolas Bonnefon     filteredData_->clearMarks();
4674bf9c5f5SNicolas Bonnefon     filteredData_->setVisibility( LogFilteredData::MarksOnly );
4684bf9c5f5SNicolas Bonnefon 
4694bf9c5f5SNicolas Bonnefon     filteredData_->addMark(18);
4704bf9c5f5SNicolas Bonnefon     filteredData_->addMark(19);
4714bf9c5f5SNicolas Bonnefon     filteredData_->addMark(20);
4724bf9c5f5SNicolas Bonnefon 
4734bf9c5f5SNicolas Bonnefon     QCOMPARE( filteredData_->getMatchingLineNumber(0), 18LL );
4744bf9c5f5SNicolas Bonnefon     QCOMPARE( filteredData_->getMatchingLineNumber(1), 19LL );
4754bf9c5f5SNicolas Bonnefon     QCOMPARE( filteredData_->getMatchingLineNumber(2), 20LL );
4764bf9c5f5SNicolas Bonnefon 
477a1e4ce92SNicolas Bonnefon     QApplication::quit();
478a1e4ce92SNicolas Bonnefon }
479a1e4ce92SNicolas Bonnefon 
lineLength()480a1e4ce92SNicolas Bonnefon void TestLogFilteredData::lineLength()
481a1e4ce92SNicolas Bonnefon {
482a1e4ce92SNicolas Bonnefon     logData_ = new LogData();
483a1e4ce92SNicolas Bonnefon 
484a1e4ce92SNicolas Bonnefon     // Register for notification file is loaded
485a1e4ce92SNicolas Bonnefon     connect( logData_, SIGNAL( loadingFinished( bool ) ),
486a1e4ce92SNicolas Bonnefon             this, SLOT( loadingFinished() ) );
487a1e4ce92SNicolas Bonnefon 
488a1e4ce92SNicolas Bonnefon     filteredData_ = logData_->getNewFilteredData();
489a1e4ce92SNicolas Bonnefon     connect( filteredData_, SIGNAL( searchProgressed( int, int ) ),
490a1e4ce92SNicolas Bonnefon             this, SLOT( searchProgressed( int, int ) ) );
491a1e4ce92SNicolas Bonnefon 
492a1e4ce92SNicolas Bonnefon     QFuture<void> future = QtConcurrent::run(this, &TestLogFilteredData::lineLengthTest);
493a1e4ce92SNicolas Bonnefon 
494a1e4ce92SNicolas Bonnefon     QApplication::exec();
495a1e4ce92SNicolas Bonnefon 
496a1e4ce92SNicolas Bonnefon     disconnect( filteredData_, 0 );
497a1e4ce92SNicolas Bonnefon     disconnect( logData_, 0 );
498a1e4ce92SNicolas Bonnefon 
499a1e4ce92SNicolas Bonnefon     delete filteredData_;
500a1e4ce92SNicolas Bonnefon     delete logData_;
501a1e4ce92SNicolas Bonnefon }
502a1e4ce92SNicolas Bonnefon 
lineLengthTest()503a1e4ce92SNicolas Bonnefon void TestLogFilteredData::lineLengthTest()
504a1e4ce92SNicolas Bonnefon {
505a1e4ce92SNicolas Bonnefon     // Line length tests
506a1e4ce92SNicolas Bonnefon 
507a1e4ce92SNicolas Bonnefon     logData_->attachFile( TMPDIR "/length_test.txt" );
508a1e4ce92SNicolas Bonnefon     // Wait for the loading to be done
509a1e4ce92SNicolas Bonnefon     waitLoadingFinished();
510a1e4ce92SNicolas Bonnefon     QCOMPARE( logData_->getNbLine(), 4LL );
511a1e4ce92SNicolas Bonnefon     signalLoadingFinishedRead();
512a1e4ce92SNicolas Bonnefon 
513a1e4ce92SNicolas Bonnefon     // Performs a search (the two middle lines matche)
514a1e4ce92SNicolas Bonnefon     filteredData_->setVisibility( LogFilteredData::MatchesOnly );
515*4fb0346eSAnton Filimonov     filteredData_->runSearch( QRegularExpression( "longer" ) );
516a1e4ce92SNicolas Bonnefon 
517a1e4ce92SNicolas Bonnefon     std::pair<int,int> progress;
518a1e4ce92SNicolas Bonnefon     do {
519a1e4ce92SNicolas Bonnefon         progress = waitSearchProgressed();
520a1e4ce92SNicolas Bonnefon         signalSearchProgressedRead();
521a1e4ce92SNicolas Bonnefon         QWARN("progress");
522a1e4ce92SNicolas Bonnefon     } while ( progress.second < 100 );
523a1e4ce92SNicolas Bonnefon 
524a1e4ce92SNicolas Bonnefon     filteredData_->addMark( 3 );
525a1e4ce92SNicolas Bonnefon 
526a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 2LL );
527a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getMaxLength(), 40 );
528a1e4ce92SNicolas Bonnefon 
529a1e4ce92SNicolas Bonnefon     filteredData_->setVisibility( LogFilteredData::MarksAndMatches );
530a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 3LL );
531a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getMaxLength(), 103 );
532a1e4ce92SNicolas Bonnefon 
533a1e4ce92SNicolas Bonnefon     filteredData_->setVisibility( LogFilteredData::MarksOnly );
534a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 1LL );
535a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getMaxLength(), 103 );
536a1e4ce92SNicolas Bonnefon 
537a1e4ce92SNicolas Bonnefon     filteredData_->addMark( 0 );
538a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 2LL );
539a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getMaxLength(), 103 );
540a1e4ce92SNicolas Bonnefon     filteredData_->deleteMark( 3 );
541a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getNbLine(), 1LL );
542a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getMaxLength(), 27 );
543a1e4ce92SNicolas Bonnefon 
544a1e4ce92SNicolas Bonnefon     filteredData_->setVisibility( LogFilteredData::MarksAndMatches );
545a1e4ce92SNicolas Bonnefon     QCOMPARE( filteredData_->getMaxLength(), 40 );
546a1e4ce92SNicolas Bonnefon 
54764c49544SNicolas Bonnefon     QApplication::quit();
54864c49544SNicolas Bonnefon }
54964c49544SNicolas Bonnefon 
550f35c72b9SNicolas Bonnefon //
551f35c72b9SNicolas Bonnefon // Private functions
552f35c72b9SNicolas Bonnefon //
loadingFinished()553f35c72b9SNicolas Bonnefon void TestLogFilteredData::loadingFinished()
554f35c72b9SNicolas Bonnefon {
5550b28d87cSNicolas Bonnefon     QMutexLocker locker( &loadingFinishedMutex_ );
5560b28d87cSNicolas Bonnefon 
5570b28d87cSNicolas Bonnefon     QWARN("loadingFinished");
5580b28d87cSNicolas Bonnefon     loadingFinished_received_ = true;
5590b28d87cSNicolas Bonnefon     loadingFinished_read_ = false;
5600b28d87cSNicolas Bonnefon 
5610b28d87cSNicolas Bonnefon     loadingFinishedCondition_.wakeOne();
5620b28d87cSNicolas Bonnefon 
5630b28d87cSNicolas Bonnefon     // Wait for the test thread to read the signal
5640b28d87cSNicolas Bonnefon     while ( ! loadingFinished_read_ )
5650b28d87cSNicolas Bonnefon         loadingFinishedCondition_.wait( locker.mutex() );
566f35c72b9SNicolas Bonnefon }
567f35c72b9SNicolas Bonnefon 
searchProgressed(int nbMatches,int completion)568f35c72b9SNicolas Bonnefon void TestLogFilteredData::searchProgressed( int nbMatches, int completion )
569f35c72b9SNicolas Bonnefon {
5700b28d87cSNicolas Bonnefon     QMutexLocker locker( &searchProgressedMutex_ );
5710b28d87cSNicolas Bonnefon 
5720b28d87cSNicolas Bonnefon     QWARN("searchProgressed");
5730b28d87cSNicolas Bonnefon     searchProgressed_received_ = true;
5740b28d87cSNicolas Bonnefon     searchProgressed_read_ = false;
5750b28d87cSNicolas Bonnefon 
5760b28d87cSNicolas Bonnefon     searchLastMatches_ = nbMatches;
5770b28d87cSNicolas Bonnefon     searchLastProgress_ = completion;
5780b28d87cSNicolas Bonnefon 
5790b28d87cSNicolas Bonnefon     searchProgressedCondition_.wakeOne();
5800b28d87cSNicolas Bonnefon 
5810b28d87cSNicolas Bonnefon     // Wait for the test thread to read the signal
5820b28d87cSNicolas Bonnefon     while ( ! searchProgressed_read_ )
5830b28d87cSNicolas Bonnefon         searchProgressedCondition_.wait( locker.mutex() );
5840b28d87cSNicolas Bonnefon }
5850b28d87cSNicolas Bonnefon 
waitSearchProgressed()5860b28d87cSNicolas Bonnefon std::pair<int,int> TestLogFilteredData::waitSearchProgressed()
5870b28d87cSNicolas Bonnefon {
5880b28d87cSNicolas Bonnefon     QMutexLocker locker( &searchProgressedMutex_ );
5890b28d87cSNicolas Bonnefon 
5900b28d87cSNicolas Bonnefon     while ( ! searchProgressed_received_ )
5910b28d87cSNicolas Bonnefon         searchProgressedCondition_.wait( locker.mutex() );
5920b28d87cSNicolas Bonnefon 
5930b28d87cSNicolas Bonnefon     QWARN("searchProgressed Received");
5940b28d87cSNicolas Bonnefon 
5950b28d87cSNicolas Bonnefon     return std::pair<int,int>(searchLastMatches_, searchLastProgress_);
5960b28d87cSNicolas Bonnefon }
5970b28d87cSNicolas Bonnefon 
waitLoadingFinished()5980b28d87cSNicolas Bonnefon void TestLogFilteredData::waitLoadingFinished()
5990b28d87cSNicolas Bonnefon {
6000b28d87cSNicolas Bonnefon     QMutexLocker locker( &loadingFinishedMutex_ );
6010b28d87cSNicolas Bonnefon 
6020b28d87cSNicolas Bonnefon     while ( ! loadingFinished_received_ )
6030b28d87cSNicolas Bonnefon         loadingFinishedCondition_.wait( locker.mutex() );
6040b28d87cSNicolas Bonnefon 
6050b28d87cSNicolas Bonnefon     QWARN("loadingFinished Received");
6060b28d87cSNicolas Bonnefon }
6070b28d87cSNicolas Bonnefon 
signalSearchProgressedRead()6080b28d87cSNicolas Bonnefon void TestLogFilteredData::signalSearchProgressedRead()
6090b28d87cSNicolas Bonnefon {
6100b28d87cSNicolas Bonnefon     QMutexLocker locker( &searchProgressedMutex_ );
6110b28d87cSNicolas Bonnefon 
6120b28d87cSNicolas Bonnefon     searchProgressed_received_ = false;
6130b28d87cSNicolas Bonnefon     searchProgressed_read_ = true;
6140b28d87cSNicolas Bonnefon     searchProgressedCondition_.wakeOne();
6150b28d87cSNicolas Bonnefon }
6160b28d87cSNicolas Bonnefon 
signalLoadingFinishedRead()6170b28d87cSNicolas Bonnefon void TestLogFilteredData::signalLoadingFinishedRead()
6180b28d87cSNicolas Bonnefon {
6190b28d87cSNicolas Bonnefon     QMutexLocker locker( &loadingFinishedMutex_ );
6200b28d87cSNicolas Bonnefon 
6210b28d87cSNicolas Bonnefon     loadingFinished_received_ = false;
6220b28d87cSNicolas Bonnefon     loadingFinished_read_ = true;
6230b28d87cSNicolas Bonnefon     loadingFinishedCondition_.wakeOne();
624f35c72b9SNicolas Bonnefon }
625f35c72b9SNicolas Bonnefon 
generateDataFiles()626f35c72b9SNicolas Bonnefon bool TestLogFilteredData::generateDataFiles()
627f35c72b9SNicolas Bonnefon {
628f35c72b9SNicolas Bonnefon     char newLine[90];
629f35c72b9SNicolas Bonnefon 
630f35c72b9SNicolas Bonnefon     QFile file( TMPDIR "/mediumlog.txt" );
631f35c72b9SNicolas Bonnefon     if ( file.open( QIODevice::WriteOnly ) ) {
632f35c72b9SNicolas Bonnefon         for (int i = 0; i < ML_NB_LINES; i++) {
633f35c72b9SNicolas Bonnefon             snprintf(newLine, 89, ml_format, i);
634f35c72b9SNicolas Bonnefon             file.write( newLine, qstrlen(newLine) );
635f35c72b9SNicolas Bonnefon         }
636f35c72b9SNicolas Bonnefon     }
637f35c72b9SNicolas Bonnefon     else {
638f35c72b9SNicolas Bonnefon         return false;
639f35c72b9SNicolas Bonnefon     }
640f35c72b9SNicolas Bonnefon     file.close();
641f35c72b9SNicolas Bonnefon 
642f35c72b9SNicolas Bonnefon     file.setFileName( TMPDIR "/smalllog.txt" );
643f35c72b9SNicolas Bonnefon     if ( file.open( QIODevice::WriteOnly ) ) {
644f35c72b9SNicolas Bonnefon         for (int i = 0; i < SL_NB_LINES; i++) {
645f35c72b9SNicolas Bonnefon             snprintf(newLine, 89, sl_format, i);
646f35c72b9SNicolas Bonnefon             file.write( newLine, qstrlen(newLine) );
647f35c72b9SNicolas Bonnefon         }
648f35c72b9SNicolas Bonnefon     }
649f35c72b9SNicolas Bonnefon     else {
650f35c72b9SNicolas Bonnefon         return false;
651f35c72b9SNicolas Bonnefon     }
652f35c72b9SNicolas Bonnefon     file.close();
653f35c72b9SNicolas Bonnefon 
654a1e4ce92SNicolas Bonnefon     file.setFileName( TMPDIR "/length_test.txt" );
655a1e4ce92SNicolas Bonnefon     if ( file.open( QIODevice::WriteOnly ) ) {
6564bf9c5f5SNicolas Bonnefon         file.write( "This line is 27 characters.\n" );
657a1e4ce92SNicolas Bonnefon         file.write( "This line is longer: 36 characters.\n" );
6584bf9c5f5SNicolas Bonnefon         file.write( "This line is even longer: 40 characters.\n" );
659a1e4ce92SNicolas Bonnefon         file.write( "This line is very long, it's actually hard to count but it is\
6604bf9c5f5SNicolas Bonnefon  probably something around 103 characters.\n" );
661a1e4ce92SNicolas Bonnefon     }
662a1e4ce92SNicolas Bonnefon     file.close();
663a1e4ce92SNicolas Bonnefon 
664f35c72b9SNicolas Bonnefon     return true;
665f35c72b9SNicolas Bonnefon }
666