mirror of https://github.com/KLayout/klayout.git
Added test for lib file reading
This commit is contained in:
parent
4908f51e1c
commit
56e84e7056
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<LibFileInfo> &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<LibFileInfo> &file_info, std::map<std::string, LibInfo> &new_lib_files);
|
||||
void read_lib_file (const std::string &lib_file, const std::string &tech, std::vector<LibFileInfo> &file_info);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<lay::LibraryController::LibFileInfo> 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<lay::LibraryController::LibFileInfo> 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");
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ TARGET = lay_tests
|
|||
include($$PWD/../../lib_ut.pri)
|
||||
|
||||
SOURCES = \
|
||||
layLibraryControllerTests.cc \
|
||||
laySalt.cc \
|
||||
layHelpIndexTest.cc \
|
||||
laySaltParsedURLTests.cc \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
# A comment
|
||||
define("noname.gds");
|
||||
define("L2", file + ".zzz", technology = "");
|
||||
define("L3", "subdir/l3.gds", technologies = [ "T2", "T3" ], replicate = false);
|
||||
|
||||
|
|
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue