-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
add_library(gif_zs STATIC ${TEST_ZS_ROOT}/gif.zs) | ||
zserio_generate_cpp( | ||
TARGET gif_zs | ||
SRC_DIR ${TEST_ZS_ROOT} | ||
GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen | ||
EXTRA_ARGS ${ZSERIO_EXTRA_ARGS} | ||
GENERATED_SOURCES_VAR GENERATED_SOURCES | ||
OUTPUT_VAR ZSERIO_LOG | ||
ERROR_VAR ZSERIO_LOG | ||
) | ||
target_link_libraries(gif_zs PUBLIC ZserioCpp17Runtime) | ||
if (ZSERIO_LOG) | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/zserio_log.txt "${ZSERIO_LOG}") | ||
check_zserio_warnings("${ZSERIO_LOG}" 0) | ||
endif () | ||
|
||
add_custom_command(OUTPUT gif_data_copy | ||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${TEST_ZS_ROOT}/../data | ||
${CMAKE_CURRENT_BINARY_DIR}/data | ||
DEPENDS ${CMAKE_SOURCE_DIR}/data/others/gif | ||
COMMENT "Copying data directory for gif test") | ||
add_custom_target(gif_data_copy_target DEPENDS gif_data_copy) | ||
add_dependencies(gif_zs gif_data_copy_target) | ||
|
||
add_custom_test(gif | ||
DEPENDS | ||
gif_zs | ||
SOURCES | ||
${CMAKE_CURRENT_SOURCE_DIR}/cpp/GifTest.cpp | ||
GENERATED_SOURCES | ||
${GENERATED_SOURCES} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
bugprone-exception-escape:gen/gif/gif_data/ApplicationExtension.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/BlockData.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/BlockData.h | ||
bugprone-exception-escape:gen/gif/gif_data/CommentExtension.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/CommentExtension.h | ||
bugprone-exception-escape:gen/gif/gif_data/ExtensionBlock.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/ExtensionTypes.h | ||
bugprone-exception-escape:gen/gif/gif_data/GifData.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/GifData.h | ||
bugprone-exception-escape:gen/gif/gif_data/ImageBlock.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/PlainTextExtension.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/RasterData.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/RasterData.h | ||
bugprone-exception-escape:gen/gif/gif_data/SubBlock.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/ZippedBlockData.cpp | ||
bugprone-exception-escape:gen/gif/gif_data/ZippedBlockData.h | ||
bugprone-exception-escape:gen/gif/gif_data/ZippedSubBlock.cpp | ||
bugprone-exception-escape:gen/gif/GifFile.cpp | ||
|
||
bugprone-misplaced-widening-cast:gen/gif/gif_data/ImageDescriptor.cpp | ||
bugprone-misplaced-widening-cast:gen/gif/screen_descriptor/ScreenDescriptor.cpp | ||
|
||
cppcoreguidelines-pro-type-reinterpret-cast:cpp/GifTest.cpp | ||
|
||
hicpp-signed-bitwise:gen/gif/gif_data/ImageDescriptor.cpp | ||
hicpp-signed-bitwise:gen/gif/screen_descriptor/ScreenDescriptor.cpp | ||
|
||
misc-no-recursion # reports also tested_release and some system headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <fstream> | ||
|
||
#include "gif/GifFile.h" | ||
#include "gtest/gtest.h" | ||
#include "zserio/RebindAlloc.h" | ||
#include "zserio/SerializeUtil.h" | ||
|
||
namespace gif | ||
{ | ||
|
||
using AllocatorType = GifFile::AllocatorType; | ||
using StringType = zserio::BasicString<zserio::RebindAlloc<AllocatorType, char>>; | ||
template <typename T> | ||
using VectorType = zserio::Vector<T, zserio::RebindAlloc<AllocatorType, T>>; | ||
using BitBufferType = zserio::BasicBitBuffer<AllocatorType>; | ||
|
||
class GifTest : public ::testing::Test | ||
{ | ||
protected: | ||
bool readFileToBuffer(const StringType& fileName, VectorType<uint8_t>& buffer) | ||
{ | ||
std::ifstream inputStream(fileName.c_str(), std::ios::binary); | ||
if (!inputStream) | ||
{ | ||
return false; | ||
} | ||
|
||
inputStream.seekg(0, inputStream.end); | ||
const size_t fileSize = static_cast<size_t>(inputStream.tellg()); | ||
inputStream.seekg(0, inputStream.beg); | ||
buffer.resize(fileSize); | ||
inputStream.read(reinterpret_cast<char*>(buffer.data()), static_cast<std::streamsize>(buffer.size())); | ||
const bool result = static_cast<bool>((inputStream)); | ||
inputStream.close(); | ||
|
||
return result; | ||
} | ||
|
||
void convertUInt8ArrayToString(const VectorType<zserio::UInt8>& array, StringType& outputString) | ||
{ | ||
for (zserio::UInt8 element : array) | ||
{ | ||
outputString.append(1, static_cast<char>(element)); | ||
} | ||
} | ||
}; | ||
|
||
TEST_F(GifTest, OnePixGif) | ||
{ | ||
const StringType onePixGifFileName("others/gif/data/1pix.gif"); | ||
VectorType<uint8_t> buffer; | ||
ASSERT_TRUE(readFileToBuffer(onePixGifFileName, buffer)); | ||
GifFile data; | ||
zserio::deserialize(BitBufferType(buffer), data); | ||
|
||
StringType fileFormat; | ||
convertUInt8ArrayToString(data.signature.format, fileFormat); | ||
const StringType expectedGifFileFormat("GIF"); | ||
ASSERT_EQ(expectedGifFileFormat, fileFormat); | ||
|
||
StringType fileVersion; | ||
convertUInt8ArrayToString(data.signature.version, fileVersion); | ||
const StringType expectedGifFileVersion("89a"); | ||
ASSERT_EQ(expectedGifFileVersion, fileVersion); | ||
|
||
const screen_descriptor::ScreenDescriptor& screenDescriptor = data.screen; | ||
const uint16_t expectedGifScreenWidth = 256; | ||
ASSERT_EQ(expectedGifScreenWidth, screenDescriptor.width); | ||
|
||
const uint16_t expectedGifScreenHeight = 256; | ||
ASSERT_EQ(expectedGifScreenHeight, screenDescriptor.height); | ||
|
||
const uint8_t expectedGifScreenBgColor = 255; | ||
ASSERT_EQ(expectedGifScreenBgColor, screenDescriptor.bgColor); | ||
|
||
const uint8_t expectedScreenBitsOfColorResolution = 7; | ||
ASSERT_EQ(expectedScreenBitsOfColorResolution, screenDescriptor.bitsOfColorResolution); | ||
|
||
const uint8_t expectedScreenBitsPerPixel = 7; | ||
ASSERT_EQ(expectedScreenBitsPerPixel, screenDescriptor.bitsPerPixel); | ||
} | ||
|
||
} // namespace gif |