PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/test/lib/foreign_interface/test_fi01.e

http://github.com/tybor/Liberty
Specman e | 37 lines | 27 code | 9 blank | 1 comment | 0 complexity | cd257c6396d0f9d0ca73b6bedb9566fb MD5 | raw file
 1class TEST_FI01
 2
 3insert
 4   EIFFELTEST_TOOLS
 5
 6create {}
 7   make
 8
 9feature {}
10   value: INTEGER_32 17
11   callback_value: INTEGER
12
13   make
14      local
15         a: FOREIGN_AGENT
16         p: FOREIGN_PARAMETERS
17         v: FOREIGN_TYPED_OBJECT[INTEGER_32]
18      do
19         -- Eiffel idiosyncracy: when calling an Eiffel feature, add Current's pointer as the first parameter
20         create {FOREIGN_EXTERNAL_FUNCTION} a.make($callback, {FAST_ARRAY[FOREIGN_TYPE] << types.pointer, types.sint32 >>}, types.sint32)
21         p.set({FAST_ARRAY[FOREIGN_OBJECT] << types.create_pointer(to_pointer), types.create_sint32(value) >>})
22
23         v ::= a.item(p)
24
25         assert(callback_value = value)
26         assert(v.item = value)
27      end
28
29   types: FOREIGN_TYPES
30
31   callback (v: like value): INTEGER
32      do
33         callback_value := v
34         Result := v
35      end
36
37end