1require_relative 'test_base' 2 3require 'dl/struct' 4 5module DL 6 class TestCUnionEntity < TestBase 7 def test_class_size 8 size = CUnionEntity.size([TYPE_DOUBLE, TYPE_CHAR]) 9 10 assert_equal SIZEOF_DOUBLE, size 11 end 12 13 def test_class_size_with_count 14 size = CUnionEntity.size([[TYPE_DOUBLE, 2], [TYPE_CHAR, 20]]) 15 16 assert_equal SIZEOF_CHAR * 20, size 17 end 18 19 def test_set_ctypes 20 union = CUnionEntity.malloc [TYPE_INT, TYPE_LONG] 21 union.assign_names %w[int long] 22 23 # this test is roundabout because the stored ctypes are not accessible 24 union['long'] = 1 25 assert_equal 1, union['long'] 26 27 union['int'] = 1 28 assert_equal 1, union['int'] 29 end 30 end 31end 32