From 1b4c09aa951e0d871d8644eb1ea8537058865bb3 Mon Sep 17 00:00:00 2001
From: Marco Biasini <marco.biasini@unibas.ch>
Date: Mon, 17 Jan 2011 10:22:47 +0100
Subject: [PATCH] address comment of Tobias regarding a75bbdf7a89

---
 modules/base/src/invalid_handle.hh       |  2 +-
 modules/img/base/tests/test_image.cc     | 10 +++++-
 modules/mol/base/pymod/export_atom.cc    |  4 +--
 modules/mol/base/pymod/export_chain.cc   |  4 +--
 modules/mol/base/pymod/export_entity.cc  |  5 +--
 modules/mol/base/pymod/export_residue.cc |  4 +--
 modules/mol/base/src/atom_base.hh        | 15 ++++++++-
 modules/mol/base/src/atom_handle.hh      | 15 +--------
 modules/mol/base/src/chain_base.hh       | 14 +++++++++
 modules/mol/base/src/chain_handle.hh     | 15 +--------
 modules/mol/base/src/entity_base.hh      | 13 ++++++++
 modules/mol/base/src/entity_handle.hh    | 14 +--------
 modules/mol/base/src/residue_base.hh     | 13 ++++++++
 modules/mol/base/src/residue_handle.hh   | 12 -------
 modules/mol/base/tests/CMakeLists.txt    |  1 +
 modules/mol/base/tests/test_chain.cc     | 23 ++++++++++++++
 modules/mol/base/tests/test_entity.cc    | 19 ++++++++++-
 modules/mol/base/tests/test_residue.cc   | 28 +++++++++++++++++
 modules/mol/base/tests/test_surface.cc   | 40 ++++++++++++++++++++++++
 modules/seq/base/tests/test_alignment.cc |  9 ++++++
 modules/seq/base/tests/test_sequence.cc  |  8 +++++
 21 files changed, 203 insertions(+), 65 deletions(-)
 create mode 100644 modules/mol/base/tests/test_surface.cc

diff --git a/modules/base/src/invalid_handle.hh b/modules/base/src/invalid_handle.hh
index 9f6861dd9..fdb56203e 100644
--- a/modules/base/src/invalid_handle.hh
+++ b/modules/base/src/invalid_handle.hh
@@ -37,7 +37,7 @@ public:
 template <typename H>
 inline void CheckHandleValidity(const H& handle)
 {
-  if (!handle.Impl())
+  if (!handle.IsValid())
     throw InvalidHandle();
 }
 
diff --git a/modules/img/base/tests/test_image.cc b/modules/img/base/tests/test_image.cc
index dde2a034f..2342cb11e 100644
--- a/modules/img/base/tests/test_image.cc
+++ b/modules/img/base/tests/test_image.cc
@@ -25,7 +25,7 @@
 #include <iostream>
 
 #include "test_image.hh"
-
+#include <ost/invalid_handle.hh>
 #include <ost/img/image.hh>
 #include <ost/img/data_observer.hh>
 #include <ost/img/observable.hh>
@@ -612,6 +612,13 @@ void test_PointToCoord() {
   BOOST_CHECK(spatial.CoordToIndex(Vec3(11.0,11.0,11.0)) == Vec3(3.0,3.0,3.0));
 }
 
+void test_ThrowInvalidImageHandle() {
+  ImageHandle image;
+  BOOST_CHECK_THROW(ost::CheckHandleValidity(image), ost::InvalidHandle);
+  image=CreateImage(Size(1,1));
+  BOOST_CHECK_NO_THROW(ost::CheckHandleValidity(image));
+}
+
 } // ns
 
 test_suite* CreateImageTest()
@@ -633,6 +640,7 @@ test_suite* CreateImageTest()
   ts->add(BOOST_TEST_CASE(&test_Copy));
   ts->add(BOOST_TEST_CASE(&test_Extract));
   ts->add(BOOST_TEST_CASE(&test_Paste));
