From 8a3667886914c1322ed4e76311012d2754630646 Mon Sep 17 00:00:00 2001 From: Stefan Bienert <stefan.bienert@unibas.ch> Date: Thu, 7 Jul 2011 14:24:35 +0200 Subject: [PATCH] Added negative test for missing data_ construct to the star parser. --- modules/io/src/mol/star_parser.cc | 5 +++-- modules/io/tests/test_star_parser.cc | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/io/src/mol/star_parser.cc b/modules/io/src/mol/star_parser.cc index 9d66fe09e..45d349071 100644 --- a/modules/io/src/mol/star_parser.cc +++ b/modules/io/src/mol/star_parser.cc @@ -331,6 +331,7 @@ void StarParser::ParseGlobal() void StarParser::Parse() { StringRef line; + std::stringstream ss; while (this->GetLine(line)) { StringRef tline=line.rtrim(); if (tline.empty()) { @@ -353,8 +354,8 @@ void StarParser::Parse() this->ConsumeLine(); break; default: - std::cout << "ERROR:" << line_num_ << ":" << tline << std::endl; - assert(0 && "unhandled top-level construct in StarParser::Parse()"); + ss << "Missing 'data_' control structure." << std::endl; + throw IOException(ss.str()); break; } } diff --git a/modules/io/tests/test_star_parser.cc b/modules/io/tests/test_star_parser.cc index 0c73327ba..6a1996775 100644 --- a/modules/io/tests/test_star_parser.cc +++ b/modules/io/tests/test_star_parser.cc @@ -21,6 +21,7 @@ */ #include <fstream> #include <ost/mol/mol.hh> +#include <ost/io/io_exception.hh> #include <ost/io/mol/star_parser.hh> #define BOOST_AUTO_TEST_DYN_LINK @@ -179,5 +180,12 @@ BOOST_AUTO_TEST_CASE(star_loop) BOOST_CHECK_EQUAL(star_p.lines[4][1], "14"); BOOST_CHECK_EQUAL(star_p.lines[4][2], "15"); } + +BOOST_AUTO_TEST_CASE(star_missing_data) +{ + std::ifstream s("testfiles/missing_data.cif"); + LoopTestParser star_p(s); + BOOST_CHECK_THROW(star_p.Parse(), IOException); +} BOOST_AUTO_TEST_SUITE_END(); -- GitLab