glib2 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/ChangeLog +3023 -0
  2. data/README +28 -0
  3. data/Rakefile +87 -0
  4. data/extconf.rb +61 -0
  5. data/sample/bookmarkfile.rb +66 -0
  6. data/sample/completion.rb +45 -0
  7. data/sample/idle.rb +41 -0
  8. data/sample/iochannel.rb +44 -0
  9. data/sample/keyfile.rb +62 -0
  10. data/sample/shell.rb +36 -0
  11. data/sample/spawn.rb +25 -0
  12. data/sample/timeout.rb +28 -0
  13. data/sample/timeout2.rb +35 -0
  14. data/sample/timer.rb +40 -0
  15. data/sample/type-register.rb +103 -0
  16. data/sample/type-register2.rb +104 -0
  17. data/sample/utils.rb +54 -0
  18. data/src/glib-enum-types.c +1032 -0
  19. data/src/glib-enum-types.h +140 -0
  20. data/src/lib/glib-mkenums.rb +199 -0
  21. data/src/lib/glib2.rb +220 -0
  22. data/src/lib/mkmf-gnome2.rb +390 -0
  23. data/src/lib/pkg-config.rb +137 -0
  24. data/src/rbgcompat.h +30 -0
  25. data/src/rbglib.c +320 -0
  26. data/src/rbglib.h +96 -0
  27. data/src/rbglib_bookmarkfile.c +595 -0
  28. data/src/rbglib_completion.c +192 -0
  29. data/src/rbglib_convert.c +195 -0
  30. data/src/rbglib_error.c +95 -0
  31. data/src/rbglib_fileutils.c +83 -0
  32. data/src/rbglib_i18n.c +44 -0
  33. data/src/rbglib_int64.c +157 -0
  34. data/src/rbglib_iochannel.c +883 -0
  35. data/src/rbglib_keyfile.c +846 -0
  36. data/src/rbglib_maincontext.c +917 -0
  37. data/src/rbglib_mainloop.c +87 -0
  38. data/src/rbglib_messages.c +150 -0
  39. data/src/rbglib_pollfd.c +111 -0
  40. data/src/rbglib_shell.c +68 -0
  41. data/src/rbglib_source.c +190 -0
  42. data/src/rbglib_spawn.c +345 -0
  43. data/src/rbglib_threads.c +51 -0
  44. data/src/rbglib_timer.c +127 -0
  45. data/src/rbglib_unicode.c +611 -0
  46. data/src/rbglib_utils.c +386 -0
  47. data/src/rbglib_win32.c +136 -0
  48. data/src/rbgobj_boxed.c +251 -0
  49. data/src/rbgobj_closure.c +337 -0
  50. data/src/rbgobj_convert.c +167 -0
  51. data/src/rbgobj_enums.c +961 -0
  52. data/src/rbgobj_fundamental.c +30 -0
  53. data/src/rbgobj_object.c +892 -0
  54. data/src/rbgobj_param.c +390 -0
  55. data/src/rbgobj_paramspecs.c +305 -0
  56. data/src/rbgobj_signal.c +963 -0
  57. data/src/rbgobj_strv.c +61 -0
  58. data/src/rbgobj_type.c +851 -0
  59. data/src/rbgobj_typeinstance.c +121 -0
  60. data/src/rbgobj_typeinterface.c +148 -0
  61. data/src/rbgobj_typemodule.c +66 -0
  62. data/src/rbgobj_typeplugin.c +49 -0
  63. data/src/rbgobj_value.c +313 -0
  64. data/src/rbgobj_valuearray.c +59 -0
  65. data/src/rbgobj_valuetypes.c +298 -0
  66. data/src/rbgobject.c +406 -0
  67. data/src/rbgobject.h +265 -0
  68. data/src/rbgprivate.h +88 -0
  69. data/src/rbgutil.c +222 -0
  70. data/src/rbgutil.h +82 -0
  71. data/src/rbgutil_callback.c +231 -0
  72. data/test/glib-test-init.rb +6 -0
  73. data/test/glib-test-utils.rb +12 -0
  74. data/test/run-test.rb +25 -0
  75. data/test/test_enum.rb +99 -0
  76. data/test/test_file_utils.rb +15 -0
  77. data/test/test_glib2.rb +120 -0
  78. data/test/test_iochannel.rb +275 -0
  79. data/test/test_key_file.rb +38 -0
  80. data/test/test_mkenums.rb +25 -0
  81. data/test/test_signal.rb +20 -0
  82. data/test/test_timeout.rb +28 -0
  83. data/test/test_unicode.rb +369 -0
  84. data/test/test_utils.rb +37 -0
  85. data/test/test_win32.rb +13 -0
  86. metadata +165 -0