+  ts->add(BOOST_TEST_CASE(&test_ThrowInvalidImageHandle));
   ts->add(BOOST_TEST_CASE(&test_Mult));
   ts->add(BOOST_TEST_CASE(&test_AddSub));
   ts->add(BOOST_TEST_CASE(&test_Interpolation));
diff --git a/modules/mol/base/pymod/export_atom.cc b/modules/mol/base/pymod/export_atom.cc
index ec7b4fbc5..67fc5a163 100644
--- a/modules/mol/base/pymod/export_atom.cc
+++ b/modules/mol/base/pymod/export_atom.cc
@@ -74,6 +74,8 @@ void export_Atom()
     .add_property("is_hetatom", &AtomBase::IsHetAtom, &AtomBase::SetHetAtom)
     .add_property("charge", &AtomBase::GetCharge, &AtomBase::SetCharge)
     .add_property("mass", &AtomBase::GetMass, &AtomBase::SetMass)
+    .add_property("valid", &AtomBase::IsValid)
+    .def("IsValid", &AtomBase::IsValid)
   ;
   generic_prop_def<AtomBase>(atom_base);
 
@@ -82,8 +84,6 @@ void export_Atom()
     .add_property("residue",&AtomHandle::GetResidue)
     .def("GetBondList", &AtomHandle::GetBondList)
     .def("GetBondCount", &AtomHandle::GetBondCount)
-    .add_property("valid", &AtomHandle::IsValid)
-    .def("IsValid", &AtomHandle::IsValid)
     .def("GetEntity", &AtomHandle::GetEntity)
     .def("GetHandle", &AtomHandle::GetHandle)
     .add_property("handle", &AtomHandle::GetHandle)
diff --git a/modules/mol/base/pymod/export_chain.cc b/modules/mol/base/pymod/export_chain.cc
index 391fc4df8..b21d5eb97 100644
--- a/modules/mol/base/pymod/export_chain.cc
+++ b/modules/mol/base/pymod/export_chain.cc
@@ -48,6 +48,8 @@ void export_Chain()
     .def("GetName", &ChainBase::GetName)
     .add_property("name", &ChainBase::GetName)
     .def(self_ns::str(self))
+    .add_property("valid", &ChainBase::IsValid)
+    .def("IsValid", &ChainBase::IsValid)
   ;
   generic_prop_def<ChainBase>(chain_base);
   class_<ChainHandle, bases<ChainBase> >("ChainHandle", init<>())
@@ -80,7 +82,6 @@ void export_Chain()
     .def("InSequence", &ChainHandle::InSequence)
     .def("Select", select_string, arg("flags")=0)
     .def("Select", select_query, arg("flags")=0)
-    .def("IsValid", &ChainHandle::IsValid)
     .def("GetMass", &ChainHandle::GetMass)
     .def("GetCenterOfMass", &ChainHandle::GetCenterOfMass)
     .def("GetCenterOfAtoms", &ChainHandle::GetCenterOfAtoms)
@@ -90,7 +91,6 @@ void export_Chain()
     .add_property("center_of_mass", &ChainHandle::GetCenterOfMass)
     .add_property("center_of_atoms", &ChainHandle::GetCenterOfAtoms)  
     .add_property("in_sequence", &ChainHandle::InSequence)  
-    .add_property("valid", &ChainHandle::IsValid)    
     .def("GetBounds", &ChainHandle::GetBounds)
     .add_property("bounds", &ChainHandle::GetBounds)
     .def("GetGeometricStart", geom_start<ChainHandle>)
diff --git a/modules/mol/base/pymod/export_entity.cc b/modules/mol/base/pymod/export_entity.cc
index 4f80a0949..3f3858ed0 100644
--- a/modules/mol/base/pymod/export_entity.cc
+++ b/modules/mol/base/pymod/export_entity.cc
@@ -75,6 +75,8 @@ void export_Entity()
     .def("GetName", &EntityBase::GetName,
         return_value_policy<copy_const_reference>())
     .def("SetName", &EntityBase::SetName)
