1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
# encoding: UTF-8
# KLayout Layout Viewer
# Copyright (C) 2006-2025 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
if !$:.member?(File::dirname($0))
$:.push(File::dirname($0))
end
load("test_prologue.rb")
class DBLayoutQuery_TestClass < TestBase
def test_1
ly = RBA::Layout::new
ly.read(ENV["TESTSRC"] + "/testdata/gds/t11.gds")
q = RBA::LayoutQuery::new("select cell.name, cell.bbox from *")
res = []
q.each(ly) do |iter|
res << iter.data.map(&:to_s).join(", ")
end
assert_equal(res.size, 2)
assert_equal(res[0], "TOPTOP, (0,0;32800,12800)")
assert_equal(res[1], "TOP, (0,0;900,900)")
end
def test_2
ly = RBA::Layout::new
ly.read(ENV["TESTSRC"] + "/testdata/gds/t11.gds")
q = RBA::LayoutQuery::new("delete TOP")
q.execute(ly)
q = RBA::LayoutQuery::new("select cell.name, cell.bbox from *")
res = []
q.each(ly) do |iter|
res << iter.data.map(&:to_s).join(", ")
end
assert_equal(res.size, 1)
assert_equal(res[0], "TOPTOP, ()")
end
def test_3
q = RBA::LayoutQuery::new("delete TOP")
assert_equal(q.property_names.sort.join(","), "bbox,cell,cell_bbox,cell_dbbox,cell_index,cell_name,dbbox,hier_levels,initial_cell,initial_cell_index,initial_cell_name,inst,instances,path,path_dtrans,path_names,path_trans,references,shape,tot_weight,weight")
end
# variables
def test_4
ly = RBA::Layout::new
ly.read(ENV["TESTSRC"] + "/testdata/gds/t11.gds")
ctx = RBA::ExpressionContext::new
ctx.var("suffix", "!")
ctx.var("all", [])
ctx.var("nonmod", "")
q = RBA::LayoutQuery::new("select cell.name + suffix from *")
res = []
q.each(ly, ctx) do |iter|
res << iter.data.inspect
end
assert_equal(res.size, 2)
assert_equal(res[0], "[\"TOPTOP!\"]")
assert_equal(res[1], "[\"TOP!\"]")
q = RBA::LayoutQuery::new("with * do var nonmod = cell.name; all.push(nonmod)")
q.execute(ly, ctx)
assert_equal(ctx.eval("all").join(","), "TOPTOP,TOP")
# not modified, because we used "var nonmod" in the query which
# creates a local variable:
assert_equal(ctx.eval("nonmod"), "")
end
end
load("test_epilogue.rb")
|