ffi-geos 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/utils_tests.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class UtilsTests < Test::Unit::TestCase
5
+ class UtilsTests < MiniTest::Unit::TestCase
6
6
  include TestHelper
7
7
 
8
8
  if defined?(Geos::Utils)
@@ -24,10 +24,10 @@ class UtilsTests < Test::Unit::TestCase
24
24
 
25
25
  if Geos::Utils.respond_to?(:relate_match)
26
26
  def test_relate_match
27
- assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF2'))
28
- assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF*'))
29
- assert(Geos::Utils.relate_match('0FFFFFFF2', 'TFFFFFFF2'))
30
- assert(!Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFFF'))
27
+ assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF2'), "'0FFFFFFF2' and '0FFFFFFF2' patterns match")
28
+ assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF*'), "'0FFFFFFF2' and '0FFFFFFF*' patterns match")
29
+ assert(Geos::Utils.relate_match('0FFFFFFF2', 'TFFFFFFF2'), "'0FFFFFFF2' and 'TFFFFFFF2' patterns match")
30
+ assert(!Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFFF'), "'0FFFFFFF2' and '0FFFFFFFF' patterns match")
31
31
  end
32
32
  end
33
33
  end
@@ -36,9 +36,9 @@ class UtilsTests < Test::Unit::TestCase
36
36
  geom = Geos.send(method, cs)
37
37
  expected_geom = read(expected)
38
38
 
39
- assert(expected_geom.eql_exact?(geom, TOLERANCE))
40
- assert(geom.valid?)
41
- assert_instance_of(klass, geom)
39
+ assert_geom_eql_exact(expected_geom, geom)
40
+ assert_geom_valid(geom)
41
+ assert_kind_of(klass, geom)
42
42
  assert_equal(type_id, geom.type_id)
43
43
 
44
44
  yield geom if block_given?
@@ -52,9 +52,17 @@ class UtilsTests < Test::Unit::TestCase
52
52
  create_method_tester('POINT(10 20)', :create_point, cs, Geos::GEOS_POINT, Geos::Point)
53
53
  end
54
54
 
55
+ def test_create_point_with_x_and_y_arguments
56
+ assert_equal('POINT (10 20)', write(Geos.create_point(10, 20), :trim => true))
57
+ end
58
+
59
+ def test_create_point_with_x_y_and_z_arguments
60
+ assert_equal('POINT Z (10 20 30)', write(Geos.create_point(10, 20, 30), :trim => true, :output_dimensions => 3))
61
+ end
62
+
55
63
  def test_bad_create_point
56
64
  cs = Geos::CoordinateSequence.new(0, 0)
57
- assert_raise(RuntimeError) do
65
+ assert_raises(RuntimeError) do
58
66
  Geos.create_point(cs)
59
67
  end
60
68
  end
@@ -75,18 +83,37 @@ class UtilsTests < Test::Unit::TestCase
75
83
  Geos::GEOS_LINESTRING,
76
84
  Geos::LineString
77
85
  ) do |geom|
78
- assert(!geom.empty?)
79
- assert(geom.valid?)
80
- assert(geom.simple?)
81
- assert(!geom.ring?)
82
- assert(geom.has_z?)
86
+ refute_geom_empty(geom)
87
+ assert_geom_valid(geom)
88
+ assert_geom_simple(geom)
89
+ refute_geom_ring(geom)
90
+ assert_geom_has_z(geom)
91
+ assert_equal(1, geom.num_geometries)
92
+ end
93
+ end
94
+
95
+ def test_create_line_string_with_array
96
+ writer.output_dimensions = 3
97
+
98
+ create_method_tester(
99
+ 'LINESTRING Z (10 20 30, 30 20 10)',
100
+ :create_line_string,
101
+ [[ 10, 20, 30 ], [ 30, 20, 10 ]],
102
+ Geos::GEOS_LINESTRING,
103
+ Geos::LineString
104
+ ) do |geom|
105
+ refute_geom_empty(geom)
106
+ assert_geom_valid(geom)
107
+ assert_geom_simple(geom)
108
+ refute_geom_ring(geom)
109
+ assert_geom_has_z(geom)
83
110
  assert_equal(1, geom.num_geometries)
84
111
  end
85
112
  end
86
113
 
87
114
  def test_create_bad_line_string
88
115
  cs = Geos::CoordinateSequence.new(1, 0)
89
- assert_raise(RuntimeError) do
116
+ assert_raises(RuntimeError) do
90
117
  Geos::create_line_string(cs)
91
118
  end
92
119
  end
@@ -113,11 +140,30 @@ class UtilsTests < Test::Unit::TestCase
113
140
  Geos::GEOS_LINEARRING,
114
141
  Geos::LinearRing
115
142
  ) do |geom|