+    .def("IsValid", &EntityBase::IsValid)
+    .add_property("valid", &EntityBase::IsValid)
   ;
   generic_prop_def<EntityBase>(ent_base);
   
@@ -92,7 +94,7 @@ void export_Entity()
     .def("GetCenterOfAtoms", &EntityHandle::GetCenterOfAtoms)
     .def("GetGeometricCenter", geom_center<EntityHandle>)
     .add_property("geometric_center", geom_center<EntityHandle>)
-    .def("IsValid", &EntityHandle::IsValid)
+
     .add_property("geometric_end", geom_end<EntityHandle>)
     .add_property("geometric_start", geom_start<EntityHandle>)
     .def("GetGeometricStart", geom_start<EntityHandle>)
@@ -122,7 +124,6 @@ void export_Entity()
     .add_property("atoms", &EntityHandle::GetAtomList)
     .add_property("chains", &EntityHandle::GetChainList)
     .add_property("bonds", &EntityHandle::GetBondList)
-    .add_property("valid", &EntityHandle::IsValid)
     .def("GetBounds", &EntityHandle::GetBounds)
     .add_property("bounds", &EntityHandle::GetBounds)
     .def("GetTransformationMatrix", &EntityHandle::GetTransformationMatrix,
diff --git a/modules/mol/base/pymod/export_residue.cc b/modules/mol/base/pymod/export_residue.cc
index 715404555..4679840ee 100644
--- a/modules/mol/base/pymod/export_residue.cc
+++ b/modules/mol/base/pymod/export_residue.cc
@@ -134,6 +134,8 @@ void export_Residue()
                    make_function(&ResidueBase::GetName,
                                  return_value_policy<copy_const_reference>()))
     .add_property("qualified_name", &ResidueBase::GetQualifiedName)
+    .def("IsValid", &ResidueBase::IsValid)
+    .add_property("valid", &ResidueBase::IsValid) 
   ;
   generic_prop_def<ResidueBase>(residue_base);
 
@@ -159,7 +161,6 @@ void export_Residue()
     .def("FindAtom", &ResidueHandle::FindAtom, args("atom_name"))
     .def("FindTorsion", &ResidueHandle::FindTorsion)
     .def("GetAtomCount", &ResidueHandle::GetAtomCount)
-    .def("IsValid", &ResidueHandle::IsValid)
     .def("GetBondCount", &ResidueHandle::GetBondCount)
     .add_property("atom_count", &ResidueHandle::GetAtomCount)
     .add_property("index", &ResidueHandle::GetIndex)
@@ -176,7 +177,6 @@ void export_Residue()
     .add_property("phi_torsion", &ResidueHandle::GetPhiTorsion)
     .add_property("psi_torsion", &ResidueHandle::GetPsiTorsion)
     .add_property("omega_torsion", &ResidueHandle::GetOmegaTorsion)
-    .add_property("valid", &ResidueHandle::IsValid) 
     .def("GetGeometricStart", geom_start<ResidueHandle>)
     .def("GetGeometricEnd", geom_end<ResidueHandle>)
     .def(self==self)
