summaryrefslogtreecommitdiff
path: root/test/xmlrpc/test_datetime.rb
diff options
context:
space:
mode:
authormneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-15 23:26:20 +0000
committermneumann <mneumann@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-15 23:26:20 +0000
commit396b1f27ca1581aa676c235a5d021828eef6257f (patch)
tree96f95f56b0a5b3cfa508a3b669b068c0705a644c /test/xmlrpc/test_datetime.rb
parent67d54f209d28019cc5d8b332706dd9950b56bdc7 (diff)
* imported and refactored original test cases
* added methods XMLRPC::XMLParser.each_installed_parser and XMLRPC::XMLWriter.each_installed_writer to simply original test cases * use Object#allocate instead of defining an empty #initialize * module XMLRPC::Marshallable is now only used for tagging git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/xmlrpc/test_datetime.rb')
-rw-r--r--test/xmlrpc/test_datetime.rb160
1 files changed, 160 insertions, 0 deletions
diff --git a/test/xmlrpc/test_datetime.rb b/test/xmlrpc/test_datetime.rb
new file mode 100644
index 00000000000..d7fbb6650f9
--- /dev/null
+++ b/test/xmlrpc/test_datetime.rb
@@ -0,0 +1,160 @@
+$LOAD_PATH.unshift '../../lib'
+require 'test/unit'
+require "xmlrpc/datetime"
+
+class Test_DateTime < Test::Unit::TestCase
+
+ def test_new
+ dt = createDateTime()
+
+ assert_instance_of(XMLRPC::DateTime, dt)
+ end
+
+ def test_new_exception
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(4.5, 13, 32, 25, 60, 60) }
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 32, 25, 60, 60) }
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 25, 60, 60) }
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 60, 60) }
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 59, 60) }
+ assert_nothing_raised(ArgumentError) { XMLRPC::DateTime.new(2001, 12, 31, 24, 59, 59) }
+
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 0, 0, -1, -1, -1) }
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 0, -1, -1, -1) }
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, -1, -1, -1) }
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, -1, -1) }
+ assert_raises(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, 0, -1) }
+ assert_nothing_raised(ArgumentError) { XMLRPC::DateTime.new(2001, 1, 1, 0, 0, 0) }
+ end
+
+
+ def test_get_values
+ y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5
+ dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
+
+ assert_equal(y, dt.year)
+ assert_equal(m, dt.month)
+ assert_equal(m, dt.mon)
+ assert_equal(d, dt.day)
+
+ assert_equal(h, dt.hour)
+ assert_equal(mi,dt.min)
+ assert_equal(s, dt.sec)
+ end
+
+ def test_set_values
+ dt = createDateTime()
+ y, m, d, h, mi, s = 1950, 12, 9, 8, 52, 30
+
+ dt.year = y
+ dt.month = m
+ dt.day = d
+ dt.hour = h
+ dt.min = mi
+ dt.sec = s
+
+ assert_equal(y, dt.year)
+ assert_equal(m, dt.month)
+ assert_equal(m, dt.mon)
+ assert_equal(d, dt.day)
+
+ assert_equal(h, dt.hour)
+ assert_equal(mi,dt.min)
+ assert_equal(s, dt.sec)
+
+ dt.mon = 5
+ assert_equal(5, dt.month)
+ assert_equal(5, dt.mon)
+ end
+
+ def test_set_exception
+ dt = createDateTime()
+
+ assert_raises(ArgumentError) { dt.year = 4.5 }
+ assert_nothing_raised(ArgumentError) { dt.year = -2000 }
+
+ assert_raises(ArgumentError) { dt.month = 0 }
+ assert_raises(ArgumentError) { dt.month = 13 }
+ assert_nothing_raised(ArgumentError) { dt.month = 7 }
+
+ assert_raises(ArgumentError) { dt.mon = 0 }
+ assert_raises(ArgumentError) { dt.mon = 13 }
+ assert_nothing_raised(ArgumentError) { dt.mon = 7 }
+
+ assert_raises(ArgumentError) { dt.day = 0 }
+ assert_raises(ArgumentError) { dt.day = 32 }
+ assert_nothing_raised(ArgumentError) { dt.day = 16 }
+
+ assert_raises(ArgumentError) { dt.hour = -1 }
+ assert_raises(ArgumentError) { dt.hour = 25 }
+ assert_nothing_raised(ArgumentError) { dt.hour = 12 }
+
+ assert_raises(ArgumentError) { dt.min = -1 }
+ assert_raises(ArgumentError) { dt.min = 60 }
+ assert_nothing_raised(ArgumentError) { dt.min = 30 }
+
+ assert_raises(ArgumentError) { dt.sec = -1 }
+ assert_raises(ArgumentError) { dt.sec = 60 }
+ assert_nothing_raised(ArgumentError) { dt.sec = 30 }
+ end
+
+ def test_to_a
+ y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5
+ dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
+ a = dt.to_a
+
+ assert_instance_of(Array, a)
+ assert_equal(6, a.size, "Returned array has wrong size")
+
+ assert_equal(y, a[0])
+ assert_equal(m, a[1])
+ assert_equal(d, a[2])
+ assert_equal(h, a[3])
+ assert_equal(mi, a[4])
+ assert_equal(s, a[5])
+ end
+
+ def test_to_time1
+ y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5
+ dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
+ time = dt.to_time
+
+ assert_not_nil(time)
+
+ assert_equal(y, time.year)
+ assert_equal(m, time.month)
+ assert_equal(d, time.day)
+ assert_equal(h, time.hour)
+ assert_equal(mi, time.min)
+ assert_equal(s, time.sec)
+ end
+
+ def test_to_time2
+ dt = createDateTime()
+ dt.year = 1969
+
+ assert_nil(dt.to_time)
+ end
+
+ def test_to_date1
+ y, m, d, h, mi, s = 1970, 3, 24, 12, 0, 5
+ dt = XMLRPC::DateTime.new(y, m, d, h, mi, s)
+ date = dt.to_date
+
+ assert_equal(y, date.year)
+ assert_equal(m, date.month)
+ assert_equal(d, date.day)
+ end
+
+ def test_to_date2
+ dt = createDateTime()
+ dt.year = 666
+
+ assert_equal(666, dt.to_date.year)
+ end
+
+
+ def createDateTime
+ XMLRPC::DateTime.new(1970, 3, 24, 12, 0, 5)
+ end
+
+end