adding tests for guidance
This commit is contained in:
+14
-11
@@ -1,10 +1,10 @@
|
||||
#include "util/exception.hpp"
|
||||
#include "util/name_table.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/exception.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <fstream>
|
||||
#include <limits>
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
@@ -17,27 +17,30 @@ NameTable::NameTable(const std::string &filename)
|
||||
{
|
||||
boost::filesystem::ifstream name_stream(filename, std::ios::binary);
|
||||
|
||||
if( !name_stream )
|
||||
if (!name_stream)
|
||||
throw exception("Failed to open " + filename + " for reading.");
|
||||
|
||||
name_stream >> m_name_table;
|
||||
|
||||
unsigned number_of_chars = 0;
|
||||
name_stream.read(reinterpret_cast<char *>(&number_of_chars), sizeof(number_of_chars));
|
||||
if( !name_stream )
|
||||
if (!name_stream)
|
||||
throw exception("Encountered invalid file, failed to read number of contained chars");
|
||||
|
||||
BOOST_ASSERT_MSG(0 != number_of_chars, "name file broken");
|
||||
m_names_char_list.resize(number_of_chars + 1); //+1 gives sentinel element
|
||||
name_stream.read(reinterpret_cast<char *>(&m_names_char_list[0]),
|
||||
number_of_chars * sizeof(m_names_char_list[0]));
|
||||
if( !name_stream )
|
||||
throw exception("Failed to read " + std::to_string(number_of_chars) + " characters from file.");
|
||||
|
||||
if (0 == m_names_char_list.size())
|
||||
m_names_char_list.back() = 0;
|
||||
if (number_of_chars > 0)
|
||||
{
|
||||
name_stream.read(reinterpret_cast<char *>(&m_names_char_list[0]),
|
||||
number_of_chars * sizeof(m_names_char_list[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "list of street names is empty";
|
||||
}
|
||||
if (!name_stream)
|
||||
throw exception("Failed to read " + std::to_string(number_of_chars) +
|
||||
" characters from file.");
|
||||
}
|
||||
|
||||
std::string NameTable::GetNameForID(const unsigned name_id) const
|
||||
|
||||
Reference in New Issue
Block a user