def test_argument625(self): path = get_lib_path() self._test("""Hoge = StructClass.new(\"Hoge\") Hoge.define_fields([]) lib = load_lib(\"{path}\") f = lib.load_func(\"print_struct2\", [[\'pointer, Hoge]]) f(nil)""".format(**locals()), "(nil)")
def test_argument510(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_uchar\", [\'uchar]) f(0) """ % locals(), "0")
def test_argument560(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_char\", [\'char]) f(-128) """ % locals(), "-128")
def test_argument330(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_int32\", [\'int32]) f(2147483647) """ % locals(), "2147483647")
def test_argument480(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_double\", [\'double]) f(3.14) """ % locals(), "3.14")
def test_argument180(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_int16\", [\'int16]) f(32767) """ % locals(), "32767")
def test_argument230(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_uint32\", [\'uint32]) f(4294967295) """ % locals(), "4294967295")
def test_return110(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_uint64_1\", [], \'uint64) print(f()) """ % locals(), "1073741824")
def test_return190(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_int64_7\", [], \'int64) print(f()) """ % locals(), "4611686018427387904")
def test_argument430(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_int64\", [\'int64]) f(9223372036854775807) """ % locals(), "9223372036854775807")
def test_argument380(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_uint64\", [\'uint64]) f(18446744073709551615) """ % locals(), "18446744073709551615")
def do_simple_array_test(self, base): header = self.get_exact_path(base + ".h") src = """from test_h2yog import Foo foo = Foo.new() foo.bar[0] = 42 print(foo.bar[0])""" self.do_test([header], get_lib_path("empty"), src, "42")
def test_argument640(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_pointer\", [\'pointer]) f(42) """ % locals(), "0x2a")
def test_argument660(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_string\", [[\'string, ENCODINGS[\"ascii\"]]]) f(\"foo\") """ % locals(), "foo")
def do_struct_test(self, header, value="42"): so = get_lib_path("empty") src = """from test_h2yog import Foo foo = Foo.new() foo.bar = {value} print(foo.bar)""".format(**locals()) self.do_test([self.get_exact_path(header)], so, src, value)
def test_argument80(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_int8\", [\'int8]) f(127) """ % locals(), "127")
def test_argument130(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_uint16\", [\'uint16]) f(65535) """ % locals(), "65535")
def test_return390(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_pointer_0\", [], \'pointer) print(f()) """ % locals(), "42")
def test_argument30(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_uint8\", [\'uint8]) f(255) """ % locals(), "255")
def test_return370(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_long_3\", [], \'long) print(f()) """ % locals(), "1073741824")
def test_return380(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_long_double\", [], \'longdouble) print(f()) """ % locals(), "3.14")
def test_return250(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_short\", [], \'short) print(f()) """ % locals(), "42")
def test_return300(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_int_2\", [], \'int) print(f()) """ % locals(), "1073741823")
def test_return200(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_float\", [], \'float) print(f()) """ % locals(), "3.1400001049")
def test_return70(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"return_int32_1\", [], \'int32) print(f()) """ % locals(), "-1073741824")
def test_load_func0(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"foo\") f() """ % locals(), "42")
def test_arguments0(self): path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_two_int\", [\'int, \'int]) f(42, 26) """ % locals(), "4226")
def test_struct70(self): base = "test_struct70" header = self.get_exact_path(base + ".h") src = """from test_h2yog import Foo, {0} foo = Foo.new() foo.bar.baz = 42 {0}(foo)""".format(base) self.do_test([header], get_lib_path(base), src, "42")
def test_argument160(self): def test_stderr(stderr): assert 0 < stderr.find("ValueError: Value must be greater or equal -32768, not -32769") path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_int16\", [\'int16]) f(-32769) """ % locals(), stderr=test_stderr)
def test_argument150(self): def test_stderr(stderr): assert 0 < stderr.find("TypeError: Value must be Fixnum, not String") path = get_lib_path() self._test(""" lib = load_lib(\"%(path)s\") f = lib.load_func(\"print_uint16\", [\'uint16]) f(\"baz\") """ % locals(), stderr=test_stderr)