fishman-uuid4r 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +41 -0
  2. data/ext/extconf.rb +17 -0
  3. data/ext/uuid4r.c +457 -0
  4. data/test/test_uuid.rb +120 -0
  5. metadata +74 -0
data/README ADDED
@@ -0,0 +1,41 @@
1
+ UUID4R
2
+ ======
3
+
4
+ This library generates and parses Universally Unique Identifier (UUID),
5
+ based on OSSP uuid C library. So, libossp-uuid library is pre-required.
6
+ OSSP uuid (http://www.ossp.org/pkg/lib/uuid/) is a ISO-C:1999 application
7
+ programming interface (API) for the generation of DCE 1.1, ISO/IEC
8
+ 11578:1996 and RFC 4122 compliant UUID. It supports DCE 1.1 variant UUIDs
9
+ of version 1 (time and node based), version 3 (name based, MD5), version 4
10
+ (random number based) and version 5 (name based, SHA-1).
11
+
12
+
13
+ PRE-REQUIRES
14
+ ============
15
+
16
+ OSSP uuid library is required to build and run UUID4R.
17
+
18
+
19
+ INSTALL
20
+ =======
21
+
22
+ $ cd ext
23
+ $ ruby extconf.rb
24
+ $ make
25
+ $ sudo make install
26
+
27
+
28
+ SAMPLE
29
+ ======
30
+
31
+ require 'uuid4r'
32
+ puts UUID4R::uuid(1)
33
+ puts UUID4R::uuid_v1
34
+ puts UUID4R::uuid(1, :str)
35
+ puts UUID4R::uuid(1, :bin)
36
+ puts UUID4R::uuid(1, :txt)
37
+ puts UUID4R::uuid_v1(:str)
38
+ puts UUID4R::uuid_v1(:bin)
39
+ puts UUID4R::uuid_v1(:txt)
40
+ puts UUID4R::uuid_v3("ns:URL", "www.sgtpepper.net")
41
+
@@ -0,0 +1,17 @@
1
+ require 'mkmf'
2
+
3
+ if File.exist?(`which uuid-config`.chomp)
4
+ $CFLAGS << " -Wall " << `uuid-config --cflags`.chomp
5
+ $LDFLAGS << " " << `uuid-config --ldflags`.chomp
6
+ end
7
+
8
+ if !have_library('ossp-uuid')
9
+ puts "OSSP uuid library required -- not found."
10
+ exit 1
11
+ end
12
+ create_makefile('uuid4r')
13
+ File.open("Makefile", "a") << <<-EOT
14
+
15
+ check: $(DLLIB)
16
+ @$(RUBY) #{File.dirname(__FILE__)}/../test/test_uuid.rb
17
+ EOT
@@ -0,0 +1,457 @@
1
+ /*
2
+ * COPYRIGHT AND LICENSE
3
+ *
4
+ * Copyright (C) 2006 Daigo Moriwaki <daigo@debian.org>
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for
7
+ * any purpose with or without fee is hereby granted, provided that
8
+ * the above copyright notice and this permission notice appear in all
9
+ * copies.
10
+ *
11
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
12
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
14
+ * IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
15
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
17
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
21
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ * SUCH DAMAGE.
23
+ *
24
+ */
25
+
26
+ #include "ruby.h"
27
+ #include "uuid.h"
28
+
29
+ VALUE rb_cUUID4R;
30
+ VALUE rb_cUUID4RCommon;
31
+ VALUE rb_cUUID4Rv1;
32
+ VALUE rb_cUUID4Rv3;
33
+ VALUE rb_cUUID4Rv4;
34
+ VALUE rb_cUUID4Rv5;
35
+ /* symbols */
36
+ ID id_fmt_bin, id_fmt_str, id_fmt_txt;
37
+
38
+ static uuid_fmt_t
39
+ rb2uuid_fmt(symbol)
40
+ VALUE symbol;
41
+ {
42
+ ID fmt;
43
+ uuid_fmt_t result;
44
+
45
+ fmt = rb_to_id(symbol);
46
+ if (fmt == id_fmt_bin)
47
+ result = UUID_FMT_BIN;
48
+ else if (fmt == id_fmt_str)
49
+ result = UUID_FMT_STR;
50
+ else if (fmt == id_fmt_txt)
51
+ result = UUID_FMT_TXT;
52
+ else
53
+ rb_raise(rb_eArgError, "wrong argument");
54
+
55
+ return result;
56
+ }
57
+
58
+ static VALUE
59
+ export(uuid, fmt)
60
+ const uuid_t *uuid;
61
+ uuid_fmt_t fmt;
62
+ {
63
+ uuid_rc_t rc;
64
+ char *str;
65
+ char *ptr; //uuid_uint8_t
66
+ VALUE result;
67
+
68
+ str = NULL;
69
+ ptr = NULL;
70
+
71
+ /* dispatch into format-specific functions */
72
+ switch (fmt) {
73
+ case UUID_FMT_BIN:
74
+ rc = uuid_export(uuid, fmt, (void **)&ptr, NULL);
75
+ result = rb_str_new(ptr, UUID_LEN_BIN);
76
+ free(ptr);
77
+ break;
78
+ case UUID_FMT_STR:
79
+ rc = uuid_export(uuid, fmt, (void **)&str, NULL);
80
+ result = rb_str_new2(str);
81
+ free(str);
82
+ break;
83
+ case UUID_FMT_TXT:
84
+ rc = uuid_export(uuid, fmt, (void **)&str, NULL);
85
+ result = rb_str_new2(str);
86
+ free(str);
87
+ break;
88
+ default:
89
+ rb_raise(rb_eArgError, "wrong argument");
90
+ }
91
+
92
+ return result;
93
+ }
94
+
95
+
96
+
97
+
98
+ static void
99
+ uuid4r_free(uuid)
100
+ uuid_t *uuid;
101
+ {
102
+ uuid_destroy(uuid);
103
+ }
104
+
105
+ static VALUE
106
+ uuid4r_alloc(klass)
107
+ VALUE klass;
108
+ {
109
+ VALUE obj;
110
+ uuid_t *uuid;
111
+
112
+ uuid_create(&uuid);
113
+ obj = Data_Wrap_Struct(klass, 0, uuid4r_free, uuid);
114
+
115
+ return obj;
116
+ }
117
+
118
+ /* UUID4R common */
119
+
120
+ VALUE
121
+ uuid4r_compare(lhs, rhs)
122
+ VALUE lhs, rhs;
123
+ {
124
+ const uuid_t *uuid_lhs;
125
+ const uuid_t *uuid_rhs;
126
+ int value;
127
+
128
+ Data_Get_Struct(lhs, uuid_t, uuid_lhs);
129
+ Data_Get_Struct(rhs, uuid_t, uuid_rhs);
130
+ uuid_compare(uuid_lhs, uuid_rhs, &value);
131
+
132
+ return INT2NUM(value);
133
+ }
134
+
135
+ VALUE
136
+ uuid4r_export(argc, argv, self)
137
+ int argc;
138
+ VALUE *argv;
139
+ VALUE self;
140
+ {
141
+ VALUE format;
142
+ uuid_fmt_t fmt;
143
+ uuid_t *uuid;
144
+
145
+ if ( rb_scan_args(argc, argv, "01", &format) == 1)
146
+ fmt = rb2uuid_fmt(format);
147
+ else
148
+ fmt = UUID_FMT_STR;
149
+
150
+ Data_Get_Struct(self, uuid_t, uuid);
151
+
152
+ return export(uuid, fmt);
153
+ }
154
+
155
+ VALUE
156
+ uuid4r_import(self, format, str)
157
+ VALUE self, format, str;
158
+ {
159
+ uuid_fmt_t fmt;
160
+ uuid_t *uuid;
161
+
162
+ uuid_create(&uuid);
163
+ fmt = rb2uuid_fmt(format);
164
+ StringValue(str);
165
+ uuid_import(uuid, fmt, RSTRING_PTR(str), RSTRING_LEN(str));
166
+
167
+ return Data_Wrap_Struct(rb_cUUID4RCommon, 0, uuid4r_free, uuid);
168
+ }
169
+
170
+ /* UUID4Rv1 */
171
+
172
+ VALUE
173
+ uuid4rv1_initialize(self)
174
+ VALUE self;
175
+ {
176
+ uuid_t *uuid;
177
+
178
+ Data_Get_Struct(self, uuid_t, uuid);
179
+ uuid_make(uuid, UUID_MAKE_V1);
180
+
181
+ return self;
182
+ }
183
+
184
+ /* UUID4Rv3 */
185
+
186
+ VALUE
187
+ uuid4rv3_initialize(self, namespace, namespace_str)
188
+ VALUE self;
189
+ VALUE namespace;
190
+ VALUE namespace_str;
191
+ {
192
+ uuid_t *uuid;
193
+ uuid_t *uuid_ns;
194
+ char *uuid_ns_str;
195
+
196
+ uuid_ns = NULL;
197
+ uuid_ns_str = NULL;
198
+ uuid_create(&uuid_ns);
199
+ uuid_load(uuid_ns, StringValueCStr(namespace));
200
+ uuid_ns_str = StringValueCStr(namespace_str);
201
+
202
+ Data_Get_Struct(self, uuid_t, uuid);
203
+ uuid_make(uuid, UUID_MAKE_V5, uuid_ns, uuid_ns_str);
204
+
205
+ return self;
206
+ }
207
+
208
+ /* UUID4Rv4 */
209
+
210
+ VALUE
211
+ uuid4rv4_initialize(self)
212
+ VALUE self;
213
+ {
214
+ uuid_t *uuid;
215
+
216
+ Data_Get_Struct(self, uuid_t, uuid);
217
+ uuid_make(uuid, UUID_MAKE_V4);
218
+
219
+ return self;
220
+ }
221
+
222
+ /* UUID4Rv5 */
223
+
224
+ VALUE
225
+ uuid4rv5_initialize(self, namespace, namespace_str)
226
+ VALUE self;
227
+ VALUE namespace;
228
+ VALUE namespace_str;
229
+ {
230
+ uuid_t *uuid;
231
+ uuid_t *uuid_ns;
232
+ char *uuid_ns_str;
233
+
234
+ uuid_ns = NULL;
235
+ uuid_ns_str = NULL;
236
+ uuid_create(&uuid_ns);
237
+ uuid_load(uuid_ns, StringValueCStr(namespace));
238
+ uuid_ns_str = StringValueCStr(namespace_str);
239
+
240
+ Data_Get_Struct(self, uuid_t, uuid);
241
+ uuid_make(uuid, UUID_MAKE_V5, uuid_ns, uuid_ns_str);
242
+
243
+ return self;
244
+ }
245
+
246
+ /* ------------ */
247
+
248
+ /**
249
+ * call-seq:
250
+ * UUID4R::uuid(1, format = :str) => uuid
251
+ * UUID4R::uuid(3, namespace, namespace_str, format = :str) => uuid
252
+ * UUID4R::uuid(4, format = :str) => uuid
253
+ * UUID4R::uuid(5, namespace, namespace_str, format = :str) => uuid
254
+ *
255
+ * Generates a DCE 1.1 with a specified version: 1, 3, 4 or 5.
256
+ * Returns an uuid as a specified format (:str, :bin, :txt).
257
+ */
258
+ VALUE
259
+ uuid4r_uuid(argc, argv, self)
260
+ int argc;
261
+ VALUE *argv;
262
+ VALUE self;
263
+ {
264
+ VALUE version;
265
+ VALUE format;
266
+ VALUE namespace;
267
+ VALUE namespace_str;
268
+ uuid_t *uuid_ns;
269
+ char *uuid_ns_str;
270
+ uuid_fmt_t fmt;
271
+ unsigned int mode = 0; /* suppress compiler warning */
272
+ uuid_t *uuid;
273
+ VALUE result;
274
+
275
+ uuid_ns = NULL;
276
+ uuid_ns_str = NULL;
277
+
278
+ switch (argc) {
279
+ case 1:
280
+ rb_scan_args(argc, argv, "11", &version, &format);
281
+ fmt = UUID_FMT_STR;
282
+ break;
283
+ case 2:
284
+ rb_scan_args(argc, argv, "11", &version, &format);
285
+ fmt = rb2uuid_fmt(format);
286
+ break;
287
+ case 3:
288
+ rb_scan_args(argc, argv, "31", &version, &namespace, &namespace_str, &format);
289
+ fmt = UUID_FMT_STR;
290
+ break;
291
+ case 4:
292
+ rb_scan_args(argc, argv, "31", &version, &namespace, &namespace_str, &format);
293
+ fmt = rb2uuid_fmt(format);
294
+ break;
295
+ default:
296
+ rb_raise(rb_eArgError, "wrong argument");
297
+ break;
298
+ }
299
+
300
+ switch (NUM2INT(version)) {
301
+ case 1: mode = UUID_MAKE_V1; break;
302
+ case 4: mode = UUID_MAKE_V4; break;
303
+ case 3:
304
+ mode = UUID_MAKE_V3;
305
+ uuid_create(&uuid_ns);
306
+ uuid_load(uuid_ns, StringValueCStr(namespace));
307
+ uuid_ns_str = StringValueCStr(namespace_str);
308
+ break;
309
+ case 5:
310
+ mode = UUID_MAKE_V5;
311
+ uuid_create(&uuid_ns);
312
+ uuid_load(uuid_ns, StringValueCStr(namespace));
313
+ uuid_ns_str = StringValueCStr(namespace_str);
314
+ break;
315
+ }
316
+ uuid_create(&uuid);
317
+ uuid_make(uuid, mode, uuid_ns, uuid_ns_str);
318
+ result = export(uuid, fmt);
319
+ if (uuid_ns)
320
+ uuid_destroy(uuid_ns);
321
+ uuid_destroy(uuid);
322
+
323
+ return result;
324
+ }
325
+
326
+ /**
327
+ * call-seq:
328
+ * UUID4R::uuid_v1(format = :str) => uuid
329
+ *
330
+ * Generates a DCE 1.1 v1 UUID from system environment.
331
+ * Returns an uuid as a specified format (:str, :bin, :txt).
332
+ */
333
+ VALUE
334
+ uuid4r_uuid_v1(argc, argv, self)
335
+ int argc;
336
+ VALUE *argv;
337
+ VALUE self;
338
+ {
339
+ VALUE rest;
340
+
341
+ if ( rb_scan_args(argc, argv, "01", &rest) == 1)
342
+ return rb_funcall(self, rb_intern("uuid"), 2, INT2NUM(1), rest);
343
+ else
344
+ return rb_funcall(self, rb_intern("uuid"), 1, INT2NUM(1));
345
+ }
346
+
347
+ /**
348
+ * call-seq:
349
+ * UUID4R::uuid_v4(format = :str) => uuid
350
+ *
351
+ * Generates a DCE 1.1 v4 UUID based a random number.
352
+ * Returns an uuid as a specified format (:str, :bin, :txt).
353
+ */
354
+ VALUE
355
+ uuid4r_uuid_v4(argc, argv, self)
356
+ int argc;
357
+ VALUE *argv;
358
+ VALUE self;
359
+ {
360
+ VALUE rest;
361
+
362
+ if ( rb_scan_args(argc, argv, "01", &rest) == 1)
363
+ return rb_funcall(self, rb_intern("uuid"), 2, INT2NUM(4), rest);
364
+ else
365
+ return rb_funcall(self, rb_intern("uuid"), 1, INT2NUM(4));
366
+ }
367
+
368
+ /**
369
+ * call-seq:
370
+ * UUID4R::uuid_v3(namespace, namespace_str, format = :str) => uuid
371
+ *
372
+ * Generates a DCE 1.1 v3 UUID with a name based with MD5.
373
+ * Returns an uuid as a specified format (:str, :bin, :txt).
374
+ */
375
+ VALUE
376
+ uuid4r_uuid_v3(argc, argv, self)
377
+ int argc;
378
+ VALUE *argv;
379
+ VALUE self;
380
+ {
381
+ VALUE namespace, namespace_str;
382
+ VALUE rest;
383
+
384
+ if ( rb_scan_args(argc, argv, "21", &namespace, &namespace_str, &rest) == 3)
385
+ return rb_funcall(self, rb_intern("uuid"), 4,
386
+ INT2NUM(3), namespace, namespace_str, rest);
387
+ else
388
+ return rb_funcall(self, rb_intern("uuid"), 3,
389
+ INT2NUM(3), namespace, namespace_str);
390
+ }
391
+
392
+ /**
393
+ * call-seq:
394
+ * UUID4R::uuid_v5(namespace, namespace_str, format = :str) => uuid
395
+ *
396
+ * Generates a DCE 1.1 v5 UUID with a name based with SHA-1.
397
+ * Returns an uuid as a specified format (:str, :bin, :txt).
398
+ */
399
+ VALUE
400
+ uuid4r_uuid_v5(argc, argv, self)
401
+ int argc;
402
+ VALUE *argv;
403
+ VALUE self;
404
+ {
405
+ VALUE namespace, namespace_str;
406
+ VALUE rest;
407
+
408
+ if ( rb_scan_args(argc, argv, "21", &namespace, &namespace_str, &rest) == 3)
409
+ return rb_funcall(self, rb_intern("uuid"), 4,
410
+ INT2NUM(5), namespace, namespace_str, rest);
411
+ else
412
+ return rb_funcall(self, rb_intern("uuid"), 3,
413
+ INT2NUM(5), namespace, namespace_str);
414
+ }
415
+
416
+
417
+ void Init_uuid4r (void) {
418
+ /* regist symbols */
419
+ id_fmt_bin = rb_intern("bin");
420
+ id_fmt_str = rb_intern("str");
421
+ id_fmt_txt = rb_intern("txt");
422
+
423
+ /* ------ UUID4R ------ */
424
+ rb_cUUID4R = rb_define_class("UUID4R", rb_cObject);
425
+ /* utilities */
426
+ rb_define_module_function(rb_cUUID4R, "uuid", uuid4r_uuid, -1);
427
+ rb_define_module_function(rb_cUUID4R, "uuid_v1", uuid4r_uuid_v1, -1);
428
+ rb_define_module_function(rb_cUUID4R, "uuid_v3", uuid4r_uuid_v3, -1);
429
+ rb_define_module_function(rb_cUUID4R, "uuid_v4", uuid4r_uuid_v4, -1);
430
+ rb_define_module_function(rb_cUUID4R, "uuid_v5", uuid4r_uuid_v5, -1);
431
+ rb_define_module_function(rb_cUUID4R, "import", uuid4r_import, 2);
432
+
433
+ /* ------ UUID4RCommon ------ */
434
+ rb_cUUID4RCommon = rb_define_class_under(rb_cUUID4R, "UUID4RCommon", rb_cObject);
435
+ rb_define_alloc_func(rb_cUUID4RCommon, uuid4r_alloc);
436
+ rb_define_method(rb_cUUID4RCommon, "export", uuid4r_export, -1);
437
+ rb_define_method(rb_cUUID4RCommon, "compare", uuid4r_compare, 1);
438
+ rb_define_alias(rb_cUUID4RCommon, "<=>", "compare");
439
+
440
+ /* ------ UUID4Rv1 ------ */
441
+ rb_cUUID4Rv1 = rb_define_class_under(rb_cUUID4R, "UUID4Rv1", rb_cUUID4RCommon);
442
+ rb_define_alloc_func(rb_cUUID4Rv1, uuid4r_alloc);
443
+ rb_define_method(rb_cUUID4Rv1, "initialize", uuid4rv1_initialize, 0);
444
+ /* ------ UUID4Rv3 ------ */
445
+ rb_cUUID4Rv3 = rb_define_class_under(rb_cUUID4R, "UUID4Rv3", rb_cUUID4RCommon);
446
+ rb_define_alloc_func(rb_cUUID4Rv3, uuid4r_alloc);
447
+ rb_define_method(rb_cUUID4Rv3, "initialize", uuid4rv3_initialize, 2);
448
+ /* ------ UUID4Rv4 ------ */
449
+ rb_cUUID4Rv4 = rb_define_class_under(rb_cUUID4R, "UUID4Rv4", rb_cUUID4RCommon);
450
+ rb_define_alloc_func(rb_cUUID4Rv4, uuid4r_alloc);
451
+ rb_define_method(rb_cUUID4Rv4, "initialize", uuid4rv4_initialize, 0);
452
+ /* ------ UUID4Rv5 ------ */
453
+ rb_cUUID4Rv5 = rb_define_class_under(rb_cUUID4R, "UUID4Rv5", rb_cUUID4RCommon);
454
+ rb_define_alloc_func(rb_cUUID4Rv5, uuid4r_alloc);
455
+ rb_define_method(rb_cUUID4Rv5, "initialize", uuid4rv5_initialize, 2);
456
+ }
457
+
@@ -0,0 +1,120 @@
1
+ require 'test/unit'
2
+ require 'uuid4r.so'
3
+
4
+ class UUIDTest < Test::Unit::TestCase
5
+ def test_uuid_v1_default
6
+ assert_kind_of(String, UUID4R::uuid_v1)
7
+ assert_kind_of(String, UUID4R::uuid(1))
8
+ end
9
+
10
+ def test_uuid_v4_default
11
+ assert_kind_of(String, UUID4R::uuid_v4)
12
+ assert_kind_of(String, UUID4R::uuid(4))
13
+ end
14
+
15
+ def test_uuid_v1_str
16
+ assert_kind_of(String, UUID4R::uuid_v1(:str))
17
+ assert(UUID4R::uuid_v1(:str).length > 0)
18
+ assert_not_equal(UUID4R::uuid_v1(:str), UUID4R::uuid_v1(:str))
19
+ end
20
+
21
+ def test_uuid_v1_bin
22
+ assert_kind_of(String, UUID4R::uuid_v1(:bin))
23
+ assert_equal(16, UUID4R::uuid_v1(:bin).length)
24
+ end
25
+
26
+ def test_uuid_v1_txt
27
+ assert_kind_of(String, UUID4R::uuid_v1(:txt))
28
+ assert(/variant: DCE 1.1/ =~ UUID4R::uuid_v1(:txt))
29
+ assert(/version: 1/ =~ UUID4R::uuid_v1(:txt))
30
+ assert(/content:/ =~ UUID4R::uuid_v1(:txt))
31
+ end
32
+
33
+ def test_uuid_v3_str
34
+ a = UUID4R::uuid(3, "ns:URL", "www.sgtpepper.net", :str)
35
+ b = UUID4R::uuid(3, "ns:URL", "www.sgtpepper.net", :str)
36
+ c = UUID4R::uuid_v3("ns:URL", "www.sgtpepper.net", :str)
37
+ d = UUID4R::uuid_v3("ns:URL", "www.sgtpepper.net")
38
+ assert_kind_of(String, a)
39
+ assert(a.length > 0)
40
+ assert_equal(a, b)
41
+ assert_equal(a, c)
42
+ assert_equal(a, d)
43
+ end
44
+
45
+ def test_uuid_v5_str
46
+ a = UUID4R::uuid(5, "ns:URL", "www.sgtpepper.net", :str)
47
+ b = UUID4R::uuid(5, "ns:URL", "www.sgtpepper.net", :str)
48
+ c = UUID4R::uuid_v5("ns:URL", "www.sgtpepper.net", :str)
49
+ d = UUID4R::uuid_v5("ns:URL", "www.sgtpepper.net")
50
+ assert_kind_of(String, a)
51
+ assert(a.length > 0)
52
+ assert_equal(a, b)
53
+ assert_equal(a, c)
54
+ assert_equal(a, d)
55
+ end
56
+
57
+ def test_import
58
+ uuid = UUID4R::import(:str, "266eb9ae-ea6e-11da-8113-0030134d803d")
59
+ assert_kind_of(UUID4R::UUID4RCommon, uuid)
60
+ end
61
+ end
62
+
63
+
64
+ class UUID4Rv1Test < Test::Unit::TestCase
65
+ def setup
66
+ @uuid = UUID4R::UUID4Rv1.new
67
+ end
68
+
69
+ def test_export_str
70
+ assert_kind_of(String, @uuid.export(:str))
71
+ assert_equal(@uuid.export, @uuid.export(:str))
72
+ end
73
+
74
+ def test_compare
75
+ uuid2 = UUID4R::UUID4Rv1.new
76
+ assert(@uuid.compare(uuid2) == -1)
77
+ assert(@uuid.compare(@uuid) == 0)
78
+ assert(uuid2.compare(@uuid) == 1)
79
+ assert_equal(-1, @uuid <=> uuid2)
80
+ assert_equal( 0, @uuid <=> @uuid)
81
+ assert_equal( 1, uuid2 <=> @uuid)
82
+ end
83
+ end
84
+
85
+
86
+ class UUID4Rv4Test < Test::Unit::TestCase
87
+ def setup
88
+ @uuid = UUID4R::UUID4Rv4.new
89
+ end
90
+
91
+ def test_export_str
92
+ assert_kind_of(String, @uuid.export(:str))
93
+ assert_equal(@uuid.export, @uuid.export(:str))
94
+ end
95
+ end
96
+
97
+
98
+ class UUID4Rv3Test < Test::Unit::TestCase
99
+ def setup
100
+ @uuid = UUID4R::UUID4Rv3.new("ns:URL", "www.sgtpepper.net")
101
+ end
102
+
103
+ def test_export_str
104
+ assert_kind_of(String, @uuid.export(:str))
105
+ assert_equal(@uuid.export, @uuid.export(:str))
106
+ end
107
+ end
108
+
109
+
110
+ class UUID4Rv5Test < Test::Unit::TestCase
111
+ def setup
112
+ @uuid = UUID4R::UUID4Rv5.new("ns:URL", "www.sgtpepper.net")
113
+ end
114
+
115
+ def test_export_str
116
+ assert_kind_of(String, @uuid.export(:str))
117
+ assert_equal(@uuid.export, @uuid.export(:str))
118
+ end
119
+ end
120
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fishman-uuid4r
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Daigo Moriwaki
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-05 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: " This library generates and parses Universally Unique Identifier (UUID),\n based on OSSP uuid C library. So, libossp-uuid library is pre-required.\n OSSP uuid (http://www.ossp.org/pkg/lib/uuid/) is a ISO-C:1999 application\n programming interface (API) for the generation of DCE 1.1, ISO/IEC\n 11578:1996 and RFC 4122 compliant UUID. It supports DCE 1.1 variant UUIDs\n of version 1 (time and node based), version 3 (name based, MD5), version 4\n (random number based) and version 5 (name based, SHA-1).\n"
23
+ email: daigo@debian.org
24
+ executables: []
25
+
26
+ extensions:
27
+ - ext/extconf.rb
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - ext/extconf.rb
32
+ - ext/uuid4r.c
33
+ - test/test_uuid.rb
34
+ - README
35
+ has_rdoc: true
36
+ homepage: http://uuid4r.rubyforge.org
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --title
42
+ - UUID4R
43
+ - --main
44
+ - README
45
+ - --line-numbers
46
+ require_paths:
47
+ - .
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: This generates and parses UUID, based on OSSP uuid C library.
73
+ test_files:
74
+ - test/test_uuid.rb