@@ -0,0 +1,15 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestGLibFileUtils < Test::Unit::TestCase
4
+ include GLibTestUtils
5
+
6
+ def test_format_size_for_display
7
+ only_glib_version(2, 16, 0)
8
+
9
+ assert_equal("1.0 KB", GLib.format_size_for_display(1024))
10
+ assert_equal("10.0 KB", GLib.format_size_for_display(1024 * 10))
11
+ assert_equal("1.0 MB", GLib.format_size_for_display(1024 * 1024))
12
+ assert_equal("1.5 MB", GLib.format_size_for_display(1024 * 1024 * 1.5))
13
+ assert_equal("1.0 GB", GLib.format_size_for_display(1024 * 1024 * 1024))
14
+ end
15
+ end
@@ -0,0 +1,120 @@
1
+ require 'test/unit'
2
+ require 'glib2'
3
+
4
+ class TestGLib < Test::Unit::TestCase
5
+
6
+ def test_version
7
+ assert_kind_of(Array, GLib::VERSION)
8
+ assert_equal(GLib::VERSION.length, 3)
9
+ assert(GLib::VERSION.all?{|i| i.is_a? Integer })
10
+
11
+ assert_kind_of(Integer, GLib::MAJOR_VERSION)
12
+ assert_kind_of(Integer, GLib::MINOR_VERSION)
13
+ assert_kind_of(Integer, GLib::MICRO_VERSION)
14
+
15
+ assert_kind_of(Array, GLib::BINDING_VERSION)
16
+ assert_equal(GLib::BINDING_VERSION.length, 3)
17
+ assert(GLib::BINDING_VERSION.all?{|i| i.is_a? Integer })
18
+ end
19
+
20
+ def test_priority
21
+ assert_kind_of(Integer, GLib::PRIORITY_HIGH)
22
+ assert_kind_of(Integer, GLib::PRIORITY_DEFAULT)
23
+ assert_kind_of(Integer, GLib::PRIORITY_HIGH_IDLE)
24
+ assert_kind_of(Integer, GLib::PRIORITY_DEFAULT_IDLE)
25
+ assert_kind_of(Integer, GLib::PRIORITY_LOW)
26
+ end
27
+
28
+ def test_int64
29
+ end
30
+
31
+ def test_convert
32
+ assert_kind_of(String, GLib.charset)
33
+
34
+ sjis = "\202\261\202\361\202\311\202\277\202\315\220\242\212E"
35
+ euc = "\244\263\244\363\244\313\244\301\244\317\300\244\263\246"
36
+ utf8 = "\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257\344\270\226\347\225\214"
37
+ assert_equal(GLib.convert(sjis, "UTF-8", "SHIFT_JIS"), utf8)
38
+ assert_equal(GLib.convert(sjis, "EUC-JP", "SHIFT_JIS"), euc)
39
+ assert_equal(GLib.convert(sjis, "SHIFT_JIS", "SHIFT_JIS"), sjis)
40
+ assert_equal(GLib.convert(euc, "UTF-8", "EUC-JP"), utf8)
41
+ assert_equal(GLib.convert(euc, "EUC-JP", "EUC-JP"), euc)
42
+ assert_equal(GLib.convert(euc, "SHIFT_JIS", "EUC-JP"), sjis)
43
+ assert_equal(GLib.convert(utf8, "UTF-8", "UTF-8"), utf8)
44
+ assert_equal(GLib.convert(utf8, "EUC-JP", "UTF-8"), euc)
45
+ assert_equal(GLib.convert(utf8, "SHIFT_JIS", "UTF-8"), sjis)
46
+
47
+ # rb_define_module_function(mGLib, "locale_to_utf8", rbglib_m_locale_to_utf8, 1);
48
+ # rb_define_module_function(mGLib, "locale_from_utf8", rbglib_m_locale_from_utf8, 1);
49
+ # rb_define_module_function(mGLib, "filename_to_utf8", rbglib_m_filename_to_utf8, 1);
50
+ # rb_define_module_function(mGLib, "filename_from_utf8", rbglib_m_filename_from_utf8, 1);
51
+ #
52
+ # rb_define_module_function(mGLib, "filename_to_uri", rbglib_m_filename_to_uri, -1);
53
+ # rb_define_module_function(mGLib, "filename_from_uri", rbglib_m_filename_from_uri, 1);
54
+
55
+ end
56
+
57
+ def test_messages
58
+ #rb_define_module_function(mGLog, "set_handler", rbglib_m_log_set_handler, 2);
59
+ #rb_define_module_function(mGLog, "remove_handler", rbglib_m_log_remove_handler, 2);
60
+ end
61
+
62
+ def test_object
63
+ assert_raises(GLib::NoPropertyError) {
64
+ GLib::Object.property("foo")
65
+ }
66
+
67
+ assert_raises(GLib::NoSignalError) {
68
+ GLib::Object.signal("foo")
69
+ }
70
+ end
71
+
72
+ def test_interface_extend
73
+ assert_raises(TypeError){
74
+ Object.__send__(:include, GLib::TypePlugin)
75
+ }
76
+ end
77
+
78
+ def test_signal_has_handler_pending
79
+ obj = GLib::Object.new
80
+ signal_name = "notify"
81
+
82
+ assert(!obj.signal_has_handler_pending?(signal_name))
83
+
84
+ h = obj.signal_connect(signal_name){}
85
+ assert(obj.signal_has_handler_pending?(signal_name))
86
+
87
+ obj.signal_handler_block(h) {
88
+ assert(obj.signal_has_handler_pending?(signal_name, true))
89
+ assert(!obj.signal_has_handler_pending?(signal_name, false))
90
+ }
91
+ assert(obj.signal_has_handler_pending?(signal_name, false))
92
+
93
+ obj.signal_handler_disconnect(h)
94
+ assert(!obj.signal_has_handler_pending?(signal_name))
95
+
96
+ obj = nil
97
+ end
98
+
99
+ def test_signal_handler_disconnect_and_gc
100
+ obj = GLib::Object.new
101
+ klass = Class.new
102
+ 1000.times {
103
+ a = klass.new
104
+ id = obj.signal_connect("notify") { p a }
105
+ obj.signal_handler_disconnect(id)
106
+ }
107
+ GC.start
108
+ ary = []
109
+ ObjectSpace.each_object(klass) { |a| ary.push(a) }
110
+ assert_operator(ary.size, :<, 1000)
111
+ end
112
+
113
+ def test_gtype
114
+ assert_equal(GLib::Object.gtype, GLib::Type["GObject"])
115
+ assert_equal(GLib::Interface.gtype, GLib::Type["GInterface"])
116
+
117
+ obj = GLib::Object.new
118
+ assert_equal(obj.gtype, GLib::Object.gtype)
119
+ end
120
+ end
@@ -0,0 +1,275 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test/unit'
4
+ require 'glib2'
5
+
6
+ require 'tempfile'
7
+ require 'nkf'
8
+
9
+ $KCODE = "U"
10
+
11
+ class TestGIOChannel < Test::Unit::TestCase
12
+ def setup
13
+ @content = "aaa\nbbb\nccc\nあああ\n"
14
+ @sjis_content = NKF.nkf("-sW", @content)
15
+
16
+ @file = Tempfile.new("glib2-content")
17
+ @file.open
18
+ @file.print(@content)
19
+ @file.close
20
+
21
+ @sjis_file = Tempfile.new("glib2-sjis-content")
22
+ @sjis_file.open
23
+ @sjis_file.print(@sjis_content)
24
+ @sjis_file.close
25
+ end
26
+
27
+ def test_open
28
+ write_test_file = Tempfile.new("glib2-write-test")
29
+
30
+ io = GLib::IOChannel.open(@file.path)
31
+ io.close
32
+
33
+ io = GLib::IOChannel.open(@file.path, "r")
34
+ assert_equal(@content, io.read)
35
+ io.close
36
+
37
+ io = GLib::IOChannel.open(write_test_file.path, "w")
38
+ assert_raises(RuntimeError){
39
+ assert_equal(@content, io.read)
40
+ }
41
+ io.close
42
+
43
+ GLib::IOChannel.open(@file.path) do |_io|
44
+ assert_equal(@content, _io.read)
45
+ end
46
+
47
+ GLib::IOChannel.open(@file.path, "r") do |_io|
48
+ assert_equal(@content, _io.read)
49
+ end
50
+
51
+ GLib::IOChannel.open(write_test_file.path, "w") do |_io|
52
+ io = _io
53
+ assert_raises(RuntimeError) do
54
+ assert_equal(@content, io.read)
55
+ end
56
+ end
57
+
58
+ assert_raises(GLib::IOChannelError) do
59
+ io.close
60
+ end
61
+
62
+ assert_raises(GLib::FileError) do
63
+ GLib::IOChannel.new("foo")
64
+ end
65
+ end
66
+
67
+ def test_getc
68
+ io = GLib::IOChannel.new(@file.path)
69
+ ["a", "b", "c", "あ"].each do |v|
70
+ 3.times do
71
+ assert_equal(v.unpack("U")[0], io.getc)
72
+ end
73
+ assert_equal("\n"[0], io.getc)
74
+ end
75
+ assert_equal(nil, io.getc)
76
+ io.close
77
+ end
78
+
79
+ def test_each_char
80
+ text = @content.split(//)
81
+ io = GLib::IOChannel.new(@file.path)
82
+ i = 0
83
+ io.each_char {|ch|
84
+ assert_equal(text[i].unpack("U")[0], ch)
85
+ i += 1
86
+ }
87
+ io.close
88
+ end
89
+
90
+ def test_readchar
91
+ io = GLib::IOChannel.new(@file.path)
92
+ text = @content.split(//)
93
+ text.each do |v|
94
+ assert_equal(v.unpack("U")[0], io.readchar)
95
+ end
96
+ assert_raises(EOFError) {
97
+ io.readchar
98
+ }
99
+ io.close
100
+ end
101
+
102
+ def test_gets
103
+ io = GLib::IOChannel.new(@file.path)
104
+ assert_equal("aaa\n", io.gets)
105
+ assert_equal("bbb\n", io.gets)
106
+ assert_equal("ccc\n", io.gets)
107
+ assert_equal("あああ\n", io.gets)
108
+ assert_equal(nil, io.gets)
109
+ io.close
110
+
111
+ io = GLib::IOChannel.new(@file.path)
112
+ assert_equal("aaa\nbbb\n", io.gets("bbb\n"))
113
+ assert_equal("ccc\nあああ\n", io.gets("bbb\n"))
114
+ assert_equal(nil, io.gets("bbb\n"))
115
+ io.close
116
+ end
117
+
118
+ def test_readline
119
+ io = GLib::IOChannel.new(@file.path)
120
+ assert_equal("aaa\n", io.readline)
121
+ assert_equal("bbb\n", io.readline)
122
+ assert_equal("ccc\n", io.readline)
123
+ assert_equal("あああ\n", io.readline)
124
+ assert_raises(EOFError) {
125
+ io.readline
126
+ }
127
+ io.close
128
+
129
+ io = GLib::IOChannel.new(@file.path)
130
+ assert_equal("aaa\nbbb\n", io.readline("bbb\n"))
131
+ assert_equal("ccc\nあああ\n", io.readline("bbb\n"))
132
+ assert_raises(EOFError) {
133
+ io.readline("bbb\n")
134
+ }
135
+ io.close
136
+ end
137
+
138
+ def test_each_line
139
+ lines = ["aaa\n", "bbb\n", "ccc\n", "あああ\n"]
140
+ io = GLib::IOChannel.new(@file.path)
141
+ i = 0
142
+ io.each {|line|
143
+ assert_equal(lines[i], line)
144
+ i += 1
145
+ }
146
+ io.close
147
+
148
+ io = GLib::IOChannel.new(@file.path)
149
+ assert_raises(RuntimeError) {
150
+ io.each {|line|
151
+ raise "test"
152
+ }
153
+ }
154
+ io.close
155
+
156
+ io = GLib::IOChannel.new(@file.path)
157
+ i = 0
158
+ io.each_line {|line|
159
+ assert_equal(lines[i], line)
160
+ i += 1
161
+ }
162
+ io.close
163
+
164
+ #Test for Enumerable
165
+ GLib::IOChannel.open(@file.path) do |_io|
166
+ io = _io
167
+ io.each_with_index do |line, _i|
168
+ assert_equal(lines[_i], line)
169
+ end
170
+ end
171
+
172
+ assert_raises(ArgumentError) do
173
+ io.each
174
+ end
175
+ end
176
+
177
+ def test_read
178
+ io = GLib::IOChannel.new(@file.path)
179
+ assert_equal(@content, io.read)
180
+ io.close
181
+
182
+ io = GLib::IOChannel.new(@file.path)
183
+ assert_equal(@content, io.read(100))
184
+ io.close
185
+
186
+ io = GLib::IOChannel.new(@file.path)
187
+ assert_equal("aaa\nbbb\n", io.read(8))
188
+ assert_equal("ccc\n", io.read(4))
189
+ assert_equal("あああ\n", io.read(10))
190
+ assert_equal("", io.read(10))
191
+ assert_equal("", io.read(10))
192
+ io.close
193
+ end
194
+
195
+ def test_seek
196
+ text = @content
197
+ io = GLib::IOChannel.new(@file.path)
198
+ io.seek(5)
199
+ assert_equal(text[5], io.getc)
200
+ io.seek(6, GLib::IOChannel::SEEK_SET)
201
+ assert_equal(text[6], io.getc)
202
+
203
+ io.seek(1, GLib::IOChannel::SEEK_CUR)
204
+ assert_equal(text[8], io.getc)
205
+
206
+ io.pos = 0
207
+ assert_equal(text[0], io.getc)
208
+
209
+ io.set_pos(2)
210
+ assert_equal(text[2], io.getc)
211
+
212
+ io.close
213
+ end
214
+
215
+ def test_write
216
+ write_test_file = Tempfile.new("glib2-write-test")
217
+
218
+ io = GLib::IOChannel.new(write_test_file.path, "w")
219
+ io.write("a\n")
220
+ io.write("あいう\n")
221
+ io.printf("a%sa\n", "a")
222
+ io.print("a", 100, "a\n")
223
+ io.puts("b", 200, "b")
224
+ io.putc("c")
225
+ io.putc("c".unpack("U")[0])
226
+ io.putc("cc".unpack("U")[0])
227
+ io.putc("あ".unpack("U")[0])
228
+ io.putc("あ")
229
+ io.putc("あい") #Ignore 2nd char
230
+ io.putc("aあ") #Ignore 2nd char
231
+ io.close
232
+
233
+ # check them
234
+ io = GLib::IOChannel.new(write_test_file.path, "r")
235
+ assert_equal("a\n", io.gets)
236
+ assert_equal("あいう\n", io.gets)
237
+ assert_equal("aaa\n", io.gets)
238
+ assert_equal("a100a\n", io.gets)
239
+ assert_equal("b\n", io.gets)
240
+ assert_equal("200\n", io.gets)
241
+ assert_equal("b\n", io.gets)
242
+ assert_equal("c".unpack("U")[0], io.getc)
243
+ assert_equal("c".unpack("U")[0], io.getc)
244
+ assert_equal("c".unpack("U")[0], io.getc)
245
+ assert_equal("あ".unpack("U")[0], io.getc)
246
+ assert_equal("あ".unpack("U")[0], io.getc)
247
+ assert_equal("あ".unpack("U")[0], io.getc)
248
+ assert_equal("a".unpack("U")[0], io.getc)
249
+ io.close
250
+ end
251
+
252
+ def test_encoding
253
+ io = GLib::IOChannel.new(@file.path)
254
+ assert_equal("UTF-8", io.encoding)
255
+ io.encoding = "Shift_JIS"
256
+ assert_equal("Shift_JIS", io.encoding)
257
+ assert_raises(GLib::ConvertError) {
258
+ io.read
259
+ }
260
+ io.close
261
+
262
+ io = GLib::IOChannel.new(@sjis_file.path)
263
+ io.encoding = "Shift_JIS"
264
+ assert_equal("Shift_JIS", io.encoding)
265
+ assert_equal(@content, io.read)
266
+ io.close
267
+ end
268
+
269
+ def test_error
270
+ assert_raises(GLib::FileError) {
271
+ # No such file or directory
272
+ GLib::IOChannel.new("foo")
273
+ }
274
+ end
275
+ end
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'tempfile'
4
+
5
+ class TestGLibKeyFile < Test::Unit::TestCase
6
+ include GLibTestUtils
7
+
8
+ def test_load_from_dirs
9
+ only_glib_version(2, 14, 0)
10
+
11
+ key_file = GLib::KeyFile.new
12
+ assert_raise(GLib::KeyFileError) do
13
+ key_file.load_from_dirs("non-existent")
14
+ end
15
+
16
+ temp = Tempfile.new("key-file")
17
+ base_name = File.basename(temp.path)
18
+ search_dirs = [File.dirname(temp.path)]
19
+ assert_raise(GLib::KeyFileError) do
20
+ key_file.load_from_dirs("non-existent", search_dirs)
21
+ end
22
+ assert_raise(GLib::KeyFileError) do
23
+ key_file.load_from_dirs(base_name, search_dirs)
24
+ end
25
+ temp.puts(<<-EOK)
26
+ [General]
27
+ key = value
28
+ EOK
29
+ temp.close
30
+ assert_equal(temp.path, key_file.load_from_dirs(base_name, search_dirs))
31
+ end
32
+
33
+ def test_desktop_constants
34
+ only_glib_version(2, 14, 0)
35
+ assert_equal("Desktop Entry", GLib::KeyFile::DESKTOP_GROUP)
36
+ assert_equal("URL", GLib::KeyFile::DESKTOP_KEY_URL)
37
+ end
38
+ end