diff --git a/modules/mol/base/src/atom_base.hh b/modules/mol/base/src/atom_base.hh
index 55581c8a1..a6ddaa7cd 100644
--- a/modules/mol/base/src/atom_base.hh
+++ b/modules/mol/base/src/atom_base.hh
@@ -48,7 +48,20 @@ class DLLEXPORT_OST_MOL AtomBase: public GenericPropContainer<AtomBase> {
 public:
   AtomBase();
   AtomBase(const impl::AtomImplPtr& impl);
-public:  
+public:
+  /// \name Handle validity
+  //@{
+  /// \brief check validity of handle
+  /// 
+  /// check, whether the bond handle points to a valid atom.
+  /// \note It is an error to use any method other than #IsValid, Impl and 
+  ///       #operator bool() when the handle is invalid. An InvalidHandle
+  ///       exception will be thrown.
+  operator bool() const { return this->IsValid(); }
+  /// \brief check validity of handle
+  /// \sa #operator bool()
+  bool IsValid() const { return Impl().get()!=0; }
+  //@}
   friend class ConstGenericPropContainer<AtomBase>;  
   ///\brief Get atom name. 
   ///
diff --git a/modules/mol/base/src/atom_handle.hh b/modules/mol/base/src/atom_handle.hh
index 04a7eea94..83a1c9046 100644
--- a/modules/mol/base/src/atom_handle.hh
+++ b/modules/mol/base/src/atom_handle.hh
@@ -40,20 +40,7 @@ public:
   AtomHandle(const impl::AtomImplPtr& impl);
 
 public:  
-  
-  /// \name Handle validity
-  //@{
-  /// \brief check validity of handle
-  /// 
-  /// check, whether the bond handle points to a valid atom.
-  /// \note It is an error to use any method other than #IsValid, Impl and 
-  ///       #operator bool() when the handle is invalid. An InvalidHandle
-  ///       exception will be thrown.
-  operator bool() const { return this->IsValid(); }
-  /// \brief check validity of handle
-  /// \sa #operator bool()
-  bool IsValid() const { return Impl().get()!=0; }
-  //@}
+
   ResidueHandle GetResidue() const;
   
   EntityHandle GetEntity() const;  
diff --git a/modules/mol/base/src/chain_base.hh b/modules/mol/base/src/chain_base.hh
index 6d4e1317a..faf7a5c98 100644
--- a/modules/mol/base/src/chain_base.hh
+++ b/modules/mol/base/src/chain_base.hh
@@ -42,6 +42,20 @@ public: // constructors
   ChainBase();
   ChainBase(const impl::ChainImplPtr& impl);
 public:
+  
+  /// \name Handle validity
+  //@{
+  /// \brief check validity of handle
+  /// 
+  /// check, whether the chain handle points to a valid handle.
+  /// \note It is an error to use any method other than #IsValid, #Impl() and 
+  ///       #operator bool() when the handle is invalid. An InvalidHandle
+  ///       exception will be thrown.
+  operator bool() const { return this->IsValid(); }
+  /// \brief check validity of handle
+  /// \sa #operator bool()
+  bool IsValid() const { return Impl().get()!=0; }
+  //@}
   friend class ConstGenericPropContainer<ChainBase>;
   String GetName() const;
 
diff --git a/modules/mol/base/src/chain_handle.hh b/modules/mol/base/src/chain_handle.hh
index 461176925..1d774dadd 100644
--- a/modules/mol/base/src/chain_handle.hh
+++ b/modules/mol/base/src/chain_handle.hh
@@ -57,20 +57,7 @@ public:
 
   ChainHandle(const impl::ChainImplPtr& impl);
   
-  /// \name Handle validity
-  //@{
-  /// \brief check validity of handle
-  /// 
-  /// check, whether the chain handle points to a valid handle.
-  /// \note It is an error to use any method other than #IsValid, #Impl() and 
-  ///       #operator bool() when the handle is invalid. An InvalidHandle
-  ///       exception will be thrown.
-  operator bool() const { return this->IsValid(); }
-  /// \brief check validity of handle
-  /// \sa #operator bool()
-  bool IsValid() const { return Impl().get()!=0; }
-  //@}
-  
+
   /// \brief Get parent entity.
   EntityHandle GetEntity() const;
 
diff --git a/modules/mol/base/src/entity_base.hh b/modules/mol/base/src/entity_base.hh
index d68e7df26..7e5c7f2d7 100644
--- a/modules/mol/base/src/entity_base.hh
+++ b/modules/mol/base/src/entity_base.hh
@@ -47,6 +47,19 @@ public:
   void SetName(const String& ent_name);
 
 public:
+  
+  /// \name Handle validity
+  //@{
+  /// \brief check validity of handle
+  /// 
+  /// check, whether the entity handle points to a valid entity.
+  /// \note It is an error to use any method other than #IsValid, #Impl and 
+  ///       #operator bool() when the handle is invalid. An InvalidHandle
+  ///       exception will be thrown.
+  operator bool() const { return this->IsValid(); }
+  /// \brief check validity of handle
+  /// \sa #operator bool()
+  bool IsValid() const { return Impl().get()!=0; }
   impl::EntityImplPtr& Impl();
   const impl::EntityImplPtr& Impl() const;
 protected:
diff --git a/modules/mol/base/src/entity_handle.hh b/modules/mol/base/src/entity_handle.hh
index 7114f54c8..a7d8f887e 100644
--- a/modules/mol/base/src/entity_handle.hh
+++ b/modules/mol/base/src/entity_handle.hh
@@ -64,19 +64,7 @@ public:
   /// default ctor. creates invalid handle.
   EntityHandle();
   
-  
-  /// \name Handle validity
-  //@{
-  /// \brief check validity of handle
-  /// 
-  /// check, whether the entity handle points to a valid entity.
-  /// \note It is an error to use any method other than #IsValid, #Impl and 
-  ///       #operator bool() when the handle is invalid. An InvalidHandle
-  ///       exception will be thrown.
-  operator bool() const { return this->IsValid(); }
-  /// \brief check validity of handle
-  /// \sa #operator bool()
-  bool IsValid() const { return Impl().get()!=0; }
+
   //@}
   /// \brief copy entity, effectively duplicating the whole data structure
   /// 
diff --git a/modules/mol/base/src/residue_base.hh b/modules/mol/base/src/residue_base.hh
index 5b0b556d3..92901bf9e 100644
--- a/modules/mol/base/src/residue_base.hh
+++ b/modules/mol/base/src/residue_base.hh
@@ -63,6 +63,19 @@ public:
   ResidueBase(const impl::ResidueImplPtr& impl);
   ResidueBase(const ResidueBase& rhs);
 public:
+  
+  /// \name Handle validity
+  //@{
+  /// \brief check validity of handle
+  ///
+  /// check, whether the residue handle points to a valid residue.
+  /// \note It is an error to use any method other than #IsValid, #Impl and
+  ///       #operator bool() when the handle is invalid. An InvalidHandle
+  ///       exception will be thrown.
+  operator bool() const { return this->IsValid(); }
+  /// \brief check validity of handle
+  /// \sa #operator bool()
+  bool IsValid() const { return Impl().get()!=0; }
   friend class ConstGenericPropContainer<ResidueBase>;
   /// \brief return residue number
   const ResNum& GetNumber() const;
diff --git a/modules/mol/base/src/residue_handle.hh b/modules/mol/base/src/residue_handle.hh
index f280509cc..5705f3de8 100644
--- a/modules/mol/base/src/residue_handle.hh
+++ b/modules/mol/base/src/residue_handle.hh
@@ -56,18 +56,6 @@ class DLLEXPORT_OST_MOL ResidueHandle : public ResidueBase {
 public:
   ResidueHandle();
 
-  /// \name Handle validity
-  //@{
-  /// \brief check validity of handle
-  ///
-  /// check, whether the residue handle points to a valid residue.
-  /// \note It is an error to use any method other than #IsValid, #Impl and
-  ///       #operator bool() when the handle is invalid. An InvalidHandle
-  ///       exception will be thrown.
-  operator bool() const { return this->IsValid(); }
-  /// \brief check validity of handle
-  /// \sa #operator bool()
-  bool IsValid() const { return Impl().get()!=0; }
   //@}
   ResidueHandle(const impl::ResidueImplPtr& impl)
     : ResidueBase(impl) {}
diff --git a/modules/mol/base/tests/CMakeLists.txt b/modules/mol/base/tests/CMakeLists.txt
index 7d57b01e3..b29f1128e 100644
--- a/modules/mol/base/tests/CMakeLists.txt
+++ b/modules/mol/base/tests/CMakeLists.txt
@@ -8,6 +8,7 @@ set(OST_MOL_BASE_UNIT_TESTS
   test_ics.cc
   test_iterators.cc
   test_query.cc
+  test_surface.cc
   test_residue.cc
   test_view.cc
   test_view_op.cc
diff --git a/modules/mol/base/tests/test_chain.cc b/modules/mol/base/tests/test_chain.cc
index 2e42ea771..f43b9f2ff 100644
--- a/modules/mol/base/tests/test_chain.cc
+++ b/modules/mol/base/tests/test_chain.cc
@@ -86,6 +86,29 @@ BOOST_AUTO_TEST_CASE(test_comparison)
 }
 
 
+BOOST_AUTO_TEST_CASE(throw_invalid_chain_handle)
+{
+  EntityHandle ent=CreateEntity();
+  ChainHandle chain=ent.FindChain("A");
+  BOOST_CHECK_THROW(CheckHandleValidity(chain), InvalidHandle);
+  XCSEditor edi=ent.EditXCS();
+  edi.InsertChain("A");
+  chain=ent.FindChain("A");
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(chain));
+}
+
+BOOST_AUTO_TEST_CASE(throw_invalid_chain_view)
+{
+  EntityHandle ent=CreateEntity();
+  ChainHandle chain=ent.FindChain("A");
+  ChainView chain_view;
+  BOOST_CHECK_THROW(CheckHandleValidity(chain_view), InvalidHandle);
+  XCSEditor edi=ent.EditXCS();
+  edi.InsertChain("A");
+  EntityView ent_view=ent.CreateFullView();  
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(ent_view.FindChain("A")));
+}
+
 BOOST_AUTO_TEST_CASE(res_pos) 
 {
   EntityHandle eh=CreateEntity();
diff --git a/modules/mol/base/tests/test_entity.cc b/modules/mol/base/tests/test_entity.cc
index ac262c406..f4fb9ca01 100644
--- a/modules/mol/base/tests/test_entity.cc
+++ b/modules/mol/base/tests/test_entity.cc
@@ -75,12 +75,29 @@ EntityHandle make_test_entity()
   res2.SetChemClass(ChemClass(ChemClass::LPeptideLinking));  
   e.AddTorsion("PHI", res1.FindAtom("C"), res2.FindAtom("N"), 
                res2.FindAtom("CA"), res2.FindAtom("C"));
-               
   return eh;
 }
 
 BOOST_AUTO_TEST_SUITE( mol_base )
 
