From 7c592358895044e03c0797fd0d36f9a1dda2ef5d Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 10 Aug 2017 01:53:35 +0200 Subject: [PATCH] Fixed a potential issue when using the db::Shape edge iterator on a non-existing hull in SimplePolygon. --- scripts/deploy-win-mingw.sh | 3 +- src/db/dbShape.h | 56 +++++++++++++++++++++++++++++++--- src/unit_tests/dbBoxScanner.cc | 16 +++++----- src/unit_tests/dbEdges.cc | 22 ++++++------- 4 files changed, 71 insertions(+), 26 deletions(-) diff --git a/scripts/deploy-win-mingw.sh b/scripts/deploy-win-mingw.sh index 3127b4fe1..329221a42 100644 --- a/scripts/deploy-win-mingw.sh +++ b/scripts/deploy-win-mingw.sh @@ -194,7 +194,8 @@ done # Run Tests set +e -TESTSRC=. TESTTMP=$build/testtmp $target/ut_runner -a >$build/ut_runner.xml +echo "Running unit tests .." +TESTSRC=. TESTTMP=$build/testtmp $target/ut_runner -a | tee $build/ut_runner.xml set -e # ---------------------------------------------------------- diff --git a/src/db/dbShape.h b/src/db/dbShape.h index 0593f0dfa..41c23772d 100644 --- a/src/db/dbShape.h +++ b/src/db/dbShape.h @@ -200,53 +200,95 @@ private: iterator_type m_type; struct contour_f { + + unsigned int operator() () const + { + return 0; + } + template unsigned int operator() (const Iter &iter) const { return iter.contour (); } + }; struct at_end_f { + + bool operator() () const + { + return true; + } + template bool operator() (const Iter &iter) const { return iter.at_end (); } + }; struct inc_f { + + bool operator() () const + { + return false; + } + template bool operator() (Iter &iter) const { iter.operator++ (); return false; - } + } + }; struct dec_f { + + bool operator() () const + { + return false; + } + template bool operator() (Iter &iter) const { iter.operator-- (); return false; } + }; struct deref_f { + + edge_type operator() () const + { + return edge_type (); + } + template edge_type operator() (const Iter &iter) const { return iter.operator* (); - } + } + }; struct at_begin_f { + + bool operator() () const + { + return true; + } + template bool operator() (const Iter &iter) const { return iter.at_begin (); - } + } + }; template @@ -259,8 +301,10 @@ private: return f (*((const polygon_ref_edge_iterator_type *) m_d.iter)); } else if (m_type == SimplePolygon) { return f (*((const simple_polygon_edge_iterator_type *) m_d.iter)); - } else { + } else if (m_type == SimplePolygonRef) { return f (*((const simple_polygon_ref_edge_iterator_type *) m_d.iter)); + } else { + return f (); } } @@ -274,8 +318,10 @@ private: return f (*((polygon_ref_edge_iterator_type *) m_d.iter)); } else if (m_type == SimplePolygon) { return f (*((simple_polygon_edge_iterator_type *) m_d.iter)); - } else { + } else if (m_type == SimplePolygonRef) { return f (*((simple_polygon_ref_edge_iterator_type *) m_d.iter)); + } else { + return f (); } } }; diff --git a/src/unit_tests/dbBoxScanner.cc b/src/unit_tests/dbBoxScanner.cc index 675b359fb..35604d1fa 100644 --- a/src/unit_tests/dbBoxScanner.cc +++ b/src/unit_tests/dbBoxScanner.cc @@ -233,16 +233,16 @@ void run_test2 (ut::TestBase *_this, size_t n, double ff, db::Coord spread, bool } if (interactions != tr.interactions) { - std::cerr << "Interactions in 'brute force' but not in 'box-scanner':" << std::endl; + tl::info << "Interactions in 'brute force' but not in 'box-scanner':"; for (std::set >::const_iterator i = interactions.begin (); i != interactions.end (); ++i) { if (tr.interactions.find (*i) == tr.interactions.end ()) { - std::cerr << " " << i->first << "-" << i->second << std::endl; + tl::info << " " << i->first << "-" << i->second; } } - std::cerr << "Interactions in 'box-scanner' but not in 'brute force':" << std::endl; + tl::info << "Interactions in 'box-scanner' but not in 'brute force':"; for (std::set >::const_iterator i = tr.interactions.begin (); i != tr.interactions.end (); ++i) { if (interactions.find (*i) == interactions.end ()) { - std::cerr << " " << i->first << "-" << i->second << std::endl; + tl::info << " " << i->first << "-" << i->second; } } } @@ -528,16 +528,16 @@ void run_test11 (ut::TestBase *_this, size_t n, double ff, db::Coord spread, boo } if (clusters != bf_clusters) { - std::cerr << "Clusters in 'brute force' but not in 'box-scanner':" << std::endl; + tl::info << "Clusters in 'brute force' but not in 'box-scanner':"; for (std::set >::const_iterator i = bf_clusters.begin (); i != bf_clusters.end (); ++i) { if (clusters.find (*i) == clusters.end ()) { - std::cerr << " " << c2s (*i) << std::endl; + tl::info << " " << c2s (*i); } } - std::cerr << "Clusters in 'box-scanner' but not in 'brute force':" << std::endl; + tl::info << "Clusters in 'box-scanner' but not in 'brute force':"; for (std::set >::const_iterator i = clusters.begin (); i != clusters.end (); ++i) { if (bf_clusters.find (*i) == bf_clusters.end ()) { - std::cerr << " " << c2s (*i) << std::endl; + tl::info << " " << c2s (*i); } } } diff --git a/src/unit_tests/dbEdges.cc b/src/unit_tests/dbEdges.cc index b3be1c4cd..26cab1982 100644 --- a/src/unit_tests/dbEdges.cc +++ b/src/unit_tests/dbEdges.cc @@ -404,7 +404,6 @@ TEST(9) ea.insert (*i); } - // std::cerr << "Interacting edges: " << ea.size () << std::endl; EXPECT_NE (ea.size (), size_t (0)); // brute force @@ -417,16 +416,16 @@ TEST(9) } if (ea != eb) { - std::cerr << "In implementation but not in brute-force:" << std::endl; + tl::info << "In implementation but not in brute-force:"; for (std::set::const_iterator i = ea.begin (); i != ea.end (); ++i) { if (eb.find (*i) == eb.end ()) { - std::cerr << " " << i->to_string () << std::endl; + tl::info << " " << i->to_string (); } } - std::cerr << "In brute-force but not in implementation:" << std::endl; + tl::info << "In brute-force but not in implementation:"; for (std::set::const_iterator i = eb.begin (); i != eb.end (); ++i) { if (ea.find (*i) == ea.end ()) { - std::cerr << " " << i->to_string () << std::endl; + tl::info << " " << i->to_string (); } } EXPECT_EQ (true, false); @@ -465,7 +464,6 @@ TEST(10) ea.insert (*i); } - // std::cerr << "Interacting edges: " << ea.size () << std::endl; EXPECT_NE (ea.size (), size_t (0)); // brute force @@ -479,20 +477,20 @@ TEST(10) } if (ea != eb) { - std::cerr << "Boxes:" << std::endl; + tl::info << "Boxes:"; for (db::Region::const_iterator j = r.begin (); ! j.at_end (); ++j) { - std::cerr << " " << j->to_string () << std::endl; + tl::info << " " << j->to_string (); } - std::cerr << "In implementation but not in brute-force:" << std::endl; + tl::info << "In implementation but not in brute-force:"; for (std::set::const_iterator i = ea.begin (); i != ea.end (); ++i) { if (eb.find (*i) == eb.end ()) { - std::cerr << " " << i->to_string () << std::endl; + tl::info << " " << i->to_string (); } } - std::cerr << "In brute-force but not in implementation:" << std::endl; + tl::info << "In brute-force but not in implementation:"; for (std::set::const_iterator i = eb.begin (); i != eb.end (); ++i) { if (ea.find (*i) == ea.end ()) { - std::cerr << " " << i->to_string () << std::endl; + tl::info << " " << i->to_string (); } } EXPECT_EQ (true, false);