Changeset - dae0a0a246f5
[Not reviewed]
stream
0 2 0
Hasan Yavuz Ă–ZDERYA - 7 years ago 2018-04-08 09:01:41
hy@ozderya.net
added one functional test for BinaryStreamReader
2 files changed with 28 insertions and 2 deletions:
0 comments (0 inline, 0 general)
tests/CMakeLists.txt
Show inline comments
 
@@ -19,6 +19,7 @@
 

	
 
# Find the QtWidgets library
 
find_package(Qt5Widgets)
 
find_package(Qt5Test)
 

	
 
include_directories("../src")
 

	
 
@@ -59,7 +60,7 @@ add_executable(TestReaders EXCLUDE_FROM_
 
  ../src/numberformat.cpp
 
  ${UI_FILES_T}
 
  )
 
qt5_use_modules(TestReaders Widgets)
 
qt5_use_modules(TestReaders Widgets Test)
 
add_test(NAME test_readers COMMAND TestReaders)
 

	
 
set(CMAKE_CTEST_COMMAND ctest -V)
tests/test_readers.cpp
Show inline comments
 
@@ -21,9 +21,12 @@
 
#define CATCH_CONFIG_RUNNER
 
#include "catch.hpp"
 

	
 
#include <QSignalSpy>
 
#include <QBuffer>
 
#include "binarystreamreader.h"
 

	
 
#include "test_helpers.h"
 

	
 
TEST_CASE("creating a BinaryStreamReader", "[reader]")
 
{
 
    QBuffer buffer;
 
@@ -31,7 +34,29 @@ TEST_CASE("creating a BinaryStreamReader
 
    BinaryStreamReader bs(&buffer);
 
}
 

	
 
// Note: this is added because `QApplication` is a must be created for widgets
 
TEST_CASE("reading data with BinaryStreamReader", "[reader]")
 
{
 
    QBuffer bufferDev;
 
    BinaryStreamReader bs(&bufferDev);
 
    bs.enable(true);
 

	
 
    TestSink sink;
 
    bs.connectSink(&sink);
 

	
 
    REQUIRE(sink._numChannels == 1);
 
    REQUIRE(sink._hasX == false);
 

	
 
    bufferDev.open(QIODevice::ReadWrite);
 
    const char data[] = {0x01, 0x02, 0x03, 0x04};
 
    bufferDev.write(data, 4);
 
    bufferDev.seek(0);
 

	
 
    QSignalSpy spy(&bufferDev, SIGNAL(readyRead()));
 
    REQUIRE(spy.wait());
 
    REQUIRE(sink.totalFed == 4);
 
}
 

	
 
// Note: this is added because `QApplication` must be created for widgets
 
#include <QApplication>
 
int main(int argc, char* argv[])
 
{
0 comments (0 inline, 0 general)