1 #include <QTest> 2 #include <QSignalSpy> 3 4 #include "log.h" 5 #include "test_utils.h" 6 7 #include "data/logdata.h" 8 #include "data/logfiltereddata.h" 9 10 #include "gmock/gmock.h" 11 12 #define TMPDIR "/tmp" 13 14 static const qint64 SL_NB_LINES = 5000LL; 15 static const int SL_LINE_PER_PAGE = 70; 16 static const char* sl_format="LOGDATA is a part of glogg, we are going to test it thoroughly, this is line %06d\n"; 17 static const int SL_LINE_LENGTH = 83; // Without the final '\n' ! 18 19 class MarksBehaviour : public testing::Test { 20 public: 21 LogData log_data; 22 SafeQSignalSpy endSpy; 23 LogFilteredData* filtered_data = nullptr; 24 25 MarksBehaviour() : endSpy( &log_data, SIGNAL( loadingFinished( LoadingStatus ) ) ) { 26 generateDataFiles(); 27 28 log_data.attachFile( TMPDIR "/smalllog.txt" ); 29 endSpy.safeWait( 10000 ); 30 31 filtered_data = log_data.getNewFilteredData(); 32 } 33 34 35 bool generateDataFiles() { 36 char newLine[90]; 37 38 QFile file( TMPDIR "/smalllog.txt" ); 39 if ( file.open( QIODevice::WriteOnly ) ) { 40 for (int i = 0; i < SL_NB_LINES; i++) { 41 snprintf(newLine, 89, sl_format, i); 42 file.write( newLine, qstrlen(newLine) ); 43 } 44 } 45 else { 46 return false; 47 } 48 file.close(); 49 50 return true; 51 } 52 }; 53 54 TEST_F( MarksBehaviour, marksIgnoresOutOfLimitLines ) { 55 filtered_data->addMark( -10 ); 56 filtered_data->addMark( SL_NB_LINES + 25 ); 57 58 // Check we still have no mark 59 for ( int i = 0; i < SL_NB_LINES; i++ ) 60 ASSERT_FALSE( filtered_data->isLineMarked( i ) ); 61 } 62 63 TEST_F( MarksBehaviour, marksAreStored ) { 64 filtered_data->addMark( 10 ); 65 filtered_data->addMark( 25 ); 66 67 // Check the marks have been put 68 ASSERT_TRUE( filtered_data->isLineMarked( 10 ) ); 69 ASSERT_TRUE( filtered_data->isLineMarked( 25 ) ); 70 } 71