palm 0.0.1
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.txt +1 -0
- data/History.txt +0 -0
- data/Manifest.txt +20 -0
- data/README.txt +41 -0
- data/Rakefile +50 -0
- data/lib/palm.rb +1 -0
- data/lib/palm/palm_record.rb +62 -0
- data/lib/palm/palm_support.rb +12 -0
- data/lib/palm/pdb.rb +370 -0
- data/lib/palm/raw_record.rb +21 -0
- data/lib/palm/version.rb +9 -0
- data/lib/palm/waba_db.rb +44 -0
- data/lib/palm/waba_io.rb +63 -0
- data/lib/palm/waba_record.rb +63 -0
- data/setup.rb +1585 -0
- data/test/HovData.pdb +0 -0
- data/test/pdb_test.rb +97 -0
- data/test/test_helper.rb +7 -0
- data/test/waba_db_test.rb +77 -0
- data/test/waba_records_test.rb +75 -0
- metadata +74 -0
data/test/HovData.pdb
ADDED
Binary file
|
data/test/pdb_test.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'enumerator'
|
3
|
+
|
4
|
+
class TC_PdbTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
setup_paths
|
7
|
+
@pdb = Palm::PDB.new
|
8
|
+
@pdb.load_file(@path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
File.delete(@temp_path) if File.exist? @temp_path
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_meta_data
|
16
|
+
assert_equal 'Trac' , @pdb.creator
|
17
|
+
assert_equal 'HovD' , @pdb.type
|
18
|
+
assert_equal 'HovData' , @pdb.name
|
19
|
+
assert_equal 1 , @pdb.version
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_times_should_be_humane
|
23
|
+
assert_instance_of(Time, @pdb.created_at)
|
24
|
+
assert_instance_of(Time, @pdb.modified_at)
|
25
|
+
assert_instance_of(Time, @pdb.backed_up_at)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_that_data_looks_right
|
29
|
+
records = @pdb.data
|
30
|
+
io = Palm::WabaStringIO.new(records.first.data)
|
31
|
+
assert_equal 072 ,io.get_byte
|
32
|
+
assert_equal 'Downtown I-5' ,io.get_string
|
33
|
+
assert_equal 'Albro Pl' ,io.get_string
|
34
|
+
assert_equal 1 ,io.get_byte
|
35
|
+
assert_equal 5 ,io.get_byte
|
36
|
+
assert_equal 5 ,io.get_byte
|
37
|
+
assert_equal 'none' ,io.get_string
|
38
|
+
assert_equal false ,io.get_bool
|
39
|
+
assert_equal 21 ,io.get_int
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_writing_data
|
43
|
+
@pdb.write_file(@temp_path)
|
44
|
+
|
45
|
+
# Ensure the file was written
|
46
|
+
assert(File.exist?(@temp_path))
|
47
|
+
assert(File.size(@temp_path) > 0)
|
48
|
+
|
49
|
+
# Ensure the files are the same size
|
50
|
+
assert_equal File.size(@path), File.size(@temp_path)
|
51
|
+
|
52
|
+
# Ensure the files are identical
|
53
|
+
assert_equal IO.read(@path), IO.read(@temp_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_round_tripping_records
|
57
|
+
@pdb.write_file(@temp_path)
|
58
|
+
@loaded = Palm::PDB.new(@temp_path)
|
59
|
+
|
60
|
+
# Ensure they are not the same instance
|
61
|
+
assert(@pdb != @loaded)
|
62
|
+
|
63
|
+
# Test that the loaded data is the same as the original
|
64
|
+
binary_data = @pdb.data.map{|record| record.data}
|
65
|
+
loaded_data = @loaded.data.map{|record| record.data}
|
66
|
+
|
67
|
+
binary_data.zip(loaded_data) do |expected, loaded|
|
68
|
+
assert_equal expected, loaded
|
69
|
+
end
|
70
|
+
|
71
|
+
# Verify that the metadata is the same
|
72
|
+
assert_equal @pdb.creator , @loaded.creator
|
73
|
+
assert_equal @pdb.type , @loaded.type
|
74
|
+
assert_equal @pdb.name , @loaded.name
|
75
|
+
assert_equal @pdb.version , @loaded.version
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_appending_records
|
79
|
+
bytes = "TEST BYTES"
|
80
|
+
r = Palm::RawRecord.new
|
81
|
+
r.data = bytes
|
82
|
+
@pdb.data << r
|
83
|
+
@pdb.write_file(@temp_path)
|
84
|
+
@loaded = Palm::PDB.new(@temp_path)
|
85
|
+
assert_equal bytes, @loaded.data.last.data
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_removing_records
|
89
|
+
removed = @pdb.data.shift
|
90
|
+
expected = @pdb.data.first
|
91
|
+
@pdb.write_file(@temp_path)
|
92
|
+
@loaded = Palm::PDB.new(@temp_path)
|
93
|
+
assert_equal expected.data, @loaded.data.first.data
|
94
|
+
assert !@pdb.data.any?{|r| r.data == removed.data}
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestCollectionPointRecord < Palm::WabaRecord
|
4
|
+
class_id 072
|
5
|
+
field :corridor, :string
|
6
|
+
field :site, :string
|
7
|
+
field :direction, :byte
|
8
|
+
field :lanes, :byte
|
9
|
+
field :hov_lane, :byte
|
10
|
+
field :ramp_type, :string
|
11
|
+
field :express, :boolean
|
12
|
+
field :cp_id, :int
|
13
|
+
end
|
14
|
+
|
15
|
+
class TC_WabaDBTest < Test::Unit::TestCase
|
16
|
+
def setup
|
17
|
+
setup_paths
|
18
|
+
@pdb = Palm::WabaDB.new(TestCollectionPointRecord)
|
19
|
+
@pdb.load(open(@path))
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
File.delete(@temp_path) if File.exist? @temp_path
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_records_exist
|
27
|
+
assert @pdb.data.length > 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_correct_class
|
31
|
+
@pdb.data.each do |record|
|
32
|
+
assert_instance_of TestCollectionPointRecord, record
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_records_look_right
|
37
|
+
cp_ids = {}
|
38
|
+
@pdb.data.each do |record|
|
39
|
+
assert record.corridor.length > 0, "Corridor should not be empty"
|
40
|
+
assert record.site.length > 0, "Site should not be empty"
|
41
|
+
assert (1..4).include?(record.direction), "Direction should be 1-4"
|
42
|
+
assert (0..9).include?(record.lanes), "Lanes should be between 0 and 9, found #{record.lanes}"
|
43
|
+
assert (0..9).include?(record.hov_lane), "Hov Lane should be between 0 and 9, found #{record.hov_lane}"
|
44
|
+
assert !cp_ids[record.cp_id], "Each cp_id should be unique, #{cp_ids[record.cp_id].inspect} overlaps with #{record.inspect}"
|
45
|
+
cp_ids[record.cp_id] = record
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_database_round_tripping
|
51
|
+
@pdb.write_file(@temp_path)
|
52
|
+
@loaded = Palm::WabaDB.new(TestCollectionPointRecord)
|
53
|
+
@loaded.load_file(@temp_path)
|
54
|
+
|
55
|
+
# Ensure they're two different objects
|
56
|
+
assert(@pdb != @loaded)
|
57
|
+
|
58
|
+
# Test that the loaded data is the same as the original
|
59
|
+
@pdb.data.zip(@loaded.data) do |expected, actual|
|
60
|
+
assert_equal expected.class.fields, actual.class.fields, "Records should have the same fields"
|
61
|
+
expected.class.fields.map{|f| f.name}.each do |name|
|
62
|
+
assert_equal expected.send(name), actual.send(name), "Field #{name} did not match"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_binary_equality
|
69
|
+
@pdb.write_file(@temp_path)
|
70
|
+
|
71
|
+
# Ensure the files are the same size
|
72
|
+
assert_equal File.size(@path), File.size(@temp_path)
|
73
|
+
# Ensure the files are identical
|
74
|
+
assert_equal IO.read(@path), IO.read(@temp_path)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestWabaRecord < Palm::WabaRecord
|
4
|
+
class_id 072
|
5
|
+
field :corridor, :string
|
6
|
+
field :site, :string
|
7
|
+
field :direction, :byte
|
8
|
+
def caps_site
|
9
|
+
site.upcase
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
class TC_WabaRecords < Test::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
@record = TestWabaRecord.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_record_has_expected_fields
|
23
|
+
assert_equal(3, TestWabaRecord.fields.length)
|
24
|
+
assert_equal [:corridor,:site,:direction], TestWabaRecord.fields.map{|f| f.name}
|
25
|
+
assert_equal [:string,:string,:byte], TestWabaRecord.fields.map{|f| f.type}
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_fields_are_readable_and_writeable
|
29
|
+
fill_record(@record)
|
30
|
+
assert_record(@record)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Odd things can happen when metaprogramming, lets make sure variables
|
34
|
+
# are stored in the right places
|
35
|
+
def test_records_dont_overlap
|
36
|
+
a = TestWabaRecord.new;
|
37
|
+
a.site = "A"
|
38
|
+
b = TestWabaRecord.new
|
39
|
+
b.site = "B"
|
40
|
+
assert_equal(a.site, "A")
|
41
|
+
assert_equal(b.site, "B")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_class_id_is_accesible
|
45
|
+
assert_equal(072, @record.class_id)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_io_round_tripping
|
49
|
+
s = ""
|
50
|
+
io = Palm::WabaStringIO.new(s, "w")
|
51
|
+
fill_record(@record)
|
52
|
+
@record.write(io)
|
53
|
+
@load_record = TestWabaRecord.new
|
54
|
+
@load_record.read( Palm::WabaStringIO.new(s, "r") )
|
55
|
+
assert_record(@load_record)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_class_can_have_helper_methods
|
59
|
+
fill_record(@record)
|
60
|
+
assert_equal "TEST SITE", @record.caps_site
|
61
|
+
end
|
62
|
+
|
63
|
+
def fill_record(record)
|
64
|
+
record.corridor = "I-5"
|
65
|
+
record.direction = 4
|
66
|
+
record.site = "Test Site"
|
67
|
+
end
|
68
|
+
|
69
|
+
def assert_record(record)
|
70
|
+
assert_equal("I-5", record.corridor)
|
71
|
+
assert_equal(4, record.direction)
|
72
|
+
assert_equal("Test Site", record.site)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: palm
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-01-02 00:00:00 -08:00
|
8
|
+
summary: Pure Ruby library for reading and writing Palm PDB databases.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: netghost@u.washington.edu
|
12
|
+
homepage: http://palm.rubyforge.org
|
13
|
+
rubyforge_project: palm
|
14
|
+
description: Pure Ruby library for reading and writing Palm PDB databases.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Adam Sanderson
|
30
|
+
files:
|
31
|
+
- CHANGELOG.txt
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- lib/palm.rb
|
37
|
+
- lib/palm/palm_record.rb
|
38
|
+
- lib/palm/palm_support.rb
|
39
|
+
- lib/palm/pdb.rb
|
40
|
+
- lib/palm/raw_record.rb
|
41
|
+
- lib/palm/version.rb
|
42
|
+
- lib/palm/waba_db.rb
|
43
|
+
- lib/palm/waba_io.rb
|
44
|
+
- lib/palm/waba_record.rb
|
45
|
+
- setup.rb
|
46
|
+
- test/HovData.pdb
|
47
|
+
- test/pdb_test.rb
|
48
|
+
- test/test_helper.rb
|
49
|
+
- test/waba_db_test.rb
|
50
|
+
- test/waba_records_test.rb
|
51
|
+
test_files:
|
52
|
+
- test/pdb_test.rb
|
53
|
+
- test/waba_db_test.rb
|
54
|
+
- test/waba_records_test.rb
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
executables: []
|
60
|
+
|
61
|
+
extensions: []
|
62
|
+
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
dependencies:
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: hoe
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 1.1.6
|
74
|
+
version:
|