Class: TestQtRuby

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
ext/ruby/qtruby/test/unittests.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



6
7
8
9
# File 'ext/ruby/qtruby/test/unittests.rb', line 6

def setup
  @app = Qt::Application.instance || Qt::Application.new(ARGV)
  assert @app
end

#test_boolean_marshallingObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'ext/ruby/qtruby/test/unittests.rb', line 99

def test_boolean_marshalling
  assert Qt::Variant.new(true).toBool
  assert !Qt::Variant.new(false).toBool

  assert !Qt::Boolean.new(true).nil?
  assert Qt::Boolean.new(false).nil?

  # Invalid variant conversion should change b to false
  b = Qt::Boolean.new(true)
  v = Qt::Variant.new("Blah")
  v.toInt(b);

  assert b.nil?
end

#test_find_childObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/ruby/qtruby/test/unittests.rb', line 83

def test_find_child
  w = Qt::Widget.new(nil)
  assert_raise(TypeError) { w.findChild(nil) }

  assert_nil w.findChild(Qt::Widget)
  w2 = Qt::Widget.new(w)

  w3 = Qt::Widget.new(w)
  w3.objectName = "Bob"
  w4 = Qt::LineEdit.new(w2)
  w4.objectName = "Bob"

  assert w.findChild(Qt::Widget,"Bob") == w3
  assert w.findChild(Qt::LineEdit,"Bob") == w4
end

#test_find_childrenObject



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
# File 'ext/ruby/qtruby/test/unittests.rb', line 52

def test_find_children
  w = Qt::Widget.new(nil)
  assert_raise(TypeError) { w.findChildren(nil) }

  assert w.findChildren(Qt::Widget) == [ ]
  w2 = Qt::Widget.new(w)

  assert w.findChildren(Qt::Widget) == [ w2 ]
  assert w.findChildren(Qt::Object) == [ w2 ]
  assert w.findChildren(Qt::LineEdit) == [ ]
  assert w.findChildren(Qt::Widget,"Bob") == [ ]
  assert w.findChildren(Qt::Object,"Bob") == [ ]

  w2.objectName = "Bob"

  assert w.findChildren(Qt::Widget) == [ w2 ]
  assert w.findChildren(Qt::Object) == [ w2 ]
  assert w.findChildren(Qt::Widget,"Bob") == [ w2 ]
  assert w.findChildren(Qt::Object,"Bob") == [ w2 ]
  assert w.findChildren(Qt::LineEdit, "Bob") == [ ]

  w3 = Qt::Widget.new(w)
  w4 = Qt::LineEdit.new(w2)
  w4.setObjectName("Bob")

  assert w.findChildren(Qt::Widget) == [ w4, w2, w3 ]
  assert w.findChildren(Qt::LineEdit) == [ w4 ]
  assert w.findChildren(Qt::Widget,"Bob") == [ w4, w2 ]    
  assert w.findChildren(Qt::LineEdit,"Bob") == [ w4 ]    
end

#test_intp_marshallingObject



114
115
116
# File 'ext/ruby/qtruby/test/unittests.rb', line 114

def test_intp_marshalling
  assert Qt::Integer.new(100).value == 100
end


11
12
13
# File 'ext/ruby/qtruby/test/unittests.rb', line 11

def test_link_against_qt4
  assert_raise(NoMethodError) { @app.setMainWidget(nil) }
end

#test_qapplication_inheritanceObject



23
24
25
26
27
# File 'ext/ruby/qtruby/test/unittests.rb', line 23

def test_qapplication_inheritance
 assert @app.inherits("Qt::Application")
 assert @app.inherits("Qt::CoreApplication")
 assert @app.inherits("Qt::Object")
end

#test_qapplication_methodsObject



15
16
17
18
19
20
21
# File 'ext/ruby/qtruby/test/unittests.rb', line 15

def test_qapplication_methods
 assert @app == Qt::Application::instance
 assert @app == Qt::CoreApplication::instance
 assert @app == Qt::Application.instance
 assert @app == Qt::CoreApplication.instance
 assert @app == $qApp
end

#test_qstring_marshallObject



36
37
38
39
40
41
# File 'ext/ruby/qtruby/test/unittests.rb', line 36

def test_qstring_marshall
  widget = Qt::Widget.new(nil)
  assert widget.objectName.nil?
  widget.objectName = "Barney"
  assert widget.objectName == "Barney"
end

#test_variant_conversionsObject



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
# File 'ext/ruby/qtruby/test/unittests.rb', line 118

def test_variant_conversions
  v = Qt::Variant.new(Qt::Variant::Invalid)

  assert !v.isValid
  assert v.isNull

  v = Qt::Variant.new(55)
  assert v.toInt == 55
  assert v.toUInt == 55
  assert v.toLongLong == 55
  assert v.toULongLong == 55
  assert Qt::Variant.new(-55).toLongLong == -55
  assert Qt::Variant.new(-55).toULongLong == 18446744073709551561
  assert v.toDouble == 55.0
  assert v.toChar == Qt::Char.new(55)
  assert v.toString == "55"
  assert v.toStringList == [ ]


  assert Qt::Variant.new("Blah").toStringList == [ "Blah" ]

  assert Qt::Variant.new(Qt::Size.new(30,40)).toSize == Qt::Size.new(30,40)
  assert Qt::Variant.new(Qt::SizeF.new(20,30)).toSizeF == Qt::SizeF.new(20,30)

  assert Qt::Variant.new(Qt::Rect.new(30,40,10,10)).toRect == Qt::Rect.new(30,40,10,10)
  assert Qt::Variant.new(Qt::RectF.new(20,30,10,10)).toRectF == Qt::RectF.new(20,30,10,10)

  assert Qt::Variant.new(Qt::Point.new(30,40)).toPoint == Qt::Point.new(30,40)
  assert Qt::Variant.new(Qt::PointF.new(20,30)).toPointF == Qt::PointF.new(20,30)


end

#test_widget_inheritanceObject



29
30
31
32
33
34
# File 'ext/ruby/qtruby/test/unittests.rb', line 29

def test_widget_inheritance
  widget = Qt::Widget.new(nil)
  assert widget.inherits("Qt::Widget")
  assert widget.inherits("Qt::Object")
  assert widget.inherits("QObject")
end

#test_widgetlistObject



43
44
45
46
47
48
49
50
# File 'ext/ruby/qtruby/test/unittests.rb', line 43

def test_widgetlist
  w1 = Qt::Widget.new(nil)
  w2 = Qt::Widget.new(w1)
  w3 = Qt::Widget.new(w1)
  w4 = Qt::Widget.new(w2)

  assert w1.children == [ w2, w3 ]
end