1 /* CFFI - An Io interface to C
2 Copyright (c) 2006 Trevor Fancher. All rights reserved.
3 All code licensed under the New BSD license.
8 PointerTest
:= UnitTest
clone do(
9 testValueWithSignedInteger
:= method(
13 assertEquals(n
, Short ptr
clone setValue(Short
clone setValue(n
)) value
)
14 assertEquals(n
, SShort ptr
clone setValue(SShort
clone setValue(n
)) value
)
16 assertEquals(n
, Long ptr
clone setValue(Long
clone setValue(n
)) value
)
17 assertEquals(n
, SLong ptr
clone setValue(SLong
clone setValue(n
)) value
)
19 // I really have no idea why these don
't pass with UnitTest, both work
20 // fine for me when testing from the CLI
21 // - The problem was the "Collecter collect"s in UnitTest.io. Still
22 // deciding if I should submit a patch "fixing" UnitTest
23 assertEquals(n, Int ptr clone setValue(Int clone setValue(n)) value)
24 assertEquals(n, SInt ptr clone setValue(SInt clone setValue(n)) value)
27 testValueWithUnsignedInteger := method(
31 assertEquals(n, UShort ptr clone setValue(UShort clone setValue(n)) value)
32 assertEquals(n, UInt ptr clone setValue(UInt clone setValue(n)) value)
33 assertEquals(n, ULong ptr clone setValue(ULong clone setValue(n)) value)
36 testValueWithDouble := method(
41 // see comment in testValueWithSignedInteger
42 assertEquals(double, Double ptr clone setValue(Double clone setValue(double)) value)
45 testPointerToPointers := method(
48 i := Int clone setValue(-87)
49 pi := Int ptr clone setValue(i)
50 ppi := Int ptr ptr clone setValue(pi)
51 pppi := Int ptr ptr ptr clone setValue(ppi)
53 assertEquals("^i" , pi typeString)
54 assertEquals("^^i" , ppi typeString)
55 assertEquals("^^^i", pppi typeString)
57 assertEquals(i value, pi value)
58 assertEquals(i value, ppi value value)
59 assertEquals(i value, pppi value value value)
62 testAddress := method(
65 pd := Double ptr clone
66 ppd := Double ptr ptr clone
67 pppd := Double ptr ptr ptr clone
69 assertEquals("0x0", pd address)
70 assertEquals("0x0", ppd address)
71 assertEquals("0x0", pppd address)
77 assertEquals(pd address, ppd value address)
78 assertEquals(pd address, pppd value value address)
79 assertEquals(ppd address, pppd value address)
83 testPointedToType := method(
86 1pS := UShort ptr clone
87 2pS := UShort ptr ptr clone
88 3pS := UShort ptr ptr ptr clone
89 4pS := UShort ptr ptr ptr ptr clone
90 5pS := UShort ptr ptr ptr ptr ptr clone
92 assertEquals(5pS proto, Types UShort ptr ptr ptr ptr ptr)
93 assertEquals(5pS pointedToType, 4pS proto)
94 assertEquals(5pS pointedToType pointedToType, 3pS proto)
95 assertEquals(5pS pointedToType pointedToType pointedToType, 2pS proto)
96 assertEquals(5pS pointedToType pointedToType pointedToType pointedToType, 1pS proto)
98 assertEquals(4pS proto, Types UShort ptr ptr ptr ptr)
99 assertEquals(4pS pointedToType, 3pS proto)
100 assertEquals(4pS pointedToType pointedToType, 2pS proto)
101 assertEquals(4pS pointedToType pointedToType pointedToType, 1pS proto)
103 assertEquals(3pS proto, Types UShort ptr ptr ptr)
104 assertEquals(3pS pointedToType, 2pS proto)
105 assertEquals(3pS pointedToType pointedToType, 1pS proto)
107 assertEquals(2pS proto, Types UShort ptr ptr)
108 assertEquals(2pS pointedToType, 1pS proto)
110 assertEquals(1pS proto, Types UShort ptr)
113 testCStringPointer := method(
119 cs := CString clone setValue(str1)
120 csp1 := CString ptr clone setValue(cs)
121 csp2 := CString ptr clone setValue(cs value)
123 assertEquals(cs value, str1)
124 assertEquals(cs value, csp1 value)
125 assertEquals(cs value, csp2 value)
129 assertEquals(cs value, str2)
130 assertEquals(cs value, csp1 value)
131 assertEquals(str1, csp2 value)