libuuidrb 0.1.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Sebastian Ohm. All rights reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ Manifest
3
+ README
4
+ Rakefile
5
+ ext/extconf.rb
6
+ ext/lib_uuid.c
7
+ ext/lib_uuid.h
8
+ ext/uuid_base64.c
9
+ ext/uuid_base64.h
10
+ libuuidrb.gemspec
11
+ test/test_compatibility.rb
12
+ test/test_functionality.rb
data/README ADDED
@@ -0,0 +1,36 @@
1
+ libuuidrb uses e2fsprogs'[1] libuuid (<uuid/uuid.h>) to generate DCE
2
+ compatible universally unique identifiers.
3
+
4
+ 0. prerequesites
5
+
6
+ $ irb
7
+ >> require 'lib_uuid'
8
+
9
+ 1. generating
10
+
11
+ >> u = LibUUID::UUID.new
12
+ => #<LibUUID::UUID:0x969decc>
13
+ >> u.to_guid # => "965555c1-2860-47f5-a3f5-a9c83a3b0b5e"
14
+ >> u.to_short_guid # => "llVVwShgR_Wj9anIOjsLXg"
15
+
16
+ or
17
+
18
+ >> LibUUID::UUID.guid # => "ca220b11-a974-4c1d-99d1-78c32d997848"
19
+ >> LibUUID::UUID.short_guid # => "8fPommPCQ7y1BSh55d7kFw"
20
+
21
+ 2. parsing
22
+
23
+ >> v = LibUUID::UUID.new(u.to_guid) # => #<LibUUID::UUID:0x9696b2c>
24
+ >> w = LibUUID::UUID.new(u.to_short_guid) # => #<LibUUID::UUID:0x9693684>
25
+ >> u == v # => true
26
+ >> u == w # => true
27
+
28
+ 3. validating
29
+
30
+ >> LibUUID::UUID.valid? u.to_guid # => true
31
+ >> LibUUID::UUID.valid? v.to_short_guid # => true
32
+ >> LibUUID::UUID.valid? u.to_guid, v.to_guid, w.to_short_guid # => true
33
+ >> LibUUID::UUID.valid? 'foo' # => false
34
+
35
+
36
+ [1] http://e2fsprogs.sourceforge.net/
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ begin
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+
6
+ Echoe.new('libuuidrb', '0.1.0') do |p|
7
+ p.author = 'Sebastian Ohm'
8
+ p.url = 'http://github.com/ohm/libuuidrb'
9
+ p.description = 'libuuidrb uses libuuid to generate DCE compatible universally unique identifiers'
10
+ p.ignore_pattern = ['tmp/*', 'script/*', 'benchmark/*']
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ desc 'valgrind functional tests'
15
+ task :valgrind do
16
+ opts = %W(
17
+ --partial-loads-ok=yes
18
+ --undef-value-errors=no
19
+ --leak-check=full
20
+ )
21
+
22
+ sh "valgrind #{opts.join(' ')} ruby test/test_functionality.rb"
23
+ end
24
+ rescue LoadError => le
25
+ puts "#{le.message}"
26
+ end
data/ext/extconf.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'mkmf'
2
+
3
+ $CFLAGS = '-Wno-char-subscripts'
4
+
5
+ extension_name = "lib_uuid"
6
+
7
+ crash "need libuuid" if !have_library "uuid"
8
+
9
+ dir_config extension_name
10
+ create_makefile extension_name
data/ext/lib_uuid.c ADDED
@@ -0,0 +1,236 @@
1
+ #include <ruby.h>
2
+ #include <uuid/uuid.h>
3
+
4
+ #include "uuid_base64.h"
5
+ #include "lib_uuid.h"
6
+
7
+ void
8
+ lib_uuid_free(lib_uuid_t *s)
9
+ {
10
+ free(s);
11
+ }
12
+
13
+ int
14
+ uuid_from_obj(VALUE obj, uuid_t uu)
15
+ {
16
+ long len;
17
+ char *ptr;
18
+
19
+ if( TYPE(obj) != T_STRING )
20
+ return -1;
21
+
22
+ len = RSTRING_LEN(obj);
23
+ ptr = RSTRING_PTR(obj);
24
+
25
+ if( len == GUID_STRLEN-1 )
26
+ return uuid_parse(ptr, uu);
27
+
28
+ if( len == SHORT_GUID_STRLEN-1)
29
+ return uuid_decode64(ptr, uu);
30
+
31
+ return -1;
32
+ }
33
+
34
+ int
35
+ uuid_validity_check(const uuid_t uu)
36
+ {
37
+ int type, variant;
38
+
39
+ type = uuid_type(uu);
40
+ if( type != UUID_TYPE_DCE_TIME && type != UUID_TYPE_DCE_RANDOM )
41
+ return -1;
42
+
43
+ variant = uuid_variant(uu);
44
+ if( variant < UUID_VARIANT_NCS || variant > UUID_VARIANT_OTHER )
45
+ return -1;
46
+
47
+ return 0;
48
+ }
49
+
50
+ VALUE
51
+ lib_uuid_new(unsigned int argc, VALUE *argv, VALUE class)
52
+ {
53
+ lib_uuid_t *s;
54
+ uuid_t parsed_uu;
55
+ VALUE ret;
56
+
57
+ if( argc > 1 )
58
+ rb_raise(rb_eArgError, "too many arguments");
59
+
60
+ if( argc == 0 )
61
+ uuid_generate(parsed_uu);
62
+
63
+ if( argc == 1 )
64
+ {
65
+ if( uuid_from_obj(argv[0], parsed_uu) == -1 )
66
+ return Qnil;
67
+
68
+ if( uuid_validity_check(parsed_uu) == -1 )
69
+ return Qnil;
70
+ }
71
+
72
+ s = ALLOC_N(lib_uuid_t, 1);
73
+ uuid_copy(s->uu, parsed_uu);
74
+ ret = Data_Wrap_Struct(class, NULL, lib_uuid_free, s);
75
+ rb_obj_call_init(ret, 0, 0);
76
+
77
+ return ret;
78
+ }
79
+
80
+ VALUE
81
+ lib_uuid_valid(unsigned int argc, VALUE *argv, VALUE class)
82
+ {
83
+ int i;
84
+ VALUE test[1];
85
+
86
+ if( argc == 0 )
87
+ rb_raise(rb_eArgError, "too few arguments");
88
+
89
+ for( i=0 ; i<argc ; i++ )
90
+ {
91
+ test[0] = argv[i];
92
+ if( lib_uuid_new(1, test, class) == Qnil )
93
+ return Qfalse;
94
+ }
95
+
96
+ return Qtrue;
97
+ }
98
+
99
+ VALUE
100
+ lib_uuid_generate_guid(VALUE class)
101
+ {
102
+ char uu_str[GUID_STRLEN];
103
+ uuid_t uu;
104
+
105
+ uuid_generate(uu);
106
+ uuid_unparse(uu, uu_str);
107
+
108
+ return rb_str_new(uu_str, GUID_STRLEN-1);
109
+ }
110
+
111
+ VALUE
112
+ lib_uuid_generate_short_guid(VALUE class)
113
+ {
114
+ char uu_str[SHORT_GUID_STRLEN];
115
+ uuid_t uu;
116
+
117
+ uuid_generate(uu);
118
+ uuid_encode64(uu, uu_str);
119
+
120
+ return rb_str_new(uu_str, SHORT_GUID_STRLEN-1);
121
+ }
122
+
123
+ VALUE
124
+ lib_uuid_initialize(VALUE self)
125
+ {
126
+ lib_uuid_t *s;
127
+
128
+ Data_Get_Struct(self, lib_uuid_t, s);
129
+ s->guid = s->short_guid = s->type = s->variant = 0;
130
+ rb_iv_set(self, "@bytes", rb_str_new((char *) s->uu, 16));
131
+
132
+ return self;
133
+ }
134
+
135
+ VALUE
136
+ lib_uuid_bytes(VALUE self)
137
+ {
138
+ return rb_iv_get(self, "@bytes");
139
+ }
140
+
141
+ VALUE
142
+ lib_uuid_type(VALUE self)
143
+ {
144
+ lib_uuid_t *s;
145
+
146
+ Data_Get_Struct(self, lib_uuid_t, s);
147
+
148
+ if( s->type == 0 )
149
+ s->type = INT2NUM(uuid_type(s->uu));
150
+
151
+ return s->type;
152
+ }
153
+
154
+ VALUE
155
+ lib_uuid_variant(VALUE self)
156
+ {
157
+ lib_uuid_t *s;
158
+
159
+ Data_Get_Struct(self, lib_uuid_t, s);
160
+
161
+ if( s->variant == 0 )
162
+ s->variant = INT2NUM(uuid_variant(s->uu));
163
+
164
+ return s->variant;
165
+ }
166
+
167
+ VALUE
168
+ lib_uuid_to_guid(VALUE self)
169
+ {
170
+ lib_uuid_t *s;
171
+ char uu_str[GUID_STRLEN];
172
+
173
+ Data_Get_Struct(self, lib_uuid_t, s);
174
+
175
+ if( s->guid == 0 )
176
+ {
177
+ uuid_unparse(s->uu, uu_str);
178
+ s->guid = rb_str_new(uu_str, GUID_STRLEN-1);
179
+ }
180
+
181
+ return s->guid;
182
+ }
183
+
184
+ VALUE
185
+ lib_uuid_to_short_guid(VALUE self)
186
+ {
187
+ lib_uuid_t *s;
188
+ char uu_str[SHORT_GUID_STRLEN];
189
+
190
+ Data_Get_Struct(self, lib_uuid_t, s);
191
+
192
+ if( s->short_guid == 0 )
193
+ {
194
+ uuid_encode64(s->uu, uu_str);
195
+ s->short_guid = rb_str_new(uu_str, SHORT_GUID_STRLEN-1);
196
+ }
197
+
198
+ return s->short_guid;
199
+ }
200
+
201
+ VALUE
202
+ lib_uuid_equality(VALUE self, VALUE other)
203
+ {
204
+ lib_uuid_t *s, *o;
205
+
206
+ if( TYPE(self) != T_DATA || TYPE(other) != T_DATA )
207
+ return Qfalse;
208
+
209
+ Data_Get_Struct(self, lib_uuid_t, s);
210
+ Data_Get_Struct(other, lib_uuid_t, o);
211
+
212
+ if( uuid_compare(s->uu, o->uu) != 0 )
213
+ return Qfalse;
214
+
215
+ return Qtrue;
216
+ }
217
+
218
+ void
219
+ Init_lib_uuid()
220
+ {
221
+ VALUE m_lib_uuid, c_lib_uuid;
222
+
223
+ m_lib_uuid = rb_define_module("LibUUID");
224
+ c_lib_uuid = rb_define_class_under(m_lib_uuid, "UUID", rb_cObject);
225
+ rb_define_singleton_method(c_lib_uuid, "new", lib_uuid_new, -1);
226
+ rb_define_singleton_method(c_lib_uuid, "valid?", lib_uuid_valid, -1);
227
+ rb_define_singleton_method(c_lib_uuid, "guid", lib_uuid_generate_guid, 0);
228
+ rb_define_singleton_method(c_lib_uuid, "short_guid", lib_uuid_generate_short_guid, 0);
229
+ rb_define_method(c_lib_uuid, "initialize", lib_uuid_initialize, 0);
230
+ rb_define_method(c_lib_uuid, "bytes", lib_uuid_bytes, 0);
231
+ rb_define_method(c_lib_uuid, "type", lib_uuid_type, 0);
232
+ rb_define_method(c_lib_uuid, "variant", lib_uuid_variant, 0);
233
+ rb_define_method(c_lib_uuid, "to_guid", lib_uuid_to_guid, 0);
234
+ rb_define_method(c_lib_uuid, "to_short_guid", lib_uuid_to_short_guid, 0);
235
+ rb_define_method(c_lib_uuid, "==", lib_uuid_equality, 1);
236
+ }
data/ext/lib_uuid.h ADDED
@@ -0,0 +1,11 @@
1
+ #include <uuid/uuid.h>
2
+
3
+ #define GUID_STRLEN 36+1
4
+ #define SHORT_GUID_STRLEN 22+1
5
+
6
+ typedef struct {
7
+
8
+ VALUE guid, short_guid, type, variant;
9
+ uuid_t uu;
10
+
11
+ } lib_uuid_t;
data/ext/uuid_base64.c ADDED
@@ -0,0 +1,52 @@
1
+ #include <uuid/uuid.h>
2
+
3
+ #include "uuid_base64.h"
4
+
5
+ void
6
+ uuid_encode64(const uuid_t uu, char *str)
7
+ {
8
+ int i;
9
+
10
+ for( i=0; i<5; i++ )
11
+ {
12
+ *str++ = e64[ uu[0] >> 2];
13
+ *str++ = e64[((uu[0] << 4) & 0x30) | (uu[1] >> 4)];
14
+ *str++ = e64[((uu[1] << 2) & 0x3c) | (uu[2] >> 6)];
15
+ *str++ = e64[ uu[2] & 0x3f];
16
+ uu += 3;
17
+ }
18
+
19
+ *str++ = e64[ uu[0] >> 2];
20
+ *str++ = e64[(uu[0] << 4) & 0x30];
21
+ *str++ = '\0';
22
+ }
23
+
24
+ int
25
+ uuid_decode64(const char *str, uuid_t uu)
26
+ {
27
+ int i, j;
28
+ unsigned char buf[3];
29
+
30
+ for( i=0; i<5; i++ )
31
+ {
32
+ buf[0] = (unsigned char) d64[str[0]] << 2 | d64[str[1]] >> 4;
33
+ buf[1] = (unsigned char) d64[str[1]] << 4 | d64[str[2]] >> 2;
34
+ buf[2] = (unsigned char) (d64[str[2]] << 6) & 0xc0 | d64[str[3]];
35
+
36
+ for( j=0; j<3; j++ )
37
+ if( buf[j] != -1 )
38
+ *uu++ = buf[j];
39
+ else
40
+ return buf[j];
41
+
42
+ str += 4;
43
+ }
44
+
45
+ buf[0] = (unsigned char) d64[str[0]] << 2 | d64[str[1]] >> 4;
46
+ if( buf[0] != -1 )
47
+ *uu++ = buf[0];
48
+ else
49
+ return buf[0];
50
+
51
+ return 0;
52
+ }
data/ext/uuid_base64.h ADDED
@@ -0,0 +1,20 @@
1
+ static const char e64[] =
2
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
3
+
4
+ static const char d64[] = {
5
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
6
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1,
8
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
9
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
10
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63,
11
+ -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
12
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
13
+ };
14
+
15
+ void
16
+ uuid_encode64(const uuid_t uu, char *str);
17
+
18
+ int
19
+ uuid_decode64(const char *str, uuid_t uu);
20
+
data/libuuidrb.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{libuuidrb}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Sebastian Ohm"]
9
+ s.date = %q{2010-03-07}
10
+ s.description = %q{libuuidrb uses libuuid to generate DCE compatible universally unique identifiers}
11
+ s.email = %q{}
12
+ s.extensions = ["ext/extconf.rb"]
13
+ s.extra_rdoc_files = ["LICENSE", "README", "ext/extconf.rb", "ext/lib_uuid.c", "ext/lib_uuid.h", "ext/uuid_base64.c", "ext/uuid_base64.h", "libuuidrb.gemspec"]
14
+ s.files = ["LICENSE", "Manifest", "README", "Rakefile", "ext/extconf.rb", "ext/lib_uuid.c", "ext/lib_uuid.h", "ext/uuid_base64.c", "ext/uuid_base64.h", "libuuidrb.gemspec", "test/test_compatibility.rb", "test/test_functionality.rb"]
15
+ s.homepage = %q{http://github.com/ohm/libuuidrb}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Libuuidrb", "--main", "README"]
17
+ s.require_paths = ["ext"]
18
+ s.rubyforge_project = %q{libuuidrb}
19
+ s.rubygems_version = %q{1.3.6}
20
+ s.summary = %q{libuuidrb uses libuuid to generate DCE compatible universally unique identifiers}
21
+ s.test_files = ["test/test_compatibility.rb", "test/test_functionality.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ begin
5
+ require File.expand_path(File.dirname(__FILE__) + '/../ext/lib_uuid')
6
+ require 'simple_uuid'
7
+ require 'uuidtools'
8
+
9
+ class TestCompatibility < Test::Unit::TestCase
10
+ def test_parsing_uuidtools_timestamp_guids
11
+ u = UUIDTools::UUID.timestamp_create
12
+ l = LibUUID::UUID.new(u.to_s)
13
+ assert_equal u.to_s, l.to_guid
14
+ assert_equal 1, l.type
15
+ assert_equal 1, l.variant
16
+ end
17
+
18
+ def test_parsing_uuidtools_random_guids
19
+ u = UUIDTools::UUID.random_create
20
+ l = LibUUID::UUID.new(u.to_s)
21
+ assert_equal u.to_s, l.to_guid
22
+ assert_equal 4, l.type
23
+ assert_equal 1, l.variant
24
+ end
25
+
26
+ def test_parsing_simple_uuid_guids
27
+ f = SimpleUUID::UUID.new
28
+ g = LibUUID::UUID.new(f.to_guid)
29
+ assert_equal f.to_guid, g.to_guid
30
+ assert_equal 1, g.type
31
+ assert_equal 1, g.variant
32
+ end
33
+ end
34
+ rescue LoadError => le
35
+ puts "Skipping compatibility tests: #{le.message}"
36
+ end
@@ -0,0 +1,109 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../ext/lib_uuid')
3
+
4
+ class TestLibUUUID < Test::Unit::TestCase
5
+
6
+ EXPR = {
7
+ :rfc => /\A[a-z0-9]{8}\-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}\Z/,
8
+ :b64 => /\A[A-Za-z0-9\-\_]{22}\Z/
9
+ }
10
+
11
+ def test_guid_generation
12
+ guids = []
13
+ 1.upto(100) { guids << LibUUID::UUID.guid }
14
+ assert_equal guids.size, guids.uniq.size
15
+ assert_equal guids.size, guids.reject {|g| (g =~ EXPR[:rfc]) != 0}.size
16
+ end
17
+
18
+ def test_short_guid_generation
19
+ short_guids = []
20
+ 1.upto(100) { short_guids << LibUUID::UUID.short_guid }
21
+ assert_equal short_guids.size, short_guids.uniq.size
22
+ assert_equal short_guids.size, short_guids.reject { |sg| (sg =~ EXPR[:b64]) != 0 }.size
23
+ end
24
+
25
+ def test_initialization
26
+ u = LibUUID::UUID.new
27
+ assert LibUUID::UUID == u.class
28
+ assert 4 == u.type
29
+ assert 1 == u.variant
30
+ end
31
+
32
+ def test_positive_equality
33
+ u = LibUUID::UUID.new
34
+ assert u == u
35
+ end
36
+
37
+ def test_negative_equality
38
+ u = LibUUID::UUID.new
39
+ v = LibUUID::UUID.new
40
+ assert u != v
41
+ assert u != 1
42
+ assert u != nil
43
+ assert u != 'foo'
44
+ end
45
+
46
+ def test_transformation_to_guid
47
+ u = LibUUID::UUID.new
48
+ assert_match EXPR[:rfc], u.to_guid
49
+ assert u.to_guid == u.to_guid
50
+ end
51
+
52
+ def test_transformation_to_short_guid
53
+ u = LibUUID::UUID.new
54
+ assert_match EXPR[:b64], u.to_short_guid
55
+ assert u.to_short_guid == u.to_short_guid
56
+ end
57
+
58
+ def test_parsing_guids
59
+ assert_nil LibUUID::UUID.new(nil)
60
+ assert_nil LibUUID::UUID.new(123)
61
+ assert_nil LibUUID::UUID.new('foo')
62
+
63
+ u = LibUUID::UUID.new
64
+ assert u == LibUUID::UUID.new(u.to_guid)
65
+ assert u == LibUUID::UUID.new(u.to_short_guid)
66
+
67
+ assert_raise ArgumentError do
68
+ LibUUID::UUID.new(u.to_guid, u.to_guid)
69
+ end
70
+ end
71
+
72
+ def test_positive_validating_guids_and_short_guids
73
+ assert LibUUID::UUID.valid?(LibUUID::UUID.guid)
74
+ assert LibUUID::UUID.valid?(LibUUID::UUID.short_guid)
75
+ assert LibUUID::UUID.valid?(LibUUID::UUID.guid, LibUUID::UUID.guid)
76
+ assert LibUUID::UUID.valid?(LibUUID::UUID.guid, LibUUID::UUID.short_guid)
77
+ assert LibUUID::UUID.valid?(LibUUID::UUID.short_guid, LibUUID::UUID.short_guid)
78
+ end
79
+
80
+ def test_negative_validating_guids_and_short_guids
81
+ assert false == LibUUID::UUID.valid?(1)
82
+ assert false == LibUUID::UUID.valid?('foo', LibUUID::UUID.short_guid)
83
+ assert false == LibUUID::UUID.valid?(nil, 'foo', LibUUID::UUID.guid)
84
+
85
+ assert_raise ArgumentError do
86
+ LibUUID::UUID.valid?
87
+ end
88
+ end
89
+
90
+ def test_accessing_raw_bytes
91
+ examples = {
92
+ "99744ce4-22ef-11df-9985-b2d60a1a84bd" =>
93
+ "\x99tL\xE4\"\xEF\x11\xDF\x99\x85\xB2\xD6\n\x1A\x84\xBD",
94
+ "9974502c-22ef-11df-9ef4-56b2ae6e82ba" =>
95
+ "\x99tP,\"\xEF\x11\xDF\x9E\xF4V\xB2\xAEn\x82\xBA",
96
+ "9974525c-22ef-11df-83d0-49d493d646c4" =>
97
+ "\x99tR\\\"\xEF\x11\xDF\x83\xD0I\xD4\x93\xD6F\xC4",
98
+ "9974546e-22ef-11df-9f68-0d1a49a6205e" =>
99
+ "\x99tTn\"\xEF\x11\xDF\x9Fh\r\x1AI\xA6 ^",
100
+ "99745680-22ef-11df-94f8-8f1188b64943" =>
101
+ "\x99tV\x80\"\xEF\x11\xDF\x94\xF8\x8F\x11\x88\xB6IC"
102
+ }
103
+
104
+ examples.each do |guid, bytes|
105
+ l = LibUUID::UUID.new(guid)
106
+ assert_equal bytes, l.bytes
107
+ end
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: libuuidrb
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Sebastian Ohm
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-07 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: libuuidrb uses libuuid to generate DCE compatible universally unique identifiers
22
+ email: ""
23
+ executables: []
24
+
25
+ extensions:
26
+ - ext/extconf.rb
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README
30
+ - ext/extconf.rb
31
+ - ext/lib_uuid.c
32
+ - ext/lib_uuid.h
33
+ - ext/uuid_base64.c
34
+ - ext/uuid_base64.h
35
+ - libuuidrb.gemspec
36
+ files:
37
+ - LICENSE
38
+ - Manifest
39
+ - README
40
+ - Rakefile
41
+ - ext/extconf.rb
42
+ - ext/lib_uuid.c
43
+ - ext/lib_uuid.h
44
+ - ext/uuid_base64.c
45
+ - ext/uuid_base64.h
46
+ - libuuidrb.gemspec
47
+ - test/test_compatibility.rb
48
+ - test/test_functionality.rb
49
+ has_rdoc: true
50
+ homepage: http://github.com/ohm/libuuidrb
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --line-numbers
56
+ - --inline-source
57
+ - --title
58
+ - Libuuidrb
59
+ - --main
60
+ - README
61
+ require_paths:
62
+ - ext
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 1
76
+ - 2
77
+ version: "1.2"
78
+ requirements: []
79
+
80
+ rubyforge_project: libuuidrb
81
+ rubygems_version: 1.3.6
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: libuuidrb uses libuuid to generate DCE compatible universally unique identifiers
85
+ test_files:
86
+ - test/test_compatibility.rb
87
+ - test/test_functionality.rb