Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/ZeroBuf.key/Index.zip
Binary file not shown.
Binary file modified doc/ZeroBuf.key/Metadata/Properties.plist
Binary file not shown.
Binary file modified doc/ZeroBuf.pdf
Binary file not shown.
6 changes: 4 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Copyright (c) HBP 2015-2016 [email protected]
# Change this number when adding tests to force a CMake run: 0
# Change this number when adding tests to force a CMake run: 1

if(NOT BOOST_FOUND)
return()
endif()

include(zerobufGenerateCxx)
zerobuf_generate_cxx(TESTSCHEMA ${CMAKE_CURRENT_BINARY_DIR} testSchema.fbs)
zerobuf_generate_cxx(TESTSCHEMA ${CMAKE_CURRENT_BINARY_DIR}/testschema
testSchema.fbs doubleString.fbs)
include_directories(${CMAKE_CURRENT_BINARY_DIR})

set(TESTSCHEMA_LIBRARY_TYPE STATIC)
set(TESTSCHEMA_INCLUDE_NAME testschema)
set(TESTSCHEMA_LINK_LIBRARIES ZeroBuf)
set(TESTSCHEMA_OMIT_EXPORT ON)
set(TESTSCHEMA_OMIT_INSTALL ON)
common_library(testschema)

set(TEST_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
Expand Down
36 changes: 36 additions & 0 deletions tests/doubleString.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

/* Copyright (c) 2016, Human Brain Project
* [email protected]
*/

#define BOOST_TEST_MODULE doubleString

#include <boost/test/unit_test.hpp>

#include <testschema/doubleString.h>
#include <iostream>

BOOST_AUTO_TEST_CASE(reallocation)
{
// Repro: allocator bug with a specific order of calls
// https://github.com/HBPVIS/ZeroBuf/pull/50
test::DoubleString doubleString;
doubleString.setKey( std::string( 1, 1 ));
doubleString.setValue( std::string( 12, 12 ));
doubleString.setKey( std::string( 8, 8 ));
doubleString.setValue( std::string( 16, 16 ));
doubleString.setKey( std::string( 12, 12 ));
doubleString.setValue( std::string( 17, 17 ));

// Try to find another combination
for( size_t i = 0; i < 1000; ++i )
{
size_t len = ::rand() % 20;
doubleString.setKey( std::string( len, len ));

len = ::rand() % 20;
doubleString.setValue( std::string( len, len ));
BOOST_CHECK_LE( doubleString.toBinary().size,
36/*header*/ + 19/*biggest hole*/ + 40/*20b strings*/ );
}
}
7 changes: 7 additions & 0 deletions tests/doubleString.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

namespace test;

table DoubleString {
key: string;
value: string;
}
2 changes: 1 addition & 1 deletion tests/empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define BOOST_TEST_MODULE empty

#include <boost/test/unit_test.hpp>
#include <testSchema.h>
#include <testschema/testSchema.h>
#include <iostream>

BOOST_AUTO_TEST_CASE(empty)
Expand Down
2 changes: 1 addition & 1 deletion tests/nestedDynamicZerobuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define BOOST_TEST_MODULE nestedDynamicZerobuf

#include <boost/test/unit_test.hpp>
#include <testSchema.h>
#include <testschema/testSchema.h>

#include <utility>

Expand Down
2 changes: 1 addition & 1 deletion tests/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Daniel Nachbaur <[email protected]>
*/

#include <testSchema.h>
#include <testschema/testSchema.h>

#define SETVALUES(type, name) \
const std::vector< type > name##Vector { type(1), type(1), type(2), type(3) }; \
Expand Down
2 changes: 0 additions & 2 deletions tests/testSchema.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,3 @@ table TestSchema {
nesteddynamic: [TestNested];
nestedMember: TestDynamic;
}

root_type TestSchema;
16 changes: 14 additions & 2 deletions zerobuf/NonMovingBaseAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ uint8_t* NonMovingBaseAllocator::updateAllocation(
}

// Check for a big enough hole
typedef std::map< size_t, size_t > ArrayMap;
//-- record allocations
typedef std::map< size_t, size_t > ArrayMap; // offset -> size
ArrayMap arrays; // sort arrays by position
for( size_t i = 0; i < _numDynamic; ++i )
{
Expand All @@ -83,8 +84,9 @@ uint8_t* NonMovingBaseAllocator::updateAllocation(
arrays[ offset ] = _getSize( i );
}

//-- find hole
uint64_t start = _staticSize;
for( ArrayMap::const_iterator i = arrays.begin(); i != arrays.end(); ++i )
for( auto i = arrays.cbegin(); i != arrays.cend(); ++i )
{
assert( i->first >= start );
if( i->first - start >= newSize )
Expand All @@ -93,7 +95,17 @@ uint8_t* NonMovingBaseAllocator::updateAllocation(
start = i->first + i->second;
}

//-- check for space after last allocation
if( getSize() - start >= newSize )
return _moveAllocation( index, copy, start, newSize );

// realloc space at the end
if( start + newSize <= getSize( ))
throw std::runtime_error(
"Internal allocator error: allocation shrinks from " +
std::to_string( getSize( )) + " to " + std::to_string( start ) +
" + " + std::to_string( newSize ));

_resize( start + newSize );
return _moveAllocation( index, copy, start, newSize );
}
Expand Down