palm 0.0.3 → 0.0.4

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.
@@ -1 +1,7 @@
1
- 0.0.1 - Initial Release
1
+ 0.0.1 - Initial Release
2
+
3
+ 0.0.3 - Minor bug fixes
4
+
5
+ 0.0.4 - Fixed some really silly binary issues,
6
+ where I was using platform specific endian encoding.
7
+ - Added some more unit tests to make myself feel better.
@@ -17,4 +17,5 @@ test/HovData.pdb
17
17
  test/pdb_test.rb
18
18
  test/test_helper.rb
19
19
  test/waba_db_test.rb
20
+ test/waba_io_test.rb
20
21
  test/waba_records_test.rb
@@ -2,7 +2,7 @@ module Palm #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -8,7 +8,8 @@ module Palm
8
8
  end
9
9
 
10
10
  def get_short
11
- read(2).unpack('s').first
11
+ s = read(2)
12
+ ((s[0] & 0xFF) << 8) | (s[1] & 0xFF)
12
13
  end
13
14
 
14
15
  def get_byte
@@ -33,17 +34,19 @@ module Palm
33
34
  end
34
35
 
35
36
  def write_short(short)
36
- write([short].pack('s'))
37
+ putc( (short >> 8) & 0xFF )
38
+ putc( (short >> 0) & 0xFF )
37
39
  end
38
40
 
39
41
  def write_byte(byte)
40
42
  putc byte
41
43
  end
42
44
 
43
- def write_int(i)
44
- [(i >> 24 & 0xFF), (i >> 16 & 0xFF), (i >> 8 & 0xFF) ,(i & 0xFF)].each do |v|
45
- putc v
46
- end
45
+ def write_int(integer)
46
+ putc( (integer >> 24) & 0xFF )
47
+ putc( (integer >> 16) & 0xFF )
48
+ putc( (integer >> 8) & 0xFF )
49
+ putc( (integer >> 0) & 0xFF )
47
50
  end
48
51
 
49
52
  def write_bool(b)
@@ -25,20 +25,6 @@ class TC_PdbTest < Test::Unit::TestCase
25
25
  assert_instance_of(Time, @pdb.backed_up_at)
26
26
  end
27
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
28
  def test_writing_data
43
29
  @pdb.write_file(@temp_path)
44
30
 
@@ -74,4 +74,66 @@ class TC_WabaDBTest < Test::Unit::TestCase
74
74
  assert_equal IO.read(@path), IO.read(@temp_path)
75
75
  end
76
76
 
77
+ def test_creating_from_scratch
78
+ @created = Palm::WabaDB.new(TestCollectionPointRecord)
79
+ @created.name = "HovData"
80
+ @created.type = "HovD"
81
+ @created.creator = "Trac"
82
+ @created.created_at = @pdb.created_at
83
+ @created.modified_at = @pdb.modified_at
84
+ @created.backed_up_at = @pdb.backed_up_at
85
+
86
+ # These are two picky bits. They don't really need to be equal
87
+ @created.version = 1
88
+ @created.modnum = 420
89
+
90
+ @pdb.data.each do |r|
91
+ n = TestCollectionPointRecord.new
92
+ # Copy each field
93
+ r.class.fields.map{|f| f.name}.each do |name|
94
+ n.send("#{name}=", r.send(name))
95
+ end
96
+ @created.data << n
97
+ end
98
+ @created.attributes = @pdb.attributes
99
+ @created.write_file(@temp_path)
100
+
101
+ # Ensure the files are the same size
102
+ assert_equal File.size(@path), File.size(@temp_path)
103
+
104
+ # First assert the headers are the same
105
+ expected_header = IO.read(@path, Palm::PDB::HEADER_LENGTH).unpack("a32 n n N N N N N N a4 a4 N")
106
+ actual_header = IO.read(@temp_path, Palm::PDB::HEADER_LENGTH).unpack("a32 n n N N N N N N a4 a4 N")
107
+
108
+ fields = [:name, :bin_attributes, :version, :created_at, :modified_at, :backed_up_at,
109
+ :modnum, :appinfo_offset, :sort_offset, :type, :creator,
110
+ :unique_id_seed]
111
+
112
+ fields.each_with_index do |field, i|
113
+ assert_equal expected_header[i], actual_header[i], "Header field #{field} should be equal"
114
+ end
115
+
116
+ # Ensure the files are identical
117
+ expected = IO.read(@path)
118
+ actual = IO.read(@temp_path)
119
+ expected.split('').zip(actual.split('')).each_with_index do |pair, i|
120
+ e,a = pair
121
+ assert_equal e,a, "At #{i}: expected '#{e}', actual'#{a}'"
122
+ end
123
+
124
+ assert_equal IO.read(@path), IO.read(@temp_path), "Bytes should be identical"
125
+ end
126
+
127
+ def test_written_records_are_binary_equivalent
128
+ @raw = Palm::PDB.new
129
+ @raw.load_file(@path)
130
+
131
+ @pdb.data.each_with_index do |r,i|
132
+ io = Palm::WabaStringIO.new(s='', "w")
133
+ r.write(io)
134
+ # The actual db will handle writing the first byte
135
+ assert_equal @raw.data[i].data[1..-1], s, "Data portion should be idential"
136
+ end
137
+ end
138
+
77
139
  end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TC_WabaIOTest < Test::Unit::TestCase
