Sha256: 691d5d82dbfccebc6edbc918cf95710fa14f784acdc0de477fd1dbd431cff105

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

#! /usr/bin/ruby

$: << File.dirname(__FILE__) + '/../lib'

require 'test/unit'
require 'ole/storage'
require 'ole/file_system'
require 'tempfile'

class TestWriteMbat < Test::Unit::TestCase
	def test_write_mbat
		Tempfile.open 'myolefile' do |temp|
			temp.binmode

			# this used to raise an error at flush time, due to failure to write the mbat
			Ole::Storage.open temp do |ole|
				# create a 10mb file
				ole.file.open 'myfile', 'w' do |f|
					s = 0.chr * 1_000_000
					10.times { f.write s }
				end
			end

			assert((10_000_000..10_100_000) === temp.size, 'check file size')

			Ole::Storage.open temp do |ole|
				assert_equal 10_000_000, ole.file.size('myfile')
				compare = ole.bbat.truncate[(0...ole.bbat.length).find { |i| ole.bbat[i] > 50_000 }..-1]
				c = Ole::Storage::AllocationTable
				# 10_000_000 * 4 / 512 / 512 rounded up is 153. but then there is room needed to store the
				# bat in the bat, and the mbat too. hence 154. 
				expect = [c::EOC] * 2 + [c::BAT] * 154 + [c::META_BAT]
				assert_equal expect, compare, 'allocation table structure'
				# the sbat should be empty. in fact the file shouldn't exist at all, so the root's first
				# block should be EOC
				assert ole.sbat.empty?
				assert_equal c::EOC, ole.root.first_block
			end
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby-ole-1.2.5 test/test_mbat.rb
ruby-ole-1.2.6 test/test_mbat.rb
ruby-ole-1.2.4 test/test_mbat.rb