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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#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 VBL_NB_LINES = 4999999LL;
static const int VBL_LINE_PER_PAGE = 70;
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";
static const int VBL_LINE_LENGTH = (76+2+7) ; // Without the final '\n' !
static const int VBL_VISIBLE_LINE_LENGTH = (76+8+4+7); // Without the final '\n' !
class PerfLogFilteredData : public testing::Test {
public:
PerfLogFilteredData()
: log_data_(), filtered_data_( log_data_.getNewFilteredData() ),
progressSpy( filtered_data_.get(), SIGNAL( searchProgressed( int, int ) ) ) {
FILELog::setReportingLevel( logERROR );
generateDataFiles();
QSignalSpy endSpy( &log_data_, SIGNAL( loadingFinished( LoadingStatus ) ) );
log_data_.attachFile( TMPDIR "/verybiglog.txt" );
if ( ! endSpy.wait( 999000 ) )
std::cerr << "Unable to attach the file!";
}
LogData log_data_;
std::unique_ptr<LogFilteredData> filtered_data_;
QSignalSpy progressSpy;
void search() {
int percent = 0;
do {
if ( progressSpy.wait( 10000 ) )
percent = qvariant_cast<int>(progressSpy.last().at(1));
else
std::cout << "Missed...\n";
// std::cout << "Progress " << percent << std::endl;
} while ( percent < 100 );
}
bool generateDataFiles() {
char newLine[90];
QFile file( TMPDIR "/verybiglog.txt" );
if ( file.open( QIODevice::WriteOnly ) ) {
for (int i = 0; i < VBL_NB_LINES; i++) {
snprintf(newLine, 89, vbl_format, i);
file.write( newLine, qstrlen(newLine) );
}
}
else {
return false;
}
file.close();
return true;
}
};
TEST_F( PerfLogFilteredData, allMatchingSearch ) {
{
TestTimer t;
filtered_data_->runSearch( QRegExp( "glogg.*this" ) );
search();
}
ASSERT_THAT( filtered_data_->getNbLine(), VBL_NB_LINES );
}
TEST_F( PerfLogFilteredData, someMatchingSearch ) {
{
TestTimer t;
filtered_data_->runSearch( QRegExp( "1?3|34" ) );
search();
}
ASSERT_THAT( filtered_data_->getNbLine(), 2874236 );
}
TEST_F( PerfLogFilteredData, noneMatchingSearch ) {
{
TestTimer t;
filtered_data_->runSearch( QRegExp( "a1?3|(w|f)f34|blah" ) );
search();
}
ASSERT_THAT( filtered_data_->getNbLine(), 0 );
}
TEST_F( PerfLogFilteredData, browsingSearchResults ) {
filtered_data_->runSearch( QRegExp( "1?3|34" ) );
search();
ASSERT_THAT( filtered_data_->getNbLine(), 2874236 );
// Read page by page from the beginning and the end, using the QStringList
// function
std::cout << "Start reading..." << std::endl;
QStringList list;
{
TestTimer t;
const int nb_results = filtered_data_->getNbLine();
for (int page = 0; page < (nb_results/VBL_LINE_PER_PAGE)-1; page++)
{
list = filtered_data_->getExpandedLines(
page * VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE );
ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE);
int page_from_end = (nb_results/VBL_LINE_PER_PAGE) - page - 1;
list = filtered_data_->getExpandedLines(
page_from_end * VBL_LINE_PER_PAGE, VBL_LINE_PER_PAGE );
ASSERT_THAT(list.count(), VBL_LINE_PER_PAGE);
}
}
}
|