4
+ def setup
5
+ setup_paths
6
+ @pdb = Palm::PDB.new
7
+ @pdb.load_file(@path)
8
+ end
9
+
10
+ def teardown
11
+ File.delete(@temp_path) if File.exist? @temp_path
12
+ end
13
+
14
+ def test_that_data_looks_right
15
+ records = @pdb.data
16
+ io = Palm::WabaStringIO.new(records.first.data)
17
+ assert_equal 072 ,io.get_byte
18
+ assert_equal 'Downtown I-5' ,io.get_string
19
+ assert_equal 'Albro Pl' ,io.get_string
20
+ assert_equal 1 ,io.get_byte
21
+ assert_equal 5 ,io.get_byte
22
+ assert_equal 5 ,io.get_byte
23
+ assert_equal 'none' ,io.get_string
24
+ assert_equal false ,io.get_bool
25
+ assert_equal 21 ,io.get_int
26
+ end
27
+
28
+ def test_reading_shorts
29
+ records = @pdb.data
30
+ io = Palm::WabaStringIO.new(records.first.data)
31
+ assert_equal 072 ,io.get_byte
32
+ # next is a string which begins with a short
33
+ # indicating the string length
34
+ assert_equal 'Downtown I-5'.length ,io.get_short
35
+ end
36
+
37
+ def test_round_tripping
38
+ io = Palm::WabaStringIO.new
39
+ # Write my data out
40
+ io.write_string "Hello"
41
+ io.write_int 42
42
+ io.write_short 7
43
+ io.write_bool true
44
+ io.write_bool nil
45
+
46
+ # Assert my position is:
47
+ # 2(short) + 5(string) + 4(int) + 2(short) +1(bool) +1(bool) = 13
48
+ assert_equal 15, io.pos
49
+
50
+ # Reset
51
+ io.seek 0
52
+
53
+ # Read back the results
54
+ assert_equal "Hello", io.get_string
55
+ assert_equal 42, io.get_int
56
+ assert_equal 7, io.get_short
57
+ assert_equal true, io.get_bool
58
+ assert_equal false, io.get_bool
59
+ end
60
+
61
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: palm
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.3
7
- date: 2007-01-04 00:00:00 -08:00
6
+ version: 0.0.4
7
+ date: 2007-01-05 00:00:00 -08:00
8
8
  summary: Pure Ruby library for reading and writing Palm PDB databases.
9
9
  require_paths:
10
10
  - lib
@@ -47,10 +47,12 @@ files:
47
47
  - test/pdb_test.rb
48
48
  - test/test_helper.rb
49
49
  - test/waba_db_test.rb
50
+ - test/waba_io_test.rb
50
51
  - test/waba_records_test.rb
51
52
  test_files:
52
53
  - test/pdb_test.rb
53
54
  - test/waba_db_test.rb
55
+ - test/waba_io_test.rb
54
56
  - test/waba_records_test.rb
55
57
  rdoc_options: []
56
58