File: main.rb

package info (click to toggle)
klayout 0.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292,204 kB
  • sloc: cpp: 2,068,428; ruby: 47,823; xml: 26,924; python: 14,404; sh: 1,812; tcl: 212; perl: 170; makefile: 112; ansic: 42
file content (216 lines) | stat: -rw-r--r-- 7,458 bytes parent folder | download
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# 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")

# Tests for the klayout executable
#
# This tests actually runs inside a KLayout/unit_tests instance but 
# only for providing the test automation.

class KLayoutMain_TestClass < TestBase

  def setup
    @klayout_home_name = "KLAYOUT_HOME"
    @klayout_home = ENV[@klayout_home_name]
    # setting "KLAYOUT_HOME" to empty means we don't search any place
    # for macros
    ENV[@klayout_home_name] = ""
  end

  def teardown
    ENV[@klayout_home_name] = @klayout_home
  end

  def klayout_bin
    # special location for MacOS
    file = File.join(RBA::Application::instance.inst_path, "klayout.app", "Contents", "MacOS", "klayout")
    if !File.exist?(file)
      file = File.join(RBA::Application::instance.inst_path, "klayout")
    end
    return file
  end

  def test_1

    # Basic
    version = `#{self.klayout_bin} -v 2>&1`
    assert_equal(version, "#{RBA::Application.instance.version}\n")

  end

  def test_2

    # Basic Ruby
    out = `#{self.klayout_bin} -b -rd v1=42 -rd v2=hello -r #{File.join(File.dirname(__FILE__), "test.rb")} 2>&1`
    assert_equal(out, "Variable v1=42 v2=hello\n")

    out = `#{self.klayout_bin} -b -rd v1=42 -rd v2=hello -r #{File.join(File.dirname(__FILE__), "test.rb")} -rm #{File.join(File.dirname(__FILE__), "test2.rb")} -rm #{File.join(File.dirname(__FILE__), "test3.rb")} 2>&1`
    assert_equal(out, "test2\ntest3\nVariable v1=42 v2=hello\n")

  end

  def test_3

    # Basic Python
    out = `#{self.klayout_bin} -b -rd v1=42 -rd v2=hello -r #{File.join(File.dirname(__FILE__), "test.py")} 2>&1`
    assert_equal(out, "Variable v1=42 v2=hello\n")

  end

  def test_4

    # Application class
    if !RBA.constants.find { |x| x == :QDialog || x == "QDialog" }

      out = `#{self.klayout_bin} -b -r #{File.join(File.dirname(__FILE__), "test_app.rb")} 2>&1`
      assert_equal(out, "RBA::Application superclass Object\nMainWindow is not there\n")

      out = `#{self.klayout_bin} -z -nc -rx -r #{File.join(File.dirname(__FILE__), "test_app.rb")} 2>&1`
      assert_equal(out, "RBA::Application superclass Object\nMainWindow is there\n")

    else
 
      # QCoreApplication for (headless) mode
      out = `#{self.klayout_bin} -b -r #{File.join(File.dirname(__FILE__), "test_app.rb")} 2>&1`
      assert_equal(out, "RBA::Application superclass RBA::QCoreApplication_Native\nMainWindow is not there\n")

      # QApplication for GUI mode
      out = `#{self.klayout_bin} -z -nc -rx -r #{File.join(File.dirname(__FILE__), "test_app.rb")} 2>&1`
      assert_equal(out, "RBA::Application superclass RBA::QApplication_Native\nMainWindow is there\n")

    end

  end

  def test_5

    # Script variables
    out = `#{self.klayout_bin} -b -wd tv1=17 -wd tv2=25 -wd tv3 -r #{File.join(File.dirname(__FILE__), "test_script.rb")} 2>&1`
    assert_equal(out, "42\ntrue\n")

  end

  def test_6

    # Editable / Non-editable mode
    out = `#{self.klayout_bin} -b -ne -r #{File.join(File.dirname(__FILE__), "test_em.rb")} 2>&1`
    assert_equal(out, "false\n")

    out = `#{self.klayout_bin} -b -e -r #{File.join(File.dirname(__FILE__), "test_em.rb")} 2>&1`
    assert_equal(out, "true\n")

  end

  def test_7

    cfg_file = File.join($ut_testtmp, "config.xml")
    File.open(cfg_file, "w") { |file| file.puts("<config/>") }

    # Special configuration file
    `#{self.klayout_bin} -b -c #{cfg_file} -r #{File.join(File.dirname(__FILE__), "test_set_config1.rb")} 2>&1`

    out = `#{self.klayout_bin} -b -c #{cfg_file} -r #{File.join(File.dirname(__FILE__), "test_read_config.rb")} 2>&1`
    assert_equal(out, "42\n")

    # Update
    `#{self.klayout_bin} -b -c #{cfg_file} -r #{File.join(File.dirname(__FILE__), "test_set_config2.rb")} 2>&1`

    out = `#{self.klayout_bin} -b -c #{cfg_file} -r #{File.join(File.dirname(__FILE__), "test_read_config.rb")} 2>&1`
    assert_equal(out, "17\n")

    # Reset
    `#{self.klayout_bin} -b -c #{cfg_file} -r #{File.join(File.dirname(__FILE__), "test_set_config1.rb")} 2>&1`

    out = `#{self.klayout_bin} -b -c #{cfg_file} -r #{File.join(File.dirname(__FILE__), "test_read_config.rb")} 2>&1`
    assert_equal(out, "42\n")

    # No update
    `#{self.klayout_bin} -b -t -c #{cfg_file} -r #{File.join(File.dirname(__FILE__), "test_set_config2.rb")} 2>&1`

    out = `#{self.klayout_bin} -b -c #{cfg_file} -r #{File.join(File.dirname(__FILE__), "test_read_config.rb")} 2>&1`
    assert_equal(out, "42\n")

  end

  def test_8

    # Loading layouts
    out = `#{self.klayout_bin} -z -nc -rx #{File.join(File.dirname(__FILE__), "test1.gds")} -r #{File.join(File.dirname(__FILE__), "test_lay.rb")} 2>&1`
    assert_equal(out, "TOP1\n")

    out = `#{self.klayout_bin} -z -nc -rx #{File.join(File.dirname(__FILE__), "test1.gds")} #{File.join(File.dirname(__FILE__), "test2.gds")} -r #{File.join(File.dirname(__FILE__), "test_lay2.rb")} 2>&1`
    assert_equal(out, "TOP1\nTOP2\n")

    out = `#{self.klayout_bin} -z -nc -rx #{File.join(File.dirname(__FILE__), "test1.gds")} #{File.join(File.dirname(__FILE__), "test2.gds")} -s -r #{File.join(File.dirname(__FILE__), "test_lay2.rb")} 2>&1`
    assert_equal(out, "TOP1;TOP2\n")

  end

  def test_9

    # Sessions
    out = `#{self.klayout_bin} -z -nc -rx -u #{File.join(File.dirname(__FILE__), "session.lys")} -r #{File.join(File.dirname(__FILE__), "test_lay2.rb")} 2>&1`
    assert_equal(out, "TOP2;TOP1\n")

  end

  def test_10

    # Headless LayoutView
    out = `#{self.klayout_bin} -b -rd input=#{File.join(File.dirname(__FILE__), "test1.gds")} -r #{File.join(File.dirname(__FILE__), "test10.rb")} 2>&1`
    assert_equal(out, "(0,0;8,8)\n")

  end

  def test_11

    # Headless LayoutView (GUI enabled)
    out = `#{self.klayout_bin} -z -rd input=#{File.join(File.dirname(__FILE__), "test1.gds")} -r #{File.join(File.dirname(__FILE__), "test10.rb")} 2>&1`
    assert_equal(out, "(0,0;8,8)\n")

  end

  def test_12

    # Application.exit(0) - Python
    out = `#{self.klayout_bin} -z -r #{File.join(File.dirname(__FILE__), "test12.py")} 2>&1`
    assert_equal(out, "Before exit()\n")

    # Application.exit(0) - Ruby
    out = `#{self.klayout_bin} -z -r #{File.join(File.dirname(__FILE__), "test12.rb")} 2>&1`
    assert_equal(out, "Before exit()\n")

    # sys.exit(0) - Python
    out = `#{self.klayout_bin} -z -r #{File.join(File.dirname(__FILE__), "test12s.py")} 2>&1`
    assert_equal(out, "Before exit()\n")

    # quit() - Python (issue #1565)
    out = `#{self.klayout_bin} -z -r #{File.join(File.dirname(__FILE__), "test12q.py")} 2>&1`
    assert_equal(out, "Before quit()\n")

  end

end

load("test_epilogue.rb")