Skip to content
Snippets Groups Projects
Commit cdb30491 authored by Gerardo Tauriello's avatar Gerardo Tauriello
Browse files

Ensure that RuleBasedProcessor is never created with a None/NULL library.

parent 0cd48003
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,7 @@ build the compound library manually.
write mode, the programs can deadlock.
:type readonly: :class:`bool`
:returns: The loaded compound lib
:returns: The loaded compound lib or None if it failed.
.. staticmethod:: Create(database)
......
......@@ -19,6 +19,7 @@
#include <limits>
#include <ost/log.hh>
#include <ost/profile.hh>
#include <ost/message.hh>
#include <ost/mol/xcs_editor.hh>
#include <ost/mol/bond_handle.hh>
#include <ost/mol/torsion_handle.hh>
......@@ -30,8 +31,6 @@
namespace ost { namespace conop {
void RuleBasedProcessor::DoProcess(DiagnosticsPtr diags,
mol::EntityHandle ent) const
{
......@@ -199,6 +198,11 @@ String RuleBasedProcessor::ToString() const {
return ss.str();
}
void RuleBasedProcessor::_CheckLib() const {
if (!lib_) {
throw Error("Cannot initialize RuleBasedProcessor without a valid "
"CompoundLib object!");
}
}
}}
......@@ -40,13 +40,19 @@ public:
lib_(compound_lib), fix_element_(true), strict_hydrogens_(false),
unk_res_treatment_(CONOP_WARN), unk_atom_treatment_(CONOP_WARN)
{
_CheckLib();
}
RuleBasedProcessor(CompoundLibPtr compound_lib, bool fe, bool sh, ConopAction ur,
ConopAction ua, bool bf, bool at, bool cn, bool aa, ConopAction zo):
RuleBasedProcessor(CompoundLibPtr compound_lib, bool fe, bool sh,
ConopAction ur, ConopAction ua, bool bf, bool at, bool cn,
bool aa, ConopAction zo):
Processor(bf, at, cn, aa, zo), lib_(compound_lib), fix_element_(fe),
strict_hydrogens_(sh), unk_res_treatment_(ur),
unk_atom_treatment_(ua) {}
unk_atom_treatment_(ua)
{
_CheckLib();
}
ConopAction GetUnkResidueTreatment() const {
return unk_res_treatment_;
}
......@@ -91,6 +97,8 @@ protected:
virtual void DoProcess(DiagnosticsPtr diags,
mol::EntityHandle ent) const;
private:
void _CheckLib() const;
CompoundLibPtr lib_;
bool fix_element_;
bool strict_hydrogens_;
......
......@@ -50,9 +50,24 @@ CompoundLibPtr load_lib()
BOOST_AUTO_TEST_SUITE(conop);
BOOST_AUTO_TEST_CASE(rule_based_init_check)
{
CompoundLibPtr lib; // null ptr is return value when library loading failed
BOOST_CHECK_THROW(RuleBasedProcessor rbc1(lib), ost::Error);
BOOST_CHECK_THROW(RuleBasedProcessor rbc2(lib, true, false, CONOP_WARN,
CONOP_WARN, false, true, true, true,
CONOP_WARN), ost::Error);
lib = load_lib();
if (!lib) { return; }
BOOST_CHECK_NO_THROW(RuleBasedProcessor rbc3(lib));
BOOST_CHECK_NO_THROW(RuleBasedProcessor rbc4(lib, true, false, CONOP_WARN,
CONOP_WARN, false, true, true,
true, CONOP_WARN));
}
BOOST_AUTO_TEST_CASE(rule_based_set_get_flags)
{
CompoundLibPtr lib=load_lib();
CompoundLibPtr lib = load_lib();
if (!lib) { return; }
RuleBasedProcessor rbc(lib);
// check the defaults
......@@ -76,7 +91,7 @@ BOOST_AUTO_TEST_CASE(rule_based_set_get_flags)
BOOST_AUTO_TEST_CASE(rule_based_connect)
{
CompoundLibPtr lib=load_lib();
CompoundLibPtr lib = load_lib();
if (!lib) { return; }
RuleBasedProcessor rbc(lib);
EntityHandle ent = CreateEntity();
......@@ -94,7 +109,7 @@ BOOST_AUTO_TEST_CASE(rule_based_connect)
BOOST_AUTO_TEST_CASE(rule_based_unk_atoms)
{
CompoundLibPtr lib = load_lib();
CompoundLibPtr lib = load_lib();
if (!lib) { return; }
RuleBasedProcessor rbc(lib);
EntityHandle ent = CreateEntity();
......@@ -125,7 +140,7 @@ BOOST_AUTO_TEST_CASE(rule_based_unk_atoms)
BOOST_AUTO_TEST_CASE(guesses_elements_of_unknown_atoms)
{
CompoundLibPtr lib = load_lib();
CompoundLibPtr lib = load_lib();
if (!lib) { return; }
RuleBasedProcessor rbc(lib);
EntityHandle ent = CreateEntity();
......@@ -142,7 +157,7 @@ BOOST_AUTO_TEST_CASE(guesses_elements_of_unknown_atoms)
BOOST_AUTO_TEST_CASE(fills_properties_of_unknown_residues)
{
CompoundLibPtr lib = load_lib();
CompoundLibPtr lib = load_lib();
if (!lib) { return; }
RuleBasedProcessor rbc(lib);
EntityHandle ent = CreateEntity();
......@@ -160,7 +175,7 @@ BOOST_AUTO_TEST_CASE(fills_properties_of_unknown_residues)
BOOST_AUTO_TEST_CASE(connects_atoms_of_unknown_residues_based_on_distance)
{
CompoundLibPtr lib = load_lib();
CompoundLibPtr lib = load_lib();
if (!lib) { return; }
RuleBasedProcessor rbc(lib);
EntityHandle ent = CreateEntity();
......@@ -177,7 +192,7 @@ BOOST_AUTO_TEST_CASE(connects_atoms_of_unknown_residues_based_on_distance)
BOOST_AUTO_TEST_CASE(rule_based_unk_res)
{
CompoundLibPtr lib = load_lib();
CompoundLibPtr lib = load_lib();
if (!lib) { return; }
RuleBasedProcessor rbc(lib);
EntityHandle ent = CreateEntity();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment