test_base.rb 3 KB
Newer Older
Brice Videau's avatar
Brice Videau committed
1
2
3
4
5
6
7
8
9
10
11
12
13
[ '../lib', 'lib' ].each { |d| $:.unshift(d) if File::directory?(d) }
require 'minitest/autorun'
require 'cconfigspace'

class CConfigSpaceTest < Minitest::Test
  def setup
    CCS.init
  end

  def test_version
    ver = CCS.version
    assert(ver.kind_of?(CCS::Version))
  end
Brice Videau's avatar
Brice Videau committed
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

  def test_datum_value
    d = CCS::Datum::new
    d[:type] = :CCS_NONE
    assert_nil( d.value )
    d[:type] = :CCS_INACTIVE
    assert_equal( CCS::Inactive, d.value )
    d[:type] = :CCS_FLOAT
    d[:value][:f] = 15.0
    assert_equal( 15.0, d.value )
    d[:type] = :CCS_INTEGER
    d[:value][:i] = 15
    assert_equal( 15, d.value )
    ptr = CCS::MemoryPointer::from_string("foo")
    d[:type] = :CCS_STRING
    d[:value][:s] = ptr
    assert_equal( "foo", d.value )
    rng = CCS::Rng::new
    d[:type] = :CCS_OBJECT
    d[:value][:o] = rng.handle
    o = d.value
    assert( o.kind_of? CCS::Rng )
    assert_equal( :CCS_RNG, d.value.object_type )
  end

  def test_from_value
    d = CCS::Datum::from_value(nil)
    assert_equal( :CCS_NONE, d[:type] )
    assert_equal( 0, d[:value][:i] )
    d = CCS::Datum::from_value(CCS::Inactive)
    assert_equal( :CCS_INACTIVE, d[:type] )
    assert_equal( 0, d[:value][:i] )
    d = CCS::Datum::from_value(false)
    assert_equal( :CCS_BOOLEAN, d[:type] )
    assert_equal( CCS::FALSE, d[:value][:i] )
    d = CCS::Datum::from_value(true)
    assert_equal( :CCS_BOOLEAN, d[:type] )
    assert_equal( CCS::TRUE, d[:value][:i] )
    d = CCS::Datum::from_value(15)
    assert_equal( :CCS_INTEGER, d[:type] )
    assert_equal( 15, d[:value][:i] )
    d = CCS::Datum::from_value(15.0)
    assert_equal( :CCS_FLOAT, d[:type] )
    assert_equal( 15.0, d[:value][:f] )
    rng = CCS::Rng::new
    d = CCS::Datum::from_value(rng)
    assert_equal( :CCS_OBJECT, d[:type] )
    assert_equal( rng.handle, d[:value][:o] )
  end
Brice Videau's avatar
Brice Videau committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

  def test_value_affect
    d = CCS::Datum::from_value(nil)
    assert_equal( :CCS_NONE, d[:type] )
    assert_equal( 0, d[:value][:i] )
    d.value = CCS::Inactive
    assert_equal( :CCS_INACTIVE, d[:type] )
    assert_equal( 0, d[:value][:i] )
    d.value = false
    assert_equal( :CCS_BOOLEAN, d[:type] )
    assert_equal( CCS::FALSE, d[:value][:i] )
    d.value = true
    assert_equal( :CCS_BOOLEAN, d[:type] )
    assert_equal( CCS::TRUE, d[:value][:i] )
    d.value = 15
    assert_equal( :CCS_INTEGER, d[:type] )
    assert_equal( 15, d[:value][:i] )
    d.value = 15.0
    assert_equal( :CCS_FLOAT, d[:type] )
    assert_equal( 15.0, d[:value][:f] )
    rng = CCS::Rng::new
    d.value = rng
    assert_equal( :CCS_OBJECT, d[:type] )
    assert_equal( rng.handle, d[:value][:o] )
    d.value = nil
    assert_equal( :CCS_NONE, d[:type] )
    assert_equal( 0, d[:value][:i] )
  end

  def test_numeric
    n = CCS::Numeric::from_value(1)
    assert_equal( 1, n.value(:CCS_NUM_INTEGER) )
    n.value = 2
    assert_equal( 2, n.value(:CCS_NUM_INTEGER) )
    n.value = 1.0
    assert_equal( 1.0, n.value(:CCS_NUM_FLOAT) )
    n = CCS::Numeric::from_value(2.0)
    assert_equal( 2.0, n.value(:CCS_NUM_FLOAT) )
  end
Brice Videau's avatar
Brice Videau committed
102
end