116
- assert(!geom.empty?)
117
- assert(geom.valid?)
118
- assert(geom.simple?)
119
- assert(geom.ring?)
120
- assert(geom.has_z?)
143
+ refute_geom_empty(geom)
144
+ assert_geom_valid(geom)
145
+ assert_geom_simple(geom)
146
+ assert_geom_ring(geom)
147
+ assert_geom_has_z(geom)
148
+ assert_equal(1, geom.num_geometries)
149
+ end
150
+ end
151
+
152
+ def test_create_linear_ring_with_array
153
+ writer.output_dimensions = 3
154
+
155
+ create_method_tester(
156
+ 'LINEARRING Z (7 8 9, 3 3 3, 11 15.2 2, 7 8 9)',
157
+ :create_linear_ring,
158
+ [[ 7, 8, 9 ], [ 3, 3, 3 ], [ 11, 15.2, 2 ], [ 7, 8, 9 ]],
159
+ Geos::GEOS_LINEARRING,
160
+ Geos::LinearRing
161
+ ) do |geom|
162
+ refute_geom_empty(geom)
163
+ assert_geom_valid(geom)
164
+ assert_geom_simple(geom)
165
+ assert_geom_ring(geom)
166
+ assert_geom_has_z(geom)
121
167
  assert_equal(1, geom.num_geometries)
122
168
  end
123
169
  end
@@ -125,7 +171,7 @@ class UtilsTests < Test::Unit::TestCase
125
171
  def test_bad_create_linear_ring
126
172
  cs = Geos::CoordinateSequence.new(1, 0)
127
173
 
128
- assert_raise(RuntimeError) do
174
+ assert_raises(RuntimeError) do
129
175
  Geos::create_linear_ring(cs)
130
176
  end
131
177
  end
@@ -202,18 +248,18 @@ class UtilsTests < Test::Unit::TestCase
202
248
  assert_equal('Polygon', geom.geom_type)
203
249
  assert_equal(Geos::GEOS_POLYGON, geom.type_id)
204
250
 
205
- assert(!geom.empty?)
206
- assert(geom.valid?)
207
- assert(geom.simple?)
208
- assert(!geom.ring?)
209
- assert(!geom.has_z?)
251
+ refute_geom_empty(geom)
252
+ assert_geom_valid(geom)
253
+ assert_geom_simple(geom)
254
+ refute_geom_ring(geom)
255
+ refute_geom_has_z(geom)
210
256
 
211
257
  assert_equal(1, geom.num_geometries)
212
258
  end
213
259
 
214
260
  if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
215
261
  def test_create_multi_point
216
- @writer.rounding_precision = 0
262
+ writer.rounding_precision = 0
217
263
  assert_equal('MULTIPOINT EMPTY', write(Geos.create_multi_point))
