diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index 8b8639f57..df342e21f 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -295,7 +295,7 @@ public: LibraryController::LibFileInfo fi; fi.name = name; - fi.path = lf; + fi.path = tl::is_absolute (lf) ? lf : tl::combine_path (tl::absolute_path (mp_fc->lib_file), lf); if (! mp_fc->tech.empty ()) { fi.tech.insert (mp_fc->tech); } @@ -315,7 +315,10 @@ public: } else if (k->first == technology_key) { fi.tech.clear (); - fi.tech.insert (k->second.to_string ()); + std::string tn = k->second.to_string (); + if (! tn.empty () && tn != "*") { + fi.tech.insert (tn); + } } else if (k->first == technologies_key) { @@ -375,11 +378,8 @@ do_read_lib_file (LibFileFunctionContext &fc) { tl::Eval eval; - DefineFunction define_function (&fc); - IncludeFunction include_function (&fc); - - eval.define_function ("define", &define_function); - eval.define_function ("include", &include_function); + eval.define_function ("define", new DefineFunction (&fc)); + eval.define_function ("include", new IncludeFunction (&fc)); eval.set_var ("file", fc.lib_file); eval.set_var ("tech", fc.tech); diff --git a/src/lay/lay/layLibraryController.h b/src/lay/lay/layLibraryController.h index 6050fa198..c7970c5a4 100644 --- a/src/lay/lay/layLibraryController.h +++ b/src/lay/lay/layLibraryController.h @@ -51,7 +51,7 @@ class MainWindow; * By making the controller a PluginDeclaration it will receive * initialization and configuration calls. */ -class LibraryController +class LAY_PUBLIC LibraryController : public lay::PluginDeclaration, public tl::Object { Q_OBJECT @@ -116,6 +116,11 @@ public: */ static LibraryController *instance (); + /** + * @brief Provided for test purposes + */ + static void read_lib_file (const std::string &lib_file, const std::string &tech, std::vector &file_info); + private slots: /** * @brief Called when the file watcher detects a change in the file system @@ -142,7 +147,6 @@ private: void sync_files (); void read_libs (const std::vector &file_info, std::map &new_lib_files); - void read_lib_file (const std::string &lib_file, const std::string &tech, std::vector &file_info); }; } diff --git a/src/lay/unit_tests/layLibraryControllerTests.cc b/src/lay/unit_tests/layLibraryControllerTests.cc new file mode 100644 index 000000000..b5785dcfa --- /dev/null +++ b/src/lay/unit_tests/layLibraryControllerTests.cc @@ -0,0 +1,76 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2026 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 "layLibraryController.h" +#include "tlUnitTest.h" +#include "tlFileUtils.h" + +TEST (1) +{ + std::string lib_file = tl::testdata () + "/lay/a.libdef"; + + std::vector file_info; + lay::LibraryController::read_lib_file (lib_file, "T1", file_info); + + tl_assert (file_info.size () == size_t (3)); + + EXPECT_EQ (file_info[0].name, ""); + EXPECT_EQ (file_info[0].path, tl::combine_path (tl::absolute_path (lib_file), "noname.gds")); + EXPECT_EQ (file_info[0].replicate, true); + EXPECT_EQ (tl::join (file_info[0].tech.begin (), file_info[0].tech.end (), ","), "T1"); + + EXPECT_EQ (file_info[1].name, "L2"); + EXPECT_EQ (file_info[1].path, tl::absolute_file_path (lib_file) + ".zzz"); + EXPECT_EQ (file_info[1].replicate, true); + EXPECT_EQ (file_info[1].tech.size (), size_t (0)); + + EXPECT_EQ (file_info[2].name, "L3"); + EXPECT_EQ (file_info[2].path, tl::combine_path (tl::absolute_path (lib_file), "subdir/l3.gds")); + EXPECT_EQ (file_info[2].replicate, false); + EXPECT_EQ (tl::join (file_info[2].tech.begin (), file_info[2].tech.end (), ","), "T2,T3"); +} + +TEST(2) +{ + std::string lib_file = tl::testdata () + "/lay/b.libdef"; + + std::vector file_info; + lay::LibraryController::read_lib_file (lib_file, "TX", file_info); + + tl_assert (file_info.size () == size_t (5)); + + EXPECT_EQ (file_info[0].name, "L0"); + EXPECT_EQ (file_info[0].path, tl::combine_path (tl::absolute_path (lib_file), "l0.gds")); + EXPECT_EQ (file_info[0].replicate, true); + EXPECT_EQ (file_info[0].tech.size (), size_t (0)); + + EXPECT_EQ (file_info[1].name, ""); + EXPECT_EQ (file_info[1].path, tl::combine_path (tl::absolute_path (lib_file), "noname.gds")); + EXPECT_EQ (file_info[1].replicate, true); + EXPECT_EQ (tl::join (file_info[1].tech.begin (), file_info[1].tech.end (), ","), "TX"); + + EXPECT_EQ (file_info[4].name, "L4"); + EXPECT_EQ (file_info[4].path, tl::combine_path (tl::absolute_path (lib_file), "l4.gds")); + EXPECT_EQ (file_info[4].replicate, true); + EXPECT_EQ (tl::join (file_info[4].tech.begin (), file_info[4].tech.end (), ","), "TX"); +} diff --git a/src/lay/unit_tests/unit_tests.pro b/src/lay/unit_tests/unit_tests.pro index adf955966..b701fe4c1 100644 --- a/src/lay/unit_tests/unit_tests.pro +++ b/src/lay/unit_tests/unit_tests.pro @@ -7,6 +7,7 @@ TARGET = lay_tests include($$PWD/../../lib_ut.pri) SOURCES = \ + layLibraryControllerTests.cc \ laySalt.cc \ layHelpIndexTest.cc \ laySaltParsedURLTests.cc \ diff --git a/testdata/lay/a.libdef b/testdata/lay/a.libdef new file mode 100644 index 000000000..ff4bc56af --- /dev/null +++ b/testdata/lay/a.libdef @@ -0,0 +1,6 @@ + +# A comment +define("noname.gds"); +define("L2", file + ".zzz", technology = ""); +define("L3", "subdir/l3.gds", technologies = [ "T2", "T3" ], replicate = false); + diff --git a/testdata/lay/b.libdef b/testdata/lay/b.libdef new file mode 100644 index 000000000..eadaf2604 --- /dev/null +++ b/testdata/lay/b.libdef @@ -0,0 +1,10 @@ + +define("L0", "l0.gds", technology = "*"); + +# relative to this file +include("../lay/a.libdef"); + +var n4 = "L4"; +var f4 = "l4.gds"; +define(n4, f4); +