+
+BOOST_AUTO_TEST_CASE(throw_invalid_ent_handle)
+{
+  EntityHandle ent;
+  BOOST_CHECK_THROW(CheckHandleValidity(ent), InvalidHandle);  
+  ent=CreateEntity();
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(ent));
+}
+
+BOOST_AUTO_TEST_CASE(throw_invalid_ent_view)
+{
+  EntityView ent_view;
+  BOOST_CHECK_THROW(CheckHandleValidity(ent_view), InvalidHandle);  
+  EntityHandle ent=CreateEntity();
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(ent.CreateFullView()));
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(ent.CreateEmptyView()));
+}
+
 BOOST_AUTO_TEST_CASE(entity_creator) 
 {
   EntityHandle eh = CreateEntity();
diff --git a/modules/mol/base/tests/test_residue.cc b/modules/mol/base/tests/test_residue.cc
index d6cc11f4a..f622f72a5 100644
--- a/modules/mol/base/tests/test_residue.cc
+++ b/modules/mol/base/tests/test_residue.cc
@@ -45,6 +45,34 @@ BOOST_AUTO_TEST_CASE(test_in_sequence)
   BOOST_CHECK(!InSequence(rA,rC));
 }
 
+
+BOOST_AUTO_TEST_CASE(throw_invalid_res_handle)
+{
+  ChainHandle chain;
+  EntityHandle ent=CreateEntity();
+  XCSEditor edi=ent.EditXCS();
+  chain=edi.InsertChain("A");
+  ResidueHandle res=chain.FindResidue(ResNum(1));
+  BOOST_CHECK_THROW(CheckHandleValidity(res), InvalidHandle);
+  edi.AppendResidue(chain, "GLY");
+  res=chain.FindResidue(ResNum(1));
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(res));
+}
+
+BOOST_AUTO_TEST_CASE(throw_invalid_res_view)
+{
+  ChainHandle chain;
+  EntityHandle ent=CreateEntity();
+  XCSEditor edi=ent.EditXCS();
+  chain=edi.InsertChain("A");
+  ResidueView res;
+  BOOST_CHECK_THROW(CheckHandleValidity(res), InvalidHandle);
+  edi.AppendResidue(chain, "GLY");
+  EntityView ent_view=ent.CreateFullView();
+  res=ent_view.FindChain("A").FindResidue(1);
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(res));
+}
+
 BOOST_AUTO_TEST_CASE(test_res_index)
 {
   EntityHandle eh=CreateEntity();
diff --git a/modules/mol/base/tests/test_surface.cc b/modules/mol/base/tests/test_surface.cc
new file mode 100644
index 000000000..6e30dcd07
--- /dev/null
+++ b/modules/mol/base/tests/test_surface.cc
@@ -0,0 +1,40 @@
+//------------------------------------------------------------------------------
+// This file is part of the OpenStructure project <www.openstructure.org>
+//
+// Copyright (C) 2008-2010 by the OpenStructure authors
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License as published by the Free
+// Software Foundation; either version 3.0 of the License, or (at your option)
+// any later version.
+// This library is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+// details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with this library; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+//------------------------------------------------------------------------------
+ 
+#include <ost/mol/surface_handle.hh>
+#include <cmath>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
+
+using namespace ost;
+using namespace ost::mol;
+
+BOOST_AUTO_TEST_SUITE( mol_base )
+
+
+BOOST_AUTO_TEST_CASE(test_throw_invalid_surface)
+{
+  SurfaceHandle surf;
+  BOOST_CHECK_THROW(CheckHandleValidity(surf), InvalidHandle);
+  
+  surf=CreateSurface();
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(surf));
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/modules/seq/base/tests/test_alignment.cc b/modules/seq/base/tests/test_alignment.cc
index 516c966a4..b4ee98a40 100644
--- a/modules/seq/base/tests/test_alignment.cc
+++ b/modules/seq/base/tests/test_alignment.cc
@@ -74,6 +74,15 @@ BOOST_AUTO_TEST_CASE(alignment_triv)
   BOOST_CHECK_NO_THROW(AlignmentFromSequenceList(list));
 }
 
