diff --git a/Makefile b/Makefile index 38908e07..b08088f2 100644 --- a/Makefile +++ b/Makefile @@ -149,6 +149,7 @@ test: \ test_significant_tags \ test_sorted_node_store \ test_sorted_way_store \ + test_osm_store \ test_tile_coordinates_set test_append_vector: \ @@ -188,6 +189,10 @@ test_options_parser: \ test/options_parser.test.o $(CXX) $(CXXFLAGS) -o test.options_parser $^ $(INC) $(LIB) $(LDFLAGS) && ./test.options_parser +test_osm_store: \ + test/osm_store.test.o + $(CXX) $(CXXFLAGS) -o test.osm_store $^ $(INC) $(LIB) $(LDFLAGS) && ./test.osm_store + test_pooled_string: \ src/mmap_allocator.o \ src/pooled_string.o \ diff --git a/include/osm_store.h b/include/osm_store.h index 171e9386..ce54cd0f 100644 --- a/include/osm_store.h +++ b/include/osm_store.h @@ -78,13 +78,13 @@ class UsedWays { // Mark a way as used void insert(WayID wayid) { std::lock_guard lock(mutex); - if (wayid>usedList.size()) usedList.resize(wayid+256); + if (wayid>=usedList.size()) usedList.resize(wayid+256); usedList[wayid] = true; } // See if a way is used bool at(WayID wayid) const { - return (wayid>usedList.size()) ? false : usedList[wayid]; + return (wayid>=usedList.size()) ? false : usedList[wayid]; } void clear() { diff --git a/test/osm_store.test.cpp b/test/osm_store.test.cpp new file mode 100644 index 00000000..61eca883 --- /dev/null +++ b/test/osm_store.test.cpp @@ -0,0 +1,27 @@ +#include +#include "external/minunit.h" +#include "osm_store.h" + +MU_TEST(test_usedways_grows_for_first_index) { + UsedWays usedWays; + usedWays.insert(0); + mu_check(usedWays.at(0)); +} + +MU_TEST(test_usedways_grows_at_current_size) { + UsedWays usedWays; + usedWays.insert(0); + usedWays.insert(256); + mu_check(usedWays.at(256)); +} + +MU_TEST_SUITE(test_suite_osm_store) { + MU_RUN_TEST(test_usedways_grows_for_first_index); + MU_RUN_TEST(test_usedways_grows_at_current_size); +} + +int main() { + MU_RUN_SUITE(test_suite_osm_store); + MU_REPORT(); + return MU_EXIT_CODE; +}