Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ target_link_libraries(UnitTests testgencpp ${Boost_LIBRARIES})
target_link_libraries(UnitTests thrift)
if(WITH_ZLIB)
target_link_libraries(UnitTests thriftz)
target_compile_definitions(UnitTests PRIVATE THRIFT_TEST_WITH_ZLIB)
endif()
add_test(NAME UnitTests COMMAND UnitTests)
if(MSVC)
Expand Down Expand Up @@ -246,6 +247,7 @@ target_link_libraries(TTransportFactoryConfigTest
target_link_libraries(TTransportFactoryConfigTest thrift)
if(WITH_ZLIB)
target_link_libraries(TTransportFactoryConfigTest thriftz)
target_compile_definitions(TTransportFactoryConfigTest PRIVATE THRIFT_TEST_WITH_ZLIB)
endif()
add_test(NAME TTransportFactoryConfigTest COMMAND TTransportFactoryConfigTest)

Expand Down
2 changes: 2 additions & 0 deletions lib/cpp/test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ gen-cpp/ChildService.cpp gen-cpp/ChildService.h gen-cpp/ParentService.cpp gen-cp
$(THRIFT) --gen cpp:templates,cob_style $<

AM_CPPFLAGS = $(BOOST_CPPFLAGS) -I$(top_srcdir)/lib/cpp/src -I$(top_srcdir)/lib/cpp/src/thrift -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I.
# The tests here always link libthriftz
AM_CPPFLAGS += -DTHRIFT_TEST_WITH_ZLIB
AM_LDFLAGS = $(BOOST_LDFLAGS)
AM_CXXFLAGS = -Wall -Wextra -pedantic

Expand Down
7 changes: 7 additions & 0 deletions lib/cpp/test/TTransportFactoryConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
#include <vector>

#include <thrift/transport/TBufferTransports.h>
#ifdef THRIFT_TEST_WITH_ZLIB
#include <thrift/transport/THeaderTransport.h>
#endif
#include <thrift/transport/THttpServer.h>
#include <thrift/transport/TTransportUtils.h>

Expand Down Expand Up @@ -75,10 +77,12 @@ BOOST_AUTO_TEST_CASE(test_framed_transport_factory_preserves_configuration) {
checkPreservesConfiguration(factory);
}

#ifdef THRIFT_TEST_WITH_ZLIB
BOOST_AUTO_TEST_CASE(test_header_transport_factory_preserves_configuration) {
THeaderTransportFactory factory;
checkPreservesConfiguration(factory);
}
#endif // THRIFT_TEST_WITH_ZLIB

BOOST_AUTO_TEST_CASE(test_http_server_transport_factory_preserves_configuration) {
THttpServerTransportFactory factory;
Expand Down Expand Up @@ -137,6 +141,8 @@ BOOST_AUTO_TEST_CASE(test_framed_transport_factory_enforces_custom_max_frame_siz
BOOST_CHECK(caught);
}

// THeaderTransport lives in libthriftz, which is only built with zlib.
#ifdef THRIFT_TEST_WITH_ZLIB
// Behavioral coverage for THeaderTransport: like TFramedTransport, the header
// receive path must reject a frame larger than the caller-configured
// maxFrameSize, not only the internal MAX_FRAME_SIZE ceiling (~1 GiB). The
Expand Down Expand Up @@ -250,6 +256,7 @@ BOOST_AUTO_TEST_CASE(test_header_transport_accepts_frame_within_max_frame_size)
BOOST_CHECK_NO_THROW(reader->readAll(&first, 1));
BOOST_CHECK_EQUAL(first, static_cast<uint8_t>('B'));
}
#endif // THRIFT_TEST_WITH_ZLIB

// TFramedTransport has three constructors. The two that take an underlying
// transport initialise maxFrameSize_ from the configuration; the one that takes
Expand Down
9 changes: 8 additions & 1 deletion lib/cpp/test/ThrifttReadCheckTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <climits>
#include <random>
#include <vector>
#include <zlib.h>
#include <thrift/TConfiguration.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/protocol/TCompactProtocol.h>
Expand All @@ -33,8 +32,11 @@
#include <memory>
#include <thrift/transport/TTransportUtils.h>
#include <thrift/transport/TBufferTransports.h>
#ifdef THRIFT_TEST_WITH_ZLIB
#include <zlib.h>
#include <thrift/transport/THeaderTransport.h>
#include <thrift/protocol/THeaderProtocol.h>
#endif
#include <thrift/TApplicationException.h>
#include <thrift/transport/TSimpleFileTransport.h>
#include <thrift/transport/TFileTransport.h>
Expand Down Expand Up @@ -330,6 +332,8 @@ BOOST_AUTO_TEST_CASE(test_tthriftjsonprotocol_read_check_exception) {
protocol->readMapEnd();
}

// THeaderTransport lives in libthriftz, which is only built with zlib.
#ifdef THRIFT_TEST_WITH_ZLIB
BOOST_AUTO_TEST_CASE(test_theadertransport_header_size_exceeds_frame) {
using apache::thrift::transport::THeaderTransport;
// Header-format frame whose declared header size (3 * 4 = 12) leaves fewer
Expand Down Expand Up @@ -537,6 +541,7 @@ BOOST_AUTO_TEST_CASE(test_theadertransport_framed_size_below_magic_word) {
}
}
}
#endif // THRIFT_TEST_WITH_ZLIB

BOOST_AUTO_TEST_CASE(test_prealloc_size_caps_reserved_capacity) {
using apache::thrift::protocol::preallocSize;
Expand All @@ -554,6 +559,7 @@ BOOST_AUTO_TEST_CASE(test_prealloc_size_caps_reserved_capacity) {
BOOST_CHECK_EQUAL(preallocSize(0xffffffffu), MAX_PREALLOC_SIZE);
}

#ifdef THRIFT_TEST_WITH_ZLIB
BOOST_AUTO_TEST_CASE(test_theadertransport_framed_size_equal_to_magic_word) {
using apache::thrift::transport::THeaderTransport;
// Boundary control for the case above: a declared size of exactly 4 covers
Expand Down Expand Up @@ -627,5 +633,6 @@ BOOST_AUTO_TEST_CASE(test_theadertransport_unknown_protocol_id_error_reply) {
int32_t seqId = 0;
BOOST_CHECK_THROW(proto.readMessageBegin(name, messageType, seqId), TApplicationException);
}
#endif // THRIFT_TEST_WITH_ZLIB

BOOST_AUTO_TEST_SUITE_END()
Loading