Commit d2d322ba by Maarten L. Hekkelman

unit test

parent 96a26eae
......@@ -238,6 +238,9 @@ ItemReference& ItemReference::operator=(const std::string& value)
if (mConst)
throw std::logic_error("Attempt to write to a constant row");
if (mRow.mData == nullptr)
throw std::logic_error("Attempt to write to an uninitialized row");
mRow.assign(mName, value, false);
return *this;
}
......@@ -1473,7 +1476,8 @@ template<class Iter>
std::tuple<Row,bool> Category::emplace(Iter b, Iter e)
{
// First, make sure all mandatory fields are supplied
std::tuple<Row,bool> result = std::make_tuple(Row(), true);
Row result;
bool isNew = true;
if (mCatValidator != nullptr and b != e)
{
......@@ -1516,15 +1520,24 @@ std::tuple<Row,bool> Category::emplace(Iter b, Iter e)
{
if (VERBOSE > 1)
std::cerr << "Not inserting new record in " << mName << " (duplicate Key)" << std::endl;
result = std::make_tuple(Row(test), false);
result = test;
isNew = false;
}
}
}
if (std::get<1>(result))
if (isNew)
{
auto nr = new ItemRow{nullptr, this, nullptr};
Row r(nr);
for (auto v = b; v != e; ++v)
r.assign(*v, true);
// if (isOrphan(r))
// throw std::runtime_error("Cannot insert row in category " + mName + " since it would be an orphan");
if (mHead == nullptr)
{
assert(mTail == nullptr);
......@@ -1538,18 +1551,13 @@ std::tuple<Row,bool> Category::emplace(Iter b, Iter e)
mTail = nr;
}
Row r(nr);
for (auto v = b; v != e; ++v)
r.assign(*v, true);
std::get<0>(result) = r;
result = r;
if (mIndex != nullptr)
mIndex->insert(nr);
}
return result;
return { result, isNew };
}
std::tuple<Row,bool> Category::emplace(Row r)
......
......@@ -2608,8 +2608,7 @@ void PDBFileParser::ParseRemarks()
}
catch (const std::exception& ex)
{
std::cerr << "Error parsing REMARK " << remarkNr << std::endl;
throw;
std::throw_with_nested(std::runtime_error("Error parsing REMARK " + std::to_string(remarkNr)));
}
}
......
......@@ -27,6 +27,8 @@
#define BOOST_TEST_MODULE LibCifPP_Test
#include <boost/test/included/unit_test.hpp>
#include <stdexcept>
// #include "cif++/DistanceMap.hpp"
#include "cif++/Cif++.hpp"
......@@ -202,7 +204,7 @@ save__cat_2.id
_item.mandatory_code yes
_item_aliases.dictionary cif_core.dic
_item_aliases.version 2.0.1
_item_type.code code
_item_type.code int
save_
save__cat_2.parent_id
......@@ -279,4 +281,17 @@ _cat_2.desc
BOOST_CHECK(cat1.size() == 2);
BOOST_CHECK(cat2.size() == 1);
// BOOST_CHECK_THROW(cat2.emplace({
// { "id", 4 },
// { "parent_id", 4 },
// { "desc", "moet fout gaan" }
// }), std::exception);
BOOST_CHECK_THROW(cat2.emplace({
{ "id", "vijf" }, // <- invalid value
{ "parent_id", 2 },
{ "desc", "moet fout gaan" }
}), std::exception);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment