test/test_roo.rb in roo-1.9.7 vs test/test_roo.rb in roo-1.10.0

- old
+ new

@@ -14,40 +14,52 @@ require 'tmpdir' require './lib/roo' #TODO # Look at formulas in excel - does not work with date/time +class Csv + def cell_postprocessing(row,col,value) + if row==1 and col==1 + return value.to_f + end + if row==1 and col==2 + return value.to_s + end + return value + end +end # Dump warnings that come from the test to open files # with the wrong spreadsheet class #STDERR.reopen "/dev/null","w" TESTDIR = File.dirname(__FILE__) TMP_PREFIX = 'oo_*' # require './' + TESTDIR + '/test_helper.rb' require TESTDIR + '/test_helper.rb' -#require 'soap/rpc/driver' require 'fileutils' require 'timeout' require 'logger' $log = Logger.new(File.join(ENV['HOME'],"roo.log")) #$log.level = Logger::WARN $log.level = Logger::DEBUG -DISPLAY_LOG = true +DISPLAY_LOG = false DB_LOG = false + if DB_LOG require 'activerecord' end include FileUtils + def running_windows? - # to do + # to do # "besser loesen" - # end - File.exists? "C:\\" + # end + File.exists? "C:\\" end if DB_LOG def activerecord_connect ActiveRecord::Base.establish_connection(:adapter => "mysql", @@ -134,17 +146,18 @@ :test_name => @method_name, :start => t1, :duration => t2-t1 ) end - if Dir.glob("oo_*") != [] - puts "nicht alle temp. Dateien geloescht" - puts Dir.glob("oo_*") - print "? " - STDOUT.flush - a = gets - end + # TODO + #if Dir.glob("oo_*") != [] + # puts "nicht alle temp. Dateien geloescht" + # puts Dir.glob("oo_*") + # print "? " + # STDOUT.flush + # a = gets + # end end end class File def File.delete_if_exist(filename) @@ -162,14 +175,15 @@ end class TestRoo < Test::Unit::TestCase OPENOFFICE = true # do Openoffice-Spreadsheet Tests? (.ods files) - EXCEL = true # do Excel Tests? (.xls files) + EXCEL = true # do Excel Tests? (.xls files) GOOGLE = false # do Google-Spreadsheet Tests? EXCELX = true # do Excelx Tests? (.xlsx files) - LIBREOFFICE = true # do Libreoffice tests? (.ods files) + LIBREOFFICE = true # do Libreoffice tests? (.ods files) + CSV = true # do CSV tests? (.csv files) ONLINE = false LONG_RUN = true GLOBAL_TIMEOUT = 48.minutes @@ -196,18 +210,19 @@ raise "invalid spreadsheet type #{formatname}" end end end # end test spreadsheet type :nodoc - options[:format] ||= [:excel, :excelx, :openoffice, :google] + options[:format] ||= [:excel, :excelx, :openoffice, :google, :libreoffice] options[:format] = [options[:format]] if options[:format].class == Symbol yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xls')) if EXCEL && options[:format].include?(:excel) yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx) yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if OPENOFFICE && options[:format].include?(:openoffice) yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google) yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if LIBREOFFICE && options[:format].include?(:libreoffice) end + # Using Date.strptime so check that it's using the method # with the value set in date_format def test_date with_each_spreadsheet(:name=>'numbers1', :format=>:google) do |oo| # should default to DDMMYYYY @@ -237,10 +252,18 @@ end if EXCELX oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx")) assert_kind_of Excelx, oo end + if LIBREOFFICE + oo = Libreoffice.new(File.join(TESTDIR,"numbers1.ods")) + assert_kind_of Libreoffice, oo + end + if CSV + oo = Csv.new(File.join(TESTDIR,"numbers1.csv")) + assert_kind_of Csv, oo + end end def test_letters assert_equal 1, GenericSpreadsheet.letter_to_number('A') assert_equal 1, GenericSpreadsheet.letter_to_number('a') @@ -249,10 +272,24 @@ assert_equal 27, GenericSpreadsheet.letter_to_number('AA') assert_equal 27, GenericSpreadsheet.letter_to_number('aA') assert_equal 27, GenericSpreadsheet.letter_to_number('Aa') assert_equal 27, GenericSpreadsheet.letter_to_number('aa') end + + def test_sheets_csv + if CSV + oo = Csv.new(File.join(TESTDIR,'numbers1.csv')) + assert_equal ["default"], oo.sheets + assert_raise(RangeError) { oo.default_sheet = "no_sheet" } + assert_raise(TypeError) { oo.default_sheet = [1,2,3] } + oo.sheets.each { |sh| + oo.default_sheet = sh + assert_equal sh, oo.default_sheet + } + end + end + def test_sheets with_each_spreadsheet(:name=>'numbers1') do |oo| assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets assert_raise(RangeError) { oo.default_sheet = "no_sheet" } assert_raise(TypeError) { oo.default_sheet = [1,2,3] } @@ -278,27 +315,31 @@ assert_equal 8, oo.cell(2,4) assert_equal 9, oo.cell(2,5) assert_equal "test", oo.cell(2,6) assert_equal :string, oo.celltype(2,6) assert_equal 11, oo.cell(2,7) - assert_equal :float, oo.celltype(2,7) + unless oo.kind_of? Csv + assert_equal :float, oo.celltype(2,7) + end assert_equal 10, oo.cell(4,1) assert_equal 11, oo.cell(4,2) assert_equal 12, oo.cell(4,3) assert_equal 13, oo.cell(4,4) assert_equal 14, oo.cell(4,5) assert_equal 10, oo.cell(4,'A') assert_equal 11, oo.cell(4,'B') assert_equal 12, oo.cell(4,'C') assert_equal 13, oo.cell(4,'D') assert_equal 14, oo.cell(4,'E') - assert_equal :date, oo.celltype(5,1) - assert_equal Date.new(1961,11,21), oo.cell(5,1) - assert_equal "1961-11-21", oo.cell(5,1).to_s + unless oo.kind_of? Csv + assert_equal :date, oo.celltype(5,1) + assert_equal Date.new(1961,11,21), oo.cell(5,1) + assert_equal "1961-11-21", oo.cell(5,1).to_s + end end end - + def test_celltype with_each_spreadsheet(:name=>'numbers1') do |oo| assert_equal :string, oo.celltype(2,6) end end @@ -328,11 +369,11 @@ end end def test_libre_office if LIBREOFFICE - oo = Libreoffice.new("test/numbers1.ods") + oo = Libreoffice.new("test/numbers1.ods") oo.default_sheet = oo.sheets.first assert_equal 41, oo.cell('a',12) end end @@ -738,25 +779,25 @@ end end end def test_excel_zipped - after Date.new(2011,8,30) do - to do - 'hier wieder das Problem, dass ausgepacktes xls File - unter Windows nicht geloescht werden kann, weil - das spreadsheet gem die Datei nicht schliesst. - Fehler von spreadsheet gem' - end - if EXCEL - begin - oo = Excel.new(File.join(TESTDIR,"bode-v1.xls.zip"), :zip) - assert oo - assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5) + after Date.new(2011,10,30) do + to do + 'hier wieder das Problem, dass ausgepacktes xls File + unter Windows nicht geloescht werden kann, weil + das spreadsheet gem die Datei nicht schliesst. + Fehler von spreadsheet gem' end + if EXCEL + begin + oo = Excel.new(File.join(TESTDIR,"bode-v1.xls.zip"), :zip) + assert oo + assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5) + end + end end - end end def test_openoffice_zipped if OPENOFFICE begin @@ -1431,70 +1472,70 @@ assert_equal expected, oo.to_yaml end end def test_no_remaining_tmp_files_openoffice - after Date.new(2011,8,30) do - # alles noch mal ueberarbeiten - # temp. Directories sollten in diesem Fall ueberhaupt nicht - # angelegt werden - if OPENOFFICE - assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei - # oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt")) - # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore - begin - oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt"), - false, - :ignore) - rescue Zip::ZipError - @tmp = Dir.glob(oo.tmpdir) - raise - end - } - assert @tmp.empty?, "temporay directory was not deleted" + after Date.new(2011,10,30) do + # alles noch mal ueberarbeiten + # temp. Directories sollten in diesem Fall ueberhaupt nicht + # angelegt werden + if OPENOFFICE + assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei + # oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt")) + # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore + begin + oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt"), + false, + :ignore) + rescue Zip::ZipError + @tmp = Dir.glob(oo.tmpdir) + raise + end + } + assert @tmp.empty?, "temporay directory was not deleted" + end end - end end def test_no_remaining_tmp_files_excel - after Date.new(2011,8,30) do - # alles noch mal ueberarbeiten - # temp. Directories sollten in diesem Fall ueberhaupt nicht - # angelegt werden - if EXCEL - prev = Dir.glob(TMP_PREFIX) - assert_raise(Ole::Storage::FormatError) { - oo = Excel.new(File.join(TESTDIR,"no_spreadsheet_file.txt"), - false, - :ignore) - } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty?, "temporary directory not removed" + after Date.new(2011,9,30) do + # alles noch mal ueberarbeiten + # temp. Directories sollten in diesem Fall ueberhaupt nicht + # angelegt werden + if EXCEL + prev = Dir.glob(TMP_PREFIX) + assert_raise(Ole::Storage::FormatError) { + oo = Excel.new(File.join(TESTDIR,"no_spreadsheet_file.txt"), + false, + :ignore) + } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty?, "temporary directory not removed" + end end - end end def test_no_remaining_tmp_files_excelx - after Date.new(2011,8,30) do - # alles noch mal ueberarbeiten - # temp. Directories sollten in diesem Fall ueberhaupt nicht - # angelegt werden - if EXCELX - prev = Dir.glob(TMP_PREFIX) - assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei + after Date.new(2011,11,1) do + # alles noch mal ueberarbeiten + # temp. Directories sollten in diesem Fall ueberhaupt nicht + # angelegt werden + if EXCELX + prev = Dir.glob(TMP_PREFIX) + assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei - # oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt")) - # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore - oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"), - false, - :ignore) + # oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt")) + # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore + oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"), + false, + :ignore) - } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty? + } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty? + end end - end end def test_no_remaining_tmp_files_google # Exception ist irgendwie anders, nochmal ansehen TODO: after Date.new(2011,6,19) do @@ -1572,71 +1613,71 @@ assert_equal ['def',42.5, 'nop'], oo.column(2) end end def test_file_warning_default - if OPENOFFICE - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError, "test/numbers1.xls is not an openoffice spreadsheet") { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls")) } - assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx")) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty? - end - if EXCEL - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods")) } - assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx")) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty?, "temporary directory was not removed" - end - if EXCELX - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods")) } - assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls")) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty? - end + if OPENOFFICE + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError, "test/numbers1.xls is not an openoffice spreadsheet") { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls")) } + assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx")) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty? + end + if EXCEL + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods")) } + assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx")) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty?, "temporary directory was not removed" + end + if EXCELX + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods")) } + assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls")) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty? + end end def test_file_warning_error - if OPENOFFICE - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty? + if OPENOFFICE + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty? - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty? - end - if EXCEL - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty?, "temporary directory was not deleted" + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty? + end + if EXCEL + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty?, "temporary directory was not deleted" - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty?, "temporary directory was not deleted" - end - if EXCELX - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false,:error) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty?, "temporary directory was not deleted" + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty?, "temporary directory was not deleted" + end + if EXCELX + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false,:error) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty?, "temporary directory was not deleted" - prev = Dir.glob(TMP_PREFIX) - assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false,:error) } - now = Dir.glob(TMP_PREFIX) - assert (now-prev).empty?, "temporary directory was not deleted" - end + prev = Dir.glob(TMP_PREFIX) + assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false,:error) } + now = Dir.glob(TMP_PREFIX) + assert (now-prev).empty?, "temporary directory was not deleted" + end end def test_file_warning_warning - after Date.new(2011,9,2) do + after Date.new(2011,10,14) do if OPENOFFICE assert_nothing_raised(TypeError) { assert_raises(Zip::ZipError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :warning) } @@ -1678,41 +1719,41 @@ end end end def test_file_warning_ignore - if OPENOFFICE - # Files, die eigentlich Openoffice- - # Files sind, aber die falsche Endung haben. - # Es soll ohne Fehlermeldung oder Warnung - # oder Abbruch die Datei geoffnet werden + if OPENOFFICE + # Files, die eigentlich Openoffice- + # Files sind, aber die falsche Endung haben. + # Es soll ohne Fehlermeldung oder Warnung + # oder Abbruch die Datei geoffnet werden - # xls - assert_nothing_raised() { - oo = Openoffice.new(File.join(TESTDIR,"type_openoffice.xls"),false, :ignore) - } - # xlsx - assert_nothing_raised() { - oo = Openoffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),false, :ignore) - } - end - if EXCEL - assert_nothing_raised() { - oo = Excel.new(File.join(TESTDIR,"type_excel.ods"),false, :ignore) - } - assert_nothing_raised() { - oo = Excel.new(File.join(TESTDIR,"type_excel.xlsx"),false, :ignore) - } - end - if EXCELX - assert_nothing_raised() { - oo = Excelx.new(File.join(TESTDIR,"type_excelx.ods"),false, :ignore) - } - assert_nothing_raised() { - oo = Excelx.new(File.join(TESTDIR,"type_excelx.xls"),false, :ignore) - } - end + # xls + assert_nothing_raised() { + oo = Openoffice.new(File.join(TESTDIR,"type_openoffice.xls"),false, :ignore) + } + # xlsx + assert_nothing_raised() { + oo = Openoffice.new(File.join(TESTDIR,"type_openoffice.xlsx"),false, :ignore) + } + end + if EXCEL + assert_nothing_raised() { + oo = Excel.new(File.join(TESTDIR,"type_excel.ods"),false, :ignore) + } + assert_nothing_raised() { + oo = Excel.new(File.join(TESTDIR,"type_excel.xlsx"),false, :ignore) + } + end + if EXCELX + assert_nothing_raised() { + oo = Excelx.new(File.join(TESTDIR,"type_excelx.ods"),false, :ignore) + } + assert_nothing_raised() { + oo = Excelx.new(File.join(TESTDIR,"type_excelx.xls"),false, :ignore) + } + end =begin if OPENOFFICE assert_nothing_raised() { assert_raises(Zip::ZipError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :ignore) } @@ -2060,51 +2101,116 @@ end end end # LONG_RUN end - def test_labeled_cells - # to do - # "more spreadsheet types" - # end - with_each_spreadsheet(:name=>'named_cells', :format=>:openoffice) do |oo| - oo.default_sheet = oo.sheets.first + def test_label + with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo| + # oo.default_sheet = oo.sheets.first begin row,col = oo.label('anton') rescue ArgumentError puts "labels error at #{oo.class}" raise end - assert_equal 5, row - assert_equal 3, col + assert_equal 5, row, "error with label in class #{oo.class}" + assert_equal 3, col, "error with label in class #{oo.class}" row,col = oo.label('anton') - assert_equal 'Anton', oo.cell(row,col) + assert_equal 'Anton', oo.cell(row,col), "error with label in class #{oo.class}" row,col = oo.label('berta') - assert_equal 'Bertha', oo.cell(row,col) + assert_equal 'Bertha', oo.cell(row,col), "error with label in class #{oo.class}" row,col = oo.label('caesar') - assert_equal 'Cäsar', oo.cell(row,col) + assert_equal 'Cäsar', oo.cell(row,col),"error with label in class #{oo.class}" row,col = oo.label('never') assert_nil row assert_nil col row,col,sheet = oo.label('anton') assert_equal 5, row assert_equal 3, col assert_equal "Sheet1", sheet + end + end + def test_method_missing_anton + with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo| + # oo.default_sheet = oo.sheets.first assert_equal "Anton", oo.anton assert_raises(NoMethodError) { row,col = oo.never } end end + def test_labels + with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo| + # oo.default_sheet = oo.sheets.first + assert_equal [ + ['anton',[5,3,'Sheet1']], + ['berta',[4,2,'Sheet1']], + ['caesar',[7,2,'Sheet1']], + ], oo.labels, "error with labels array in class #{oo.class}" + end + end + # def test_labeled_cells + # to do + # "more spreadsheet types" + # end + # with_each_spreadsheet(:name=>'named_cells', :format=>[:openoffice,:excelx,:libreoffice]) do |oo| + # oo.default_sheet = oo.sheets.first + # begin + # row,col = oo.label('anton') + # rescue ArgumentError + # puts "labels error at #{oo.class}" + # raise + # end + # assert_equal 5, row + # assert_equal 3, col + # + # row,col = oo.label('anton') + # assert_equal 'Anton', oo.cell(row,col) + # + # row,col = oo.label('berta') + # assert_equal 'Bertha', oo.cell(row,col) + # + # row,col = oo.label('caesar') + # assert_equal 'Cäsar', oo.cell(row,col) + # + # row,col = oo.label('never') + # assert_nil row + # assert_nil col + # + # row,col,sheet = oo.label('anton') + # assert_equal 5, row + # assert_equal 3, col + # assert_equal "Sheet1", sheet + # + # assert_equal "Anton", oo.anton + # assert_raises(NoMethodError) { + # row,col = oo.never + # } + # + # #assert_equal [ + ## ['anton',['Sheet1',5,3]], + ## ['berta',['Sheet1',4,2]], + ## ['caesar',['Sheet1',7,2]], + ## ], oo.labels, "error with labels array in class #{oo.class}" + ## Reihenfolge row,col,sheet analog zu #label + # assert_equal [ + # ['anton',[5,3,'Sheet1']], + # ['berta',[4,2,'Sheet1']], + # ['caesar',[7,2,'Sheet1']], + # ], oo.labels, "error with labels array in class #{oo.class}" + # end + # end + + def test_bug_excel_last_row_255 if LONG_RUN local_only do oo = Excel.new(File.join('..','confidential','ScienceStaff.xls')) oo.default_sheet = oo.sheets.first @@ -2162,11 +2268,11 @@ [4.0, 5.0, 6.0], [7.0, 8.0, nil] ], oo.to_matrix(1,1,3,3) end end def test_bug_date_mileszs - after Date.new(2011,8,28) do + after Date.new(2011,11,1) do # to do # "An richtige Stelle kopieren. Ist das Dokument vertraulich?" # 'ist auf dem Netbook nicht vorhanden' # end oo = Excel.new "/home/tp/Documents/feb-sales-analysis.xls" @@ -2197,10 +2303,12 @@ end #end end def test_bug_xlsx_reference_cell + + if EXCELX =begin If cell A contains a string and cell B references cell A. When reading the value of cell B, the result will be "0.0" instead of the value of cell A. With the attached test case, I ran the following code: @@ -2215,18 +2323,19 @@ where the expected result is "A: TestString" "B: TestString" =end - xlsx = Excelx.new(File.join('test', "formula_string_error.xlsx")) - xlsx.default_sheet = xlsx.sheets.first - assert_equal 'Teststring', xlsx.cell('a',1) - assert_equal 'Teststring', xlsx.cell('a',2) + xlsx = Excelx.new(File.join('test', "formula_string_error.xlsx")) + xlsx.default_sheet = xlsx.sheets.first + assert_equal 'Teststring', xlsx.cell('a',1) + assert_equal 'Teststring', xlsx.cell('a',2) + end end - + def test_bug_guest_list_2011_05_05 - after Date.new(2011,8,28) do + after Date.new(2011,11,1) do oo = Excel.new(File.join("..","confidential","guest_list_addresses.xls")) oo.default_sheet = oo.sheets.first assert_equal "lalala", oo.cell('a',1) # anderer Inhalt im Spreadsheet assert_equal :string, oo.celltype('a',1) end @@ -2246,39 +2355,41 @@ end # don't test it with other spreadsheet types! this was only a problem # with .xlsx files def test_bug_date_not_recognized_2011_05_21 - #oo = Excelx.new(File.join(TESTDIR,'2011-05-21_sample_date_problem.xlsx')) - oo = Excelx.new(File.join('..','confidential','2011-05-21_sample_date_problem.xlsx')) - oo.default_sheet = oo.sheets.first - assert_equal Date.new(2011,3,24), oo.b4 - assert_equal Date.new(2011,3,25), oo.b5 - assert_equal Date.new(2011,5,5), oo.b6 - assert_equal Date.new(2012,3,23), oo.b7 + if EXCELX + oo = Excelx.new(File.join('..','confidential','2011-05-21_sample_date_problem.xlsx')) + oo.default_sheet = oo.sheets.first + assert_equal Date.new(2011,3,24), oo.b4 + assert_equal Date.new(2011,3,25), oo.b5 + assert_equal Date.new(2011,5,5), oo.b6 + assert_equal Date.new(2012,3,23), oo.b7 + end end def test_bug_string_as_a_date_2011_05_21_spreadsheet_only - after Date.new(2011,8,28) do - # to do - # 'wieder entfernen' - # end - require 'spreadsheet' - book = Spreadsheet.open File.join('..','confidential','2011-05-21_sample_type_problem.xls') - sheet1 = book.worksheet 0 - sheet1.each_with_index do |row,rownum| - # p row[0] - if rownum == 2 - assert_equal 68, row[6] + after Date.new(2011,12,28) do + if EXCEL + # to do + # 'wieder entfernen' + # end + require 'spreadsheet' + book = Spreadsheet.open File.join('..','confidential','2011-05-21_sample_type_problem.xls') + sheet1 = book.worksheet 0 + sheet1.each_with_index do |row,rownum| + # p row[0] + if rownum == 2 + assert_equal 68, row[6] + end end - end end end def test_bug_string_as_a_date_2011_05_21 - after Date.new(2011,8,28) do + after Date.new(2011,11,1) do #oo = Excel.new(File.join(TESTDIR,'2011-05-21_sample_type_problem.xls')) oo = Excel.new(File.join('..','confidential','2011-05-21_sample_type_problem.xls')) oo.default_sheet = oo.sheets.first assert_equal 68, oo.g2 assert_equal 72, oo.g3 @@ -2352,28 +2463,138 @@ end end # 2011-08-11 def test_bug_openoffice_formula_missing_letters - if OPENOFFICE - # Dieses Dokument wurde mit LibreOffice angelegt. - # Keine Ahnung, ob es damit zusammenhaengt, das diese - # Formeln anders sind, als in der Datei formula.ods, welche - # mit Openoffice angelegt wurde. - # Bei den Openoffice-Dateien ist in diesem Feld in der XML- - # Datei of: als Prefix enthalten, waehrend in dieser Datei - # irgendetwas mit oooc: als Prefix verwendet wird. - oo = Openoffice.new(File.join(TESTDIR,'dreimalvier.ods')) - oo.default_sheet = oo.sheets.first - assert_equal '=SUM([.A1:.D1])', oo.formula('e',1) - assert_equal '=SUM([.A2:.D2])', oo.formula('e',2) - assert_equal '=SUM([.A3:.D3])', oo.formula('e',3) - assert_equal [ - [1,5,'=SUM([.A1:.D1])'], - [2,5,'=SUM([.A2:.D2])'], - [3,5,'=SUM([.A3:.D3])'], - ], oo.formulas + if LIBREOFFICE + # Dieses Dokument wurde mit LibreOffice angelegt. + # Keine Ahnung, ob es damit zusammenhaengt, das diese + # Formeln anders sind, als in der Datei formula.ods, welche + # mit Openoffice angelegt wurde. + # Bei den Openoffice-Dateien ist in diesem Feld in der XML- + # Datei of: als Prefix enthalten, waehrend in dieser Datei + # irgendetwas mit oooc: als Prefix verwendet wird. + oo = Openoffice.new(File.join(TESTDIR,'dreimalvier.ods')) + oo.default_sheet = oo.sheets.first + assert_equal '=SUM([.A1:.D1])', oo.formula('e',1) + assert_equal '=SUM([.A2:.D2])', oo.formula('e',2) + assert_equal '=SUM([.A3:.D3])', oo.formula('e',3) + assert_equal [ + [1,5,'=SUM([.A1:.D1])'], + [2,5,'=SUM([.A2:.D2])'], + [3,5,'=SUM([.A3:.D3])'], + ], oo.formulas + end + end + +=begin + def test_postprocessing_and_types_in_csv + if CSV + oo = Csv.new(File.join(TESTDIR,'csvtypes.csv')) + oo.default_sheet = oo.sheets.first + assert_equal(1,oo.a1) + assert_equal(:float,oo.celltype('A',1)) + assert_equal("2",oo.b1) + assert_equal(:string,oo.celltype('B',1)) + assert_equal("Mayer",oo.c1) + assert_equal(:string,oo.celltype('C',1)) + end + end +=end + +=begin + def test_postprocessing_with_callback_function + if CSV + oo = Csv.new(File.join(TESTDIR,'csvtypes.csv')) + oo.default_sheet = oo.sheets.first + + # + assert_equal(1, oo.last_column) + end + end +=end + +=begin + def x_123 + class ::Csv + def cell_postprocessing(row,col,value) + if row < 3 + return nil + end + return value + end + end + end +=end + + def test_nil_rows_and_lines_csv + to do + 'wieder aktivieren' end +=begin + x_123 + if CSV + oo = Csv.new(File.join(TESTDIR,'Bibelbund.csv')) + oo.default_sheet = oo.sheets.first + assert_equal 3, oo.first_row + end +=end + end + + def test_bug_pfand_from_windows_phone_xlsx + with_each_spreadsheet(:name=>'Pfand_from_windows_phone', :format=>:excelx) do |oo| + oo.default_sheet = oo.sheets.first + assert_equal ['Blatt1','Blatt2','Blatt3'], oo.sheets + assert_equal 'Summe', oo.cell('b',1) + + assert_equal Date.new(2011,9,14), oo.cell('a',2) + assert_equal :date, oo.celltype('a',2) + assert_equal Date.new(2011,9,15), oo.cell('a',3) + assert_equal :date, oo.celltype('a',3) + + assert_equal 3.81, oo.cell('b',2) + assert_equal "SUM(C2:L2)", oo.formula('b',2) + assert_equal 0.7, oo.cell('c',2) + end # each + end + + def test_comment + to do + "more spreadsheet types" + end + with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice, + :excelx]) do |oo| + oo.default_sheet = oo.sheets.first + assert_equal 'Kommentar fuer B4',oo.comment('b',4) + assert_equal 'Kommentar fuer B5',oo.comment('b',5) + assert_nil oo.comment('b',99) + # no comment at the second page + oo.default_sheet = oo.sheets[1] + assert_nil oo.comment('b',4) + end + end + + def test_comment? + with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice, + :excelx]) do |oo| + oo.default_sheet = oo.sheets.first + assert_equal true, oo.comment?('b',4) + assert_equal false, oo.comment?('b',99) + end + end + + def test_comments + with_each_spreadsheet(:name=>'comments', :format=>[:openoffice,:libreoffice, + :excelx]) do |oo| + oo.default_sheet = oo.sheets.first + assert_equal [ + [4, 2, "Kommentar fuer B4"], + [5, 2, "Kommentar fuer B5"], + ], oo.comments(oo.sheets.first), "comments error in class #{oo.class}" + # no comments at the second page + oo.default_sheet = oo.sheets[1] + assert_equal [], oo.comments, "comments error in class #{oo.class}" + end end end # class