wxruby3-shapes 0.9.0.pre.beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +12 -0
  3. data/CREDITS.md +18 -0
  4. data/INSTALL.md +39 -0
  5. data/LICENSE +21 -0
  6. data/README.md +118 -0
  7. data/assets/screenshot.png +0 -0
  8. data/bin/wx-shapes +9 -0
  9. data/lib/wx/shapes/arrow_base.rb +86 -0
  10. data/lib/wx/shapes/arrows/circle_arrow.rb +39 -0
  11. data/lib/wx/shapes/arrows/diamond_arrow.rb +33 -0
  12. data/lib/wx/shapes/arrows/open_arrow.rb +56 -0
  13. data/lib/wx/shapes/arrows/solid_arrow.rb +69 -0
  14. data/lib/wx/shapes/art/shape_canvas/page.xpm +73 -0
  15. data/lib/wx/shapes/auto_layout.rb +358 -0
  16. data/lib/wx/shapes/base.rb +33 -0
  17. data/lib/wx/shapes/canvas_history.rb +84 -0
  18. data/lib/wx/shapes/connection_point.rb +238 -0
  19. data/lib/wx/shapes/core.rb +19 -0
  20. data/lib/wx/shapes/diagram.rb +659 -0
  21. data/lib/wx/shapes/events.rb +389 -0
  22. data/lib/wx/shapes/printout.rb +136 -0
  23. data/lib/wx/shapes/serializable.rb +440 -0
  24. data/lib/wx/shapes/serialize/core.rb +40 -0
  25. data/lib/wx/shapes/serialize/id.rb +82 -0
  26. data/lib/wx/shapes/serialize/wx.rb +104 -0
  27. data/lib/wx/shapes/serializer/json.rb +258 -0
  28. data/lib/wx/shapes/serializer/yaml.rb +125 -0
  29. data/lib/wx/shapes/shape.rb +2129 -0
  30. data/lib/wx/shapes/shape_canvas.rb +3285 -0
  31. data/lib/wx/shapes/shape_data_object.rb +43 -0
  32. data/lib/wx/shapes/shape_handle.rb +287 -0
  33. data/lib/wx/shapes/shape_list.rb +161 -0
  34. data/lib/wx/shapes/shapes/bitmap_shape.rb +257 -0
  35. data/lib/wx/shapes/shapes/circle_shape.rb +136 -0
  36. data/lib/wx/shapes/shapes/control_shape.rb +483 -0
  37. data/lib/wx/shapes/shapes/curve_shape.rb +231 -0
  38. data/lib/wx/shapes/shapes/diamond_shape.rb +62 -0
  39. data/lib/wx/shapes/shapes/edit_text_shape.rb +317 -0
  40. data/lib/wx/shapes/shapes/ellipse_shape.rb +106 -0
  41. data/lib/wx/shapes/shapes/flex_grid_shape.rb +78 -0
  42. data/lib/wx/shapes/shapes/grid_shape.rb +404 -0
  43. data/lib/wx/shapes/shapes/line_shape.rb +907 -0
  44. data/lib/wx/shapes/shapes/multi_sel_rect.rb +214 -0
  45. data/lib/wx/shapes/shapes/ortho_shape.rb +357 -0
  46. data/lib/wx/shapes/shapes/polygon_shape.rb +294 -0
  47. data/lib/wx/shapes/shapes/rect_shape.rb +378 -0
  48. data/lib/wx/shapes/shapes/round_ortho_shape.rb +131 -0
  49. data/lib/wx/shapes/shapes/round_rect_shape.rb +142 -0
  50. data/lib/wx/shapes/shapes/square_shape.rb +119 -0
  51. data/lib/wx/shapes/shapes/text_shape.rb +324 -0
  52. data/lib/wx/shapes/thumbnail.rb +234 -0
  53. data/lib/wx/shapes/version.rb +12 -0
  54. data/lib/wx/shapes/wx.rb +29 -0
  55. data/lib/wx/shapes.rb +18 -0
  56. data/lib/wx/wx-shapes/base.rb +87 -0
  57. data/lib/wx/wx-shapes/cmd/sampler.rb +58 -0
  58. data/lib/wx/wx-shapes/cmd/test.rb +27 -0
  59. data/rakelib/yard/templates/default/fulldoc/html/css/wxruby3.css +7 -0
  60. data/rakelib/yard/templates/default/layout/html/setup.rb +5 -0
  61. data/rakelib/yard/yard/relative_markdown_links/version.rb +8 -0
  62. data/rakelib/yard/yard/relative_markdown_links.rb +39 -0
  63. data/rakelib/yard/yard-custom-templates.rb +2 -0
  64. data/rakelib/yard/yard-relative_markdown_links.rb +4 -0
  65. data/samples/demo/art/AlignBottom.xpm +35 -0
  66. data/samples/demo/art/AlignCenter.xpm +35 -0
  67. data/samples/demo/art/AlignLeft.xpm +35 -0
  68. data/samples/demo/art/AlignMiddle.xpm +35 -0
  69. data/samples/demo/art/AlignRight.xpm +35 -0
  70. data/samples/demo/art/AlignTop.xpm +35 -0
  71. data/samples/demo/art/Bitmap.xpm +25 -0
  72. data/samples/demo/art/Circle.xpm +22 -0
  73. data/samples/demo/art/Curve.xpm +21 -0
  74. data/samples/demo/art/Diamond.xpm +22 -0
  75. data/samples/demo/art/EditText.xpm +21 -0
  76. data/samples/demo/art/Ellipse.xpm +22 -0
  77. data/samples/demo/art/FixedRect.xpm +22 -0
  78. data/samples/demo/art/FlexGrid.xpm +22 -0
  79. data/samples/demo/art/GC.xpm +23 -0
  80. data/samples/demo/art/Grid.xpm +22 -0
  81. data/samples/demo/art/Line.xpm +21 -0
  82. data/samples/demo/art/NoSource.xpm +69 -0
  83. data/samples/demo/art/OrthoLine.xpm +21 -0
  84. data/samples/demo/art/Rect.xpm +22 -0
  85. data/samples/demo/art/RoundOrthoLine.xpm +21 -0
  86. data/samples/demo/art/RoundRect.xpm +22 -0
  87. data/samples/demo/art/Shadow.xpm +23 -0
  88. data/samples/demo/art/StandAloneLine.xpm +22 -0
  89. data/samples/demo/art/Text.xpm +21 -0
  90. data/samples/demo/art/Tool.xpm +23 -0
  91. data/samples/demo/art/sample.xpm +251 -0
  92. data/samples/demo/demo.rb +658 -0
  93. data/samples/demo/frame_canvas.rb +422 -0
  94. data/samples/demo/images/motyl.bmp +0 -0
  95. data/samples/demo/images/motyl2.bmp +0 -0
  96. data/samples/sample1/art/sample.xpm +251 -0
  97. data/samples/sample1/sample.rb +263 -0
  98. data/samples/sample2/art/sample.xpm +251 -0
  99. data/samples/sample2/sample.rb +133 -0
  100. data/samples/sample2/sample_canvas.rb +35 -0
  101. data/samples/sample2/sample_shape.rb +108 -0
  102. data/samples/sample3/art/sample.xpm +251 -0
  103. data/samples/sample3/sample.rb +281 -0
  104. data/samples/sample4/art/sample.xpm +251 -0
  105. data/samples/sample4/sample.rb +180 -0
  106. data/tests/art/motyl.bmp +0 -0
  107. data/tests/lib/wxapp_runner.rb +64 -0
  108. data/tests/serializer_tests.rb +521 -0
  109. data/tests/test_grid_shapes.rb +42 -0
  110. data/tests/test_serialize.rb +7 -0
  111. data/tests/test_serialize_yaml.rb +17 -0
  112. metadata +242 -0
