diff --git a/src/CompressedVectorReaderImpl.cpp b/src/CompressedVectorReaderImpl.cpp index c25a02c..934d96d 100644 --- a/src/CompressedVectorReaderImpl.cpp +++ b/src/CompressedVectorReaderImpl.cpp @@ -150,13 +150,16 @@ namespace e57 "packetType=" + toString( dpkt->header.packetType ) ); } - // Have good packet, initialize channels - for ( auto &channel : channels_ ) + // Have good packet, initialize channels if we have records + if ( maxRecordCount_ > 0 ) { - channel.currentPacketLogicalOffset = dataLogicalOffset; - channel.currentBytestreamBufferIndex = 0; - channel.currentBytestreamBufferLength = - dpkt->getBytestreamBufferLength( channel.bytestreamNumber ); + for ( auto &channel : channels_ ) + { + channel.currentPacketLogicalOffset = dataLogicalOffset; + channel.currentBytestreamBufferIndex = 0; + channel.currentBytestreamBufferLength = + dpkt->getBytestreamBufferLength( channel.bytestreamNumber ); + } } } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2a19b98..a84fad7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,6 +36,11 @@ target_compile_options( testE57 $<${compiler_is_msvc}:/utf-8> ) +target_compile_definitions( testE57 + PRIVATE + E57_VALIDATION_LEVEL=${E57_VALIDATION_LEVEL} +) + target_include_directories( testE57 PRIVATE ../src diff --git a/test/include/Helpers.h b/test/include/Helpers.h index 55aa0d6..411bcb7 100644 --- a/test/include/Helpers.h +++ b/test/include/Helpers.h @@ -15,3 +15,11 @@ } #define E57_ASSERT_THROW( code ) ASSERT_THROW( code, e57::E57Exception ) + +// For readability of preprocessor using E57_VALIDATION_LEVEL +#define VALIDATION_OFF 0 +#define VALIDATION_BASIC 1 +#define VALIDATION_DEEP 2 + +#define VALIDATE_BASIC ( E57_VALIDATION_LEVEL > VALIDATION_OFF ) +#define VALIDATE_DEEP ( E57_VALIDATION_LEVEL > VALIDATION_BASIC ) diff --git a/test/src/test_SimpleReader.cpp b/test/src/test_SimpleReader.cpp index e2551f6..428a11c 100644 --- a/test/src/test_SimpleReader.cpp +++ b/test/src/test_SimpleReader.cpp @@ -45,6 +45,42 @@ TEST( SimpleReaderData, Empty ) delete reader; } +TEST( SimpleReaderData, ZeroPoints ) +{ + e57::Reader *reader = nullptr; + + E57_ASSERT_NO_THROW( reader = new e57::Reader( TestData::Path() + "/self/ZeroPoints.e57", {} ) ); + + ASSERT_TRUE( reader->IsOpen() ); + EXPECT_EQ( reader->GetImage2DCount(), 0 ); + EXPECT_EQ( reader->GetData3DCount(), 1 ); + + e57::E57Root fileHeader; + ASSERT_TRUE( reader->GetE57Root( fileHeader ) ); + + CheckFileHeader( fileHeader ); + EXPECT_EQ( fileHeader.guid, "Zero Points GUID" ); + + e57::Data3D data3DHeader; + ASSERT_TRUE( reader->ReadData3D( 0, data3DHeader ) ); + + ASSERT_EQ( data3DHeader.pointCount, 0 ); + + const uint64_t cNumPoints = data3DHeader.pointCount; + + e57::Data3DPointsFloat pointsData( data3DHeader ); + + auto vectorReader = reader->SetUpData3DPointsData( 0, cNumPoints, pointsData ); + + const uint64_t cNumRead = vectorReader.read(); + + vectorReader.close(); + + EXPECT_EQ( cNumRead, cNumPoints ); + + delete reader; +} + TEST( SimpleReaderData, ZeroPointsInvalid ) { e57::Reader *reader = nullptr; @@ -101,11 +137,20 @@ TEST( SimpleReaderData, InvalidCVHeader ) e57::Data3DPointsFloat pointsData( data3DHeader ); +// This test should fail if validation is ON, but pass if it is OFF +#if VALIDATE_BASIC E57_ASSERT_THROW( { auto vectorReader = reader->SetUpData3DPointsData( 0, cNumPoints, pointsData ); vectorReader.close(); } ); +#else + E57_ASSERT_NO_THROW( { + auto vectorReader = reader->SetUpData3DPointsData( 0, cNumPoints, pointsData ); + + vectorReader.close(); + } ); +#endif delete reader; }