-
Notifications
You must be signed in to change notification settings - Fork 298
/
PointerTest.io
133 lines (100 loc) · 4.03 KB
/
PointerTest.io
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* CFFI - An Io interface to C
Copyright (c) 2006 Trevor Fancher. All rights reserved.
All code licensed under the New BSD license.
*/
CFFI
PointerTest := UnitTest clone do(
testValueWithSignedInteger := method(
appendProto(Types)
n := -986
assertEquals(n, Short ptr clone setValue(Short clone setValue(n)) value)
assertEquals(n, SShort ptr clone setValue(SShort clone setValue(n)) value)
assertEquals(n, Long ptr clone setValue(Long clone setValue(n)) value)
assertEquals(n, SLong ptr clone setValue(SLong clone setValue(n)) value)
// I really have no idea why these don't pass with UnitTest, both work
// fine for me when testing from the CLI
// - The problem was the "Collecter collect"s in UnitTest.io. Still
// deciding if I should submit a patch "fixing" UnitTest
assertEquals(n, Int ptr clone setValue(Int clone setValue(n)) value)
assertEquals(n, SInt ptr clone setValue(SInt clone setValue(n)) value)
)
testValueWithUnsignedInteger := method(
appendProto(Types)
n := 856
assertEquals(n, UShort ptr clone setValue(UShort clone setValue(n)) value)
assertEquals(n, UInt ptr clone setValue(UInt clone setValue(n)) value)
assertEquals(n, ULong ptr clone setValue(ULong clone setValue(n)) value)
)
testValueWithDouble := method(
appendProto(Types)
double := -85.66747
// see comment in testValueWithSignedInteger
assertEquals(double, Double ptr clone setValue(Double clone setValue(double)) value)
)
testPointerToPointers := method(
appendProto(Types)
i := Int clone setValue(-87)
pi := Int ptr clone setValue(i)
ppi := Int ptr ptr clone setValue(pi)
pppi := Int ptr ptr ptr clone setValue(ppi)
assertEquals("^i" , pi typeString)
assertEquals("^^i" , ppi typeString)
assertEquals("^^^i", pppi typeString)
assertEquals(i value, pi value)
assertEquals(i value, ppi value value)
assertEquals(i value, pppi value value value)
)
testAddress := method(
appendProto(Types)
pd := Double ptr clone
ppd := Double ptr ptr clone
pppd := Double ptr ptr ptr clone
assertEquals("0x0", pd address)
assertEquals("0x0", ppd address)
assertEquals("0x0", pppd address)
pd setValue(-76.894)
ppd setValue(pd)
pppd setValue(ppd)
assertEquals(pd address, ppd value address)
assertEquals(pd address, pppd value value address)
assertEquals(ppd address, pppd value address)
)
testPointedToType := method(
appendProto(Types)
1pS := UShort ptr clone
2pS := UShort ptr ptr clone
3pS := UShort ptr ptr ptr clone
4pS := UShort ptr ptr ptr ptr clone
5pS := UShort ptr ptr ptr ptr ptr clone
assertEquals(5pS proto, Types UShort ptr ptr ptr ptr ptr)
assertEquals(5pS pointedToType, 4pS proto)
assertEquals(5pS pointedToType pointedToType, 3pS proto)
assertEquals(5pS pointedToType pointedToType pointedToType, 2pS proto)
assertEquals(5pS pointedToType pointedToType pointedToType pointedToType, 1pS proto)
assertEquals(4pS proto, Types UShort ptr ptr ptr ptr)
assertEquals(4pS pointedToType, 3pS proto)
assertEquals(4pS pointedToType pointedToType, 2pS proto)
assertEquals(4pS pointedToType pointedToType pointedToType, 1pS proto)
assertEquals(3pS proto, Types UShort ptr ptr ptr)
assertEquals(3pS pointedToType, 2pS proto)
assertEquals(3pS pointedToType pointedToType, 1pS proto)
assertEquals(2pS proto, Types UShort ptr ptr)
assertEquals(2pS pointedToType, 1pS proto)
assertEquals(1pS proto, Types UShort ptr)
)
testCStringPointer := method(
appendProto(Types)
str1 := "abc"
str2 := "def"
cs := CString clone setValue(str1)
csp1 := CString ptr clone setValue(cs)
csp2 := CString ptr clone setValue(cs value)
assertEquals(cs value, str1)
assertEquals(cs value, csp1 value)
assertEquals(cs value, csp2 value)
cs setValue(str2)
assertEquals(cs value, str2)
assertEquals(cs value, csp1 value)
assertEquals(str1, csp2 value)
)
)