diff --git a/src/rdb/rdb/rdbRVEReader.cc b/src/rdb/rdb/rdbRVEReader.cc index 2bcdff3cc..14e3139af 100644 --- a/src/rdb/rdb/rdbRVEReader.cc +++ b/src/rdb/rdb/rdbRVEReader.cc @@ -83,7 +83,7 @@ public: std::vector points; std::vector edges; - ex = tl::Extractor (m_input_stream.get_line ().c_str ()); + ex = tl::Extractor (get_line ().c_str ()); ex.read (s, " "); ex.read (res); @@ -99,7 +99,7 @@ public: std::string cat_name; id_type waived_tag_id = db.tags ().tag ("waived").id (); - while (! m_input_stream.at_end ()) { + while (! at_end ()) { // TODO: check if this is correct: when a new category is started the // cell name is reset. Any shape not having a specific cell will go into the @@ -108,7 +108,7 @@ public: // Read the category name unless we have some already (that we got when parsing the shapes). if (cat_name.empty ()) { - ex = tl::Extractor (m_input_stream.get_line ().c_str ()); + ex = tl::Extractor (get_line ().c_str ()); const char *start = ex.skip (); if (! *start) { break; @@ -127,11 +127,11 @@ public: Category *cath = db.create_category (cat_name); cat_name.clear (); - if (m_input_stream.at_end ()) { + if (at_end ()) { error (tl::to_string (tr ("Unexpected end of file"))); } - ex = tl::Extractor (m_input_stream.get_line ().c_str ()); + ex = tl::Extractor (get_line ().c_str ()); size_t n1, n2, n3; ex.read (n1); ex.read (n2); @@ -142,11 +142,11 @@ public: std::string desc; for (size_t i = 0; i < n3; ++i) { - if (m_input_stream.at_end ()) { + if (at_end ()) { error (tl::to_string (tr ("Unexpected end of file"))); } - std::string l = m_input_stream.get_line (); + std::string l = get_line (); if (l.size () > 3 && l[0] == 'W' && l[1] == 'E' && isdigit (l[2])) { size_t n = 0; @@ -178,12 +178,12 @@ public: bool waived = (w != waivers.end ()); // TODO: add waiver string somehow ... - if (m_input_stream.at_end ()) { + if (at_end ()) { warn (tl::to_string (tr ("Unexpected end of file before the specified number of shapes was read - stopping."))); break; } - s = m_input_stream.get_line (); + s = get_line (); ex = tl::Extractor (s.c_str ()); @@ -221,11 +221,11 @@ public: while (true) { - if (m_input_stream.at_end ()) { + if (at_end ()) { error (tl::to_string (tr ("Unexpected end of file"))); } - ex = tl::Extractor (m_input_stream.get_line ().c_str ()); + ex = tl::Extractor (get_line ().c_str ()); char c = *ex.skip (); if (isalpha (c)) { @@ -340,11 +340,11 @@ public: if (point > 0) { - if (m_input_stream.at_end ()) { + if (at_end ()) { error (tl::to_string (tr ("Unexpected end of file"))); } - ex = tl::Extractor (m_input_stream.get_line ().c_str ()); + ex = tl::Extractor (get_line ().c_str ()); } @@ -368,11 +368,11 @@ public: if (point > 0) { - if (m_input_stream.at_end ()) { + if (at_end ()) { error (tl::to_string (tr ("Unexpected end of file"))); } - ex = tl::Extractor (m_input_stream.get_line ().c_str ()); + ex = tl::Extractor (get_line ().c_str ()); } @@ -424,6 +424,26 @@ public: private: tl::TextInputStream m_input_stream; tl::AbsoluteProgress m_progress; + std::string m_line; + + bool at_end () + { + return m_input_stream.at_end (); + } + + const std::string &get_line () + { + m_line.clear (); + while (! m_input_stream.at_end ()) { + m_line = m_input_stream.get_line (); + // skip lines starting with "//" (#522) + if (m_line.size () < 2 || m_line[0] != '/' || m_line[1] != '/') { + break; + } + m_line.clear (); + } + return m_line; + } void warn (const std::string &msg) { diff --git a/src/rdb/unit_tests/rdb.cc b/src/rdb/unit_tests/rdb.cc index d4ba26c0a..106f74874 100644 --- a/src/rdb/unit_tests/rdb.cc +++ b/src/rdb/unit_tests/rdb.cc @@ -20,8 +20,6 @@ */ - - #include "rdb.h" #include "tlUnitTest.h" #include "dbBox.h" diff --git a/src/rdb/unit_tests/rdbRVEReaderTests.cc b/src/rdb/unit_tests/rdbRVEReaderTests.cc new file mode 100644 index 000000000..110398787 --- /dev/null +++ b/src/rdb/unit_tests/rdbRVEReaderTests.cc @@ -0,0 +1,78 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2020 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "rdb.h" +#include "rdbReader.h" +#include "tlUnitTest.h" +#include "tlFileUtils.h" +#include "tlLog.h" + +void run_rve_test (tl::TestBase *_this, const std::string &fn_rve, const std::string &fn_au) +{ + rdb::Database db; + + { + tl::InputFile input (tl::testsrc_private () + "/testdata/rve/" + fn_rve); + tl::InputStream is (input); + rdb::Reader reader (is); + reader.read (db); + } + + std::string tmp = _this->tmp_file (); + db.save (tmp); + + std::string au_path = tl::absolute_file_path (tl::testsrc_private () + "/testdata/rve/" + fn_au); + + std::string txt, au_txt; + + try { + tl::InputFile input (au_path); + tl::InputStream is (input); + tl::TextInputStream ts (is); + au_txt = ts.read_all (); + } catch (tl::Exception &ex) { + tl::error << ex.msg (); + } + + { + tl::InputFile input (tmp); + tl::InputStream is (input); + tl::TextInputStream ts (is); + txt = ts.read_all (); + } + + if (au_txt != txt) { + tl::error << "Golden and actual data differs:"; + tl::error << " cp " << tmp << " " << au_path; + } + EXPECT_EQ (au_txt == txt, true); +} + +TEST(1) +{ + run_rve_test (_this, "rve1.db", "rve1_au.txt"); +} + +TEST(2) +{ + run_rve_test (_this, "rve2.db", "rve2_au.txt"); +} diff --git a/src/rdb/unit_tests/unit_tests.pro b/src/rdb/unit_tests/unit_tests.pro index 2453bc017..ed51891c5 100644 --- a/src/rdb/unit_tests/unit_tests.pro +++ b/src/rdb/unit_tests/unit_tests.pro @@ -8,6 +8,7 @@ include($$PWD/../../lib_ut.pri) SOURCES = \ rdb.cc \ + rdbRVEReaderTests.cc INCLUDEPATH += $$RDB_INC $$TL_INC $$DB_INC $$GSI_INC DEPENDPATH += $$RDB_INC $$TL_INC $$DB_INC $$GSI_INC