Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cutting committed Sep 27, 2016
2 parents a92c8f5 + bc3fffb commit 2b1639c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Trunk (not yet released)
AVRO-1849: C++: printJson fails on record with no fields.
(Simon Woodford vai tomwhite)

AVRO-1853: C++: Compiler::toBin crashes on empty string.
(Zoltan Ivanfi via tomwhite)

Avro 1.8.1 (14 May 2016)

INCOMPATIBLE CHANGES
Expand Down
6 changes: 6 additions & 0 deletions lang/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ endif()

if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS_DEBUG "-fstack-protector-all -D_GLIBCXX_DEBUG")
# Unset _GLIBCXX_DEBUG for avrogencpp.cc because using Boost Program Options
# leads to linking errors when compiling with _GLIBCXX_DEBUG as described on
# http://stackoverflow.com/questions/19729036/
set_source_files_properties(impl/avrogencpp.cc PROPERTIES COMPILE_FLAGS "-U_GLIBCXX_DEBUG")
endif ()


Expand Down Expand Up @@ -142,6 +147,7 @@ unittest (SpecificTests)
unittest (DataFileTests)
unittest (JsonTests)
unittest (AvrogencppTests)
unittest (CompilerTests)

add_dependencies (AvrogencppTests bigrecord_hh bigrecord_r_hh bigrecord2_hh
tweet_hh
Expand Down
8 changes: 5 additions & 3 deletions lang/c++/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
set -e # exit on error

function usage {
echo "Usage: $0 {test|dist|clean}"
echo "Usage: $0 {test|dist|clean|install|doc}"
exit 1
}

Expand Down Expand Up @@ -76,10 +76,11 @@ function do_dist() {

case "$target" in
test)
(cd build && make && cd .. \
(cd build && cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug .. && make && cd .. \
&& ./build/buffertest \
&& ./build/unittest \
&& ./build/CodecTests \
&& ./build/CompilerTests \
&& ./build/StreamTests \
&& ./build/SpecificTests \
&& ./build/AvrogencppTests \
Expand All @@ -88,6 +89,7 @@ case "$target" in
;;

dist)
(cd build && cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Release ..)
do_dist
do_doc
;;
Expand All @@ -102,7 +104,7 @@ case "$target" in
;;

install)
(cd build && make install)
(cd build && cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Release .. && make install)
;;

*)
Expand Down
7 changes: 4 additions & 3 deletions lang/c++/impl/Compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ static void assertType(const Entity& e, EntityType et)

static vector<uint8_t> toBin(const std::string& s)
{
vector<uint8_t> result;
result.resize(s.size());
std::copy(s.c_str(), s.c_str() + s.size(), &result[0]);
vector<uint8_t> result(s.size());
if (s.size() > 0) {
std::copy(s.c_str(), s.c_str() + s.size(), &result[0]);
}
return result;
}

Expand Down
70 changes: 70 additions & 0 deletions lang/c++/test/CompilerTests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <sstream>

#include <boost/test/included/unit_test_framework.hpp>
#include <boost/test/unit_test.hpp>

#include "Compiler.hh"
#include "ValidSchema.hh"

// Assert that empty defaults don't make json schema compilation violate bounds
// checks, as they did in AVRO-1853. Please note that on Linux bounds are only
// checked in Debug builds (CMAKE_BUILD_TYPE=Debug).
void testEmptyBytesDefault()
{
std::string input = "{\n\
\"type\": \"record\",\n\
\"name\": \"testrecord\",\n\
\"fields\": [\n\
{\n\
\"name\": \"testbytes\",\n\
\"type\": \"bytes\",\n\
\"default\": \"\"\n\
}\n\
]\n\
}\n\
";
std::string expected = "{\n\
\"type\": \"record\",\n\
\"name\": \"testrecord\",\n\
\"fields\": [\n\
{\n\
\"name\": \"testbytes\",\n\
\"type\": \"bytes\"\n\
}\n\
]\n\
}\n\
";

avro::ValidSchema schema = avro::compileJsonSchemaFromString(input);
std::ostringstream actual;
schema.toJson(actual);
BOOST_CHECK_EQUAL(expected, actual.str());
}

boost::unit_test::test_suite*
init_unit_test_suite(int argc, char* argv[])
{
using namespace boost::unit_test;

test_suite* ts= BOOST_TEST_SUITE("Avro C++ unit tests for Compiler.cc");
ts->add(BOOST_TEST_CASE(&testEmptyBytesDefault));
return ts;
}

0 comments on commit 2b1639c

Please sign in to comment.