11ee847caSNicolas Bonnefon #include <QTest> 21ee847caSNicolas Bonnefon #include <QSignalSpy> 31ee847caSNicolas Bonnefon 41ee847caSNicolas Bonnefon #include "log.h" 51ee847caSNicolas Bonnefon #include "test_utils.h" 61ee847caSNicolas Bonnefon 71ee847caSNicolas Bonnefon #include "data/logdata.h" 81ee847caSNicolas Bonnefon 91ee847caSNicolas Bonnefon #include "gmock/gmock.h" 101ee847caSNicolas Bonnefon 111ee847caSNicolas Bonnefon #define TMPDIR "/tmp" 121ee847caSNicolas Bonnefon 131ee847caSNicolas Bonnefon static const qint64 VBL_NB_LINES = 4999999LL; 141ee847caSNicolas Bonnefon static const int VBL_LINE_PER_PAGE = 70; 151ee847caSNicolas 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"; 161ee847caSNicolas Bonnefon static const int VBL_LINE_LENGTH = (76+2+7) ; // Without the final '\n' ! 171ee847caSNicolas Bonnefon static const int VBL_VISIBLE_LINE_LENGTH = (76+8+4+7); // Without the final '\n' ! 181ee847caSNicolas Bonnefon 191ee847caSNicolas Bonnefon class PerfLogData : public testing::Test { 201ee847caSNicolas Bonnefon public: 211ee847caSNicolas Bonnefon PerfLogData() { 221ee847caSNicolas Bonnefon FILELog::setReportingLevel( logERROR ); 231ee847caSNicolas Bonnefon 241ee847caSNicolas Bonnefon generateDataFiles(); 251ee847caSNicolas Bonnefon } 261ee847caSNicolas Bonnefon 271ee847caSNicolas Bonnefon bool generateDataFiles() { 281ee847caSNicolas Bonnefon char newLine[90]; 291ee847caSNicolas Bonnefon 301ee847caSNicolas Bonnefon QFile file( TMPDIR "/verybiglog.txt" ); 311ee847caSNicolas Bonnefon if ( file.open( QIODevice::WriteOnly ) ) { 321ee847caSNicolas Bonnefon for (int i = 0; i < VBL_NB_LINES; i++) { 331ee847caSNicolas Bonnefon snprintf(newLine, 89, vbl_format, i); 341ee847caSNicolas Bonnefon file.write( newLine, qstrlen(newLine) ); 351ee847caSNicolas Bonnefon } 361ee847caSNicolas Bonnefon } 371ee847caSNicolas Bonnefon else { 381ee847caSNicolas Bonnefon return false; 391ee847caSNicolas Bonnefon } 401ee847caSNicolas Bonnefon file.close(); 411ee847caSNicolas Bonnefon 421ee847caSNicolas Bonnefon return true; 431ee847caSNicolas Bonnefon } 441ee847caSNicolas Bonnefon }; 451ee847caSNicolas Bonnefon 461ee847caSNicolas Bonnefon TEST_F( PerfLogData, simpleLoad ) { 471ee847caSNicolas Bonnefon LogData log_data; 481ee847caSNicolas Bonnefon QSignalSpy progressSpy( &log_data, SIGNAL( loadingProgressed( int ) ) ); 491ee847caSNicolas Bonnefon QSignalSpy endSpy( &log_data, SIGNAL( loadingFinished( LoadingStatus ) ) ); 501ee847caSNicolas Bonnefon 511ee847caSNicolas Bonnefon { 521ee847caSNicolas Bonnefon TestTimer t; 531ee847caSNicolas Bonnefon 541ee847caSNicolas Bonnefon log_data.attachFile( TMPDIR "/verybiglog.txt" ); 551ee847caSNicolas Bonnefon ASSERT_TRUE( endSpy.wait( 20000 ) ); 561ee847caSNicolas Bonnefon } 571ee847caSNicolas Bonnefon 581ee847caSNicolas Bonnefon // Blocks of 5 MiB + 1 for the start notification (0%) 591ee847caSNicolas Bonnefon ASSERT_THAT( progressSpy.count(), log_data.getFileSize() / (5LL*1024*1024) + 2 ); 601ee847caSNicolas Bonnefon ASSERT_THAT( endSpy.count(), 1 ); 611ee847caSNicolas Bonnefon QList<QVariant> arguments = endSpy.takeFirst(); 621ee847caSNicolas Bonnefon ASSERT_THAT( arguments.at(0).toInt(), 631ee847caSNicolas Bonnefon static_cast<int>( LoadingStatus::Successful ) ); 641ee847caSNicolas Bonnefon 651ee847caSNicolas Bonnefon ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES ); 661ee847caSNicolas Bonnefon ASSERT_THAT( log_data.getMaxLength(), VBL_VISIBLE_LINE_LENGTH ); 671ee847caSNicolas Bonnefon ASSERT_THAT( log_data.getLineLength( 123 ), VBL_VISIBLE_LINE_LENGTH ); 681ee847caSNicolas Bonnefon ASSERT_THAT( log_data.getFileSize(), VBL_NB_LINES * (VBL_LINE_LENGTH+1LL) ); 691ee847caSNicolas Bonnefon } 701ee847caSNicolas Bonnefon 711ee847caSNicolas Bonnefon class PerfLogDataRead : public PerfLogData { 721ee847caSNicolas Bonnefon public: 73*dfb2a39cSNicolas Bonnefon PerfLogDataRead() : PerfLogData(), log_data(), endSpy( 741ee847caSNicolas Bonnefon &log_data, SIGNAL( loadingFinished( LoadingStatus ) ) ) { 751ee847caSNicolas Bonnefon log_data.attachFile( TMPDIR "/verybiglog.txt" ); 76*dfb2a39cSNicolas Bonnefon endSpy.wait( 20000 ); 771ee847caSNicolas Bonnefon } 781ee847caSNicolas Bonnefon 791ee847caSNicolas Bonnefon LogData log_data; 801ee847caSNicolas Bonnefon SafeQSignalSpy endSpy; 811ee847caSNicolas Bonnefon }; 821ee847caSNicolas Bonnefon 831ee847caSNicolas Bonnefon TEST_F( PerfLogDataRead, sequentialRead ) { 84*dfb2a39cSNicolas Bonnefon ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES ); 851ee847caSNicolas Bonnefon // Read all lines sequentially 861ee847caSNicolas Bonnefon QString s; 871ee847caSNicolas Bonnefon { 881ee847caSNicolas Bonnefon TestTimer t; 891ee847caSNicolas Bonnefon 901ee847caSNicolas Bonnefon for (int i = 0; i < VBL_NB_LINES; i++) { 911ee847caSNicolas Bonnefon s = log_data.getLineString(i); 921ee847caSNicolas Bonnefon } 931ee847caSNicolas Bonnefon } 941ee847caSNicolas Bonnefon } 951ee847caSNicolas Bonnefon 961ee847caSNicolas Bonnefon TEST_F( PerfLogDataRead, sequentialReadExpanded ) { 97*dfb2a39cSNicolas Bonnefon ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES ); 981ee847caSNicolas Bonnefon // Read all lines sequentially (expanded) 991ee847caSNicolas Bonnefon QString s; 1001ee847caSNicolas Bonnefon { 1011ee847caSNicolas Bonnefon TestTimer t; 1021ee847caSNicolas Bonnefon 1031ee847caSNicolas Bonnefon for (int i = 0; i < VBL_NB_LINES; i++) { 1041ee847caSNicolas Bonnefon s = log_data.getExpandedLineString(i); 1051ee847caSNicolas Bonnefon } 1061ee847caSNicolas Bonnefon } 1071ee847caSNicolas Bonnefon } 1081ee847caSNicolas Bonnefon 1091ee847caSNicolas Bonnefon TEST_F( PerfLogDataRead, randomPageRead ) { 110*dfb2a39cSNicolas Bonnefon ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES ); 1111ee847caSNicolas Bonnefon // Read page by page from the beginning and the end, using the QStringList 1121ee847caSNicolas Bonnefon // function 1131ee847caSNicolas Bonnefon QStringList list; 1141ee847caSNicolas Bonnefon { 1151ee847caSNicolas Bonnefon TestTimer t; 1161ee847caSNicolas Bonnefon 1171ee847caSNicolas Bonnefon for (int page = 0; page < (VBL_NB_LINES/VBL_LINE_PER_PAGE)-1; page++) 1181ee847caSNicolas Bonnefon { 1191ee847caSNicolas Bonnefon list = log_data.getLines( page*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE ); 120*dfb2a39cSNicolas Bonnefon ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE); 1211ee847caSNicolas Bonnefon int page_from_end = (VBL_NB_LINES/VBL_LINE_PER_PAGE) - page - 1; 1221ee847caSNicolas Bonnefon list = log_data.getLines( page_from_end*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE ); 123*dfb2a39cSNicolas Bonnefon ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE); 1241ee847caSNicolas Bonnefon } 1251ee847caSNicolas Bonnefon } 1261ee847caSNicolas Bonnefon } 1271ee847caSNicolas Bonnefon 1281ee847caSNicolas Bonnefon TEST_F( PerfLogDataRead, randomPageReadExpanded ) { 129*dfb2a39cSNicolas Bonnefon ASSERT_THAT( log_data.getNbLine(), VBL_NB_LINES ); 1301ee847caSNicolas Bonnefon // Read page by page from the beginning and the end, using the QStringList 1311ee847caSNicolas Bonnefon // function 1321ee847caSNicolas Bonnefon QStringList list; 1331ee847caSNicolas Bonnefon { 1341ee847caSNicolas Bonnefon TestTimer t; 1351ee847caSNicolas Bonnefon 1361ee847caSNicolas Bonnefon for (int page = 0; page < (VBL_NB_LINES/VBL_LINE_PER_PAGE)-1; page++) 1371ee847caSNicolas Bonnefon { 1381ee847caSNicolas Bonnefon list = log_data.getExpandedLines( page*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE ); 139*dfb2a39cSNicolas Bonnefon ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE); 1401ee847caSNicolas Bonnefon int page_from_end = (VBL_NB_LINES/VBL_LINE_PER_PAGE) - page - 1; 1411ee847caSNicolas Bonnefon list = log_data.getExpandedLines( page_from_end*VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE ); 142*dfb2a39cSNicolas Bonnefon ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE); 1431ee847caSNicolas Bonnefon } 1441ee847caSNicolas Bonnefon } 1451ee847caSNicolas Bonnefon } 146