test/test_roo.rb in roo-0.8.1 vs test/test_roo.rb in roo-0.8.2

- old
+ new

@@ -24,11 +24,11 @@ if DB_LOG # gem 'activerecord', '< 2.0.0' # require 'activerecord' # require_gem 'activerecord', '< 2.0.0' - gem 'activerecord', '< 2.0.0' + #gem 'activerecord', '< 2.0.0' require 'activerecord' end include FileUtils @@ -58,27 +58,10 @@ 'formula' => 'o10837434939102457526.3022866619437760118', }[spreadsheetname] rescue raise "unknown spreadsheetname: #{spreadsheetname}" end - -if false - case spreadsheetname - when 'numbers1' - return "o10837434939102457526.4784396906364855777" - when 'borders' - return "o10837434939102457526.664868920231926255" - when 'simple_spreadsheet' - return "o1087434939102457526.1774445811568867358" - when 'testnichtvorhandenBibelbund.ods' - return "invalidkeyforanyspreadsheet" # !!! intentionally false key - when "only_one_sheet" - return "o10837434939102457526.762705759906130135" - else - raise "unknown spreadsheetname: #{spreadsheetname}" - end - end # false end if DB_LOG if ! (defined?(@connected) and @connected) activerecord_connect @@ -108,28 +91,39 @@ # p self.class.to_s #p @method_name #p t1 #p t2-t1 domain = Testrun.create( - :class => self.class.to_s, - :test => @method_name, + :class_name => self.class.to_s, + :test_name => @method_name, :start => t1, :duration => t2-t1 ) end end end +class File + + def File.delete_if_exist(filename) + if File.exist?(filename) + File.delete(filename) + end + end + +end + class TestRoo < Test::Unit::TestCase OPENOFFICE = true # do Openoffice-Spreadsheet Tests? EXCEL = true # do Excel Tests? GOOGLE = true # do Google-Spreadsheet Tests? OPENOFFICEWRITE = false # experimental: write access with OO-Documents ONLINE = true LONG_RUN = false + LONG_RUN_EXCEL = false GLOBAL_TIMEOUT = 2*12*60 # seconds # helper method def after(d) @@ -1537,16 +1531,16 @@ 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_openoffice + def test_huge_document_to_csv_openoffice if LONG_RUN if OPENOFFICE assert_nothing_raised(Timeout::Error) { Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| - File.delete("/tmp/Bibelbund.csv") + File.delete_if_exist("/tmp/Bibelbund.csv") oo = Openoffice.new(File.join("test","Bibelbund.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') @@ -1557,12 +1551,12 @@ } # nothing_raised end # OPENOFFICE end end - def test_to_csv_excel - if LONG_RUN + def test_huge_document_to_csv_excel + if LONG_RUN_EXCEL if EXCEL assert_nothing_raised(Timeout::Error) { Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| File.delete("/tmp/Bibelbund.csv") oo = Excel.new(File.join("test","Bibelbund.xls")) @@ -1574,11 +1568,11 @@ } end end # LONG_RUN end # def to_csv - def test_to_csv_google + def test_huge_document_to_csv_google # maybe a better example... TODO: after Date.new(2008,1,30) do if GOOGLE assert_nothing_raised(Timeout::Error) { Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| @@ -1594,11 +1588,65 @@ end # Timeout } # nothing_raised end # GOOGLE end # after end + +def test_to_csv_openoffice + if OPENOFFICE + #assert_nothing_raised(Timeout::Error) { + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + File.delete_if_exist("/tmp/numbers1.csv") + oo = Openoffice.new(File.join("test","numbers1.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') + assert oo.to_csv("/tmp/numbers1.csv") + assert File.exists?("/tmp/numbers1.csv") + assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv` + end # Timeout + #} # nothing_raised + end # OPENOFFICE + end + def test_to_csv_excel + if EXCEL + #assert_nothing_raised(Timeout::Error) { + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + File.delete_if_exist("/tmp/numbers1_excel.csv") + oo = Excel.new(File.join("test","numbers1.xls")) + oo.default_sheet = oo.sheets.first + assert oo.to_csv("/tmp/numbers1_excel.csv") + assert File.exists?("/tmp/numbers1_excel.csv") + assert_equal "", `diff test/numbers1_excel.csv /tmp/numbers1_excel.csv` + end + #} + end + end # def to_csv + + def test_to_csv_google +# maybe a better example... TODO: +after Date.new(2008,1,30) do + if GOOGLE + #assert_nothing_raised(Timeout::Error) { + Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| + File.delete_if_exist("/tmp/numbers1.csv") if File.exists?("/tmp/numbers1.csv") + oo = Google.new(key_of('numbers1')) + 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') + assert oo.to_csv("/tmp/numbers1.csv") + assert File.exists?("/tmp/numbers1.csv") + assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv` + end # Timeout + #} # nothing_raised + end # GOOGLE +end # after + end + def test_bug_mehrere_datum if OPENOFFICE oo = Openoffice.new(File.join("test","numbers1.ods")) oo.default_sheet = 'Sheet5' assert_equal :date, oo.celltype('A',4) @@ -2150,16 +2198,14 @@ 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','Bibelbund.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" + assert_equal 3735, oo.column('a').size + #assert_equal 499, oo.column('a').size end } end end end @@ -2181,11 +2227,11 @@ end end def test_column_huge_document_google if LONG_RUN - if GOOGLE_NEW + if GOOGLE assert_nothing_raised(Timeout::Error) { Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length| #puts Time.now.to_s + "column Openoffice gestartet" oo = Google.new(key_of('Bibelbund')) oo.default_sheet = oo.sheets.first @@ -2294,11 +2340,11 @@ } end def test_info - expected_templ = "File: test/numbers1%s\n"+ + expected_templ = "File: 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"+ @@ -2339,12 +2385,11 @@ if GOOGLE ext = "" expected = sprintf(expected_templ,ext) oo = Google.new(key_of("numbers1")) #$log.debug(expected) - #$log.debug expected.gsub(/test\/numbers1/,key_of("numbers1")) - assert_equal expected.gsub(/test\/numbers1/,key_of("numbers1")), oo.info + assert_equal expected.gsub(/numbers1/,key_of("numbers1")), oo.info end end def test_bug_excel_numbers1_sheet5_last_row oo = Excel.new(File.join("test","numbers1.xls")) @@ -2419,11 +2464,11 @@ end def test_bug_bbu_openoffice oo = Openoffice.new(File.join('test','bbu.ods')) assert_nothing_raised() { - assert_equal "File: test/bbu.ods + assert_equal "File: bbu.ods Number of sheets: 3 Sheets: 2007_12, Tabelle2, Tabelle3 Sheet 1: First row: 1 Last row: 4 @@ -2443,11 +2488,11 @@ end def test_bug_bbu_excel oo = Excel.new(File.join('test','bbu.xls')) assert_nothing_raised() { - assert_equal "File: test/bbu.xls + assert_equal "File: bbu.xls Number of sheets: 3 Sheets: 2007_12, Tabelle2, Tabelle3 Sheet 1: First row: 1 Last row: 4 @@ -2490,7 +2535,14 @@ assert_nil oo.last_row assert_nil oo.first_column assert_nil oo.last_column end end # false + +# def teardown +# puts "Options:" +# puts "OPENOFFICE = #{OPENOFFICE}" +# puts "EXCEL = #{EXCEL}" +# puts "GOOGLE = #{GOOGLE}" +# end end # class