@@ -0,0 +1,521 @@
1
+ require 'wx/shapes'
2
+
3
+ module SerializerTestMixin
4
+
5
+ class PropTest
6
+
7
+ include Wx::SF::Serializable
8
+
9
+ property :prop_a
10
+ property prop_b: ->(obj, *val) { obj.instance_variable_set(:@prop_b, val.first) unless val.empty?; obj.instance_variable_get(:@prop_b) }
11
+ property prop_c: :serialize_prop_c
12
+ property(:prop_d, :prop_e) do |id, obj, *val|
13
+ case id
14
+ when :prop_d
15
+ obj.instance_variable_set('@prop_d', val.first) unless val.empty?
16
+ obj.instance_variable_get('@prop_d')
17
+ when :prop_e
18
+ obj.instance_variable_set('@prop_e', val.first) unless val.empty?
19
+ obj.instance_variable_get('@prop_e')
20
+ end
21
+ end
22
+ property :prop_f, :prop_g, handler: :serialize_props_f_and_g
23
+
24
+ def initialize
25
+ @prop_a = 'string'
26
+ @prop_b = 123
27
+ @prop_c = :symbol
28
+ @prop_d = 100.123
29
+ @prop_e = [1,2,3]
30
+ @prop_f = {_1: 1, _2: 2, _3: 3}
31
+ @prop_g = 1..10
32
+ end
33
+
34
+ attr_accessor :prop_a
35
+
36
+ def serialize_prop_c(*val)
37
+ @prop_c = val.first unless val.empty?
38
+ @prop_c
39
+ end
40
+ private :serialize_prop_c
41
+
42
+ def serialize_props_f_and_g(id, *val)
43
+ case id
44
+ when :prop_f
45
+ @prop_f = val.shift unless val.empty?
46
+ @prop_f
47
+ when :prop_g
48
+ @prop_g = val.shift unless val.empty?
49
+ @prop_g
50
+ end
51
+ end
52
+
53
+ def ==(other)
54
+ self.class === other &&
55
+ @prop_a == other.prop_a &&
56
+ @prop_b == other.instance_variable_get('@prop_b') &&
57
+ @prop_c == other.instance_variable_get('@prop_c') &&
58
+ @prop_d == other.instance_variable_get('@prop_d') &&
59
+ @prop_e == other.instance_variable_get('@prop_e') &&
60
+ @prop_g == other.instance_variable_get('@prop_g') &&
61
+ @prop_f == other.instance_variable_get('@prop_f')
62
+ end
63
+ end
64
+
65
+ def test_properties
66
+ obj = PropTest.new
67
+ obj_serial = obj.serialize
68
+ obj_new = nil
69
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
70
+ assert_instance_of(PropTest, obj_new)
71
+ assert_equal(obj, obj_new)
72
+ end
73
+
74
+ def test_wx_data
75
+ obj = Wx::Point.new(10, 90)
76
+ obj_serial = obj.serialize
77
+ obj_new = nil
78
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
79
+ assert_instance_of(Wx::Point, obj_new)
80
+ assert_equal(obj, obj_new)
81
+
82
+ obj = Wx::RealPoint.new(10, 90)
83
+ obj_serial = obj.serialize
84
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
85
+ assert_instance_of(Wx::RealPoint, obj_new)
86
+ assert_equal(obj, obj_new)
87
+
88
+ obj = Wx::Size.new(100, 900)
89
+ obj_serial = obj.serialize
90
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
91
+ assert_instance_of(Wx::Size, obj_new)
92
+ assert_equal(obj, obj_new)
93
+
94
+ obj = Wx::Rect.new(10, 20, 100, 900)
95
+ obj_serial = obj.serialize
96
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
97
+ assert_instance_of(Wx::Rect, obj_new)
98
+ assert_equal(obj, obj_new)
99
+
100
+ obj = Wx::Colour.new('red')
101
+ obj_serial = obj.serialize
102
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
103
+ assert_instance_of(Wx::Colour, obj_new)
104
+ assert_equal(obj, obj_new)
105
+
106
+ obj = Wx::Pen.new('black')
107
+ obj_serial = obj.serialize
108
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
109
+ assert_instance_of(Wx::Pen, obj_new)
110
+ assert_equal(obj, obj_new)
111
+ end
112
+
113
+ def test_core
114
+ obj = [Wx::Point.new(10, 90), Wx::Point.new(20, 80)]
115
+ obj_serial = obj.serialize
116
+ obj_new = nil
117
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
118
+ assert_equal(obj, obj_new)
119
+
120
+ obj = { '1' => Wx::Point.new(10, 90), '2' => Wx::Point.new(20, 80) }
121
+ obj_serial = obj.serialize
122
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
123
+ assert_equal(obj, obj_new)
124
+
125
+ Struct.new('MyStruct', :one, :two) unless defined? Struct::MyStruct
126
+ obj = Struct::MyStruct.new(one: Wx::Point.new(10, 90), two: Wx::Point.new(20, 80))
127
+ obj_serial = obj.serialize
128
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
129
+ assert_equal(obj, obj_new)
130
+
131
+ obj = ::Set.new(%i[one two three])
132
+ obj_serial = obj.serialize
133
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
134
+ assert_equal(obj, obj_new)
135
+
136
+ obj = OpenStruct.new(one: Wx::Point.new(10, 90), two: Wx::Point.new(20, 80))
137
+ obj_serial = obj.serialize
138
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
139
+ assert_equal(obj, obj_new)
140
+
141
+ obj = [1, nil, 2]
142
+ obj_serial = obj.serialize
143
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
144
+ assert_equal(obj, obj_new)
145
+ end
146
+
147
+ class PointsOwner
148
+ include Wx::SF::Serializable
149
+
150
+ property :points
151
+
152
+ def initialize(points = [])
153
+ @points = points
154
+ end
155
+
156
+ attr_accessor :points
157
+
158
+ def ==(other)
159
+ self.class === other && @points == other.points
160
+ end
161
+ end
162
+
163
+ def test_composition
164
+ obj = PointsOwner.new([Wx::Point.new(10, 90), Wx::Point.new(20, 80)])
165
+ obj_serial = obj.serialize
166
+ obj_new = nil
167
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
168
+ assert_equal(obj, obj_new)
169
+ end
170
+
171
+ def test_connection_point
172
+ obj = Wx::SF::ConnectionPoint.new(nil, Wx::SF::ConnectionPoint::CPTYPE::TOPLEFT)
173
+ obj_serial = obj.serialize
174
+ obj_new = nil
175
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
176
+ assert_instance_of(obj.class, obj_new)
177
+ assert_equal(obj.type, obj_new.type)
178
+ assert_equal(obj.relative_position, obj_new.relative_position)
179
+ assert_equal(obj.ortho_direction, obj_new.ortho_direction)
180
+ end
181
+
182
+ class SerializedBase
183
+ include Wx::SF::Serializable
184
+
185
+ property :a
186
+ property :b
187
+ property :c
188
+
189
+ def initialize(a=nil, b=nil, c=nil)
190
+ @a = a
191
+ @b = b
192
+ @c = c
193
+ end
194
+
195
+ attr_accessor :a, :b, :c
196
+
197
+ def ==(other)
198
+ self.class === other && self.a == other.a && self.b == other.b && self.c == other.c
199
+ end
200
+ end
201
+
202
+ class SerializedDerived < SerializedBase
203
+ contains :d
204
+ excludes :c
205
+
206
+ def initialize(a=nil, b=nil, d=nil)
207
+ super(a, b)
208
+ @d = d
209
+ self.c = 'FIXED'
210
+ end
211
+
212
+ attr_accessor :d
213
+
214
+ def ==(other)
215
+ super && self.d == other.d
216
+ end
217
+ end
218
+
219
+ def test_exclusion
220
+ obj = SerializedBase.new(1, :hello, 'World')
221
+ obj_serial = obj.serialize
222
+ obj_new = nil
223
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
224
+ assert_equal(obj, obj_new)
225
+
226
+ obj = SerializedDerived.new(2, :derived, 103.50)
227
+ obj_serial = obj.serialize
228
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
229
+ assert_equal(obj, obj_new)
230
+ end
231
+
232
+ class SerializedBase2
233
+ include Wx::SF::Serializable
234
+
235
+ property :list
236
+
237
+ def initialize(list = [])
238
+ @list = list
239
+ end
240
+
241
+ attr_reader :list
242
+
243
+ def set_list(list)
244
+ @list.insert(0, *(list || []))
245
+ end
246
+ private :set_list
247
+
248
+ def ==(other)
249
+ self.class === other && self.list == other.list
250
+ end
251
+ end
252
+
253
+ class SerializedDerived2 < SerializedBase2
254
+
255
+ def initialize(list = [])
256
+ super
257
+ @fixed_item = Wx::Point.new(30, 30)
258
+ @fixed_item.disable_serialize
259
+ self.list << @fixed_item
260
+ end
261
+
262
+ end
263
+
264
+ class SerializedDerived2_1 < SerializedBase2
265
+ property :extra_item, force: true
266
+
267
+ def initialize(list = [], extra = nil)
268
+ super(list)
269
+ set_extra_item(extra)
270
+ end
271
+
272
+ attr_reader :extra_item
273
+
274
+ def set_extra_item(extra)
275
+ @extra_item = extra
276
+ if @extra_item
277
+ @extra_item.disable_serialize
278
+ list << @extra_item
279
+ end
280
+ end
281
+ private :set_extra_item
282
+
283
+ def ==(other)
284
+ super(other) && @extra_item == other.extra_item
285
+ end
286
+ end
287
+
288
+ class SerializedBase3
289
+ include Wx::SF::Serializable
290
+
291
+ property :list
292
+
293
+ def initialize(list = ::Set.new)
294
+ @list = ::Set === list ? list : ::Set.new(list)
295
+ end
296
+
297
+ attr_reader :list
298
+
299
+ def set_list(list)
300
+ @list.merge(list || [])
301
+ end
302
+ private :set_list
303
+
304
+ def ==(other)
305
+ self.class === other && self.list == other.list
306
+ end
307
+ end
308
+
309
+ class SerializedDerived3 < SerializedBase3
310
+
311
+ def initialize(list = [])
312
+ super
313
+ @fixed_item = Wx::Point.new(30, 30)
314
+ @fixed_item.disable_serialize
315
+ self.list << @fixed_item
316
+ end
317
+
318
+ end
319
+
320
+ def test_disable
321
+ obj = SerializedBase2.new([Wx::Point.new(1,1), Wx::Point.new(2,2), Wx::Point.new(3,3)])
322
+ obj_serial = obj.serialize
323
+ obj_new = nil
324
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
325
+ assert_equal(obj, obj_new)
326
+
327
+ obj = SerializedDerived2.new([Wx::Point.new(1,1), Wx::Point.new(2,2), Wx::Point.new(3,3)])
328
+ obj_serial = obj.serialize
329
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
330
+ assert_equal(obj, obj_new)
331
+
332
+ obj = SerializedDerived2_1.new([Wx::Point.new(1,1), Wx::Point.new(2,2), Wx::Point.new(3,3)], Wx::Size.new(40, 40))
333
+ obj_serial = obj.serialize
334
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
335
+ assert_equal(obj, obj_new)
336
+
337
+ obj = SerializedDerived3.new([Wx::Point.new(1,1), Wx::Point.new(2,2), Wx::Point.new(3,3)])
338
+ obj_serial = obj.serialize
339
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
340
+ assert_equal(obj, obj_new)
341
+ end
342
+
343
+ class Identifiable
344
+ include Wx::SF::Serializable
345
+
346
+ property :id, :sym
347
+
348
+ def initialize(sym = nil)
349
+ @id = sym ? Wx::SF::Serializable::ID.new : nil
350
+ @sym = sym
351
+ end
352
+
353
+ attr_accessor :sym
354
+ attr_reader :id
355
+
356
+ def set_id(id)
357
+ @id = id
358
+ end
359
+ private :set_id
360
+ end
361
+
362
+ class Container
363
+ include Wx::SF::Serializable
364
+
365
+ property :map
366
+
367
+ def initialize(map = {})
368
+ @map = map
369
+ end
370
+
371
+ attr_reader :map
372
+
373
+ def set_map(map)
374
+ @map.replace(map)
375
+ end
376
+ private :set_map
377
+ end
378
+
379
+ class RefUser
380
+ include Wx::SF::Serializable
381
+
382
+ property :ref1, :ref2, :ref3
383
+
384
+ def initialize(*rids)
385
+ @ref1, @ref2, @ref3 = *rids
386
+ end
387
+
388
+ attr_accessor :ref1, :ref2, :ref3
389
+ end
390
+
391
+ def test_ids
392
+ container = Container.new
393
+ id_obj = Identifiable.new(:one)
394
+ container.map[id_obj.id] = id_obj
395
+ id_obj = Identifiable.new(:two)
396
+ container.map[id_obj.id] = id_obj
397
+ id_obj = Identifiable.new(:three)
398
+ container.map[id_obj.id] = id_obj
399
+ ref_obj = RefUser.new(*container.map.keys)
400
+ obj_serial = [container, ref_obj].serialize
401
+ obj_new = nil
402
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
403
+ assert_instance_of(Array, obj_new)
404
+ assert_instance_of(Container, obj_new.first)
405
+ assert_instance_of(RefUser, obj_new.last)
406
+ assert_instance_of(Wx::SF::Serializable::ID, obj_new.last.ref1)
407
+ assert_instance_of(Wx::SF::Serializable::ID, obj_new.last.ref2)
408
+ assert_instance_of(Wx::SF::Serializable::ID, obj_new.last.ref3)
409
+ assert_equal(:one, obj_new.first.map[obj_new.last.ref1].sym)
410
+ assert_equal(:two, obj_new.first.map[obj_new.last.ref2].sym)
411
+ assert_equal(:three, obj_new.first.map[obj_new.last.ref3].sym)
412
+ end
413
+
414
+ def test_nested_hash_with_complex_keys
415
+ id_obj = Identifiable.new(:one)
416
+ id_obj2 = Identifiable.new(:two)
417
+ h = {
418
+ [
419
+ { id_obj.id => id_obj }
420
+ ] => 'one',
421
+ [
422
+ { id_obj2.id => id_obj2 }
423
+ ] => 'two'
424
+ }
425
+ obj_serial = h.serialize
426
+ obj_new = nil
427
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
428
+ assert_instance_of(::Hash, obj_new)
429
+ obj_new.each_pair do |k,v|
430
+ assert_instance_of(::Array, k)
431
+ assert_instance_of(::String, v)
432
+ assert_instance_of(::Hash, k.first)
433
+ assert_instance_of(Wx::SF::Serializable::ID, k.first.first.first)
434
+ assert_equal(v, k.first[k.first.first.first].sym.to_s)
435
+ end
436
+ end
437
+
438
+ def test_shape
439
+ obj = Wx::SF::Shape.new
440
+ obj.set_relative_position(Wx::RealPoint.new(100, 99))
441
+ obj_serial = obj.serialize
442
+ obj_new = nil
443
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
444
+ assert_instance_of(Wx::SF::Shape, obj_new)
445
+ assert_equal(obj.get_relative_position, obj_new.get_relative_position)
446
+ end
447
+
448
+ def test_line_shape
449
+ obj = Wx::SF::LineShape.new(Wx::RealPoint.new(100, 100), Wx::RealPoint.new(400, 400))
450
+ obj.set_src_arrow(Wx::SF::SolidArrow)
451
+ obj.set_trg_arrow(Wx::SF::SolidArrow)
452
+ obj_serial = obj.serialize
453
+ obj_new = nil
454
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
455
+ assert_instance_of(Wx::SF::LineShape, obj_new)
456
+ assert_equal(obj.get_src_point, obj_new.get_src_point)
457
+ assert_equal(obj.get_trg_point, obj_new.get_trg_point)
458
+ assert_instance_of(Wx::SF::SolidArrow, obj_new.get_src_arrow)
459
+ assert_equal(obj_new.id, obj_new.get_src_arrow.get_parent_shape.id)
460
+ assert_instance_of(Wx::SF::SolidArrow, obj_new.get_trg_arrow)
461
+ assert_equal(obj_new.id, obj_new.get_trg_arrow.get_parent_shape.id)
462
+ end
463
+
464
+ def test_rect_shape
465
+ obj = Wx::SF::RectShape.new
466
+ obj.set_relative_position(Wx::RealPoint.new(100, 99))
467
+ obj.set_rect_size(20.0, 20.0)
468
+ obj_serial = obj.serialize
469
+ obj_new = nil
470
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
471
+ assert_instance_of(Wx::SF::RectShape, obj_new)
472
+ assert_equal(obj.get_relative_position, obj_new.get_relative_position)
473
+ assert_equal(Wx::RealPoint.new(20.0, 20.0), obj_new.get_rect_size)
474
+ end
475
+
476
+ def test_grid_shape
477
+ obj = Wx::SF::GridShape.new
478
+ obj.set_relative_position(Wx::RealPoint.new(100, 99))
479
+ obj.set_rect_size(20.0, 20.0)
480
+ obj.set_dimensions(2, 3)
481
+ obj.accept_child(Wx::SF::RectShape)
482
+ assert(obj.append_to_grid(Wx::SF::RectShape.new)) # should be cell 0,0
483
+ assert(obj.insert_to_grid(1, 0, Wx::SF::RectShape.new)) # cell 1,0
484
+ obj_serial = obj.serialize
485
+ obj_new = nil
486
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
487
+ assert_instance_of(Wx::SF::GridShape, obj_new)
488
+ assert_equal(obj.get_relative_position, obj_new.get_relative_position)
489
+ assert_equal(Wx::RealPoint.new(20.0, 20.0), obj_new.get_rect_size)
490
+ assert_instance_of(Wx::SF::RectShape, obj_new.get_managed_shape(0, 0))
491
+ assert_nil(obj_new.get_managed_shape(0, 1))
492
+ assert_nil(obj_new.get_managed_shape(0, 2))
493
+ assert_instance_of(Wx::SF::RectShape, obj_new.get_managed_shape(1, 0))
494
+ assert_nil(obj_new.get_managed_shape(1, 1))
495
+ assert_nil(obj_new.get_managed_shape(1, 2))
496
+ end
497
+
498
+ def test_bitmap_shape
499
+ obj = Wx::SF::BitmapShape.new
500
+ assert(obj.create_from_file(:motyl, Wx::BitmapType::BITMAP_TYPE_BMP))
501
+ obj.set_relative_position(Wx::RealPoint.new(100, 99))
502
+ obj_serial = obj.serialize(pretty: true)
503
+ obj_new = nil
504
+ assert_nothing_raised { obj_new = Wx::SF::Serializable.deserialize(obj_serial) }
505
+ assert_instance_of(Wx::SF::BitmapShape, obj_new)
506
+ assert_equal(obj.get_relative_position, obj_new.get_relative_position)
507
+ assert(obj_new.instance_variable_get('@bitmap').ok?)
508
+ end
509
+
510
+ def test_canvas
511
+ frame = Wx::Frame.new(nil)
512
+ frame.set_size([800, 600])
513
+ frame.client_rect
514
+ canvas = Wx::SF::ShapeCanvas.new(Wx::SF::Diagram.new, frame)
515
+ io = StringIO.new
516
+ assert_nothing_raised { canvas.save_canvas(io, compact: false) }
517
+ io.rewind
518
+ assert_nothing_raised { canvas.load_canvas(io) }
519
+ end
520
+
521
+ end
@@ -0,0 +1,42 @@
1
+
2
+ require_relative './lib/wxapp_runner'
3
+ require 'wx/shapes'
4
+
5
+ class GridShapeTests < Test::Unit::TestCase
6
+
7
+ def test_grid_shape
8
+ obj = Wx::SF::GridShape.new
9
+ obj.set_relative_position(Wx::RealPoint.new(100, 99))
10
+ obj.set_rect_size(20.0, 20.0)
11
+ obj.set_dimensions(2, 3)
12
+ obj.accept_child(Wx::SF::RectShape)
13
+ assert(obj.append_to_grid(Wx::SF::RectShape.new)) # should be cell 0,0
14
+ assert(obj.insert_to_grid(1, 0, Wx::SF::RectShape.new)) # cell 1,0
15
+ assert_instance_of(Wx::SF::RectShape, obj.get_managed_shape(0, 0))
16
+ assert_nil(obj.get_managed_shape(0, 1))
17
+ assert_nil(obj.get_managed_shape(0, 2))
18
+ assert_instance_of(Wx::SF::RectShape, obj.get_managed_shape(1, 0))
19
+ assert_nil(obj.get_managed_shape(1, 1))
20
+ assert_nil(obj.get_managed_shape(1, 2))
21
+ assert_nothing_raised { obj.do_children_layout }
22
+ end
23
+
24
+ def test_flex_grid_shape
25
+ obj = Wx::SF::FlexGridShape.new
26
+ obj.set_relative_position(Wx::RealPoint.new(100, 99))
27
+ obj.set_rect_size(20.0, 20.0)
28
+ obj.set_dimensions(2, 3)
29
+ obj.accept_child(Wx::SF::RectShape)
30
+ assert(obj.append_to_grid(Wx::SF::RectShape.new)) # should be cell 0,0
31
+ assert(obj.insert_to_grid(1, 0, Wx::SF::RectShape.new)) # cell 1,0
32
+ assert_instance_of(Wx::SF::RectShape, obj.get_managed_shape(0, 0))
33
+ assert_nil(obj.get_managed_shape(0, 1))
34
+ assert_nil(obj.get_managed_shape(0, 2))
35
+ assert_instance_of(Wx::SF::RectShape, obj.get_managed_shape(1, 0))
36
+ assert_nil(obj.get_managed_shape(1, 1))
37
+ assert_nil(obj.get_managed_shape(1, 2))
38
+ assert_nothing_raised { obj.do_children_layout }
39
+ end
40
+
41
+
42
+ end
@@ -0,0 +1,7 @@
1
+
2
+ require_relative './lib/wxapp_runner'
3
+ require_relative './serializer_tests'
4
+
5
+ class SerializeTests < Test::Unit::TestCase
6
+ include SerializerTestMixin
7
+ end
@@ -0,0 +1,17 @@
1
+
2
+ require_relative './lib/wxapp_runner'
3
+ require_relative './serializer_tests'
4
+
5
+ class YamlSerializeTests < Test::Unit::TestCase
6
+
7
+ include SerializerTestMixin
8
+
9
+ def self.startup
10
+ Wx::SF::Serializable.default_format = :yaml
11
+ end
12
+
13
+ def self.shutdown
14
+ Wx::SF::Serializable.default_format = nil
15
+ end
16
+
17
+ end