+BOOST_AUTO_TEST_CASE(aln_throw_invalid)
+{
+  AlignmentHandle s;
+  BOOST_CHECK_THROW(CheckHandleValidity(s), InvalidHandle);
+  s=CreateAlignment();
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(s));
+}
+
+
 BOOST_AUTO_TEST_CASE(alignment_count_and_length)
 {
   AlignmentHandle a = CreateAlignment();
diff --git a/modules/seq/base/tests/test_sequence.cc b/modules/seq/base/tests/test_sequence.cc
index 264a902ea..d628e14dd 100644
--- a/modules/seq/base/tests/test_sequence.cc
+++ b/modules/seq/base/tests/test_sequence.cc
@@ -65,6 +65,14 @@ BOOST_AUTO_TEST_CASE(seq_triv)
   BOOST_CHECK_THROW(s.SetString("1"), InvalidSequence);
 }
 
+BOOST_AUTO_TEST_CASE(seq_throw_invalid)
+{
+  SequenceHandle s;
+  BOOST_CHECK_THROW(CheckHandleValidity(s), InvalidHandle);
+  s=CreateSequence("A", "abcd");
+  BOOST_CHECK_NO_THROW(CheckHandleValidity(s));
+}
+
 BOOST_AUTO_TEST_CASE(seq_length)
 {
   SequenceHandle s=CreateSequence("S1", "abfcdadeaf");
-- 
GitLab