Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 71a56aa5a1
Fetching contributors…

Cannot retrieve contributors at this time

4919 lines (4574 sloc) 169.719 kB
#damit keine falschen Vermutungen aufkommen: Ich habe religioes rein gar nichts
# mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
# Spreadsheet-Datei mit ca. 3500 Zeilen 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
#
TESTDIR = File.dirname(__FILE__)
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 = false
DB_LOG = false
if DB_LOG
require 'activerecord'
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
def key_of(spreadsheetname)
begin
return {
'numbers1' => "o10837434939102457526.4784396906364855777",
'borders' => "o10837434939102457526.664868920231926255",
'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
"only_one_sheet" => "o10837434939102457526.762705759906130135",
"write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
'formula' => 'o10837434939102457526.3022866619437760118',
'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
}[spreadsheetname]
rescue
raise "unknown spreadsheetname: #{spreadsheetname}"
end
end
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}"
STDOUT.flush
end
unlogged_run result, &block
t2 = Time.now
if DISPLAY_LOG
puts "\t#{t2-t1} seconds"
end
if DB_LOG
domain = Testrun.create(
: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
# :nodoc
class Fixnum
def minutes
self * 60
end
end
class TestRoo < Test::Unit::TestCase
OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
EXCEL = true # do Excel Tests?
GOOGLE = false # do Google-Spreadsheet Tests?
GNUMERIC_ODS = false # do gnumeric with ods files Tests?
EXCELX = true # do Excel-X Tests? (.xlsx-files)
OPENOFFICEWRITE = false # experimental: write access with OO-Documents
ONLINE = true
LONG_RUN = false
GLOBAL_TIMEOUT = 48.minutes #*60 # 2*12*60 # seconds
def setup
#if DISPLAY_LOG
# puts " GLOBAL_TIMEOUT = #{GLOBAL_TIMEOUT}"
#end
end
def test_internal_minutes
assert_equal 42*60, 42.minutes
end
def test_date
assert Google.date?("21/11/1962")
assert_equal Date.new(1962,11,21), Google.to_date("21/11/1962")
assert !Google.date?("21")
assert_nil Google.to_date("21")
assert !Google.date?("21/11")
assert_nil Google.to_date("21/11")
assert !Google.date?("Mittwoch/21/1961")
assert_nil Google.to_date("Mittwoch/21/1961")
end
def test_classes
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
assert_kind_of Openoffice, oo
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
assert_kind_of Excel, oo
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
assert_kind_of Google, oo
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
assert_kind_of Excelx, oo
end
end
def test_letters
assert_equal 1, GenericSpreadsheet.letter_to_number('A')
assert_equal 1, GenericSpreadsheet.letter_to_number('a')
assert_equal 2, GenericSpreadsheet.letter_to_number('B')
assert_equal 26, GenericSpreadsheet.letter_to_number('Z')
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 DONT_test_simple_google
if GOOGLE
go = Google.new("egal")
assert_equal "42", go.cell(1,1)
end
end
def test_sheets_openoffice
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
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]
}
oo.sheets.each { |sh|
oo.default_sheet = sh
assert_equal sh, oo.default_sheet
}
end
end
def test_sheets_gnumeric_ods
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
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]
}
oo.sheets.each { |sh|
oo.default_sheet = sh
assert_equal sh, oo.default_sheet
}
end
end
def test_sheets_excel
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
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]
}
oo.sheets.each { |sh|
oo.default_sheet = sh
assert_equal sh, oo.default_sheet
}
end
end
def test_sheets_excelx
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
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]
}
oo.sheets.each { |sh|
oo.default_sheet = sh
assert_equal sh, oo.default_sheet
}
end
end
def test_sheets_google
if GOOGLE
oo = Google.new(key_of("numbers1"))
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]
}
oo.sheets.each { |sh|
oo.default_sheet = sh
assert_equal sh, oo.default_sheet
}
end
end
def test_cell_openoffice
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.cell(1,1)
assert_equal 2, oo.cell(1,2)
assert_equal 3, oo.cell(1,3)
assert_equal 4, oo.cell(1,4)
assert_equal 5, oo.cell(2,1)
assert_equal 6, oo.cell(2,2)
assert_equal 7, oo.cell(2,3)
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 :string, oo.celltype(2,6)
assert_equal 11, oo.cell(2,7)
# assert_equal "float", oo.celltype(2,7)
assert_equal :float, oo.celltype(2,7)
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, 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
def test_cell_gnumeric_ods
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.cell(1,1)
assert_equal 2, oo.cell(1,2)
assert_equal 3, oo.cell(1,3)
assert_equal 4, oo.cell(1,4)
assert_equal 5, oo.cell(2,1)
assert_equal 6, oo.cell(2,2)
assert_equal 7, oo.cell(2,3)
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 :string, oo.celltype(2,6)
assert_equal 11, oo.cell(2,7)
# assert_equal "float", oo.celltype(2,7)
assert_equal :float, oo.celltype(2,7)
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, 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
def test_cell_excel
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.cell(1,1)
assert_equal 2, oo.cell(1,2)
assert_equal 3, oo.cell(1,3)
assert_equal 4, oo.cell(1,4)
assert_equal 5, oo.cell(2,1)
assert_equal 6, oo.cell(2,2)
assert_equal 7, oo.cell(2,3)
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 :string, oo.celltype(2,6)
assert_equal 11, oo.cell(2,7)
# assert_equal "float", oo.celltype(2,7)
assert_equal :float, oo.celltype(2,7)
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, 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
def test_cell_excelx
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_kind_of Float, oo.cell(1,1)
assert_equal 1, oo.cell(1,1)
assert_equal 2, oo.cell(1,2)
assert_equal 3, oo.cell(1,3)
assert_equal 4, oo.cell(1,4)
assert_equal 5, oo.cell(2,1)
assert_equal 6, oo.cell(2,2)
assert_equal 7, oo.cell(2,3)
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 :string, oo.celltype(2,6)
assert_equal 11, oo.cell(2,7)
# assert_equal "float", oo.celltype(2,7)
assert_equal :float, oo.celltype(2,7)
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, 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
def test_cell_google
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.cell(1,1)
assert_equal 2, oo.cell(1,2)
assert_equal 3, oo.cell(1,3)
assert_equal 4, oo.cell(1,4)
assert_equal 5, oo.cell(2,1)
assert_equal 6, oo.cell(2,2)
assert_equal 7, oo.cell(2,3)
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 :string, oo.celltype(2,6)
assert_equal 11, oo.cell(2,7)
# assert_equal "float", oo.celltype(2,7)
assert_equal :float, oo.celltype(2,7), "Inhalt: --#{oo.cell(2,7)}--"
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, 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 # GOOGLE
end
def test_celltype
###
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal :string, oo.celltype(2,6)
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal :string, oo.celltype(2,6)
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = oo.sheets.first
assert_equal :string, oo.celltype(2,6)
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal :string, oo.celltype(2,6)
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal :string, oo.celltype(2,6)
end
end
def test_cell_address
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal "tata", oo.cell(6,1)
assert_equal "tata", oo.cell(6,'A')
assert_equal "tata", oo.cell('A',6)
assert_equal "tata", oo.cell(6,'a')
assert_equal "tata", oo.cell('a',6)
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('a','f')
}
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('f','a')
}
assert_equal "thisisc8", oo.cell(8,3)
assert_equal "thisisc8", oo.cell(8,'C')
assert_equal "thisisc8", oo.cell('C',8)
assert_equal "thisisc8", oo.cell(8,'c')
assert_equal "thisisc8", oo.cell('c',8)
assert_equal "thisisd9", oo.cell('d',9)
assert_equal "thisisa11", oo.cell('a',11)
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal "tata", oo.cell(6,1)
assert_equal "tata", oo.cell(6,'A')
assert_equal "tata", oo.cell('A',6)
assert_equal "tata", oo.cell(6,'a')
assert_equal "tata", oo.cell('a',6)
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('a','f')
}
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('f','a')
}
assert_equal "thisisc8", oo.cell(8,3)
assert_equal "thisisc8", oo.cell(8,'C')
assert_equal "thisisc8", oo.cell('C',8)
assert_equal "thisisc8", oo.cell(8,'c')
assert_equal "thisisc8", oo.cell('c',8)
assert_equal "thisisd9", oo.cell('d',9)
assert_equal "thisisa11", oo.cell('a',11)
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = oo.sheets.first
assert_equal "tata", oo.cell(6,'A')
assert_equal "tata", oo.cell(6,1)
assert_equal "tata", oo.cell('A',6)
assert_equal "tata", oo.cell(6,'a')
assert_equal "tata", oo.cell('a',6)
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('a','f')
}
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('f','a')
}
assert_equal "thisisc8", oo.cell(8,3)
assert_equal "thisisc8", oo.cell(8,'C')
assert_equal "thisisc8", oo.cell('C',8)
assert_equal "thisisc8", oo.cell(8,'c')
assert_equal "thisisc8", oo.cell('c',8)
assert_equal "thisisd9", oo.cell('d',9)
assert_equal "thisisa11", oo.cell('a',11)
#assert_equal "lulua", oo.cell('b',10)
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal "tata", oo.cell(6,1)
assert_equal "tata", oo.cell(6,'A')
assert_equal "tata", oo.cell('A',6)
assert_equal "tata", oo.cell(6,'a')
assert_equal "tata", oo.cell('a',6)
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('a','f')
}
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('f','a')
}
assert_equal "thisisc8", oo.cell(8,3)
assert_equal "thisisc8", oo.cell(8,'C')
assert_equal "thisisc8", oo.cell('C',8)
assert_equal "thisisc8", oo.cell(8,'c')
assert_equal "thisisc8", oo.cell('c',8)
assert_equal "thisisd9", oo.cell('d',9)
assert_equal "thisisa11", oo.cell('a',11)
#assert_equal "lulua", oo.cell('b',10)
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal "tata", oo.cell(6,1)
assert_equal "tata", oo.cell(6,'A')
assert_equal "tata", oo.cell('A',6)
assert_equal "tata", oo.cell(6,'a')
assert_equal "tata", oo.cell('a',6)
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('a','f')
}
assert_raise(ArgumentError) {
assert_equal "tata", oo.cell('f','a')
}
assert_equal "thisisc8", oo.cell(8,3)
assert_equal "thisisc8", oo.cell(8,'C')
assert_equal "thisisc8", oo.cell('C',8)
assert_equal "thisisc8", oo.cell(8,'c')
assert_equal "thisisc8", oo.cell('c',8)
assert_equal "thisisd9", oo.cell('d',9)
assert_equal "thisisa11", oo.cell('a',11)
end
end
# Version of the (XML) office document
# please note that "1.0" is returned even if it was created with OpenOffice V. 2.0
def test_officeversion
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
assert_equal "1.0", oo.officeversion
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
assert_equal "1.0", oo.officeversion
end
if EXCEL
# excel does not have a officeversion
end
if EXCELX
# excelx does not have a officeversion
#TODO: gibt es hier eine Versionsnummer
end
if GOOGLE
# google does not have a officeversion
end
end
#TODO: inkonsequente Lieferung Fixnum/Float
def test_rows
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"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 GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_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
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
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,42,43,44,45], 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 EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
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,42,43,44,45], 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 GOOGLE
oo = Google.new(key_of("numbers1"))
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,42,43,44,45], 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
end
def test_last_row
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 18, oo.last_row
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 18, oo.last_row
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = oo.sheets.first
assert_equal 18, oo.last_row
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal 18, oo.last_row
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal 18, oo.last_row
end
end
def test_last_column
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 7, oo.last_column
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 7, oo.last_column
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = oo.sheets.first
assert_equal 7, oo.last_column
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal 7, oo.last_column
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal 7, oo.last_column
end
end
def test_last_column_as_letter
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 'G', oo.last_column_as_letter
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 'G', oo.last_column_as_letter
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 1 # oo.sheets.first
assert_equal 'G', oo.last_column_as_letter
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal 'G', oo.last_column_as_letter
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal 'G', oo.last_column_as_letter
end
end
def test_first_row
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.first_row
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.first_row
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 1 # oo.sheets.first
assert_equal 1, oo.first_row
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.first_row
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.first_row
end
end
def test_first_column
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.first_column
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.first_column
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 1 # oo.sheets.first
assert_equal 1, oo.first_column
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.first_column
end
if GOOGLE
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.first_column
end
}
end
end
def test_first_column_as_letter_openoffice
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 'A', oo.first_column_as_letter
end
end
def test_first_column_as_letter_gnumeric_ods
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 'A', oo.first_column_as_letter
end
end
def test_first_column_as_letter_excel
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 1 # oo.sheets.first
assert_equal 'A', oo.first_column_as_letter
end
end
def test_first_column_as_letter_excelx
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal 'A', oo.first_column_as_letter
end
end
def test_first_column_as_letter_google
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal 'A', oo.first_column_as_letter
end
end
def test_sheetname
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = "Name of Sheet 2"
assert_equal 'I am sheet 2', oo.cell('C',5)
assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = "Name of Sheet 2"
assert_equal 'I am sheet 2', oo.cell('C',5)
assert_raise(RangeError) {
oo.default_sheet = "non existing sheet name"
}
assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = "Name of Sheet 2"
assert_equal 'I am sheet 2', oo.cell('C',5)
assert_raise(RangeError) {
oo.default_sheet = "non existing sheet name"
}
assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
assert_raise(RuntimeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
assert_raise(RuntimeError) { dummy = oo.formula('C',5,"non existing sheet name")}
#assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
#assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = "Name of Sheet 2"
assert_equal 'I am sheet 2', oo.cell('C',5)
assert_raise(RangeError) {
oo.default_sheet = "non existing sheet name"
}
assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = "Name of Sheet 2"
assert_equal 'I am sheet 2', oo.cell('C',5)
assert_raise(RangeError) {
oo.default_sheet = "non existing sheet name"
}
assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
#2008-12-04: assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.set_value('C',5,42,"non existing sheet name")}
assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
end
end
def test_boundaries
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = "Name of Sheet 2"
assert_equal 2, oo.first_column
assert_equal 'B', oo.first_column_as_letter
assert_equal 5, oo.first_row
assert_equal 'E', oo.last_column_as_letter
assert_equal 14, oo.last_row
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = "Name of Sheet 2"
assert_equal 2, oo.first_column
assert_equal 'B', oo.first_column_as_letter
assert_equal 5, oo.first_row
assert_equal 'E', oo.last_column_as_letter
assert_equal 14, oo.last_row
end
if EXCEL
#-- Excel
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 2 # "Name of Sheet 2"
assert_equal 2, oo.first_column
assert_equal 'B', oo.first_column_as_letter
assert_equal 5, oo.first_row
assert_equal 'E', oo.last_column_as_letter
assert_equal 14, oo.last_row
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = "Name of Sheet 2"
assert_equal 2, oo.first_column
assert_equal 'B', oo.first_column_as_letter
assert_equal 5, oo.first_row
assert_equal 'E', oo.last_column_as_letter
assert_equal 14, oo.last_row
end
end
def test_multiple_letters
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"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 GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_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
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 3 # "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 EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
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
end
def test_argument_error
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
before Date.new(2007,7,20) do
assert_raise(ArgumentError) {
#oo.default_sheet = "first sheet"
oo.default_sheet = "Tabelle1"
}
end
assert_nothing_raised(ArgumentError) {
# oo.default_sheet = 1
#oo.default_sheet = "first sheet"
oo.default_sheet = "Tabelle1"
}
end
end
def test_empty_eh
if OPENOFFICE #-- OpenOffice
oo = Openoffice.new(File.join(TESTDIR,"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 GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_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
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 1
assert oo.empty?('a',14)
assert ! oo.empty?('a',15)
assert oo.empty?('a',20)
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert oo.empty?('a',14)
assert ! oo.empty?('a',15)
assert oo.empty?('a',20)
end
end
def test_writeopenoffice
if OPENOFFICEWRITE
File.cp(File.join(TESTDIR,"numbers1.ods"),
File.join(TESTDIR,"numbers2.ods"))
File.cp(File.join(TESTDIR,"numbers2.ods"),
File.join(TESTDIR,"bak_numbers2.ods"))
oo = Openoffice.new(File.join(TESTDIR,"numbers2.ods"))
oo.default_sheet = oo.sheets.first
oo.first_row.upto(oo.last_row) {|y|
oo.first_column.upto(oo.last_column) {|x|
unless oo.empty?(y,x)
# oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == "float"
oo.set(y, x, oo.cell(y,x) + 7) if oo.celltype(y,x) == :float
end
}
}
oo.save
oo1 = Openoffice.new(File.join(TESTDIR,"numbers2.ods"))
oo2 = Openoffice.new(File.join(TESTDIR,"bak_numbers2.ods"))
#p oo2.to_s
assert_equal 999, oo2.cell('a',1), oo2.cell('a',1)
assert_equal oo2.cell('a',1) + 7, oo1.cell('a',1)
assert_equal oo2.cell('b',1)+7, oo1.cell('b',1)
assert_equal oo2.cell('c',1)+7, oo1.cell('c',1)
assert_equal oo2.cell('d',1)+7, oo1.cell('d',1)
assert_equal oo2.cell('a',2)+7, oo1.cell('a',2)
assert_equal oo2.cell('b',2)+7, oo1.cell('b',2)
assert_equal oo2.cell('c',2)+7, oo1.cell('c',2)
assert_equal oo2.cell('d',2)+7, oo1.cell('d',2)
assert_equal oo2.cell('e',2)+7, oo1.cell('e',2)
File.cp(File.join(TESTDIR,"bak_numbers2.ods"),
File.join(TESTDIR,"numbers2.ods"))
end
end
def test_reload
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.cell(1,1)
oo.reload
assert_equal 1, oo.cell(1,1)
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.cell(1,1)
oo.reload
assert_equal 1, oo.cell(1,1)
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 1 # oo.sheets.first
assert_equal 1, oo.cell(1,1)
oo.reload
assert_equal 1, oo.cell(1,1)
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal 1, oo.cell(1,1)
oo.reload
assert_equal 1, oo.cell(1,1)
end
end
def test_bug_contiguous_cells
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = "Sheet4"
assert_equal Date.new(2007,06,16), oo.cell('a',1)
assert_equal 10, oo.cell('b',1)
assert_equal 10, oo.cell('c',1)
assert_equal 10, oo.cell('d',1)
assert_equal 10, oo.cell('e',1)
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = "Sheet4"
assert_equal Date.new(2007,06,16), oo.cell('a',1)
assert_equal 10, oo.cell('b',1)
assert_equal 10, oo.cell('c',1)
assert_equal 10, oo.cell('d',1)
assert_equal 10, oo.cell('e',1)
end
if EXCEL
# dieser Test ist fuer Excel sheets nicht noetig,
# da der Bug nur bei OO-Dokumenten auftrat
end
if GOOGLE
# dieser Test ist fuer Google sheets nicht noetig,
# da der Bug nur bei OO-Dokumenten auftrat
end
end
def test_bug_italo_ve
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = "Sheet5"
assert_equal 1, oo.cell('A',1)
assert_equal 5, oo.cell('b',1)
assert_equal 5, oo.cell('c',1)
assert_equal 2, oo.cell('a',2)
assert_equal 3, oo.cell('a',3)
end
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = "Sheet5"
assert_equal 1, oo.cell('A',1)
assert_equal 5, oo.cell('b',1)
assert_equal 5, oo.cell('c',1)
assert_equal 2, oo.cell('a',2)
assert_equal 3, oo.cell('a',3)
end
if GNUMERIC_ODS
oo = Openoffice.new(File.join(TESTDIR,"gnumeric_numbers1.ods"))
oo.default_sheet = "Sheet5"
assert_equal 1, oo.cell('A',1)
assert_equal 5, oo.cell('b',1)
assert_equal 5, oo.cell('c',1)
assert_equal 2, oo.cell('a',2)
assert_equal 3, oo.cell('a',3)
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 5
assert_equal 1, oo.cell('A',1)
assert_equal 5, oo.cell('b',1)
assert_equal 5, oo.cell('c',1)
assert_equal 2, oo.cell('a',2)
assert_equal 3, oo.cell('a',3)
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = "Sheet5" # oo.sheets[5-1]
assert_equal 1, oo.cell('A',1)
assert_equal 5, oo.cell('b',1)
assert_equal 5, oo.cell('c',1)
assert_equal 2, oo.cell('a',2)
assert_equal 3, oo.cell('a',3)
end
#if GOOGLE
# oo = Google.new(key_of("numbers1"))
# oo.default_sheet = "Sheet5"
# assert_equal 1, oo.cell('A',1)
# assert_equal 5, oo.cell('b',1)
# assert_equal 5, oo.cell('c',1)
# assert_equal 2, oo.cell('a',2)
# assert_equal 3, oo.cell('a',3)
#end
end
#2008-01-30
def test_italo_table
local_only do
oo = Openoffice.new(File.join(TESTDIR,"simple_spreadsheet_from_italo.ods"))
oo.default_sheet = oo.sheets.first
assert_equal '1', oo.cell('A',1)
assert_equal '1', oo.cell('B',1)
assert_equal '1', oo.cell('C',1)
# 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
oo = Excel.new(File.join(TESTDIR,"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)
assert_equal '1', oo.cell('C',1)
# 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
end
end
def test_formula_openoffice
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"formula.ods"))
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 21, oo.cell('A',7)
assert_equal :formula, oo.celltype('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(oo.sheets.first)
# 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
end
def test_formula_excel
if defined? excel_supports_formulas
if EXCEL
oo = Excel.new(File.join(TESTDIR,"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
# 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
end
end
def test_formula_google
if GOOGLE
oo = Google.new(key_of("formula"))
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 21, oo.cell('A',7)
assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
assert_equal :formula, oo.celltype('A',7)
# assert_equal "=[Sheet2.A1]", oo.formula('C',7)
# !!! different from formulas in Openoffice
#was: assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
# has Google changed their format of formulas/references to other sheets?
assert_equal "=Sheet2!R[-6]C[-2]", 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(oo.sheets.first)
# different format than in openoffice spreadsheets:
#was:
# assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
# [7, 2, "=SUM(R1C1:R[-1]C[0])"],
# [7, 3, "=sheet2!R[-6]C[-2]"],
# [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
# oo.formulas(oo.sheets.first)
assert_equal [[7, 1, "=SUM(R[-6]C:R[-1]C)"],
[7, 2, "=SUM(R1C1:R[-1]C)"],
[7, 3, "=Sheet2!R[-6]C[-2]"],
[8, 2, "=SUM(R1C1:R[-1]C)"]],
oo.formulas(oo.sheets.first)
end # GOOGLE
end
def test_formula_excelx
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"formula.xlsx"))
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 21, oo.cell('A',7)
assert_equal :formula, oo.celltype('A',7)
after Date.new(9999,12,31) do
#steht nicht in Datei, oder?
#nein, diesen Bezug habe ich nur in der Openoffice-Datei
assert_equal "=[Sheet2.A1]", oo.formula('C',7)
end
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.sheets.first)
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.sheets.first)
# 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
end
def test_borders_sheets_openoffice
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"borders.ods"))
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 = oo.sheets.first
assert_equal 5, oo.first_row
assert_equal 10, oo.last_row
assert_equal 3, oo.first_column
assert_equal 7, 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
end
def test_borders_sheets_excel
if EXCEL
oo = Excel.new(File.join(TESTDIR,"borders.xls"))
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_equal 5, oo.first_row
assert_equal 10, oo.last_row
assert_equal 3, oo.first_column
assert_equal 7, 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
assert_equal 9, oo.last_column
end
end
def test_borders_sheets_excelx
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"borders.xlsx"))
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 = oo.sheets.first
assert_equal 5, oo.first_row
assert_equal 10, oo.last_row
assert_equal 3, oo.first_column
assert_equal 7, 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
end
def test_borders_sheets_google
if GOOGLE
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Google.new(key_of("borders"))
oo.default_sheet = oo.sheets[0]
assert_equal oo.sheets.first, oo.default_sheet
assert_equal 5, oo.first_row
oo.default_sheet = oo.sheets[1]
assert_equal 'Sheet2', oo.default_sheet
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 = oo.sheets.first
assert_equal 5, oo.first_row
assert_equal 10, oo.last_row
assert_equal 3, oo.first_column
assert_equal 7, 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
}
end
end
def yaml_entry(row,col,type,value)
"cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
end
def test_to_yaml
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
assert_equal \
"--- \n"+yaml_entry(12,3,"float",43.0) +
yaml_entry(12,4,"float",44.0) +
yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
assert_equal \
"--- \n"+yaml_entry(12,3,"float",43.0)+
yaml_entry(12,4,"float",44.0)+
yaml_entry(12,5,"float",45.0)+
yaml_entry(15,3,"float",43.0)+
yaml_entry(15,4,"float",44.0)+
yaml_entry(15,5,"float",45.0)+
yaml_entry(16,3,"string","dreiundvierzig")+
yaml_entry(16,4,"string","vierundvierzig")+
yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
#example: puts oo.to_yaml({}, 12,3)
#example: puts oo.to_yaml({"probe" => "bodenproben_2007-06-30"}, 12,3)
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 1
assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
assert_equal \
"--- \n"+yaml_entry(12,3,"float",43.0) +
yaml_entry(12,4,"float",44.0) +
yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
assert_equal \
"--- \n"+yaml_entry(12,3,"float",43.0)+
yaml_entry(12,4,"float",44.0)+
yaml_entry(12,5,"float",45.0)+
yaml_entry(15,3,"float",43.0)+
yaml_entry(15,4,"float",44.0)+
yaml_entry(15,5,"float",45.0)+
yaml_entry(16,3,"string","dreiundvierzig")+
yaml_entry(16,4,"string","vierundvierzig")+
yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
assert_equal \
"--- \n"+yaml_entry(12,3,"float",43.0) +
yaml_entry(12,4,"float",44.0) +
yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
assert_equal \
"--- \n"+yaml_entry(12,3,"float",43.0)+
yaml_entry(12,4,"float",44.0)+
yaml_entry(12,5,"float",45.0)+
yaml_entry(15,3,"float",43.0)+
yaml_entry(15,4,"float",44.0)+
yaml_entry(15,5,"float",45.0)+
yaml_entry(16,3,"string","dreiundvierzig")+
yaml_entry(16,4,"string","vierundvierzig")+
yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
end
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
assert_equal \
"--- \n"+yaml_entry(12,3,"float",43.0) +
yaml_entry(12,4,"float",44.0) +
yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
assert_equal \
"--- \n"+yaml_entry(12,3,"float",43.0)+
yaml_entry(12,4,"float",44.0)+
yaml_entry(12,5,"float",45.0)+
yaml_entry(15,3,"float",43.0)+
yaml_entry(15,4,"float",44.0)+
yaml_entry(15,5,"float",45.0)+
yaml_entry(16,3,"string","dreiundvierzig")+
yaml_entry(16,4,"string","vierundvierzig")+
yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
#example: puts oo.to_yaml({}, 12,3)
#example: puts oo.to_yaml({"probe" => "bodenproben_2007-06-30"}, 12,3)
end
end
if false
def test_soap_server
#threads = []
#threads << Thread.new("serverthread") do
fork do
p "serverthread started"
puts "in child, pid = #$$"
puts `/usr/bin/ruby rooserver.rb`
p "serverthread finished"
end
#threads << Thread.new("clientthread") do
p "clientthread started"
sleep 10
proxy = SOAP::RPC::Driver.new("http://localhost:12321","spreadsheetserver")
proxy.add_method('cell','row','col')
proxy.add_method('officeversion')
proxy.add_method('last_row')
proxy.add_method('last_column')
proxy.add_method('first_row')
proxy.add_method('first_column')
proxy.add_method('sheets')
proxy.add_method('set_default_sheet','s')
proxy.add_method('ferien_fuer_region', 'region')
sheets = proxy.sheets
p sheets
proxy.set_default_sheet(sheets.first)
assert_equal 1, proxy.first_row
assert_equal 1, proxy.first_column
assert_equal 187, proxy.last_row
assert_equal 7, proxy.last_column
assert_equal 42, proxy.cell('C',8)
assert_equal 43, proxy.cell('F',12)
assert_equal "1.0", proxy.officeversion
p "clientthread finished"
#end
#threads.each {|t| t.join }
puts "fertig"
Process.kill("INT",pid)
pid = Process.wait
puts "child terminated, pid= #{pid}, status= #{$?.exitstatus}"
end
end # false
def split_coord(s)
letter = ""
number = 0
i = 0
while i<s.length and "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".include?(s[i,1])
letter += s[i,1]
i+=1
end
while i<s.length and "01234567890".include?(s[i,1])
number = number*10 + s[i,1].to_i
i+=1
end
if letter=="" or number==0
raise ArgumentError
end
return letter,number
end
#def sum(s,expression)
# arg = expression.split(':')
# b,z = split_coord(arg[0])
# first_row = z
# first_col = Openoffice.letter_to_number(b)
# b,z = split_coord(arg[1])
# last_row = z
# last_col = Openoffice.letter_to_number(b)
# result = 0
# first_row.upto(last_row) {|row|
# first_col.upto(last_col) {|col|
# result = result + s.cell(row,col)
# }
# }
# result
#end
#def test_dsl
# s = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
# s.default_sheet = s.sheets.first
#
# s.set 'a',1, 5
# s.set 'b',1, 3
# s.set 'c',1, 7
# s.set('a',2, s.cell('a',1)+s.cell('b',1))
# assert_equal 8, s.cell('a',2)
#
# assert_equal 15, sum(s,'A1:C1')
# end
#def test_create_spreadsheet1
# name = File.join(TESTDIR,'createdspreadsheet.ods')
# rm(name) if File.exists?(File.join(TESTDIR,'createdspreadsheet.ods'))
# # anlegen, falls noch nicht existierend
# s = Openoffice.new(name,true)
# assert File.exists?(name)
#end
#def test_create_spreadsheet2
# # anlegen, falls noch nicht existierend
# s = Openoffice.new(File.join(TESTDIR,"createdspreadsheet.ods"),true)
# s.set 'a',1,42
# s.set 'b',1,43
# s.set 'c',1,44
# s.save
#
# #after Date.new(2007,7,3) do
# # t = Openoffice.new(File.join(TESTDIR,"createdspreadsheet.ods"))
# # assert_equal 42, t.cell(1,'a')
# # assert_equal 43, t.cell('b',1)
# # assert_equal 44, t.cell('c',3)
# #end
#end
def test_only_one_sheet
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"only_one_sheet.ods"))
# oo.default_sheet = oo.sheets.first
assert_equal 42, oo.cell('B',4)
assert_equal 43, oo.cell('C',4)
assert_equal 44, oo.cell('D',4)
oo.default_sheet = oo.sheets.first
assert_equal 42, oo.cell('B',4)
assert_equal 43, oo.cell('C',4)
assert_equal 44, oo.cell('D',4)
end
if EXCEL
oo = Excel.new(File.join(TESTDIR,"only_one_sheet.xls"))
# oo.default_sheet = oo.sheets.first
assert_equal 42, oo.cell('B',4)
assert_equal 43, oo.cell('C',4)
assert_equal 44, oo.cell('D',4)
oo.default_sheet = oo.sheets.first
assert_equal 42, oo.cell('B',4)
assert_equal 43, oo.cell('C',4)
assert_equal 44, oo.cell('D',4)
end
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"only_one_sheet.xlsx"))
# oo.default_sheet = oo.sheets.first
assert_equal 42, oo.cell('B',4)
assert_equal 43, oo.cell('C',4)
assert_equal 44, oo.cell('D',4)
oo.default_sheet = oo.sheets.first
assert_equal 42, oo.cell('B',4)
assert_equal 43, oo.cell('C',4)
assert_equal 44, oo.cell('D',4)
end
if GOOGLE
oo = Google.new(key_of("only_one_sheet"))
# oo.default_sheet = oo.sheets.first
assert_equal 42, oo.cell('B',4)
assert_equal 43, oo.cell('C',4)
assert_equal 44, oo.cell('D',4)
oo.default_sheet = oo.sheets.first
assert_equal 42, oo.cell('B',4)
assert_equal 43, oo.cell('C',4)
assert_equal 44, oo.cell('D',4)
end
end
def test_excel_open_from_uri_and_zipped
if EXCEL
if ONLINE
url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
excel = Excel.new(url, :zip)
excel.default_sheet = excel.sheets.first
assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
excel.remove_tmp # don't forget to remove the temporary files
end
end
end
#TODO: xlsx-Datei anpassen!
def test_excelx_open_from_uri_and_zipped
#TODO: gezippte xlsx Datei online zum Testen suchen
after Date.new(2999,6,30) do
if EXCELX
if ONLINE
url = 'http://stiny-leonhard.de/bode-v1.xlsx.zip'
excel = Excelx.new(url, :zip)
assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
excel.remove_tmp # don't forget to remove the temporary files
end
end
end
end
def test_openoffice_open_from_uri_and_zipped
if OPENOFFICE
if ONLINE
url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
sheet = Openoffice.new(url, :zip)
#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
end
def SKIP_test_excel_zipped
after Date.new(2009,1,10) do
if EXCEL
$log.level = Logger::DEBUG
excel = Excel.new(File.join(TESTDIR,"bode-v1.xls.zip"), :zip)
assert excel
# muss Fehler bringen, weil kein default_sheet gesetzt wurde
assert_raises (ArgumentError) {
assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
}
$log.level = Logger::WARN
excel.default_sheet = excel.sheets.first
assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
excel.remove_tmp # don't forget to remove the temporary files
end
end
end
def test_excelx_zipped
# TODO: bode...xls bei Gelegenheit nach .xlsx konverieren lassen und zippen!
if EXCELX
after Date.new(2999,7,30) do
# diese Datei gibt es noch nicht gezippt
excel = Excelx.new(File.join(TESTDIR,"bode-v1.xlsx.zip"), :zip)
assert excel
assert_raises (ArgumentError) {
assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
}
excel.default_sheet = excel.sheets.first
assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
excel.remove_tmp # don't forget to remove the temporary files
end
end
end
def test_openoffice_zipped
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), :zip)
assert oo
# muss Fehler bringen, weil kein default_sheet gesetzt wurde
assert_raises (ArgumentError) {
assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
}
oo.default_sheet = oo.sheets.first
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
end
def test_bug_ric
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"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)
#}
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)
end
end
def test_mehrteilig
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"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
#if EXCELX
# after Date.new(2008,6,1) do
# #Datei gibt es noch nicht
# oo = Excelx.new(File.join(TESTDIR,"Bibelbund1.xlsx"))
# 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
end
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_if_exist("/tmp/Bibelbund.csv")
oo = Openoffice.new(File.join(TESTDIR,"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')
assert oo.to_csv("/tmp/Bibelbund.csv")
assert File.exists?("/tmp/Bibelbund.csv")
assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
end # Timeout
} # nothing_raised
end # OPENOFFICE
end
end
def test_huge_document_to_csv_excel
if LONG_RUN
if EXCEL
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
File.delete_if_exist("/tmp/Bibelbund.csv")
oo = Excel.new(File.join(TESTDIR,"Bibelbund.xls"))
oo.default_sheet = oo.sheets.first
assert oo.to_csv("/tmp/Bibelbund.csv")
assert File.exists?("/tmp/Bibelbund.csv")
assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
end
}
end
end # LONG_RUN
end # def to_csv
def test_huge_document_to_csv_excelx
after Date.new(2008,8,27) do
if LONG_RUN
if EXCELX
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
File.delete_if_exist("/tmp/Bibelbund.csv")
oo = Excelx.new(File.join(TESTDIR,"Bibelbund.xlsx"))
oo.default_sheet = oo.sheets.first
assert oo.to_csv("/tmp/Bibelbund.csv")
assert File.exists?("/tmp/Bibelbund.csv")
assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
end
}
end
end # LONG_RUN
end
end
def test_huge_document_to_csv_google
# maybe a better example... TODO:
if GOOGLE and LONG_RUN
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
File.delete("/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
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(TESTDIR,"numbers1.ods"))
# bug?, 2008-01-15 from Troy Davis
assert oo.to_csv("/tmp/numbers1.csv",oo.sheets.first)
assert File.exists?("/tmp/numbers1.csv")
assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
oo.default_sheet = oo.sheets.first
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(TESTDIR,"numbers1.xls"))
# bug?, 2008-01-15 from Troy Davis
assert oo.to_csv("/tmp/numbers1_excel.csv",oo.sheets.first)
assert File.exists?("/tmp/numbers1_excel.csv")
assert_equal "", `diff test/numbers1_excel.csv /tmp/numbers1_excel.csv`
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 test_to_csv_excelx
if EXCELX
#assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
File.delete_if_exist("/tmp/numbers1.csv")
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
# bug?, 2008-01-15 from Troy Davis
assert oo.to_csv("/tmp/numbers1.csv",oo.sheets.first)
assert File.exists?("/tmp/numbers1.csv")
assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
oo.default_sheet = oo.sheets.first
assert oo.to_csv("/tmp/numbers1.csv")
assert File.exists?("/tmp/numbers1.csv")
assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
end
#}
end
end
def test_to_csv_google
# maybe a better example... TODO:
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 oo.to_csv("/tmp/numbers1.csv")
assert File.exists?("/tmp/numbers1.csv")
assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
# bug?, 2008-01-15 from Troy Davis
assert oo.to_csv("/tmp/numbers1.csv",oo.sheets.first)
assert File.exists?("/tmp/numbers1.csv")
assert_equal "", `diff test/numbers1.csv /tmp/numbers1.csv`
end # Timeout
#} # nothing_raised
end # GOOGLE
end
def test_bug_mehrere_datum
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = 'Sheet5'
assert_equal :date, oo.celltype('A',4)
assert_equal :date, oo.celltype('B',4)
assert_equal :date, oo.celltype('C',4)
assert_equal :date, oo.celltype('D',4)
assert_equal :date, oo.celltype('E',4)
assert_equal Date.new(2007,11,21), oo.cell('A',4)
assert_equal Date.new(2007,11,21), oo.cell('B',4)
assert_equal Date.new(2007,11,21), oo.cell('C',4)
assert_equal Date.new(2007,11,21), oo.cell('D',4)
assert_equal Date.new(2007,11,21), oo.cell('E',4)
assert_equal :float, oo.celltype('A',5)
assert_equal :float, oo.celltype('B',5)
assert_equal :float, oo.celltype('C',5)
assert_equal :float, oo.celltype('D',5)
assert_equal :float, oo.celltype('E',5)
assert_equal 42, oo.cell('A',5)
assert_equal 42, oo.cell('B',5)
assert_equal 42, oo.cell('C',5)
assert_equal 42, oo.cell('D',5)
assert_equal 42, oo.cell('E',5)
assert_equal :string, oo.celltype('A',6)
assert_equal :string, oo.celltype('B',6)
assert_equal :string, oo.celltype('C',6)
assert_equal :string, oo.celltype('D',6)
assert_equal :string, oo.celltype('E',6)
assert_equal "ABC", oo.cell('A',6)
assert_equal "ABC", oo.cell('B',6)
assert_equal "ABC", oo.cell('C',6)
assert_equal "ABC", oo.cell('D',6)
assert_equal "ABC", oo.cell('E',6)
end # Openoffice
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = 'Sheet5'
assert_equal :date, oo.celltype('A',4)
assert_equal :date, oo.celltype('B',4)
assert_equal :date, oo.celltype('C',4)
assert_equal :date, oo.celltype('D',4)
assert_equal :date, oo.celltype('E',4)
assert_equal Date.new(2007,11,21), oo.cell('A',4)
assert_equal Date.new(2007,11,21), oo.cell('B',4)
assert_equal Date.new(2007,11,21), oo.cell('C',4)
assert_equal Date.new(2007,11,21), oo.cell('D',4)
assert_equal Date.new(2007,11,21), oo.cell('E',4)
assert_equal :float, oo.celltype('A',5)
assert_equal :float, oo.celltype('B',5)
assert_equal :float, oo.celltype('C',5)
assert_equal :float, oo.celltype('D',5)
assert_equal :float, oo.celltype('E',5)
assert_equal 42, oo.cell('A',5)
assert_equal 42, oo.cell('B',5)
assert_equal 42, oo.cell('C',5)
assert_equal 42, oo.cell('D',5)
assert_equal 42, oo.cell('E',5)
assert_equal :string, oo.celltype('A',6)
assert_equal :string, oo.celltype('B',6)
assert_equal :string, oo.celltype('C',6)
assert_equal :string, oo.celltype('D',6)
assert_equal :string, oo.celltype('E',6)
assert_equal "ABC", oo.cell('A',6)
assert_equal "ABC", oo.cell('B',6)
assert_equal "ABC", oo.cell('C',6)
assert_equal "ABC", oo.cell('D',6)
assert_equal "ABC", oo.cell('E',6)
end # Excel
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = 'Sheet5'
assert_equal :date, oo.celltype('A',4)
assert_equal :date, oo.celltype('B',4)
assert_equal :date, oo.celltype('C',4)
assert_equal :date, oo.celltype('D',4)
assert_equal :date, oo.celltype('E',4)
assert_equal Date.new(2007,11,21), oo.cell('A',4)
assert_equal Date.new(2007,11,21), oo.cell('B',4)
assert_equal Date.new(2007,11,21), oo.cell('C',4)
assert_equal Date.new(2007,11,21), oo.cell('D',4)
assert_equal Date.new(2007,11,21), oo.cell('E',4)
assert_equal :float, oo.celltype('A',5)
assert_equal :float, oo.celltype('B',5)
assert_equal :float, oo.celltype('C',5)
assert_equal :float, oo.celltype('D',5)
assert_equal :float, oo.celltype('E',5)
assert_equal 42, oo.cell('A',5)
assert_equal 42, oo.cell('B',5)
assert_equal 42, oo.cell('C',5)
assert_equal 42, oo.cell('D',5)
assert_equal 42, oo.cell('E',5)
assert_equal :string, oo.celltype('A',6)
assert_equal :string, oo.celltype('B',6)
assert_equal :string, oo.celltype('C',6)
assert_equal :string, oo.celltype('D',6)
assert_equal :string, oo.celltype('E',6)
assert_equal "ABC", oo.cell('A',6)
assert_equal "ABC", oo.cell('B',6)
assert_equal "ABC", oo.cell('C',6)
assert_equal "ABC", oo.cell('D',6)
assert_equal "ABC", oo.cell('E',6)
end # Excelx
end
def test_multiple_sheets
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"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 # OPENOFFICE
if EXCEL
$debug = true
oo = Excel.new(File.join(TESTDIR,"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 # times
$debug = false
end # EXCEL
if GOOGLE
oo = Google.new(key_of("numbers1"))
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 EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
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_openoffice
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"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
end
def test_bug_empty_sheet_excelx
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"formula.xlsx"))
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
end
def test_find_by_row_huge_document_openoffice
if LONG_RUN
if OPENOFFICE
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Openoffice.new(File.join(TESTDIR,"Bibelbund.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_huge_document_excel
if LONG_RUN
if EXCEL
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Excel.new(File.join(TESTDIR,"Bibelbund.xls"))
oo.default_sheet = oo.sheets.first
rec = oo.find 20
assert rec
#jetzt als Hash assert_equal "Brief aus dem Sekretariat", rec[0]
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_huge_document_excelx
if LONG_RUN
if EXCEL
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Excelx.new(File.join(TESTDIR,"Bibelbund.xlsx"))
oo.default_sheet = oo.sheets.first
rec = oo.find 20
assert 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]['TITEL']
end
end
end
end
def test_find_by_row_openoffice
if OPENOFFICE
oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
oo.default_sheet = oo.sheets.first
oo.header_line = nil
rec = oo.find 16
assert rec
assert_nil oo.header_line
# keine Headerlines in diesem Beispiel definiert
assert_equal "einundvierzig", rec[0]
#assert_equal false, rec
rec = oo.find 15
assert rec
assert_equal 41,rec[0]
end
end
def test_find_by_row_excel
if EXCEL
oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
oo.default_sheet = oo.sheets.first
oo.header_line = nil
rec = oo.find 16
assert rec
# keine Headerlines in diesem Beispiel definiert
assert_equal "einundvierzig", rec[0]
rec = oo.find 15
assert rec
assert_equal 41,rec[0]
end
end
def test_find_by_row_excelx
if EXCELX
oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
oo.default_sheet = oo.sheets.first
oo.header_line = nil
rec = oo.find 16
assert rec
# keine Headerlines in diesem Beispiel definiert
assert_equal "einundvierzig", rec[0]
rec = oo.find 15
assert rec
assert_equal 41,rec[0]
end
end
def test_find_by_row_google
if GOOGLE
oo = Google.new(key_of("numbers1"))
oo.default_sheet = oo.sheets.first
oo.header_line = nil
rec = oo.find 16
assert rec
# keine Headerlines in diesem Beispiel definiert
assert_equal "einundvierzig", rec[0]
rec = oo.find 15
assert rec
assert_equal 41,rec[0]
end
end
def test_find_by_row_huge_document_google
if LONG_RUN
if GOOGLE
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Google.new(key_of("Bibelbund"))
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(TESTDIR,"Bibelbund.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(TESTDIR,"Bibelbund.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
#TODO: temporaerer Test
def test_seiten_als_date
oo = Excelx.new(File.join(TESTDIR,"Bibelbund.xlsx"))
oo.default_sheet = oo.sheets.first
assert_equal 'Bericht aus dem Sekretariat', oo.cell(13,1)
assert_equal '1981-4', oo.cell(13,'D')
assert_equal [:numeric_or_formula,"General"], oo.excelx_type(13,'E')
assert_equal '428', oo.excelx_value(13,'E')
assert_equal 428.0, oo.cell(13,'E')
end
def test_find_by_conditions_excelx
if LONG_RUN
if EXCELX
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Excelx.new(File.join(TESTDIR,"Bibelbund.xlsx"))
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_find_by_conditions_google
if LONG_RUN
if GOOGLE
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Google.new(key_of("Bibelbund"))
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_column_openoffice
after Date.new(2008,9,30) do
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(TESTDIR,'numbers1.ods'))
oo.default_sheet = oo.sheets.first
assert_equal expected, oo.column(1)
assert_equal expected, oo.column('a')
end
end
end
end
def test_column_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(TESTDIR,'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_excelx
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 EXCELX
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Excelx.new(File.join(TESTDIR,'numbers1.xlsx'))
oo.default_sheet = oo.sheets.first
assert_equal expected, oo.column(1)
assert_equal expected, oo.column('a')
end
end
end
def test_column_google
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 GOOGLE
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Google.new(key_of('numbers1'))
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|
oo = Openoffice.new(File.join(TESTDIR,'Bibelbund.ods'))
oo.default_sheet = oo.sheets.first
assert_equal 3735, oo.column('a').size
#assert_equal 499, oo.column('a').size
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|
oo = Excel.new(File.join(TESTDIR,'Bibelbund.xls'))
oo.default_sheet = oo.sheets.first
assert_equal 3735, oo.column('a').size
#assert_equal 499, oo.column('a').size
end
}
end
end
end
def test_column_huge_document_excelx
if LONG_RUN
if EXCELX
assert_nothing_raised(Timeout::Error) {
Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
oo = Excelx.new(File.join(TESTDIR,'Bibelbund.xlsx'))
oo.default_sheet = oo.sheets.first
assert_equal 3735, oo.column('a').size
#assert_equal 499, oo.column('a').size
end
}
end
end
end
def test_column_huge_document_google
if LONG_RUN
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
#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_simple_spreadsheet_find_by_condition_openoffice
oo = Openoffice.new(File.join(TESTDIR,"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 test_simple_spreadsheet_find_by_condition_excel
if EXCEL
$debug = true
oo = Excel.new(File.join(TESTDIR,"simple_spreadsheet.xls"))
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']
#cannot be tested because excel cannot return the result of formulas:
# assert_equal 1.75 , erg[1]['Sum']
assert_equal "Task 1" , erg[1]['Comment']
$debug = false
end
end
def test_simple_spreadsheet_find_by_condition_excelx
if EXCELX
# die dezimalen Seiten bekomme ich seltsamerweise als Date
oo = Excelx.new(File.join(TESTDIR,"simple_spreadsheet.xlsx"))
oo.default_sheet = oo.sheets.first
oo.header_line = 3
erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
#expected = { "Start time"=>10.75,
# "Pause"=>0.0,
# "Sum" => 1.75,
# "End time" => 12.5,
# "Pause" => 0.0,
# "Sum"=> 1.75,
# "Comment" => "Task 1",
# "Date" => Date.new(2007,5,7)}
assert_equal Date.new(2007,5,7), erg[1]['Date']
assert_equal 10.75,erg[1]['Start time']
assert_equal 12.5, erg[1]['End time']
assert_equal 0.0, erg[1]['Pause']