218
264
  assert_equal('MULTIPOINT (0 0, 10 10)', write(Geos.create_multi_point(
219
265
  read('POINT(0 0)'),
@@ -222,7 +268,7 @@ class UtilsTests < Test::Unit::TestCase
222
268
  end
223
269
 
224
270
  def test_create_bad_multi_point
225
- assert_raise(TypeError) do
271
+ assert_raises(TypeError) do
226
272
  Geos.create_multi_point(
227
273
  read('POINT(0 0)'),
228
274
  read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
@@ -233,7 +279,7 @@ class UtilsTests < Test::Unit::TestCase
233
279
 
234
280
  if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_line_string)
235
281
  def test_create_multi_line_string
236
- @writer.rounding_precision = 0
282
+ writer.rounding_precision = 0
237
283
  assert_equal('MULTILINESTRING EMPTY', write(Geos.create_multi_line_string))
238
284
  assert_equal('MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))', write(Geos.create_multi_line_string(
239
285
  read('LINESTRING(0 0, 10 10)'),
@@ -242,7 +288,7 @@ class UtilsTests < Test::Unit::TestCase
242
288
  end
243
289
 
244
290
  def test_create_bad_multi_line_string
245
- assert_raise(TypeError) do
291
+ assert_raises(TypeError) do
246
292
  Geos.create_multi_point(
247
293
  read('POINT(0 0)'),
248
294
  read('LINESTRING(0 0, 10 0)')
@@ -253,7 +299,7 @@ class UtilsTests < Test::Unit::TestCase
253
299
 
254
300
  if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_polygon)
255
301
  def test_create_multi_polygon
256
- @writer.rounding_precision = 0
302
+ writer.rounding_precision = 0
257
303
  assert_equal('MULTIPOLYGON EMPTY', write(Geos.create_multi_polygon))
258
304
  assert_equal('MULTIPOLYGON (((0 0, 0 5, 5 5, 5 0, 0 0)), ((10 10, 10 15, 15 15, 15 10, 10 10)))', write(Geos.create_multi_polygon(
259
305
  read('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'),
@@ -262,7 +308,7 @@ class UtilsTests < Test::Unit::TestCase
262
308
  end
263
309
 
264
310
  def test_create_bad_multi_polygon
265
- assert_raise(TypeError) do
311
+ assert_raises(TypeError) do
266
312
  Geos.create_multi_polygon(
267
313
  read('POINT(0 0)'),
268
314
  read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
@@ -273,7 +319,7 @@ class UtilsTests < Test::Unit::TestCase
273
319
 
274
320
  if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
275
321
  def test_create_geometry_collection
276
- @writer.rounding_precision = 0
322
+ writer.rounding_precision = 0
277
323
  assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_geometry_collection))
278
324
  assert_equal('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0)), POLYGON ((10 10, 10 15, 15 15, 15 10, 10 10)))',
279
325
  write(Geos.create_geometry_collection(
@@ -289,7 +335,7 @@ class UtilsTests < Test::Unit::TestCase
289
335
  end
290
336
 
291
337
  def test_create_bad_geometry_collection
292
- assert_raise(TypeError) do
338
+ assert_raises(TypeError) do
293
339
  Geos.create_geometry_collection(
294
340
  read('POINT(0 0)'),
295
341
  read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'),
@@ -346,4 +392,40 @@ class UtilsTests < Test::Unit::TestCase
346
392
  assert_equal('LINEARRING EMPTY', write(Geos.create_empty_linear_ring))
347
393
  end
348
394
  end
395
+
396
+ def test_create_geometry_segfault
397
+ # This used to segfault before moving the autorelease code to before
398
+ # the initialization. It didn't occur 100% of the time. The cause was
399
+ # GEOS taking ownership of CoordinateSequences and deleting them out from
400
+ # under us and GC blowing up.
401
+
402
+ assert_raises(RuntimeError) do
403
+ cs = Geos::CoordinateSequence.new(0, 2)
404
+ Geos.create_point(cs)
405
+ GC.start
406
+ end
407
+
408
+ assert_raises(RuntimeError) do
409
+ cs = Geos::CoordinateSequence.new(1, 2)
410
+ Geos.create_line_string(cs)
411
+ GC.start
412
+ end
413
+
414
+ assert_raises(RuntimeError) do
415
+ cs = Geos::CoordinateSequence.new(1, 2)
416
+ Geos.create_linear_ring(cs)
417
+ GC.start
418
+ end
419
+
420
+ assert_raises(RuntimeError) do
421
+ cs = Geos::CoordinateSequence.new([
422
+ [0, 0],
423
+ [0, 5],
424
+ [5, 5],
425
+ [0, 5]
426
+ ])
427
+ Geos.create_linear_ring(cs)
428
+ GC.start
429
+ end
430
+ end
349
431
  end
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class WkbReaderTests < Test::Unit::TestCase
5
+ class WkbReaderTests < MiniTest::Unit::TestCase
6
6
  include TestHelper
7
7
 
8
8
  def setup
@@ -17,11 +17,11 @@ class WkbReaderTests < Test::Unit::TestCase
17
17
  else
18
18
  @wkb_reader.read(g)
19
19
  end
20
- assert(geom)
20
+ refute_nil(geom)
21
21
  assert_equal(type_id, geom.type_id)
22
22
  assert_equal(geom_type, geom.geom_type)
23
- assert(geom.is_a?(klass))
24
- assert(read(expected).eql_exact?(geom, TOLERANCE))
23
+ assert_kind_of(klass, geom)
24
+ assert_geom_eql_exact(read(expected), geom)
25
25
  assert_equal(srid, geom.srid)
26
26
  end
27
27
 
@@ -185,4 +185,24 @@ class WkbReaderTests < Test::Unit::TestCase
185
185
  false
186
186
  )
187
187
  end
188
+
189
+ def test_read_with_srid
190
+ assert_equal(43,
191
+ @wkb_reader.read("\x01\x01\x00\x00\x20\x2B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x40\x00\x00\x00\x00\x00\x00\x1C\x40").srid)
192
+
193
+ assert_equal(4326,
194
+ @wkb_reader.read("\x01\x01\x00\x00\x20\x2B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x18\x40\x00\x00\x00\x00\x00\x00\x1C\x40", {
195
+ :srid => 4326
196
+ }).srid)
197
+ end
198
+
199
+ def test_read_hex_srid
200
+ assert_equal(43,
201
+ @wkb_reader.read_hex('01010000202B00000000000000000018400000000000001C40').srid)
202
+
203
+ assert_equal(4326,
204
+ @wkb_reader.read_hex('01010000202B00000000000000000018400000000000001C40', {
205
+ :srid => 4326
206
+ }).srid)
207
+ end
188
208
  end
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class WkbWriterTests < Test::Unit::TestCase
5
+ class WkbWriterTests < MiniTest::Unit::TestCase
6
6
  include TestHelper
7
7
 
8
8
  def setup
@@ -198,7 +198,7 @@ class WkbWriterTests < Test::Unit::TestCase
198
198
  end
199
199
 
200
200
  def test_try_bad_byte_order_value
201
- assert_raise(TypeError) do
201
+ assert_raises(TypeError) do
202
202
  wkb_tester(
203
203
  '010100008000000000000018400000000000001C400000000000002040',
204
204
  'POINT(6 7 8)',
@@ -209,7 +209,7 @@ class WkbWriterTests < Test::Unit::TestCase
209
209
  )
210
210
  end
211
211
 
212
- assert_raise(TypeError) do
212
+ assert_raises(TypeError) do
213
213
  wkb_tester(
214
214
  '010100008000000000000018400000000000001C400000000000002040',
215
215
  'POINT(6 7 8)',
@@ -394,7 +394,7 @@ class WkbWriterTests < Test::Unit::TestCase
394
394
  end
395
395
 
396
396
  def test_try_bad_byte_order_value_binary
397
- assert_raise(TypeError) do
397
+ assert_raises(TypeError) do
398
398
  wkb_tester(
399
399
  "\x01\x01\x00\x00\x80\x00\x00\x00\x00\x00\x00\x18\x40\x00\x00\x00\x00\x00\x00\x1C\x40\x00\x00\x00\x00\x00\x00\x20\x40",
400
400
  'POINT(6 7 8)',
@@ -406,7 +406,7 @@ class WkbWriterTests < Test::Unit::TestCase
406
406
  )
407
407
  end
408
408
 
409
- assert_raise(TypeError) do
409
+ assert_raises(TypeError) do
410
410
  wkb_tester(
411
411
  "\x01\x01\x00\x00\x80\x00\x00\x00\x00\x00\x00\x18\x40\x00\x00\x00\x00\x00\x00\x1C\x40\x00\x00\x00\x00\x00\x00\x20\x40",
412
412
  'POINT(6 7 8)',
@@ -2,16 +2,16 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class WktReaderTests < Test::Unit::TestCase
5
+ class WktReaderTests < MiniTest::Unit::TestCase
6
6
  include TestHelper
7
7
 
8
8
  def wkt_tester(type_id, geom_type, klass, *geoms)
9
9
  geoms.each do |g|
10
10
  geom = read(g)
11
- assert(geom)
11
+ refute_nil(geom)
12
12
  assert_equal(type_id, geom.type_id)
13
13
  assert_equal(geom_type, geom.geom_type)
14
- assert(geom.is_a?(klass))
14
+ assert_kind_of(klass, geom)
15
15
  end
16
16
  end
17
17
 
@@ -109,12 +109,17 @@ class WktReaderTests < Test::Unit::TestCase
109
109
  geom = read('LINEARRING(0 0, 1 1, 2 2, 3 3, 0 0)')
110
110
  assert_equal(Geos::GEOS_LINEARRING, geom.type_id)
111
111
  assert_equal('LinearRing', geom.geom_type)
112
- assert(geom.is_a?(Geos::LinearRing))
112
+ assert_kind_of(Geos::LinearRing, geom)
113
113
  end
114
114
 
115
115
  def test_read_exception
116
- assert_raise(RuntimeError) do
116
+ assert_raises(RuntimeError) do
117
117
  read('gibberish')
118
118
  end
119
119
  end
120
+
121
+ def test_read_with_srid
122
+ assert_equal(0, read('POINT (0 0)').srid)
123
+ assert_equal(4326, read('POINT (0 0)', :srid => 4326).srid)
124
+ end
120
125
  end
@@ -2,7 +2,7 @@
2
2
  $: << File.dirname(__FILE__)
3
3
  require 'test_helper'
4
4
 
5
- class WktWriterTests < Test::Unit::TestCase
5
+ class WktWriterTests < MiniTest::Unit::TestCase
6
6
  include TestHelper
7
7
 
8
8
  def test_write_point
@@ -91,12 +91,12 @@ class WktWriterTests < Test::Unit::TestCase
91
91
  assert_equal('POINT (3 2)', write(geom_2d))
92
92
 
93
93
  # 1 is invalid
94
- assert_raise(RuntimeError) do
94
+ assert_raises(RuntimeError) do
95
95
  writer.output_dimensions = 1
96
96
  end
97
97
 
98
98
  # 4 is invalid
99
- assert_raise(RuntimeError) do
99
+ assert_raises(RuntimeError) do
100
100
  writer.output_dimensions = 4
101
101
  end
102
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-geos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-17 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -59,6 +59,38 @@ dependencies:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.9'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: turn
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
62
94
  description: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
63
95
  email: dark.panda@gmail.com
64
96
  executables: []
@@ -94,9 +126,13 @@ files:
94
126
  - lib/ffi-geos/wkt_reader.rb
95
127
  - lib/ffi-geos/wkt_writer.rb
96
128
  - test/coordinate_sequence_tests.rb
129
+ - test/geometry_collection_tests.rb
97
130
  - test/geometry_tests.rb
131
+ - test/line_string_tests.rb
132
+ - test/linear_ring_tests.rb
98
133
  - test/misc_tests.rb
99
134
  - test/point_tests.rb
135
+ - test/polygon_tests.rb
100
136
  - test/prepared_geometry_tests.rb
101
137
  - test/strtree_tests.rb
102
138
  - test/test_helper.rb
@@ -125,15 +161,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
161
  version: '0'
126
162
  requirements: []
127
163
  rubyforge_project:
128
- rubygems_version: 1.8.24
164
+ rubygems_version: 1.8.23
129
165
  signing_key:
130
166
  specification_version: 3
131
167
  summary: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
132
168
  test_files:
133
169
  - test/coordinate_sequence_tests.rb
170
+ - test/geometry_collection_tests.rb
134
171
  - test/geometry_tests.rb
172
+ - test/line_string_tests.rb
173
+ - test/linear_ring_tests.rb
135
174
  - test/misc_tests.rb
136
175
  - test/point_tests.rb
176
+ - test/polygon_tests.rb
137
177
  - test/prepared_geometry_tests.rb
138
178
  - test/strtree_tests.rb
139
179
  - test/test_helper.rb