Fix unit-test

This commit is contained in:
Patrick Niklaus 2017-05-29 11:28:38 +00:00 committed by Patrick Niklaus
parent 7eab227ab1
commit a544935e7d
2 changed files with 35 additions and 9 deletions

View File

@ -1,6 +1,8 @@
#include "util/indexed_data.hpp"
#include "util/exception.hpp"
#include <boost/filesystem.hpp>
#include <boost/test/test_case_template.hpp>
#include <boost/test/unit_test.hpp>
@ -34,11 +36,18 @@ BOOST_AUTO_TEST_CASE(check_variable_group_block_bitops)
template <typename IndexedData, typename Offsets, typename Data>
void test_rw(const Offsets &offsets, const Data &data)
{
std::stringstream sstr;
IndexedData indexed_data;
indexed_data.write(sstr, offsets.begin(), offsets.end(), data.begin());
auto path = boost::filesystem::unique_path();
const std::string str = sstr.str();
{
storage::io::FileWriter writer(path, storage::io::FileWriter::HasNoFingerprint);
indexed_data.write(writer, offsets.begin(), offsets.end(), data.begin());
}
storage::io::FileReader reader(path, storage::io::FileReader::HasNoFingerprint);
auto length = reader.GetSize();
std::string str(length, '\0');
reader.ReadInto(const_cast<char *>(str.data()), length);
#if 0
std::cout << "\n" << typeid(IndexedData).name() << "\nsaved size = " << str.size() << "\n";
@ -175,14 +184,21 @@ BOOST_AUTO_TEST_CASE(check_corrupted_memory)
BOOST_AUTO_TEST_CASE(check_string_view)
{
std::stringstream sstr;
auto path = boost::filesystem::unique_path();
std::string name_data = "hellostringview";
std::vector<std::uint32_t> name_offsets = {0, 5, 11, 15};
IndexedData<VariableGroupBlock<16, StringView>> indexed_data;
indexed_data.write(sstr, name_offsets.begin(), name_offsets.end(), name_data.begin());
{
storage::io::FileWriter writer(path, storage::io::FileWriter::HasNoFingerprint);
indexed_data.write(writer, name_offsets.begin(), name_offsets.end(), name_data.begin());
}
storage::io::FileReader reader(path, storage::io::FileReader::HasNoFingerprint);
auto length = reader.GetSize();
std::string str(length, '\0');
reader.ReadInto(const_cast<char *>(str.data()), length);
const std::string str = sstr.str();
indexed_data.reset(str.c_str(), str.c_str() + str.size());
BOOST_CHECK_EQUAL(indexed_data.at(0), "hello");

View File

@ -1,6 +1,7 @@
#include "util/name_table.hpp"
#include "util/exception.hpp"
#include <boost/filesystem.hpp>
#include <boost/test/test_case_template.hpp>
#include <boost/test/unit_test.hpp>
@ -19,7 +20,6 @@ using namespace osrm::util;
std::string PrapareNameTableData(std::vector<std::string> &data, bool fill_all)
{
std::stringstream sstr;
NameTable::IndexedData indexed_data;
std::vector<unsigned char> name_char_data;
std::vector<std::uint32_t> name_offsets;
@ -54,9 +54,19 @@ std::string PrapareNameTableData(std::vector<std::string> &data, bool fill_all)
}
name_offsets.push_back(name_char_data.size());
indexed_data.write(sstr, name_offsets.begin(), name_offsets.end(), name_char_data.begin());
auto path = boost::filesystem::unique_path();
{
storage::io::FileWriter writer(path, storage::io::FileWriter::HasNoFingerprint);
indexed_data.write(
writer, name_offsets.begin(), name_offsets.end(), name_char_data.begin());
}
return sstr.str();
storage::io::FileReader reader(path, storage::io::FileReader::HasNoFingerprint);
auto length = reader.GetSize();
std::string str(length, '\0');
reader.ReadInto(const_cast<char *>(str.data()), length);
return str;
}
BOOST_AUTO_TEST_CASE(check_name_table_fill)