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.
- data/ChangeLog +3023 -0
- data/README +28 -0
- data/Rakefile +87 -0
- data/extconf.rb +61 -0
- data/sample/bookmarkfile.rb +66 -0
- data/sample/completion.rb +45 -0
- data/sample/idle.rb +41 -0
- data/sample/iochannel.rb +44 -0
- data/sample/keyfile.rb +62 -0
- data/sample/shell.rb +36 -0
- data/sample/spawn.rb +25 -0
- data/sample/timeout.rb +28 -0
- data/sample/timeout2.rb +35 -0
- data/sample/timer.rb +40 -0
- data/sample/type-register.rb +103 -0
- data/sample/type-register2.rb +104 -0
- data/sample/utils.rb +54 -0
- data/src/glib-enum-types.c +1032 -0
- data/src/glib-enum-types.h +140 -0
- data/src/lib/glib-mkenums.rb +199 -0
- data/src/lib/glib2.rb +220 -0
- data/src/lib/mkmf-gnome2.rb +390 -0
- data/src/lib/pkg-config.rb +137 -0
- data/src/rbgcompat.h +30 -0
- data/src/rbglib.c +320 -0
- data/src/rbglib.h +96 -0
- data/src/rbglib_bookmarkfile.c +595 -0
- data/src/rbglib_completion.c +192 -0
- data/src/rbglib_convert.c +195 -0
- data/src/rbglib_error.c +95 -0
- data/src/rbglib_fileutils.c +83 -0
- data/src/rbglib_i18n.c +44 -0
- data/src/rbglib_int64.c +157 -0
- data/src/rbglib_iochannel.c +883 -0
- data/src/rbglib_keyfile.c +846 -0
- data/src/rbglib_maincontext.c +917 -0
- data/src/rbglib_mainloop.c +87 -0
- data/src/rbglib_messages.c +150 -0
- data/src/rbglib_pollfd.c +111 -0
- data/src/rbglib_shell.c +68 -0
- data/src/rbglib_source.c +190 -0
- data/src/rbglib_spawn.c +345 -0
- data/src/rbglib_threads.c +51 -0
- data/src/rbglib_timer.c +127 -0
- data/src/rbglib_unicode.c +611 -0
- data/src/rbglib_utils.c +386 -0
- data/src/rbglib_win32.c +136 -0
- data/src/rbgobj_boxed.c +251 -0
- data/src/rbgobj_closure.c +337 -0
- data/src/rbgobj_convert.c +167 -0
- data/src/rbgobj_enums.c +961 -0
- data/src/rbgobj_fundamental.c +30 -0
- data/src/rbgobj_object.c +892 -0
- data/src/rbgobj_param.c +390 -0
- data/src/rbgobj_paramspecs.c +305 -0
- data/src/rbgobj_signal.c +963 -0
- data/src/rbgobj_strv.c +61 -0
- data/src/rbgobj_type.c +851 -0
- data/src/rbgobj_typeinstance.c +121 -0
- data/src/rbgobj_typeinterface.c +148 -0
- data/src/rbgobj_typemodule.c +66 -0
- data/src/rbgobj_typeplugin.c +49 -0
- data/src/rbgobj_value.c +313 -0
- data/src/rbgobj_valuearray.c +59 -0
- data/src/rbgobj_valuetypes.c +298 -0
- data/src/rbgobject.c +406 -0
- data/src/rbgobject.h +265 -0
- data/src/rbgprivate.h +88 -0
- data/src/rbgutil.c +222 -0
- data/src/rbgutil.h +82 -0
- data/src/rbgutil_callback.c +231 -0
- data/test/glib-test-init.rb +6 -0
- data/test/glib-test-utils.rb +12 -0
- data/test/run-test.rb +25 -0
- data/test/test_enum.rb +99 -0
- data/test/test_file_utils.rb +15 -0
- data/test/test_glib2.rb +120 -0
- data/test/test_iochannel.rb +275 -0
- data/test/test_key_file.rb +38 -0
- data/test/test_mkenums.rb +25 -0
- data/test/test_signal.rb +20 -0
- data/test/test_timeout.rb +28 -0
- data/test/test_unicode.rb +369 -0
- data/test/test_utils.rb +37 -0
- data/test/test_win32.rb +13 -0
- metadata +165 -0
data/src/rbgutil.h
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/************************************************
|
3
|
+
|
4
|
+
rbgutil.h -
|
5
|
+
|
6
|
+
$Author: sakai $
|
7
|
+
$Date: 2007/07/08 03:17:21 $
|
8
|
+
|
9
|
+
Copyright (C) 2002,2003 Masao Mutoh
|
10
|
+
************************************************/
|
11
|
+
|
12
|
+
#ifndef __RBGUTIL_H__
|
13
|
+
#define __RBGUTIL_H__
|
14
|
+
|
15
|
+
#include <glib-object.h>
|
16
|
+
#include "ruby.h"
|
17
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
18
|
+
# include <ruby/encoding.h>
|
19
|
+
#endif
|
20
|
+
#include "rbglib.h"
|
21
|
+
|
22
|
+
#ifdef __cplusplus
|
23
|
+
extern "C" {
|
24
|
+
#endif /* __cplusplus */
|
25
|
+
|
26
|
+
#define G_DEF_SETTER(klass, name) \
|
27
|
+
rb_funcall(klass, rbgutil_id_module_eval, 1, rb_str_new2( \
|
28
|
+
"def " name "=(val); set_" name "(val); val; end\n"))
|
29
|
+
#define G_DEF_SETTERS(klass) rbgutil_def_setters(klass)
|
30
|
+
|
31
|
+
#define G_SET_PROPERTIES(self, hash) (rbgutil_set_properties(self, hash))
|
32
|
+
#define G_SET_SYMBOL_PROPERTY(gtype, name) \
|
33
|
+
rbgobj_register_property_getter(gtype, name, rbgutil_sym_g2r_func)
|
34
|
+
#define G_PROTECT_CALLBACK(func, data) (rbgutil_invoke_callback((VALUE(*)(VALUE))func, (VALUE)data))
|
35
|
+
|
36
|
+
#define GLIST2ARY(list) (rbgutil_glist2ary(list))
|
37
|
+
#define GLIST2ARY_FREE(list) (rbgutil_glist2ary_and_free(list))
|
38
|
+
#define GLIST2ARYF(list) (GLIST2ARY_FREE(list))
|
39
|
+
#define GLIST2ARY2(list, gtype) (rbgutil_glist2ary_boxed(list, gtype))
|
40
|
+
#define GLIST2ARY2F(list, gtype) (rbgutil_glist2ary_boxed_and_free(list, gtype))
|
41
|
+
#define GLIST2ARY_STR(list) (rbgutil_glist2ary_string(list))
|
42
|
+
#define GLIST2ARY_STR_FREE(list) (rbgutil_glist2ary_string_and_free(list))
|
43
|
+
#define GSLIST2ARY(list) (rbgutil_gslist2ary(list))
|
44
|
+
#define GSLIST2ARY_FREE(list) (rbgutil_gslist2ary_and_free(list))
|
45
|
+
#define GSLIST2ARYF(list) (GSLIST2ARY_FREE(list))
|
46
|
+
#define GSLIST2ARY2(list, gtype) (rbgutil_gslist2ary_boxed(list, gtype))
|
47
|
+
#define GSLIST2ARY2F(list, gtype) (rbgutil_gslist2ary_boxed_and_free(list, gtype))
|
48
|
+
|
49
|
+
#define RBG_STRING_SET_UTF8_ENCODING(string) \
|
50
|
+
(rbgutil_string_set_utf8_encoding(string))
|
51
|
+
|
52
|
+
extern VALUE rbgutil_def_setters(VALUE klass);
|
53
|
+
extern void rbgutil_set_properties(VALUE self, VALUE hash);
|
54
|
+
extern VALUE rbgutil_glist2ary(GList* list);
|
55
|
+
extern VALUE rbgutil_glist2ary_boxed(GList* list, GType gtype);
|
56
|
+
extern VALUE rbgutil_glist2ary_string(GList* list);
|
57
|
+
extern VALUE rbgutil_glist2ary_and_free(GList* list);
|
58
|
+
extern VALUE rbgutil_glist2ary_boxed_and_free(GList* list, GType gtype);
|
59
|
+
extern VALUE rbgutil_glist2ary_string_and_free(GList* list);
|
60
|
+
extern VALUE rbgutil_gslist2ary(GSList* list);
|
61
|
+
extern VALUE rbgutil_gslist2ary_and_free(GSList* list);
|
62
|
+
extern VALUE rbgutil_gslist2ary_boxed(GSList* list, GType gtype);
|
63
|
+
extern VALUE rbgutil_gslist2ary_boxed_and_free(GSList* list, GType gtype);
|
64
|
+
extern VALUE rbgutil_protect(VALUE (*proc) (VALUE), VALUE data);
|
65
|
+
extern VALUE rbgutil_invoke_callback(VALUE (*func)(VALUE), VALUE arg);
|
66
|
+
extern void rbgutil_start_callback_dispatch_thread(void);
|
67
|
+
extern void rbgutil_stop_callback_dispatch_thread(void);
|
68
|
+
|
69
|
+
extern VALUE rbgutil_string_set_utf8_encoding(VALUE string);
|
70
|
+
|
71
|
+
/*< protected >*/
|
72
|
+
RUBY_GLIB2_VAR ID rbgutil_id_module_eval;
|
73
|
+
extern VALUE rbgutil_sym_g2r_func(const GValue *from);
|
74
|
+
|
75
|
+
/* deprecated */
|
76
|
+
#define G_BLOCK_PROC rb_block_proc
|
77
|
+
|
78
|
+
#ifdef __cplusplus
|
79
|
+
}
|
80
|
+
#endif /* __cplusplus */
|
81
|
+
|
82
|
+
#endif /* __RBGLIB_H__ */
|
@@ -0,0 +1,231 @@
|
|
1
|
+
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
|
2
|
+
/**********************************************************************
|
3
|
+
|
4
|
+
utils_callback.c -
|
5
|
+
|
6
|
+
$Author: sakai $
|
7
|
+
$Date: 2007/07/14 07:16:18 $
|
8
|
+
|
9
|
+
Copyright (C) 2007 Ruby-GNOME2 Project
|
10
|
+
|
11
|
+
**********************************************************************/
|
12
|
+
|
13
|
+
#include "rbgprivate.h"
|
14
|
+
|
15
|
+
#ifdef HAVE_UNISTD_H
|
16
|
+
# include <unistd.h>
|
17
|
+
#endif
|
18
|
+
#ifdef HAVE_IO_H
|
19
|
+
# include <io.h>
|
20
|
+
# define pipe(phandles) _pipe(phandles, 128, _O_BINARY)
|
21
|
+
#endif
|
22
|
+
#include <fcntl.h>
|
23
|
+
#include <errno.h>
|
24
|
+
|
25
|
+
#ifndef HAVE_RB_ERRINFO
|
26
|
+
# define rb_errinfo() (ruby_errinfo)
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#ifndef HAVE_RUBY_NATIVE_THREAD_P
|
30
|
+
# define ruby_native_thread_p() is_ruby_native_thread()
|
31
|
+
#endif
|
32
|
+
|
33
|
+
static VALUE rbgutil_eGLibCallbackNotInitializedError;
|
34
|
+
static ID id_exit_application;
|
35
|
+
|
36
|
+
/**********************************************************************/
|
37
|
+
|
38
|
+
VALUE
|
39
|
+
rbgutil_protect(VALUE (*func) (VALUE), VALUE data)
|
40
|
+
{
|
41
|
+
int state = 0;
|
42
|
+
VALUE ret = rb_protect(func, data, &state);
|
43
|
+
VALUE e = rb_errinfo();
|
44
|
+
if (state && !NIL_P(e))
|
45
|
+
rb_funcall(mGLib, id_exit_application, 2, e, INT2NUM(EXIT_FAILURE));
|
46
|
+
return ret;
|
47
|
+
}
|
48
|
+
|
49
|
+
/**********************************************************************/
|
50
|
+
|
51
|
+
#ifdef HAVE_NATIVETHREAD
|
52
|
+
|
53
|
+
typedef struct _CallbackRequest {
|
54
|
+
VALUE (*function)(VALUE);
|
55
|
+
VALUE argument;
|
56
|
+
VALUE result;
|
57
|
+
GMutex *done_mutex;
|
58
|
+
GCond *done_cond;
|
59
|
+
} CallbackRequest;
|
60
|
+
|
61
|
+
static GMutex *callback_dispatch_thread_mutex = NULL;
|
62
|
+
static GAsyncQueue *callback_request_queue = NULL;
|
63
|
+
static ID id_callback_dispatch_thread;
|
64
|
+
static gint callback_pipe_fds[2] = {-1, -1};
|
65
|
+
|
66
|
+
#define CALLBACK_PIPE_READY_MESSAGE "R"
|
67
|
+
#define CALLBACK_PIPE_READY_MESSAGE_SIZE 1
|
68
|
+
|
69
|
+
static VALUE
|
70
|
+
exec_callback(VALUE data)
|
71
|
+
{
|
72
|
+
CallbackRequest *request = (CallbackRequest *)data;
|
73
|
+
return request->function(request->argument);
|
74
|
+
}
|
75
|
+
|
76
|
+
static VALUE
|
77
|
+
process_request(CallbackRequest *request)
|
78
|
+
{
|
79
|
+
g_mutex_lock(request->done_mutex);
|
80
|
+
request->result = rbgutil_protect(exec_callback, (VALUE)request);
|
81
|
+
g_cond_signal(request->done_cond);
|
82
|
+
g_mutex_unlock(request->done_mutex);
|
83
|
+
|
84
|
+
return Qnil;
|
85
|
+
}
|
86
|
+
|
87
|
+
static VALUE
|
88
|
+
mainloop(void)
|
89
|
+
{
|
90
|
+
for (;;) {
|
91
|
+
CallbackRequest *request;
|
92
|
+
gchar ready_message_buffer[CALLBACK_PIPE_READY_MESSAGE_SIZE];
|
93
|
+
|
94
|
+
rb_thread_wait_fd(callback_pipe_fds[0]);
|
95
|
+
if (read(callback_pipe_fds[0], ready_message_buffer,
|
96
|
+
CALLBACK_PIPE_READY_MESSAGE_SIZE
|
97
|
+
) != CALLBACK_PIPE_READY_MESSAGE_SIZE ||
|
98
|
+
strncmp(ready_message_buffer,
|
99
|
+
CALLBACK_PIPE_READY_MESSAGE,
|
100
|
+
CALLBACK_PIPE_READY_MESSAGE_SIZE) != 0) {
|
101
|
+
g_error("failed to read valid callback dispatcher message");
|
102
|
+
continue;
|
103
|
+
}
|
104
|
+
request = g_async_queue_pop(callback_request_queue);
|
105
|
+
if (!request)
|
106
|
+
break;
|
107
|
+
|
108
|
+
rb_thread_create(process_request, request);
|
109
|
+
}
|
110
|
+
|
111
|
+
close(callback_pipe_fds[0]);
|
112
|
+
callback_pipe_fds[0] = -1;
|
113
|
+
close(callback_pipe_fds[1]);
|
114
|
+
callback_pipe_fds[1] = -1;
|
115
|
+
|
116
|
+
return Qnil;
|
117
|
+
}
|
118
|
+
|
119
|
+
static void
|
120
|
+
queue_callback_request(CallbackRequest *request)
|
121
|
+
{
|
122
|
+
g_async_queue_push(callback_request_queue, request);
|
123
|
+
write(callback_pipe_fds[1],
|
124
|
+
CALLBACK_PIPE_READY_MESSAGE,
|
125
|
+
CALLBACK_PIPE_READY_MESSAGE_SIZE);
|
126
|
+
}
|
127
|
+
|
128
|
+
static VALUE
|
129
|
+
invoke_callback_in_ruby_thread(VALUE (*func)(VALUE), VALUE arg)
|
130
|
+
{
|
131
|
+
CallbackRequest request;
|
132
|
+
|
133
|
+
g_mutex_lock(callback_dispatch_thread_mutex);
|
134
|
+
if (callback_pipe_fds[0] == -1) {
|
135
|
+
g_error("Please call rbgutil_start_callback_dispatch_thread() "
|
136
|
+
"to dispatch a callback from non-ruby thread before "
|
137
|
+
"callbacks are requested from non-ruby thread.");
|
138
|
+
g_mutex_unlock(callback_dispatch_thread_mutex);
|
139
|
+
return Qnil;
|
140
|
+
}
|
141
|
+
|
142
|
+
request.function = func;
|
143
|
+
request.argument = arg;
|
144
|
+
request.result = Qnil;
|
145
|
+
request.done_mutex = g_mutex_new();
|
146
|
+
request.done_cond = g_cond_new();
|
147
|
+
|
148
|
+
g_mutex_lock(request.done_mutex);
|
149
|
+
queue_callback_request(&request);
|
150
|
+
g_mutex_unlock(callback_dispatch_thread_mutex);
|
151
|
+
|
152
|
+
g_cond_wait(request.done_cond, request.done_mutex);
|
153
|
+
g_mutex_unlock(request.done_mutex);
|
154
|
+
|
155
|
+
g_cond_free(request.done_cond);
|
156
|
+
g_mutex_free(request.done_mutex);
|
157
|
+
|
158
|
+
|
159
|
+
return request.result;
|
160
|
+
}
|
161
|
+
#endif
|
162
|
+
|
163
|
+
/**********************************************************************/
|
164
|
+
|
165
|
+
VALUE
|
166
|
+
rbgutil_invoke_callback(VALUE (*func)(VALUE), VALUE arg)
|
167
|
+
{
|
168
|
+
#ifdef HAVE_NATIVETHREAD
|
169
|
+
if (!ruby_native_thread_p()) {
|
170
|
+
return invoke_callback_in_ruby_thread(func, arg);
|
171
|
+
}
|
172
|
+
#endif
|
173
|
+
return rbgutil_protect(func, arg);
|
174
|
+
}
|
175
|
+
|
176
|
+
/**********************************************************************/
|
177
|
+
|
178
|
+
void
|
179
|
+
rbgutil_start_callback_dispatch_thread(void)
|
180
|
+
{
|
181
|
+
#ifdef HAVE_NATIVETHREAD
|
182
|
+
VALUE callback_dispatch_thread;
|
183
|
+
|
184
|
+
g_mutex_lock(callback_dispatch_thread_mutex);
|
185
|
+
callback_dispatch_thread = rb_ivar_get(mGLib, id_callback_dispatch_thread);
|
186
|
+
if (NIL_P(callback_dispatch_thread)) {
|
187
|
+
if (pipe(callback_pipe_fds) == -1)
|
188
|
+
rb_sys_fail("pipe()");
|
189
|
+
|
190
|
+
callback_dispatch_thread = rb_thread_create(mainloop, NULL);
|
191
|
+
rb_ivar_set(mGLib, id_callback_dispatch_thread,
|
192
|
+
callback_dispatch_thread);
|
193
|
+
}
|
194
|
+
g_mutex_unlock(callback_dispatch_thread_mutex);
|
195
|
+
#endif
|
196
|
+
}
|
197
|
+
|
198
|
+
void
|
199
|
+
rbgutil_stop_callback_dispatch_thread(void)
|
200
|
+
{
|
201
|
+
#ifdef HAVE_NATIVETHREAD
|
202
|
+
VALUE callback_dispatch_thread;
|
203
|
+
|
204
|
+
g_mutex_lock(callback_dispatch_thread_mutex);
|
205
|
+
callback_dispatch_thread = rb_ivar_get(mGLib, id_callback_dispatch_thread);
|
206
|
+
if (!NIL_P(callback_dispatch_thread)) {
|
207
|
+
queue_callback_request(NULL);
|
208
|
+
rb_ivar_set(mGLib, id_callback_dispatch_thread, Qnil);
|
209
|
+
}
|
210
|
+
g_mutex_unlock(callback_dispatch_thread_mutex);
|
211
|
+
#endif
|
212
|
+
}
|
213
|
+
|
214
|
+
void Init_gutil_callback()
|
215
|
+
{
|
216
|
+
id_exit_application = rb_intern("exit_application");
|
217
|
+
rbgutil_eGLibCallbackNotInitializedError =
|
218
|
+
rb_define_class_under(mGLib, "CallbackNotInitializedError",
|
219
|
+
rb_eRuntimeError);
|
220
|
+
|
221
|
+
#ifdef HAVE_NATIVETHREAD
|
222
|
+
if (!g_thread_supported())
|
223
|
+
g_thread_init(NULL);
|
224
|
+
|
225
|
+
id_callback_dispatch_thread = rb_intern("callback_dispatch_thread");
|
226
|
+
rb_ivar_set(mGLib, id_callback_dispatch_thread, Qnil);
|
227
|
+
|
228
|
+
callback_request_queue = g_async_queue_new();
|
229
|
+
callback_dispatch_thread_mutex = g_mutex_new();
|
230
|
+
#endif
|
231
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module GLibTestUtils
|
2
|
+
private
|
3
|
+
def only_glib_version(major, minor, micro)
|
4
|
+
unless GLib.check_version?(major, minor, micro)
|
5
|
+
omit("Require GLib >= #{major}.#{minor}.#{micro}")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def only_win32
|
10
|
+
omit("Only for Win32 platform") unless GLib.os_win32?
|
11
|
+
end
|
12
|
+
end
|
data/test/run-test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
base = File.expand_path(File.join(File.dirname(__FILE__)))
|
4
|
+
top = File.expand_path(File.join(base, ".."))
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(top)
|
7
|
+
require 'test/glib-test-init'
|
8
|
+
|
9
|
+
if system("which make > /dev/null")
|
10
|
+
system("cd #{top.dump} && make > /dev/null") or exit(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(top, "src"))
|
14
|
+
$LOAD_PATH.unshift(File.join(top, "src", "lib"))
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift(base)
|
17
|
+
require 'glib-test-utils'
|
18
|
+
|
19
|
+
require 'glib2'
|
20
|
+
|
21
|
+
if !defined?(Test::Unit::AutoRunner)
|
22
|
+
require 'test-unit'
|
23
|
+
end
|
24
|
+
|
25
|
+
exit Test::Unit::AutoRunner.run(true, base)
|
data/test/test_enum.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require 'glib2'
|
4
|
+
|
5
|
+
class TestEnum < Test::Unit::TestCase
|
6
|
+
def test_enum_by_symbol
|
7
|
+
original = [0x00c1].pack("U*") # A with acute
|
8
|
+
|
9
|
+
assert_equal(GLib::UTF8.normalize(original, GLib::NormalizeMode::NFD),
|
10
|
+
GLib::UTF8.normalize(original, :nfd))
|
11
|
+
assert_equal(GLib::UTF8.normalize(original, GLib::NormalizeMode::NFD),
|
12
|
+
GLib::UTF8.normalize(original, :NFD))
|
13
|
+
|
14
|
+
assert_raise(TypeError) do
|
15
|
+
GLib::UTF8.normalize(original, :unknown)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_enum_by_string
|
20
|
+
original = [0x00c1].pack("U*") # A with acute
|
21
|
+
|
22
|
+
assert_equal(GLib::UTF8.normalize(original, GLib::NormalizeMode::NFD),
|
23
|
+
GLib::UTF8.normalize(original, "nfd"))
|
24
|
+
assert_equal(GLib::UTF8.normalize(original, GLib::NormalizeMode::NFD),
|
25
|
+
GLib::UTF8.normalize(original, "NFD"))
|
26
|
+
|
27
|
+
assert_raise(TypeError) do
|
28
|
+
GLib::UTF8.normalize(original, "unknown")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_flags_simple
|
33
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS, :keep_comments)
|
34
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS, :KEEP_COMMENTS)
|
35
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS, "keep_comments")
|
36
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS, "KEEP_COMMENTS")
|
37
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS, "keep COMMENTS")
|
38
|
+
|
39
|
+
assert_raise(TypeError) do
|
40
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS, :unknown)
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_raise(TypeError) do
|
44
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS, "UNKNOWN")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_flags_by_array
|
49
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS |
|
50
|
+
GLib::KeyFile::KEEP_TRANSLATIONS,
|
51
|
+
[:keep_comments, :keep_translations])
|
52
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS |
|
53
|
+
GLib::KeyFile::KEEP_TRANSLATIONS,
|
54
|
+
[:keep_COMMENTS, "KEEP_TRANSLATIONS"])
|
55
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS |
|
56
|
+
GLib::KeyFile::KEEP_TRANSLATIONS,
|
57
|
+
["keep_comments", "KEEP_translations"])
|
58
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS |
|
59
|
+
GLib::KeyFile::KEEP_TRANSLATIONS,
|
60
|
+
[:keep_comments, GLib::KeyFile::KEEP_TRANSLATIONS])
|
61
|
+
|
62
|
+
assert_raise(TypeError) do
|
63
|
+
assert_key_file_load(GLib::KeyFile::KEEP_COMMENTS |
|
64
|
+
GLib::KeyFile::KEEP_TRANSLATIONS,
|
65
|
+
[:keep_comments, nil, :keep_translations])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_flags_or
|
70
|
+
assert_equal(GLib::KeyFile::KEEP_COMMENTS,
|
71
|
+
GLib::KeyFile::KEEP_COMMENTS | [])
|
72
|
+
assert_equal(GLib::KeyFile::KEEP_COMMENTS |
|
73
|
+
GLib::KeyFile::KEEP_TRANSLATIONS ,
|
74
|
+
GLib::KeyFile::KEEP_COMMENTS | [:keep_translations])
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
def assert_key_file_load(flags, convenience_flags)
|
79
|
+
data = <<-EOD
|
80
|
+
[SECTION]
|
81
|
+
KEY=VALUE
|
82
|
+
# comment
|
83
|
+
|
84
|
+
KEY[ja]=値
|
85
|
+
EOD
|
86
|
+
|
87
|
+
expected_key_file = GLib::KeyFile.new
|
88
|
+
expected_key_file.load_from_data(data, flags)
|
89
|
+
|
90
|
+
actual_key_file = GLib::KeyFile.new
|
91
|
+
actual_key_file.load_from_data(data, convenience_flags)
|
92
|
+
|
93
|
+
assert_equal(expected_key_file.get_value("SECTION", "KEY"),
|
94
|
+
actual_key_file.get_value("SECTION", "KEY"))
|
95
|
+
|
96
|
+
assert_equal(expected_key_file.to_data,
|
97
|
+
actual_key_file.to_data)
|
98
|
+
end
|
99
|
+
end
|