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