# This file is part of Metasm, the Ruby assembly manipulation suite # Copyright (C) 2006-2009 Yoann GUILLOT # # Licence is LGPL, see LICENCE in the top-level directory require 'test/unit' require 'metasm' class TestDynldr < Test::Unit::TestCase def cp @cp ||= Metasm::Ia32.new.new_cparser end def test_parse_c assert_nothing_raised { cp.parse("static int i_1=42; __stdcall __int64 foo_1(const char*);") } assert_kind_of(Metasm::C::Function, cp.toplevel.symbol['foo_1'].type) assert_raise(Metasm::ParseError) { cp.parse("static extern int fu;") } cp.readtok until cp.eos? assert_nothing_raised { cp.parse("const volatile volatile const char const * const * blarg_0;") } assert_nothing_raised { cp.parse("void *ptr = &ptr;") } assert_raise(Metasm::ParseError) { cp.parse("void *ptr = ptr;") } cp.readtok until cp.eos? assert_nothing_raised { cp.parse("struct { int sz; } bla = { .sz = sizeof(bla) };") } assert_raise(Metasm::ParseError) { cp.parse("signed unsigned int fu;") } cp.readtok until cp.eos? assert_raise(Metasm::ParseError) { cp.parse("long long long fu;") } cp.readtok until cp.eos? assert_raise(Metasm::ParseError) { cp.parse < :size) assert_equal(12, s.length) assert_equal(12, s.i) assert_raise(RuntimeError) { s.l = 42 } assert_nothing_raised { s.j = 0x12345678 } assert_nothing_raised { s.inner.k = 0x3333_3333 } assert_equal(4, s.inner.stroff) assert_equal("0C0000007856341233333333", s.str.unpack('H*')[0].upcase) end end