[DRE-commits] [ruby-ole] 01/05: Imported Upstream version 1.2.11.7

Youhei SASAKI uwabami-guest at alioth.debian.org
Mon Aug 5 15:35:34 UTC 2013


This is an automated email from the git hooks/post-receive script.

uwabami-guest pushed a commit to branch master
in repository ruby-ole.

commit ad53fd8693b8c68cea668a351ba08a5f99b02a62
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date:   Tue Aug 6 00:04:32 2013 +0900

    Imported Upstream version 1.2.11.7
---
 ChangeLog                      |   27 +++++++++++++++++
 Rakefile                       |   36 ++++++++++++----------
 data/propids.yaml              |   56 -----------------------------------
 lib/ole/ranges_io.rb           |   11 +++++--
 lib/ole/storage/base.rb        |   37 ++++++++++-------------
 lib/ole/storage/file_system.rb |    2 +-
 lib/ole/storage/meta_data.rb   |    6 ++--
 lib/ole/storage/version.rb     |    2 +-
 lib/ole/support.rb             |   64 ++++++++++++++++------------------------
 lib/ole/types/property_set.rb  |   45 ++++++++++++++++++++++++----
 metadata.yml                   |    9 +++---
 ruby-ole.gemspec               |    4 +--
 test/test_filesystem.rb        |   28 ++++++++++++++++--
 test/test_ranges_io.rb         |   12 +++++++-
 test/test_storage.rb           |    1 +
 test/test_support.rb           |   17 +++--------
 test/test_types.rb             |    1 +
 17 files changed, 190 insertions(+), 168 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cd7f5d0..ce72cb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+== 1.2.11.7 / 2013-06-24
