test/test_roo.rb in roo-0.6.1 vs test/test_roo.rb in roo-0.7.0

- old
+ new

@@ -1,30 +1,95 @@ -# damit keine falschen Vermutungen aufkommen: Ich habe religoes rein gar nichts -# mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse +#damit keine falschen Vermutungen aufkommen: Ich habe religoes rein gar nichts +# mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse # Spreadsheet-Datei oeffentlich im Netz, die sich ganz gut zum Testen eignete. # +#-- +# these test cases were developed to run under Linux OS, some commands +# (like 'diff') must be changed (or commented out ;-)) if you want to run +# the tests under another OS +# require File.dirname(__FILE__) + '/test_helper.rb' #require 'soap/rpc/driver' require 'fileutils' require 'timeout' + +# helper method +def local_only + if ENV["roo_local"] == "thomas-p" + yield + end +end + +DISPLAY_LOG = false +DB_LOG = false + +if DB_LOG + require 'active_record' +end + include FileUtils +if DB_LOG + def activerecord_connect + ActiveRecord::Base.establish_connection(:adapter => "mysql", + :database => "test_runs", + :host => "localhost", + :username => "root", + :socket => "/var/run/mysqld/mysqld.sock") + end + + class Testrun < ActiveRecord::Base + end +end + +class Test::Unit::TestCase + if DB_LOG + if ! (defined?(@connected) and @connected) + activerecord_connect + else + @connected = true + end + end + alias unlogged_run run + def run(result, &block) + t1 = Time.now + #RAILS_DEFAULT_LOGGER.debug "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}" + if DISPLAY_LOG + print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}" + end + unlogged_run result, &block + t2 = Time.now + if DISPLAY_LOG + puts "\t#{t2-t1} seconds" + end + # record = {'class' => self.class.to_s, + # 'test' => @method_name, + # 'start' => t1, + # 'duration' => t2-t1} + # open('test_runs.yml','a') { |f| YAML.dump(record, f) } + # #-- + if DB_LOG + domain = Testrun.create(:class => self.class.to_s, + :test => @method_name, + :start => t1, + :duration => t2-t1 + ) + end + end +end + class TestRoo < Test::Unit::TestCase OPENOFFICE = true # do Openoffice-Spreadsheet Tests? EXCEL = true # do Excel Tests? GOOGLE = false # do Google-Spreadsheet Tests? OPENOFFICEWRITE = false # experimental: write access with OO-Documents ONLINE = false + LONG_RUN = false + GLOBAL_TIMEOUT = 10*60 # seconds - # helper method - def local_only - if ENV["roo_local"] == "thomas-p" - yield - end - end # helper method def after(d) if DateTime.now > d yield @@ -44,10 +109,13 @@ @goo = Google.new(ENV['GOOGLE_MAIL'], ENV['GOOGLE_PASSWORD'], ENV['GOOGLE_KEY'],"Roo Testspreadheet") end end + if DISPLAY_LOG + puts "GLOBAL_TIMEOUT = #{GLOBAL_TIMEOUT}" + end end def test_letters assert_equal 1, Openoffice.letter_to_number('A') assert_equal 1, Openoffice.letter_to_number('a') @@ -322,25 +390,27 @@ end end end def test_rows - #-- OpenOffice - oo = Openoffice.new(File.join("test","numbers1.ods")) - oo.default_sheet = oo.sheets.first - assert_equal 41, oo.cell('a',12) - assert_equal 42, oo.cell('b',12) - assert_equal 43, oo.cell('c',12) - assert_equal 44, oo.cell('d',12) - assert_equal 45, oo.cell('e',12) - assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12) - assert_equal "einundvierzig", oo.cell('a',16) - assert_equal "zweiundvierzig", oo.cell('b',16) - assert_equal "dreiundvierzig", oo.cell('c',16) - assert_equal "vierundvierzig", oo.cell('d',16) - assert_equal "fuenfundvierzig", oo.cell('e',16) - assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig"], oo.row(16) + if OPENOFFICE + #-- OpenOffice + oo = Openoffice.new(File.join("test","numbers1.ods")) + oo.default_sheet = oo.sheets.first + assert_equal 41, oo.cell('a',12) + assert_equal 42, oo.cell('b',12) + assert_equal 43, oo.cell('c',12) + assert_equal 44, oo.cell('d',12) + assert_equal 45, oo.cell('e',12) + assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12) + assert_equal "einundvierzig", oo.cell('a',16) + assert_equal "zweiundvierzig", oo.cell('b',16) + assert_equal "dreiundvierzig", oo.cell('c',16) + assert_equal "vierundvierzig", oo.cell('d',16) + assert_equal "fuenfundvierzig", oo.cell('e',16) + assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig"], oo.row(16) + end if EXCEL #-- Excel oo = Excel.new(File.join("test","numbers1.xls")) oo.default_sheet = oo.sheets.first assert_equal 41, oo.cell('a',12) @@ -475,15 +545,19 @@ @goo.default_sheet = 1 # @goo.sheets.first assert_equal 1, @goo.first_column end end + def test_first_column_as_letter_openoffice + if OPENOFFICE #-- OpenOffice + oo = Openoffice.new(File.join("test","numbers1.ods")) + oo.default_sheet = oo.sheets.first + assert_equal 'A', oo.first_column_as_letter + end + end + def test_first_column_as_letter - #-- OpenOffice - oo = Openoffice.new(File.join("test","numbers1.ods")) - oo.default_sheet = oo.sheets.first - assert_equal 'A', oo.first_column_as_letter if EXCEL #-- Excel oo = Excel.new(File.join("test","numbers1.xls")) oo.default_sheet = 1 # oo.sheets.first assert_equal 'A', oo.first_column_as_letter @@ -530,17 +604,19 @@ end end def test_multiple_letters #-- OpenOffice - oo = Openoffice.new(File.join("test","numbers1.ods")) - oo.default_sheet = "Sheet3" - assert_equal "i am AA", oo.cell('AA',1) - assert_equal "i am AB", oo.cell('AB',1) - assert_equal "i am BA", oo.cell('BA',1) - assert_equal 'BA', oo.last_column_as_letter - assert_equal "i am BA", oo.cell(1,'BA') + if OPENOFFICE + oo = Openoffice.new(File.join("test","numbers1.ods")) + oo.default_sheet = "Sheet3" + assert_equal "i am AA", oo.cell('AA',1) + assert_equal "i am AB", oo.cell('AB',1) + assert_equal "i am BA", oo.cell('BA',1) + assert_equal 'BA', oo.last_column_as_letter + assert_equal "i am BA", oo.cell(1,'BA') + end if EXCEL #-- Excel oo = Excel.new(File.join("test","numbers1.xls")) oo.default_sheet = 3 # "Sheet3" assert_equal "i am AA", oo.cell('AA',1) @@ -558,26 +634,32 @@ def test_argument_error if EXCEL oo = Excel.new(File.join("test","numbers1.xls")) before Date.new(2007,7,20) do assert_raise(ArgumentError) { - oo.default_sheet = "first sheet" + #oo.default_sheet = "first sheet" + oo.default_sheet = "Tabelle1" } end - assert_nothing_raised(ArgumentError) { - oo.default_sheet = 1 - } + after Date.new(2007,7,20) do + assert_nothing_raised(ArgumentError) { + # oo.default_sheet = 1 + #oo.default_sheet = "first sheet" + oo.default_sheet = "Tabelle1" + } + end end end def test_empty_eh - #-- OpenOffice - oo = Openoffice.new(File.join("test","numbers1.ods")) - oo.default_sheet = oo.sheets.first - assert oo.empty?('a',14) - assert ! oo.empty?('a',15) - assert oo.empty?('a',20) + if OPENOFFICE #-- OpenOffice + oo = Openoffice.new(File.join("test","numbers1.ods")) + oo.default_sheet = oo.sheets.first + assert oo.empty?('a',14) + assert ! oo.empty?('a',15) + assert oo.empty?('a',20) + end if EXCEL #-- Excel oo = Excel.new(File.join("test","numbers1.xls")) oo.default_sheet = 1 assert oo.empty?('a',14) @@ -723,61 +805,61 @@ # assert_equal 1, oo.cell('A',2) # assert_equal 2, oo.cell('B',2) # assert_equal 1, oo.cell('C',2) # are stored as strings, not numbers - + assert_equal 1, oo.cell('A',2).to_i assert_equal 2, oo.cell('B',2).to_i assert_equal 1, oo.cell('C',2).to_i - + assert_equal 1, oo.cell('A',3) assert_equal 3, oo.cell('B',3) assert_equal 1, oo.cell('C',3) - + assert_equal 'A', oo.cell('A',4) assert_equal 'A', oo.cell('B',4) assert_equal 'A', oo.cell('C',4) - + # assert_equal '0.01', oo.cell('A',5) # assert_equal '0.01', oo.cell('B',5) # assert_equal '0.01', oo.cell('C',5) # assert_equal 0.01, oo.cell('A',5) assert_equal 0.01, oo.cell('B',5) assert_equal 0.01, oo.cell('C',5) assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5) - - - # 1.0 - - # Cells values in row 1: - assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s - assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s - assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s - - # Cells values in row 2: - assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s - assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s - assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s - - # Cells values in row 3: - assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s - assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s - assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s - - # Cells values in row 4: - assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s - assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s - assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s - - # Cells values in row 5: - assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s - assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s - assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s + + # 1.0 + + # Cells values in row 1: + assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s + assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s + assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s + + # Cells values in row 2: + assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s + assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s + assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s + + # Cells values in row 3: + assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s + assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s + assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s + + # Cells values in row 4: + assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s + assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s + assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s + + # Cells values in row 5: + assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s + assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s + assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s + oo = Excel.new(File.join("test","simple_spreadsheet_from_italo.xls")) oo.default_sheet = oo.sheets.first assert_equal '1', oo.cell('A',1) assert_equal '1', oo.cell('B',1) @@ -785,68 +867,68 @@ # assert_equal 1, oo.cell('A',2) # assert_equal 2, oo.cell('B',2) # assert_equal 1, oo.cell('C',2) # are stored as strings, not numbers - + assert_equal 1, oo.cell('A',2).to_i assert_equal 2, oo.cell('B',2).to_i assert_equal 1, oo.cell('C',2).to_i - + assert_equal 1, oo.cell('A',3) assert_equal 3, oo.cell('B',3) assert_equal 1, oo.cell('C',3) - + assert_equal 'A', oo.cell('A',4) assert_equal 'A', oo.cell('B',4) assert_equal 'A', oo.cell('C',4) - + # assert_equal '0.01', oo.cell('A',5) # assert_equal '0.01', oo.cell('B',5) # assert_equal '0.01', oo.cell('C',5) # assert_equal 0.01, oo.cell('A',5) assert_equal 0.01, oo.cell('B',5) assert_equal 0.01, oo.cell('C',5) assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5) - - - # 1.0 - - # Cells values in row 1: - assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s - assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s - assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s - - # Cells values in row 2: - assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s - assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s - assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s - - # Cells values in row 3: - assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s - assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s - assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s - - # Cells values in row 4: - assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s - assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s - assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s - - # Cells values in row 5: - #assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s - #assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s - #assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s - # why do we get floats here? in the spreadsheet the cells were defined - # to be percentage - # TODO: should be fixed - # the excel gem does not support the cell type 'percentage' these - # cells are returned to be of the type float. - assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s - assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s - assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s + + + # 1.0 + + # Cells values in row 1: + assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s + assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s + assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s + + # Cells values in row 2: + assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s + assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s + assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s + + # Cells values in row 3: + assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s + assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s + assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s + + # Cells values in row 4: + assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s + assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s + assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s + + # Cells values in row 5: + #assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s + #assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s + #assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s + # why do we get floats here? in the spreadsheet the cells were defined + # to be percentage + # TODO: should be fixed + # the excel gem does not support the cell type 'percentage' these + # cells are returned to be of the type float. + assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s + assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s + assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s end end def test_formula @@ -865,11 +947,11 @@ assert_nil oo.formula('A',6) assert_equal [[7, 1, "=SUM([.A1:.A6])"], [7, 2, "=SUM([.$A$1:.B6])"], [7, 3, "=[Sheet2.A1]"], [8, 2, "=SUM([.$A$1:.B7])"], - ], oo.formulas + ], oo.formulas(oo.sheets.first) after Date.new(2007,6,25) do # setting a cell oo.set('A',15, 41) assert_equal 41, oo.cell('A',15) @@ -879,11 +961,45 @@ assert_equal 42.5, oo.cell('A',17) end #after Date.new(2007,7,30) do # assert_equal 21, oo.solve('a',7) #end + end + if defined? excel_supports_formulas + if EXCEL + oo = Excel.new(File.join("test","formula.xls")) + oo.default_sheet = oo.sheets.first + assert_equal 1, oo.cell('A',1) + assert_equal 2, oo.cell('A',2) + assert_equal 3, oo.cell('A',3) + assert_equal 4, oo.cell('A',4) + assert_equal 5, oo.cell('A',5) + assert_equal 6, oo.cell('A',6) + assert_equal :formula, oo.celltype('A',7) + assert_equal 21, oo.cell('A',7) + assert_equal " = [Sheet2.A1]", oo.formula('C',7) + assert_nil oo.formula('A',6) + assert_equal [[7, 1, " = SUM([.A1:.A6])"], + [7, 2, " = SUM([.$A$1:.B6])"], + [7, 3, " = [Sheet2.A1]"], + [8, 2, " = SUM([.$A$1:.B7])"], + ], oo.formulas + after Date.new(2007,6,25) do + # setting a cell + oo.set('A',15, 41) + assert_equal 41, oo.cell('A',15) + oo.set('A',16, "41") + assert_equal "41", oo.cell('A',16) + oo.set('A',17, 42.5) + assert_equal 42.5, oo.cell('A',17) + end + #after Date.new(2007,7,30) do + # assert_equal 21, oo.solve('a',7) + #end + + end end end def test_borders_sheets @@ -894,44 +1010,34 @@ assert_equal 11, oo.last_row assert_equal 4, oo.first_column assert_equal 8, oo.last_column oo.default_sheet = oo.sheets.first - #assert_nil oo.first_row assert_equal 5, oo.first_row - #assert_nil oo.last_row assert_equal 10, oo.last_row assert_equal 3, oo.first_column - #assert_nil oo.first_column assert_equal 7, oo.last_column - #assert_nil oo.last_column oo.default_sheet = oo.sheets[2] assert_equal 7, oo.first_row assert_equal 12, oo.last_row assert_equal 5, oo.first_column assert_equal 9, oo.last_column end if EXCEL oo = Excel.new(File.join("test","borders.xls")) - #p oo.sheets - #p oo.sheets[1] oo.default_sheet = oo.sheets[1] assert_equal 6, oo.first_row assert_equal 11, oo.last_row assert_equal 4, oo.first_column assert_equal 8, oo.last_column oo.default_sheet = 1 # oo.sheets.first - #assert_nil oo.first_row assert_equal 5, oo.first_row - #assert_nil oo.last_row assert_equal 10, oo.last_row assert_equal 3, oo.first_column - #assert_nil oo.first_column assert_equal 7, oo.last_column - #assert_nil oo.last_column oo.default_sheet = 3 # oo.sheets[2] assert_equal 7, oo.first_row assert_equal 12, oo.last_row assert_equal 5, oo.first_column @@ -1029,11 +1135,11 @@ p "clientthread finished" #end #threads.each {|t| t.join } puts "fertig" Process.kill("INT",pid) - pid=Process.wait + pid = Process.wait puts "child terminated, pid= #{pid}, status= #{$?.exitstatus}" end end # false def split_coord(s) @@ -1083,11 +1189,11 @@ # # assert_equal 15, sum(s,'A1:C1') # end #def test_create_spreadsheet1 - # name=File.join('test','createdspreadsheet.ods') + # name = File.join('test','createdspreadsheet.ods') # rm(name) if File.exists?(File.join('test','createdspreadsheet.ods')) # # anlegen, falls noch nicht existierend # s = Openoffice.new(name,true) # assert File.exists?(name) #end @@ -1150,11 +1256,12 @@ def test_openoffice_open_from_uri_and_zipped if ONLINE url = 'http://spazioinwind.libero.it/s2/rata.ods.zip' sheet = Openoffice.new(url, :zip) - assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5) + #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5) + assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f sheet.remove_tmp # don't forget to remove the temporary files end end def test_excel_zipped @@ -1171,136 +1278,116 @@ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5) oo.remove_tmp # don't forget to remove the temporary files end def test_bug_ric - oo = Openoffice.new(File.join("test","ric.ods")) - oo.default_sheet = oo.sheets.first - assert oo.empty?('A',1) - assert oo.empty?('B',1) - assert oo.empty?('C',1) - assert oo.empty?('D',1) - expected = 1 - letter = 'e' - while letter <= 'u' - assert_equal expected, oo.cell(letter,1) - letter.succ! - expected += 1 - end - #assert_equal 2, oo.cell('f',1) - #assert_equal 3, oo.cell('g',1) - #assert_equal 4, oo.cell('h',1) - #assert_equal 5, oo.cell('i',1) - #assert_equal 6, oo.cell('j',1) - #assert_equal 7, oo.cell('k',1) - #assert_equal 8, oo.cell('l',1) - #assert_equal 9, oo.cell('m',1) - #assert_equal 10, oo.cell('n',1) - #assert_equal 11, oo.cell('o',1) - #assert_equal 12, oo.cell('p',1) - #assert_equal 13, oo.cell('q',1) - #assert_equal 14, oo.cell('r',1) - #assert_equal 15, oo.cell('s',1) - #assert_equal 16, oo.cell('t',1) - #assert_equal 17, oo.cell('u',1) - assert_equal 'J', oo.cell('v',1) - assert_equal 'P', oo.cell('w',1) - assert_equal 'B', oo.cell('x',1) - assert_equal 'All', oo.cell('y',1) - assert_equal 0, oo.cell('a',2) - assert oo.empty?('b',2) - assert oo.empty?('c',2) - assert oo.empty?('d',2) + oo = Openoffice.new(File.join("test","ric.ods")) + oo.default_sheet = oo.sheets.first + assert oo.empty?('A',1) + assert oo.empty?('B',1) + assert oo.empty?('C',1) + assert oo.empty?('D',1) + expected = 1 + letter = 'e' + while letter <= 'u' + assert_equal expected, oo.cell(letter,1) + letter.succ! + expected += 1 + end + #assert_equal 2, oo.cell('f',1) + #assert_equal 3, oo.cell('g',1) + #assert_equal 4, oo.cell('h',1) + #assert_equal 5, oo.cell('i',1) + #assert_equal 6, oo.cell('j',1) + #assert_equal 7, oo.cell('k',1) + #assert_equal 8, oo.cell('l',1) + #assert_equal 9, oo.cell('m',1) + #assert_equal 10, oo.cell('n',1) + #assert_equal 11, oo.cell('o',1) + #assert_equal 12, oo.cell('p',1) + #assert_equal 13, oo.cell('q',1) + #assert_equal 14, oo.cell('r',1) + #assert_equal 15, oo.cell('s',1) + #assert_equal 16, oo.cell('t',1) + #assert_equal 17, oo.cell('u',1) + assert_equal 'J', oo.cell('v',1) + assert_equal 'P', oo.cell('w',1) + assert_equal 'B', oo.cell('x',1) + assert_equal 'All', oo.cell('y',1) + assert_equal 0, oo.cell('a',2) + assert oo.empty?('b',2) + assert oo.empty?('c',2) + assert oo.empty?('d',2) - #'e'.upto('s') {|letter| - # assert_equal 'B', oo.cell(letter,2) - #} - after Date.new(2007,10,1) do - assert_equal 'B', oo.cell('e',2) - assert_equal 'B', oo.cell('f',2) - assert_equal 'B', oo.cell('g',2) - assert_equal 'B', oo.cell('h',2) - assert_equal 'B', oo.cell('i',2) - assert_equal 'B', oo.cell('j',2) - assert_equal 'B', oo.cell('k',2) - assert_equal 'B', oo.cell('l',2) - assert_equal 'B', oo.cell('m',2) - assert_equal 'B', oo.cell('n',2) - assert_equal 'B', oo.cell('o',2) - assert_equal 'B', oo.cell('p',2) - assert_equal 'B', oo.cell('q',2) - assert_equal 'B', oo.cell('r',2) - assert_equal 'B', oo.cell('s',2) - end + #'e'.upto('s') {|letter| + # assert_equal 'B', oo.cell(letter,2) + #} + assert_equal 'B', oo.cell('e',2) + assert_equal 'B', oo.cell('f',2) + assert_equal 'B', oo.cell('g',2) + assert_equal 'B', oo.cell('h',2) + assert_equal 'B', oo.cell('i',2) + assert_equal 'B', oo.cell('j',2) + assert_equal 'B', oo.cell('k',2) + assert_equal 'B', oo.cell('l',2) + assert_equal 'B', oo.cell('m',2) + assert_equal 'B', oo.cell('n',2) + assert_equal 'B', oo.cell('o',2) + assert_equal 'B', oo.cell('p',2) + assert_equal 'B', oo.cell('q',2) + assert_equal 'B', oo.cell('r',2) + assert_equal 'B', oo.cell('s',2) - assert oo.empty?('t',2) - assert oo.empty?('u',2) - assert_equal 0 , oo.cell('v',2) - assert_equal 0 , oo.cell('w',2) - assert_equal 15 , oo.cell('x',2) - assert_equal 15 , oo.cell('y',2) + assert oo.empty?('t',2) + assert oo.empty?('u',2) + assert_equal 0 , oo.cell('v',2) + assert_equal 0 , oo.cell('w',2) + assert_equal 15 , oo.cell('x',2) + assert_equal 15 , oo.cell('y',2) end def test_mehrteilig if OPENOFFICE oo = Openoffice.new(File.join("test","Bibelbund1.ods")) oo.default_sheet = oo.sheets.first assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A') end end - def test_to_csv - after Date.new(2007,10,20) do + def test_to_csv_openoffice + if LONG_RUN if OPENOFFICE assert_nothing_raised(Timeout::Error) { - Timeout::timeout(40*60*2) do |timeout_length| - #puts Time.now.to_s + "test_to_csv Openoffice gestartet" - oo = Openoffice.new(File.join("test","Bibelbund.ods")) + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + oo = Openoffice.new(File.join("test","Bibelbund500.ods")) oo.default_sheet = oo.sheets.first assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A') assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A') assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A') - #puts Time.now.to_s + "vor to_csv" - #assert oo.to_csv - #puts Time.now.to_s + "nach to_csv" - - #puts Time.now.to_s + "vor to_csv(datei)" assert oo.to_csv("/tmp/Bibelbund.csv") - #puts Time.now.to_s + "nach to_csv(datei)" - #puts Time.now.to_s + "vor File.exist" assert File.exists?("/tmp/Bibelbund.csv") - #puts Time.now.to_s + "nach File.exist" assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv` - #puts Time.now.to_s + "test_to_csv Openoffice beendet" end # Timeout } # nothing_raised end # OPENOFFICE - end # after + end + end - after Date.new(2007,10,20) do + def test_to_csv_excel + if LONG_RUN if EXCEL assert_nothing_raised(Timeout::Error) { - Timeout::timeout(40*60*2) do |timeout_length| - #puts Time.now.to_s + "test_to_csv Excel gestartet" - oo = Excel.new(File.join("test","Bibelbund.xls")) + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + oo = Excel.new(File.join("test","Bibelbund500.xls")) oo.default_sheet = oo.sheets.first - #puts Time.now.to_s + "vor to_csv" - #assert oo.to_csv - #puts Time.now.to_s + "nach to_csv" - #Timeout:timeout(3*60)) do |timeout_length| - #puts Time.now.to_s + "vor to_csv(datei)" assert oo.to_csv("/tmp/Bibelbund.csv") - #puts Time.now.to_s + "nach to_csv(datei)" - #puts Time.now.to_s + "vor File.exist" assert File.exists?("/tmp/Bibelbund.csv") - #puts Time.now.to_s + "nach File.exist" assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv` - #puts Time.now.to_s + "test_to_csv Excel beendet" end } end - end + end # LONG_RUN end # def to_csv def test_bug_mehrere_datum if OPENOFFICE oo = Openoffice.new(File.join("test","numbers1.ods")) @@ -1371,6 +1458,517 @@ assert_equal "ABC", oo.cell('D',6) assert_equal "ABC", oo.cell('E',6) end # Excel end + def test_multiple_sheets + if OPENOFFICE + oo = Openoffice.new(File.join("test","numbers1.ods")) + 2.times do + oo.default_sheet = "Tabelle1" + assert_equal 1, oo.cell(1,1) + assert_equal 1, oo.cell(1,1,"Tabelle1") + assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2") + sheetname = 'Sheet5' + assert_equal :date, oo.celltype('A',4,sheetname) + assert_equal :date, oo.celltype('B',4,sheetname) + assert_equal :date, oo.celltype('C',4,sheetname) + assert_equal :date, oo.celltype('D',4,sheetname) + assert_equal :date, oo.celltype('E',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname) + assert_equal :float, oo.celltype('A',5,sheetname) + assert_equal :float, oo.celltype('B',5,sheetname) + assert_equal :float, oo.celltype('C',5,sheetname) + assert_equal :float, oo.celltype('D',5,sheetname) + assert_equal :float, oo.celltype('E',5,sheetname) + assert_equal 42, oo.cell('A',5,sheetname) + assert_equal 42, oo.cell('B',5,sheetname) + assert_equal 42, oo.cell('C',5,sheetname) + assert_equal 42, oo.cell('D',5,sheetname) + assert_equal 42, oo.cell('E',5,sheetname) + assert_equal :string, oo.celltype('A',6,sheetname) + assert_equal :string, oo.celltype('B',6,sheetname) + assert_equal :string, oo.celltype('C',6,sheetname) + assert_equal :string, oo.celltype('D',6,sheetname) + assert_equal :string, oo.celltype('E',6,sheetname) + assert_equal "ABC", oo.cell('A',6,sheetname) + assert_equal "ABC", oo.cell('B',6,sheetname) + assert_equal "ABC", oo.cell('C',6,sheetname) + assert_equal "ABC", oo.cell('D',6,sheetname) + assert_equal "ABC", oo.cell('E',6,sheetname) + oo.reload + end + end + if EXCEL + oo = Excel.new(File.join("test","numbers1.xls")) + 2.times do + oo.default_sheet = "Tabelle1" + assert_equal 1, oo.cell(1,1) + assert_equal 1, oo.cell(1,1,"Tabelle1") + assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2") + sheetname = 'Sheet5' + assert_equal :date, oo.celltype('A',4,sheetname) + assert_equal :date, oo.celltype('B',4,sheetname) + assert_equal :date, oo.celltype('C',4,sheetname) + assert_equal :date, oo.celltype('D',4,sheetname) + assert_equal :date, oo.celltype('E',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname) + assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname) + assert_equal :float, oo.celltype('A',5,sheetname) + assert_equal :float, oo.celltype('B',5,sheetname) + assert_equal :float, oo.celltype('C',5,sheetname) + assert_equal :float, oo.celltype('D',5,sheetname) + assert_equal :float, oo.celltype('E',5,sheetname) + assert_equal 42, oo.cell('A',5,sheetname) + assert_equal 42, oo.cell('B',5,sheetname) + assert_equal 42, oo.cell('C',5,sheetname) + assert_equal 42, oo.cell('D',5,sheetname) + assert_equal 42, oo.cell('E',5,sheetname) + assert_equal :string, oo.celltype('A',6,sheetname) + assert_equal :string, oo.celltype('B',6,sheetname) + assert_equal :string, oo.celltype('C',6,sheetname) + assert_equal :string, oo.celltype('D',6,sheetname) + assert_equal :string, oo.celltype('E',6,sheetname) + assert_equal "ABC", oo.cell('A',6,sheetname) + assert_equal "ABC", oo.cell('B',6,sheetname) + assert_equal "ABC", oo.cell('C',6,sheetname) + assert_equal "ABC", oo.cell('D',6,sheetname) + assert_equal "ABC", oo.cell('E',6,sheetname) + oo.reload + end + end + end + + def test_bug_empty_sheet + oo = Openoffice.new(File.join("test","formula.ods")) + oo.default_sheet = 'Sheet3' # is an empty sheet + assert_nothing_raised(NoMethodError) { + oo.to_csv(File.join("/","tmp","emptysheet.csv")) + } + assert_equal "", `cat /tmp/emptysheet.csv` + end + + def test_find_by_row_openoffice + if LONG_RUN + if OPENOFFICE + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + oo = Openoffice.new(File.join("test","Bibelbund500.ods")) + oo.default_sheet = oo.sheets.first + rec = oo.find 20 + assert rec + # assert_equal "Brief aus dem Sekretariat", rec[0] + #p rec + assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL'] + + rec = oo.find 22 + assert rec + # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0] + assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL'] + end + end + end + end + + def test_find_by_row_excel + if LONG_RUN + if EXCEL + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + oo = Excel.new(File.join("test","Bibelbund500.xls")) + oo.default_sheet = oo.sheets.first + rec = oo.find 20 + assert rec + assert_equal "Brief aus dem Sekretariat", rec[0] + + rec = oo.find 22 + assert rec + assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0] + end + end + end + end + + def test_find_by_conditions_openoffice + if LONG_RUN + if OPENOFFICE + assert_nothing_raised(Timeout::Error) { + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + oo = Openoffice.new(File.join("test","Bibelbund500.ods")) + oo.default_sheet = oo.sheets.first + #----------------------------------------------------------------- + zeilen = oo.find(:all, :conditions => { + 'TITEL' => 'Brief aus dem Sekretariat' + } + ) + assert_equal 2, zeilen.size + assert_equal [{"VERFASSER"=>"Almassy, Annelene von", + "INTERNET"=>nil, + "SEITE"=>316.0, + "KENNUNG"=>"Aus dem Bibelbund", + "OBJEKT"=>"Bibel+Gem", + "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#", + "NUMMER"=>"1982-3", + "TITEL"=>"Brief aus dem Sekretariat"}, + {"VERFASSER"=>"Almassy, Annelene von", + "INTERNET"=>nil, + "SEITE"=>222.0, + "KENNUNG"=>"Aus dem Bibelbund", + "OBJEKT"=>"Bibel+Gem", + "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#", + "NUMMER"=>"1983-2", + "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen + + #---------------------------------------------------------- + zeilen = oo.find(:all, + :conditions => { 'VERFASSER' => 'Almassy, Annelene von' } + ) + assert_equal 13, zeilen.size + #---------------------------------------------------------- + zeilen = oo.find(:all, :conditions => { + 'TITEL' => 'Brief aus dem Sekretariat', + 'VERFASSER' => 'Almassy, Annelene von', + } + ) + assert_equal 2, zeilen.size + assert_equal [{"VERFASSER"=>"Almassy, Annelene von", + "INTERNET"=>nil, + "SEITE"=>316.0, + "KENNUNG"=>"Aus dem Bibelbund", + "OBJEKT"=>"Bibel+Gem", + "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#", + "NUMMER"=>"1982-3", + "TITEL"=>"Brief aus dem Sekretariat"}, + {"VERFASSER"=>"Almassy, Annelene von", + "INTERNET"=>nil, + "SEITE"=>222.0, + "KENNUNG"=>"Aus dem Bibelbund", + "OBJEKT"=>"Bibel+Gem", + "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#", + "NUMMER"=>"1983-2", + "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen + + # Result as an array + zeilen = oo.find(:all, + :conditions => { + 'TITEL' => 'Brief aus dem Sekretariat', + 'VERFASSER' => 'Almassy, Annelene von', + }, :array => true) + assert_equal 2, zeilen.size + assert_equal [ + [ + "Brief aus dem Sekretariat", + "Almassy, Annelene von", + "Bibel+Gem", + "1982-3", + 316.0, + nil, + "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#", + "Aus dem Bibelbund", + ], + [ + "Brief aus dem Sekretariat", + "Almassy, Annelene von", + "Bibel+Gem", + "1983-2", + 222.0, + nil, + "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#", + "Aus dem Bibelbund", + ]] , zeilen + end # Timeout + } # nothing_raised + end + end + end + + def test_find_by_conditions_excel + if LONG_RUN + if EXCEL + assert_nothing_raised(Timeout::Error) { + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + oo = Excel.new(File.join("test","Bibelbund500.xls")) + oo.default_sheet = oo.sheets.first + #----------------------------------------------------------------- + zeilen = oo.find(:all, :conditions => { + 'TITEL' => 'Brief aus dem Sekretariat' + } + ) + assert_equal 2, zeilen.size + assert_equal [{"VERFASSER"=>"Almassy, Annelene von", + "INTERNET"=>nil, + "SEITE"=>316.0, + "KENNUNG"=>"Aus dem Bibelbund", + "OBJEKT"=>"Bibel+Gem", + "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#", + "NUMMER"=>"1982-3", + "TITEL"=>"Brief aus dem Sekretariat"}, + {"VERFASSER"=>"Almassy, Annelene von", + "INTERNET"=>nil, + "SEITE"=>222.0, + "KENNUNG"=>"Aus dem Bibelbund", + "OBJEKT"=>"Bibel+Gem", + "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#", + "NUMMER"=>"1983-2", + "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen + + #---------------------------------------------------------- + zeilen = oo.find(:all, + :conditions => { 'VERFASSER' => 'Almassy, Annelene von' } + ) + assert_equal 13, zeilen.size + #---------------------------------------------------------- + zeilen = oo.find(:all, :conditions => { + 'TITEL' => 'Brief aus dem Sekretariat', + 'VERFASSER' => 'Almassy, Annelene von', + } + ) + assert_equal 2, zeilen.size + assert_equal [{"VERFASSER"=>"Almassy, Annelene von", + "INTERNET"=>nil, + "SEITE"=>316.0, + "KENNUNG"=>"Aus dem Bibelbund", + "OBJEKT"=>"Bibel+Gem", + "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#", + "NUMMER"=>"1982-3", + "TITEL"=>"Brief aus dem Sekretariat"}, + {"VERFASSER"=>"Almassy, Annelene von", + "INTERNET"=>nil, + "SEITE"=>222.0, + "KENNUNG"=>"Aus dem Bibelbund", + "OBJEKT"=>"Bibel+Gem", + "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#", + "NUMMER"=>"1983-2", + "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen + end # Timeout + } # nothing_raised + end + end + end + + def test_columns_openoffice + expected = [1.0,5.0,nil,10.0,Date.new(1961,11,21),'tata',nil,nil,nil,nil,'thisisa11',41.0,nil,nil,41.0,'einundvierzig',nil,Date.new(2007,5,31)] + if OPENOFFICE + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + oo = Openoffice.new(File.join('test','numbers1.ods')) + oo.default_sheet = oo.sheets.first + assert_equal expected, oo.column(1) + assert_equal expected, oo.column('a') + end + end + end + + def test_columns_excel + expected = [1.0,5.0,nil,10.0,Date.new(1961,11,21),'tata',nil,nil,nil,nil,'thisisa11',41.0,nil,nil,41.0,'einundvierzig',nil,Date.new(2007,5,31)] + if EXCEL + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + oo = Excel.new(File.join('test','numbers1.xls')) + oo.default_sheet = oo.sheets.first + assert_equal expected, oo.column(1) + assert_equal expected, oo.column('a') + end + end + end + + def test_column_huge_document_openoffice + if LONG_RUN + if OPENOFFICE + assert_nothing_raised(Timeout::Error) { + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + #puts Time.now.to_s + "column Openoffice gestartet" + oo = Openoffice.new(File.join('test','Bibelbund500.ods')) + oo.default_sheet = oo.sheets.first + #assert_equal 3735, oo.column('a').size + assert_equal 499, oo.column('a').size + #puts Time.now.to_s + "column Openoffice beendet" + end + } + end + end + end + + def test_column_huge_document_excel + if LONG_RUN + if EXCEL + assert_nothing_raised(Timeout::Error) { + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + #puts Time.now.to_s + "column Excel gestartet" + oo = Excel.new(File.join('test','Bibelbund500.xls')) + oo.default_sheet = oo.sheets.first + #assert_equal 3735, oo.column('a').size + assert_equal 499, oo.column('a').size + #puts Time.now.to_s + "column Excel beendet" + end + } + end + end + end + + def test_simple_spreadsheet_find_by_condition_openoffice + oo = Openoffice.new(File.join("test","simple_spreadsheet.ods")) + oo.default_sheet = oo.sheets.first + oo.header_line = 3 + erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'}) + assert_equal Date.new(2007,05,07), erg[1]['Date'] + assert_equal 10.75 , erg[1]['Start time'] + assert_equal 12.50 , erg[1]['End time'] + assert_equal 0 , erg[1]['Pause'] + assert_equal 1.75 , erg[1]['Sum'] + assert_equal "Task 1" , erg[1]['Comment'] + end + + def DONT_test_false_encoding + ex = Excel.new(File.join('test','false_encoding.xls')) + ex.default_sheet = ex.sheets.first + assert_equal "Sheet1", ex.sheets.first + ex.first_row.upto(ex.last_row) do |row| + ex.first_column.upto(ex.last_column) do |col| + content = ex.cell(row,col) + puts "#{row}/#{col}" + #puts content if ! ex.empty?(row,col) or ex.formula?(row,col) + if ex.formula?(row,col) + #! ex.empty?(row,col) + puts content + end + end + end + end + + def test_bug_false_borders_with_formulas + ex = Excel.new(File.join('test','false_encoding.xls')) + ex.default_sheet = ex.sheets.first + assert_equal 1, ex.first_row + assert_equal 3, ex.last_row + assert_equal 1, ex.first_column + assert_equal 4, ex.last_column + end + + def test_fe + ex = Excel.new(File.join('test','false_encoding.xls')) + ex.default_sheet = ex.sheets.first + #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2007,11,1), ex.cell('a',1) + #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('a',1) + #DOES NOT WORK IN EXCEL FILES: assert_equal '=TODAY()', ex.formula('a',1) + + #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2008,2,9), ex.cell('B',1) + #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('B',1) + #DOES NOT WORK IN EXCEL FILES: assert_equal "=A1+100", ex.formula('B',1) + + #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2008,2,9), ex.cell('C',1) + #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('C',1) + #DOES NOT WORK IN EXCEL FILES: assert_equal "=C1", ex.formula('C',1) + + assert_equal 'H1', ex.cell('A',2) + assert_equal 'H2', ex.cell('B',2) + assert_equal 'H3', ex.cell('C',2) + assert_equal 'H4', ex.cell('D',2) + assert_equal 'R1', ex.cell('A',3) + assert_equal 'R2', ex.cell('B',3) + assert_equal 'R3', ex.cell('C',3) + assert_equal 'R4', ex.cell('D',3) + end + + def test_excel_does_not_support_formulas + ex = Excel.new(File.join('test','false_encoding.xls')) + ex.default_sheet = ex.sheets.first + assert_raise(RuntimeError) { + void = ex.formula('a',1) + } + assert_raise(RuntimeError) { + void = ex.formula?('a',1) + } + assert_raise(RuntimeError) { + void = ex.formulas(ex.sheets.first) + } + + end + + def test_info + expected_templ = "File: test/numbers1%s\n"+ + "Number of sheets: 5\n"+ + "Sheets: Tabelle1, Name of Sheet 2, Sheet3, Sheet4, Sheet5\n"+ + "Sheet 1:\n"+ + " First row: 1\n"+ + " Last row: 18\n"+ + " First column: A\n"+ + " Last column: G\n"+ + "Sheet 2:\n"+ + " First row: 5\n"+ + " Last row: 14\n"+ + " First column: B\n"+ + " Last column: E\n"+ + "Sheet 3:\n"+ + " First row: 1\n"+ + " Last row: 1\n"+ + " First column: A\n"+ + " Last column: BA\n"+ + "Sheet 4:\n"+ + " First row: 1\n"+ + " Last row: 1\n"+ + " First column: A\n"+ + " Last column: E\n"+ + "Sheet 5:\n"+ + " First row: 1\n"+ + " Last row: 6\n"+ + " First column: A\n"+ + " Last column: E" + if OPENOFFICE + ext = ".ods" + expected = sprintf(expected_templ,ext) + oo = Openoffice.new(File.join("test","numbers1.ods")) + assert_equal expected, oo.info + end + if EXCEL + ext = ".xls" + expected = sprintf(expected_templ,ext) + oo = Excel.new(File.join("test","numbers1.xls")) + assert_equal expected, oo.info + end + end + + def test_bug_excel_numbers1_sheet5_last_row + oo = Excel.new(File.join("test","numbers1.xls")) + oo.default_sheet = "Tabelle1" + assert_equal 1, oo.first_row + assert_equal 18, oo.last_row + assert_equal Openoffice.letter_to_number('A'), oo.first_column + assert_equal Openoffice.letter_to_number('G'), oo.last_column + oo.default_sheet = "Name of Sheet 2" + assert_equal 5, oo.first_row + assert_equal 14, oo.last_row + assert_equal Openoffice.letter_to_number('B'), oo.first_column + assert_equal Openoffice.letter_to_number('E'), oo.last_column + oo.default_sheet = "Sheet3" + assert_equal 1, oo.first_row + assert_equal 1, oo.last_row + assert_equal Openoffice.letter_to_number('A'), oo.first_column + assert_equal Openoffice.letter_to_number('BA'), oo.last_column + oo.default_sheet = "Sheet4" + assert_equal 1, oo.first_row + assert_equal 1, oo.last_row + assert_equal Openoffice.letter_to_number('A'), oo.first_column + assert_equal Openoffice.letter_to_number('E'), oo.last_column + oo.default_sheet = "Sheet5" + assert_equal 1, oo.first_row + assert_equal 6, oo.last_row + assert_equal Openoffice.letter_to_number('A'), oo.first_column + assert_equal Openoffice.letter_to_number('E'), oo.last_column + end + + def test_should_raise_file_not_found_error + if OPENOFFICE + assert_raise(IOError) { + oo = Openoffice.new(File.join('testnichtvorhanden','Bibelbund.ods')) + } + end + if EXCEL + assert_raise(IOError) { + oo = Excel.new(File.join('testnichtvorhanden','Bibelbund.xls')) + } + end + end end # class