1 require "#{File.expand_path(File.dirname(__FILE__))}/../test_helper"
7 class TestTypeDB < Test::Unit::TestCase
10 assert_instance_of Module, LWES, "LWES is not a module"
11 assert_instance_of Class, LWES::TypeDB, "LWES::TypeDB is not a class"
15 assert_nothing_raised do
16 LWES::TypeDB.new("#{File.dirname(__FILE__)}/test1.esf")
20 def TODO_test_raises_on_parse_error
21 # tmp_err = $stderr.dup
22 # $stderr.reopen("/dev/null", "a")
24 LWES::TypeDB.new(__FILE__)
29 # $stderr.reopen(tmp_err)
35 [ :SenderPort, LWES::U_INT_16],
37 [ :enc, LWES::INT_16],
38 [ :SiteID, LWES::U_INT_16],
39 [ :ReceiptTime, LWES::INT_64],
40 [ :SenderIP, LWES::IP_ADDR ]
43 [ :t_ip_addr, LWES::IP_ADDR],
44 [ :t_bool, LWES::BOOLEAN],
45 [ :t_uint64, LWES::U_INT_64],
46 [ :t_uint32, LWES::U_INT_32],
47 [ :t_int64, LWES::INT_64],
48 [ :t_string, LWES::STRING],
49 [ :t_int32, LWES::INT_32],
50 [ :t_uint16, LWES::U_INT_16],
51 [ :t_int16, LWES::INT_16 ]
54 result = LWES::TypeDB.new("#{File.dirname(__FILE__)}/test1.esf").to_hash
55 assert_equal expect, result
58 def test_create_classes
59 tdb = LWES::TypeDB.new("#{File.dirname(__FILE__)}/test2.esf")
60 classes = tdb.create_classes!(:parent => TestTypeDB)
61 classes.each { |k| assert_kind_of Class, k }
64 def test_namespaced_esf
65 tdb = LWES::TypeDB.new("#{File.dirname(__FILE__)}/namespaced.esf")
66 classes = tdb.create_classes!(:parent => Abcde)
67 expect = %w(Abcde::A::B::C::Event
68 Abcde::A::B::C::Event::Bool
69 Abcde::A::B::C::Event::String)
70 assert_equal expect, classes.map { |i| i.to_s }
71 Abcde.__send__ :remove_const, :A
74 def test_invalid_file_type_error
75 assert_raises(TypeError) { LWES::TypeDB.new(nil) }
78 def test_empty_struct_ok
79 # even with LWES 0.22.3, the "ERROR" message is non-fatal
80 # the next version (as of lwes trunk r344) will no longer
81 # spew a non-fatal "ERROR" message.
82 tdb = LWES::TypeDB.new("#{File.dirname(__FILE__)}/meta_only.esf")
83 classes = tdb.create_classes!
84 assert_equal %w(Meta::Info::Only), classes.map { |x| x.to_s }
85 Object.__send__ :remove_const, :Meta