Skip to content

Commit

Permalink
{standard} Read a properly-formed compressed vector with 0 points
Browse files Browse the repository at this point in the history
A compressed vector with 0 points must still have a data packet.

Part of #262
  • Loading branch information
asmaloney committed Oct 26, 2023
1 parent d4d5496 commit 9fd689d
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/CompressedVectorReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/include/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
45 changes: 45 additions & 0 deletions test/src/test_SimpleReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9fd689d

Please sign in to comment.