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
 
@@ -16,12 +16,13 @@
 
# You should have received a copy of the GNU General Public License
 
# along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
#
 

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

	
 
include_directories("../src")
 

	
 
add_executable(Test EXCLUDE_FROM_ALL
 
  test.cpp
 
  test_stream.cpp
 
@@ -56,12 +57,12 @@ add_executable(TestReaders EXCLUDE_FROM_
 
  ../src/binarystreamreadersettings.cpp
 
  ../src/endiannessbox.cpp
 
  ../src/numberformatbox.cpp
 
  ../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)
 
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
 
add_dependencies(check Test TestReaders)
tests/test_readers.cpp
Show inline comments
 
@@ -18,23 +18,48 @@
 
*/
 

	
 
// This tells Catch to provide a main() - only do this in one cpp file per executable
 
#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;
 

	
 
    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[])
 
{
 
    QApplication a(argc, argv);
 

	
 
    int result = Catch::Session().run( argc, argv );
0 comments (0 inline, 0 general)