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