File: tc_time.rb

package info (click to toggle)
libdbi-ruby 0.4.3-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 472 kB
  • ctags: 619
  • sloc: ruby: 4,583; makefile: 62; perl: 12
file content (77 lines) | stat: -rw-r--r-- 2,066 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
##############################################################################
# tc_time.rb
#
# Test case for the DBI::Time class (currently) located in the utils.rb file.
##############################################################################
$LOAD_PATH.unshift(Dir.pwd)
$LOAD_PATH.unshift(File.dirname(Dir.pwd))
$LOAD_PATH.unshift("../../lib")
$LOAD_PATH.unshift("../../lib/dbi")
$LOAD_PATH.unshift("lib")

require 'dbi'
require 'test/unit'

Deprecate.set_action(proc { })

class TC_DBI_Time < Test::Unit::TestCase
   def setup
      @time     = Time.new
      @dbi_time = DBI::Time.new
   end

   def test_constructor
      assert_nothing_raised{ DBI::Time.new(9) }
      assert_nothing_raised{ DBI::Time.new(9, 41) }
      assert_nothing_raised{ DBI::Time.new(9, 41, 20) }
      assert_nothing_raised{ DBI::Time.new(Date.new) }
      assert_nothing_raised{ DBI::Time.new(Time.now) }
   end

   def test_hour
      assert_respond_to(@dbi_time, :hour)
      assert_respond_to(@dbi_time, :hour=)
      assert_equal(0, @dbi_time.hour)
   end

   def test_minute
      assert_respond_to(@dbi_time, :minute)
      assert_respond_to(@dbi_time, :minute=)
      assert_equal(0, @dbi_time.minute)
   end

   # Alias for minute
   def test_min
      assert_respond_to(@dbi_time, :min)
      assert_respond_to(@dbi_time, :min=)
      assert_equal(0, @dbi_time.min)
   end

   def test_second
      assert_respond_to(@dbi_time, :second)
      assert_respond_to(@dbi_time, :second=)
      assert_equal(0, @dbi_time.second)
   end

   def test_sec
      assert_respond_to(@dbi_time, :sec)
      assert_respond_to(@dbi_time, :sec=)
      assert_equal(0, @dbi_time.sec)
   end

   def test_to_time
      assert_respond_to(@dbi_time, :to_time)
      assert_equal(@time, DBI::Time.new(@time).to_time)
      #assert_equal(@time.object_id, DBI::Time.new(@time).object_id) # Fails ??
   end

   def test_to_s
      assert_respond_to(@dbi_time, :to_s)
      assert_equal("00:00:00", @dbi_time.to_s)
   end

   def teardown
      @time     = nil
      @dbi_time = nil
   end
end