+
+- Various encoding fixes to make tests pass on current rubies.
+- Fix RangesIO#write behaviour when passed an encoded string (github #14,
+  romuloceccon).
+- Fix Dirent#each_child attempting iteration on file children (github #13).
+- Unused variable fixes to avoid warnings (github #12, kachick).
+
+== 1.2.11.6 / 2012-12-10
+
+- Fix breakage of writable IO stream detection on Windows (github #11).
+
+== 1.2.11.5 / 2012-11-06
+
+- Fix breakage of IO.parse_mode on Rubinius (issue #10).
+- Make tests pass on rubinius (issue #11).
+- Improve RangesIO test coverage.
+- Don't warn when mbat_start is AVAIL instead of EOC (github #9).
+
+== 1.2.11.4 / 2012-07-03
+
+- Embed PropertySet meta data GUIDs and field lists, to avoid hitting the
+  filesystem and remove dependency on YAML.
+- Update Rakefile to avoid warnings about both deprecated tasks and space
+  before parentheses.
+- Remove Dirent#children=.
+
 == 1.2.11.3 / 2012-02-25
 
 - Various fixes for ruby 1.9.3 - handle iconv deprecation and
diff --git a/Rakefile b/Rakefile
index 4c70480..e99094c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,8 +1,5 @@
 require 'rubygems'
-require 'rake/rdoctask'
 require 'rake/testtask'
-require 'rake/packagetask'
-require 'rake/gempackagetask'
 
 require 'rbconfig'
 require 'fileutils'
@@ -31,20 +28,29 @@ rescue LoadError
 	# Rcov not available
 end
 
-Rake::RDocTask.new do |t|
-	t.rdoc_dir = 'doc'
-	t.rdoc_files.include 'lib/**/*.rb'
-	t.rdoc_files.include 'README', 'ChangeLog'
-	t.title    = "#{PKG_NAME} documentation"
-	t.options += %w[--line-numbers --inline-source --tab-width 2]
-	t.main	   = 'README'
+begin
+	require 'rdoc/task'
+	RDoc::Task.new do |t|
+		t.rdoc_dir = 'doc'
+		t.rdoc_files.include 'lib/**/*.rb'
+		t.rdoc_files.include 'README', 'ChangeLog'
+		t.title    = "#{PKG_NAME} documentation"
+		t.options += %w[--line-numbers --inline-source --tab-width 2]
+		t.main	   = 'README'
+	end
+rescue LoadError
+	# RDoc not available or too old (<2.4.2)
 end
 
-Rake::GemPackageTask.new(spec) do |t|
-	t.gem_spec = spec
-	t.need_tar = true
-	t.need_zip = false
-	t.package_dir = 'build'
+begin
+	require 'rubygems/package_task'
+	Gem::PackageTask.new(spec) do |t|
+		t.need_tar = true
+		t.need_zip = false
+		t.package_dir = 'build'
+	end
+rescue LoadError
+	# RubyGems too old (<1.3.2)
 end
 
 desc 'Run various benchmarks'
diff --git a/data/propids.yaml b/data/propids.yaml
deleted file mode 100644
index 9ac43ff..0000000
--- a/data/propids.yaml
+++ /dev/null
@@ -1,56 +0,0 @@
-"{f29f85e0-4ff9-1068-ab91-08002b27b3d9}":
-  - FMTID_SummaryInformation
-  - 2:  doc_title
-    3:  doc_subject
-    4:  doc_author
-    5:  doc_keywords
-    6:  doc_comments
-    7:  doc_template
-    8:  doc_last_author
-    9:  doc_rev_number
-    10: doc_edit_time
-    11: doc_last_printed
-    12: doc_created_time
-    13: doc_last_saved_time
-    14: doc_page_count
-    15: doc_word_count
-    16: doc_char_count
-    18: doc_app_name
-    19: security
-
-"{d5cdd502-2e9c-101b-9397-08002b2cf9ae}":
-  - FMTID_DocSummaryInfo
-  - 2:  doc_category
-    3:  doc_presentation_target
-    4:  doc_byte_count
-    5:  doc_line_count
-    6:  doc_para_count
-    7:  doc_slide_count
-    8:  doc_note_count
-    9:  doc_hidden_count
-    10: mmclips
-    11: scale_crop
-    12: heading_pairs
-    13: doc_part_titles
-    14: doc_manager
-    15: doc_company
-    16: links_up_to_date
-
-"{d5cdd505-2e9c-101b-9397-08002b2cf9ae}":
-  - FMTID_UserDefinedProperties
-  - {}
-
-# just dumped these all here. if i can confirm any of these
-# better, i can update this file so they're recognized.
-#0b63e343-9ccc-11d0-bcdb-00805fccce04
-#0b63e350-9ccc-11d0-bcdb-00805fccce04 NetLibrary propset?
-#31f400a0-fd07-11cf-b9bd-00aa003db18e ScriptInfo propset?
-#49691c90-7e17-101a-a91c-08002b2ecda9 Query propset?
-#560c36c0-503a-11cf-baa1-00004c752a9a
-#70eb7a10-55d9-11cf-b75b-00aa0051fe20 HTMLInfo propset
-#85ac0960-1819-11d1-896f-00805f053bab message propset?
-#aa568eec-e0e5-11cf-8fda-00aa00a14f93 NNTP SummaryInformation propset?
-#b725f130-47ef-101a-a5f1-02608c9eebac Storage propset
-#c82bf596-b831-11d0-b733-00aa00a1ebd2 NetLibraryInfo propset
-#c82bf597-b831-11d0-b733-00aa00a1ebd2 LinkInformation propset?
-#d1b5d3f0-c0b3-11cf-9a92-00a0c908dbf1 LinkInformation propset?
diff --git a/lib/ole/ranges_io.rb b/lib/ole/ranges_io.rb
index 7d27239..20918ed 100644
--- a/lib/ole/ranges_io.rb
+++ b/lib/ole/ranges_io.rb
@@ -1,6 +1,6 @@
 # encoding: ASCII-8BIT
 
-# need IO::Mode
+# need Ole::IOMode
 require 'ole/support'
 
 #
@@ -57,7 +57,7 @@ class RangesIO
 		mode, params = 'r', mode if Hash === mode
 		ranges = params[:ranges]
 		@params = {:close_parent => false}.merge params
-		@mode = IO::Mode.new mode
+		@mode = Ole::IOMode.new mode
 		@io = io
 		# initial position in the file
 		@pos = 0
@@ -195,6 +195,11 @@ class RangesIO
 	end
 
 	def write data
+		# duplicates object to avoid side effects for the caller, but do so only if
+		# encoding isn't already ASCII-8BIT (slight optimization)
+		if data.respond_to?(:encoding) and data.encoding != Encoding::ASCII_8BIT
+			data = data.dup.force_encoding(Encoding::ASCII_8BIT)
+		end
 		return 0 if data.empty?
 		data_pos = 0
 		# if we don't have room, we can use the truncate hook to make more space.
@@ -255,7 +260,7 @@ end
 class RangesIONonResizeable < RangesIO # :nodoc:
 	def initialize io, mode='r', params={}
 		mode, params = 'r', mode if Hash === mode
-		flags = IO::Mode.new(mode).flags & ~IO::TRUNC
+		flags = Ole::IOMode.new(mode).flags & ~IO::TRUNC
 		super io, flags, params
 	end
 end
diff --git a/lib/ole/storage/base.rb b/lib/ole/storage/base.rb
index e552133..781f023 100644
--- a/lib/ole/storage/base.rb
+++ b/lib/ole/storage/base.rb
@@ -50,20 +50,22 @@ module Ole # :nodoc:
 				raise ArgumentError, 'unable to specify mode string with io object' if mode
 				[false, arg]
 			end
-			# do we have this file opened for writing? don't know of a better way to tell
-			# (unless we parse the mode string in the open case)
-			# hmmm, note that in ruby 1.9 this doesn't work anymore. which is all the more
-			# reason to use mode string parsing when available, and fall back to something like
-			# io.writeable? otherwise.
+			# force encoding, to avoid picking up source encoding with StringIO or files in text mode
+			@io.set_encoding Encoding::ASCII_8BIT if @io.respond_to?(:set_encoding)
+			# do we have this file opened for writing? use mode when provided,
+			# otherwise try no-op methods which will raise if read-only
 			@writeable = begin
 				if mode
-					IO::Mode.new(mode).writeable?
+					IOMode.new(mode).writeable?
 				else
+					# works on mri 1.8 & jruby
 					@io.flush
-					# this is for the benefit of ruby-1.9
-					# generates warnings on jruby though... :/
-					if RUBY_PLATFORM != 'java' and @io.respond_to?(:syswrite)
-						@io.syswrite('')
+					begin
+						# works on mri 1.9 & rubinius, throws EBADF on windows
+						@io.write_nonblock('') if @io.respond_to?(:write_nonblock)
+					rescue Errno::EBADF
+						# for windows
+						@io.syswrite('');
 					end
 					true
 				end
@@ -135,7 +137,7 @@ module Ole # :nodoc:
 				def to_tree idx=0
 					return [] if idx == Dirent::EOT
 					d = self[idx]
-					d.children = to_tree d.child
+					to_tree(d.child).each { |child| d << child }
 					raise FormatError, "directory #{d.inspect} used twice" if d.idx
 					d.idx = idx
 					to_tree(d.prev) + [d] + to_tree(d.next)
@@ -229,7 +231,6 @@ module Ole # :nodoc:
 			# delete a lot of stuff, and free up trailing blocks, the file size never shrinks. this can
 			# be fixed easily, add an io truncate
 			@bbat.truncate!
-			before = @io.size
 			@io.truncate @bbat.block_size * (@bbat.length + 1)
 			while true
 				# get total bbat size. equivalent to @bbat.to_s.length, but for the factoring in of
@@ -390,7 +391,7 @@ module Ole # :nodoc:
 				# 3 for this value. 
 				# transacting_signature != "\x00" * 4 or
 				if threshold != 4096 or
-					 num_mbat == 0 && mbat_start != AllocationTable::EOC or
+					 num_mbat == 0 && ![AllocationTable::EOC, AllocationTable::AVAIL].include?(mbat_start) or
 					 reserved != "\x00" * 6
 					Log.warn "may not be a valid OLE2 structured storage file"
 				end
@@ -786,14 +787,6 @@ module Ole # :nodoc:
 				@name = name
 			end
 
-			# needed to add reset of @name_lookup here. might be better to just
-			# remove this method as its only used in one place anyway.
-			def children= children
-				@children = []
-				@name_lookup = {}
-				children.each { |child| self << child }
-			end
-
 			def open mode='r'
 				raise Errno::EISDIR unless file?
 				io = RangesIOMigrateable.new self, mode
@@ -840,7 +833,7 @@ module Ole # :nodoc:
 			end
 
 			def each_child(&block)
-				@children.each(&block)
+				@children.each(&block) if dir?
 			end
 
 			# flattens the tree starting from here into +dirents+. note it modifies its argument.
diff --git a/lib/ole/storage/file_system.rb b/lib/ole/storage/file_system.rb
index 63f5f1a..5c113e0 100644
--- a/lib/ole/storage/file_system.rb
+++ b/lib/ole/storage/file_system.rb
@@ -151,7 +151,7 @@ module Ole # :nodoc:
 			end
 
 			def open path, mode='r', &block
-				if IO::Mode.new(mode).create?
+				if IOMode.new(mode).create?
 					begin
 						dirent = dirent_from_path path
 					rescue Errno::ENOENT
diff --git a/lib/ole/storage/meta_data.rb b/lib/ole/storage/meta_data.rb
index 3b5b8c4..e185cc1 100644
--- a/lib/ole/storage/meta_data.rb
+++ b/lib/ole/storage/meta_data.rb
@@ -76,8 +76,8 @@ module Ole
 				# byte_order: 0xffe
 				# windows_version: 0x00000a03 (win31 apparently)
 				# marker: 0xffffffff
-				compobj_version, byte_order, windows_version, marker, clsid =
-					data.unpack("vvVVa#{Types::Clsid::SIZE}")
+				# compobj_version, byte_order, windows_version, marker, clsid =
+				# 	data.unpack("vvVVa#{Types::Clsid::SIZE}")
 				strings = []
 				i = 28
 				while i < data.length
@@ -137,7 +137,7 @@ module Ole
 
 			def method_missing name, *args, &block
 				return super unless args.empty?
-				pair = Types::PropertySet::PROPERTY_MAP[name.to_s] or return super
+				return super unless Types::PropertySet::PROPERTY_MAP[name.to_s]
 				self[name]
 			end
 		end
diff --git a/lib/ole/storage/version.rb b/lib/ole/storage/version.rb
index b19c44c..65ecacf 100644
--- a/lib/ole/storage/version.rb
+++ b/lib/ole/storage/version.rb
@@ -2,7 +2,7 @@
 
 module Ole # :nodoc:
 	class Storage
-		VERSION = '1.2.11.3'
+		VERSION = '1.2.11.7'
 	end
 end
 
diff --git a/lib/ole/support.rb b/lib/ole/support.rb
index e815cc4..5301516 100644
--- a/lib/ole/support.rb
+++ b/lib/ole/support.rb
@@ -11,14 +11,6 @@ require 'stringio'
 require 'enumerator'
 
 class String # :nodoc:
-	# plural of String#index. returns all offsets of +string+. rename to indices?
-	#
-	# note that it doesn't check for overlapping values.
-	def indexes string
-		# in some ways i'm surprised that $~ works properly in this case...
-		to_enum(:scan, /#{Regexp.quote string}/m).map { $~.begin 0 }
-	end
-
 	def each_chunk size
 		(length / size.to_f).ceil.times { |i| yield self[i * size, size] }
 	end
@@ -165,34 +157,8 @@ module RecursivelyEnumerable # :nodoc:
 	end
 end
 
-# can include File::Constants
-class IO
-	# this is for jruby
-	include File::Constants unless defined?(RDONLY)
-
-	# nabbed from rubinius, and modified
-	def self.parse_mode mode
-		ret = 0
-
-		case mode[0, 1]
-		when 'r'; ret |= RDONLY
-		when 'w'; ret |= WRONLY | CREAT | TRUNC
-		when 'a'; ret |= WRONLY | CREAT | APPEND
-		else raise ArgumentError, "illegal access mode #{mode}"
-		end
-
-		(1...mode.length).each do |i|
-			case mode[i, 1]
-			when '+'; ret = (ret & ~(RDONLY | WRONLY)) | RDWR
-			when 'b'; ret |= Mode::BINARY
-			else raise ArgumentError, "illegal access mode #{mode}"
-			end
-		end
-	
-		ret
-	end
-
-	class Mode
+module Ole
+	class IOMode
 		# ruby 1.9 defines binary as 0, which isn't very helpful.
 		# its 4 in rubinius. no longer using
 		#
@@ -207,9 +173,31 @@ class IO
 		include Constants
 		NAMES = %w[rdonly wronly rdwr creat trunc append binary]
 
+		# nabbed from rubinius, and modified
+		def self.parse_mode mode
+			ret = 0
+
+			case mode[0, 1]
+			when 'r'; ret |= RDONLY
+			when 'w'; ret |= WRONLY | CREAT | TRUNC
+			when 'a'; ret |= WRONLY | CREAT | APPEND
+			else raise ArgumentError, "illegal access mode #{mode}"
+			end
+
+			(1...mode.length).each do |i|
+				case mode[i, 1]
+				when '+'; ret = (ret & ~(RDONLY | WRONLY)) | RDWR
+				when 'b'; ret |= BINARY
+				else raise ArgumentError, "illegal access mode #{mode}"
+				end
+			end
+
+			ret
+		end
+
 		attr_reader :flags
 		def initialize flags
-			flags = IO.parse_mode flags.to_str if flags.respond_to? :to_str
+			flags = self.class.parse_mode flags.to_str if flags.respond_to? :to_str
 			raise ArgumentError, "invalid flags - #{flags.inspect}" unless Fixnum === flags
 			@flags = flags
 		end
@@ -251,7 +239,7 @@ class IO
 =end
 
 		def inspect
-			names = NAMES.map { |name| name if (flags & Mode.const_get(name.upcase)) != 0 }
+			names = NAMES.map { |name| name if (flags & IOMode.const_get(name.upcase)) != 0 }
 			names.unshift 'rdonly' if (flags & 0x3) == 0
 			"#<#{self.class} #{names.compact * '|'}>"
 		end
diff --git a/lib/ole/types/property_set.rb b/lib/ole/types/property_set.rb
index ce8662d..999fdae 100644
--- a/lib/ole/types/property_set.rb
+++ b/lib/ole/types/property_set.rb
@@ -1,7 +1,5 @@
 # encoding: ASCII-8BIT
 
-require 'yaml'
-
 module Ole
 	module Types
 		#
@@ -24,8 +22,45 @@ module Ole
 			}
 
 			# define a smattering of the property set guids. 
-			DATA = YAML.load_file(File.dirname(__FILE__) + '/../../../data/propids.yaml').
-				inject({}) { |hash, (key, value)| hash.update Clsid.parse(key) => value }
+			DATA = {
+				Clsid.parse('{f29f85e0-4ff9-1068-ab91-08002b27b3d9}') => ['FMTID_SummaryInformation', {
+					2  => 'doc_title',
+					3  => 'doc_subject',
+					4  => 'doc_author',
+					5  => 'doc_keywords',
+					6  => 'doc_comments',
+					7  => 'doc_template',
+					8  => 'doc_last_author',
+					9  => 'doc_rev_number',
+					10 => 'doc_edit_time',
+					11 => 'doc_last_printed',
+					12 => 'doc_created_time',
+					13 => 'doc_last_saved_time',
+					14 => 'doc_page_count',
+					15 => 'doc_word_count',
+					16 => 'doc_char_count',
+					18 => 'doc_app_name',
+					19 => 'security'
+				}],
+				Clsid.parse('{d5cdd502-2e9c-101b-9397-08002b2cf9ae}') => ['FMTID_DocSummaryInfo', {
+					2  => 'doc_category',
+					3  => 'doc_presentation_target',
+					4  => 'doc_byte_count',
+					5  => 'doc_line_count',
+					6  => 'doc_para_count',
+					7  => 'doc_slide_count',
+					8  => 'doc_note_count',
+					9  => 'doc_hidden_count',
+					10 => 'mmclips',
+					11 => 'scale_crop',
+					12 => 'heading_pairs',
+					13 => 'doc_part_titles',
+					14 => 'doc_manager',
+					15 => 'doc_company',
+					16 => 'links_up_to_date'
+				}],
+				Clsid.parse('{d5cdd505-2e9c-101b-9397-08002b2cf9ae}') => ['FMTID_UserDefinedProperties', {}]
+			}
 
 			# create an inverted map of names to guid/key pairs
 			PROPERTY_MAP = DATA.inject({}) do |h1, (guid, data)|
@@ -33,7 +68,7 @@ module Ole
 			end
 
 			module Constants
-				DATA.each { |guid, (name, map)| const_set name, guid }
+				DATA.each { |guid, (name, _)| const_set name, guid }
 			end
 
 			include Constants
diff --git a/metadata.yml b/metadata.yml
index ec9094f..35e1aad 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,14 +1,14 @@
 --- !ruby/object:Gem::Specification 
 name: ruby-ole
 version: !ruby/object:Gem::Version 
-  hash: 101
+  hash: 109
   prerelease: false
   segments: 
   - 1
   - 2
   - 11
-  - 3
-  version: 1.2.11.3
+  - 7
+  version: 1.2.11.7
 platform: ruby
 authors: 
 - Charles Lowe
@@ -16,7 +16,7 @@ autorequire:
 bindir: bin
 cert_chain: []
 
-date: 2012-02-25 00:00:00 -05:00
+date: 2013-06-24 00:00:00 +10:00
 default_executable: 
 dependencies: []
 
@@ -35,7 +35,6 @@ files:
 - Rakefile
 - ChangeLog
 - ruby-ole.gemspec
-- data/propids.yaml
 - bin/oletool
 - lib/ole/storage.rb
 - lib/ole/storage/file_system.rb
diff --git a/ruby-ole.gemspec b/ruby-ole.gemspec
index 8f3a66d..0282cf3 100644
--- a/ruby-ole.gemspec
+++ b/ruby-ole.gemspec
@@ -1,4 +1,4 @@
-$:.unshift (File.dirname(__FILE__) + '/lib')
+$:.unshift File.dirname(__FILE__) + '/lib'
 require 'ole/storage/version'
 
 PKG_NAME = 'ruby-ole'
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
 	s.rubyforge_project = %q{ruby-ole}
 
 	s.executables = ['oletool']
-	s.files  = ['README', 'COPYING', 'Rakefile', 'ChangeLog', 'ruby-ole.gemspec', 'data/propids.yaml']
+	s.files  = ['README', 'COPYING', 'Rakefile', 'ChangeLog', 'ruby-ole.gemspec']
 	s.files += Dir.glob('lib/**/*.rb')
 	s.files += Dir.glob('test/{test_*.rb,*.doc,oleWithDirs.ole,test_SummaryInformation}')
 	s.files += Dir.glob('bin/*')
diff --git a/test/test_filesystem.rb b/test/test_filesystem.rb
index ece00b7..bcb2889 100755
--- a/test/test_filesystem.rb
+++ b/test/test_filesystem.rb
@@ -1,4 +1,5 @@
 #! /usr/bin/ruby
+# encoding: ASCII-8BIT
 
 #
 # = NOTE
@@ -564,10 +565,9 @@ class OleFsFileStatTest < Test::Unit::TestCase
 	# an additional test i added for coverage. i've tried to make the inspect
 	# string on the ole stat match that of the regular one.
 	def test_inspect
-		expect = '#<Ole::Storage::FileClass::Stat ino=0, uid=0, size=72, rdev=0, nlink=1, dev=0, blocks=2, gid=0, ftype=file, blksize=64>'
-		# normalize them, as instance_variables order is undefined
+		# normalize, as instance_variables order is undefined
 		normalize = proc { |s| s[/ (.*)>$/, 1].split(', ').sort.join(', ') }
-		assert_equal normalize[expect], normalize[@ole.file.stat('file1').inspect]
+		assert_match %r{blocks=2.*ftype=file.*size=72}, normalize[@ole.file.stat('file1').inspect]
 	end
 end
 
@@ -594,20 +594,24 @@ class OleFsFileMutatingTest < Test::Unit::TestCase
 		Ole::Storage.open(@io) {
 			|zf|
 
+			blockCalled = nil
 			zf.file.open("test_open_write_entry", "w") {
 				|f|
 				blockCalled = true
 				f.write "This is what I'm writing"
 			}
+			assert(blockCalled)
 			assert_equal("This is what I'm writing",
 										zf.file.read("test_open_write_entry"))
 
+			blockCalled = nil
 			# Test with existing entry
 			zf.file.open("file1", "w") {
 				|f|
 				blockCalled = true
 				f.write "This is what I'm writing too"
 			}
+			assert(blockCalled)
 			assert_equal("This is what I'm writing too",
 										zf.file.read("file1"))
 		}
@@ -902,6 +906,24 @@ class OleUnicodeTest < Test::Unit::TestCase
 			end
 		end
 	end
+
+	def test_write_utf8_string
+		programmer = "programa\xC3\xA7\xC3\xA3o "
+		programmer.force_encoding Encoding::UTF_8 if programmer.respond_to? :encoding
+		Ole::Storage.open @io do |ole|
+			ole.file.open '1', 'w' do |writer|
+				writer.write(programmer)
+				writer.write('ruby')
+			end
+		end
+		Ole::Storage.open @io do |ole|
+			ole.file.open '1', 'r' do |reader|
+				s = reader.read
+				s = s.force_encoding('UTF-8') if s.respond_to?(:encoding)
+				assert_equal(programmer + 'ruby', s)
+			end
+		end
+	end
 end
 
 # Copyright (C) 2002, 2003 Thomas Sondergaard
diff --git a/test/test_ranges_io.rb b/test/test_ranges_io.rb
index 41853c0..5db892d 100755
--- a/test/test_ranges_io.rb
+++ b/test/test_ranges_io.rb
@@ -29,6 +29,14 @@ class TestRangesIO < Test::Unit::TestCase
 		assert_equal true, f.closed?
 	end
 
+	def test_combine
+		ranges = [[0, 100], 100...200, [200, 100]]
+		io = RangesIO.new STDOUT, 'r+', :ranges => ranges
+		assert_equal [[0, 300]], io.ranges
+		io = RangesIO.new STDOUT, 'r+', :ranges => ranges, :combine => false
+		assert_equal [[0, 100], [100, 100], [200, 100]], io.ranges
+	end
+
 	def test_basics
 		assert_equal 160, @io.size
 		assert_match %r{size=160}, @io.inspect
@@ -44,6 +52,8 @@ class TestRangesIO < Test::Unit::TestCase
 		@io.seek(-10, IO::SEEK_CUR)
 		@io.pos += 20
 		assert_equal 70, @io.pos
+		@io.rewind
+		assert_equal 0, @io.pos
 		# seeking past the end doesn't throw an exception for normal
 		# files, even in read mode, but RangesIO does
 		assert_raises(Errno::EINVAL) { @io.seek 500 }
@@ -97,7 +107,7 @@ class TestRangesIO < Test::Unit::TestCase
 		end
 		# will be fine
 		@io = RangesIONonResizeable.new(StringIO.new, 'w', :ranges => [])
-		assert_equal '#<IO::Mode wronly|creat>', @io.instance_variable_get(:@mode).inspect
+		assert_equal '#<Ole::IOMode wronly|creat>', @io.instance_variable_get(:@mode).inspect
 	end
 end
 
diff --git a/test/test_storage.rb b/test/test_storage.rb
index eecd696..219fd92 100755
--- a/test/test_storage.rb
+++ b/test/test_storage.rb
@@ -1,4 +1,5 @@
 #! /usr/bin/ruby
+# coding: utf-8
 
 $: << File.dirname(__FILE__) + '/../lib'
 #require 'rubygems'
diff --git a/test/test_support.rb b/test/test_support.rb
index 11116c5..893c90c 100755
--- a/test/test_support.rb
+++ b/test/test_support.rb
@@ -36,15 +36,6 @@ class TestSupport < Test::Unit::TestCase
 		assert_equal str, dst.string
 	end
 
-	def test_string
-		str = "aa aa ||| aa aa"
-		assert_equal [0, 3, 10, 13], str.indexes('aa')
-		# this is mostly a check that regexp quote is used.
-		assert_equal [6, 7, 8], str.indexes('|')
-		# note not [6, 7] - no overlaps
-		assert_equal [6], str.indexes('||')
-	end
-
 	def test_symbol
 		array = (1..10).to_a
 		assert_equal 55, array.inject(&:+)
@@ -53,7 +44,7 @@ end
 
 class TestIOMode < Test::Unit::TestCase
 	def mode s
-		IO::Mode.new s
+		Ole::IOMode.new s
 	end
 
 	def test_parse
@@ -83,9 +74,9 @@ class TestIOMode < Test::Unit::TestCase
 	end
 	
 	def test_inspect
-		assert_equal '#<IO::Mode rdonly>', IO::Mode.new('r').inspect
-		assert_equal '#<IO::Mode rdwr|creat|trunc|binary>', IO::Mode.new('wb+').inspect
-		assert_equal '#<IO::Mode wronly|creat|append>', IO::Mode.new('a').inspect
+		assert_equal '#<Ole::IOMode rdonly>', mode('r').inspect
+		assert_equal '#<Ole::IOMode rdwr|creat|trunc|binary>', mode('wb+').inspect
+		assert_equal '#<Ole::IOMode wronly|creat|append>', mode('a').inspect
 	end
 end
 
diff --git a/test/test_types.rb b/test/test_types.rb
index 521c66e..153c820 100755
--- a/test/test_types.rb
+++ b/test/test_types.rb
@@ -1,4 +1,5 @@
 #! /usr/bin/ruby
+# encoding: ASCII-8BIT
 
 $: << File.dirname(__FILE__) + '/../lib'
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-ole.git



More information about the Pkg-ruby-extras-commits mailing list