xref: /haiku/src/bin/rc/tests/type.rdef (revision e221c09e508ffc3c62738140c9b6fc4fa211662a)
1
2type #'smpl' simple { int8 x };
3resource(801) simple { 4 };
4resource(802) simple { 257 };
5resource(803) simple { (int64)-1 };
6
7// Type codes do not have to be unique, so even though #'BYTE' is used
8// for the int8 built-in type, we can also use it for our own types.
9type #'BYTE' mybyte { int8 x };
10resource(805) mybyte { 4 };
11resource(806) mybyte { 257 };
12resource(807) mybyte { (int64)-1 };
13//resource(808) (mybyte) 123;  // invalid cast
14//resource(809) (mybyte) "yeah";  // invalid cast
15
16type #'RAWT' myraw { array x };
17resource(810) myraw { array { $"1234" } };
18resource(811) myraw { x = array { $"1234" } };
19resource(812) myraw { $"1234" };
20resource(813) (raw) myraw { $"1234" };
21resource(814) (myraw) myraw { $"1234" };
22resource(815) myraw;
23//resource(816) (myraw) array { $"1234" };  // invalid cast
24
25// all resources become "0100000002000000000300"
26type #'what' type1 { int32 a, int32 b, bool d, int16 e };  // size 11
27resource(810) type1 { 1, 2, false, 3 };
28resource(811) type1 { d = false, 1, 2, 3 };
29resource(812) type1 { d = false, e = 3, b = 2, 1 };
30resource(813) type1 { d = false, e = 3, 6, 7, a = 1, b = 2 };
31resource(814) type1 { 6, 7, false, 9, d = false, e = 3, a = 1, b = 2 };
32
33type #'RECT' myrect { float left, float top, float bottom, float right };
34
35// becomes { 1.00000, 2.00000, 3.00000, 4.00000 }
36resource(820) myrect { 1, 2, 3, 4 };
37
38// becomes { 1.00000, 2.00000, 3.00000, 4.00000 }
39resource(821) myrect { left = 1, 2, 3, 4 };
40
41// becomes { 3.00000, 2.00000, 4.00000, 5.00000 }
42resource(822) myrect { 1, 2, left = 3, 4, 5 };
43
44// becomes { 3.00000, 2.00000, 4.00000, 0 }
45resource(823) myrect { 1, 2, left = 3, 4 };
46
47// becomes { 2.00000, 1.00000, 3.00000, 4.00000 }
48resource(824) myrect { top = 1, 2, 3, 4 };
49
50// becomes { 1.00000, 0.00000, 0.00000, 0.00000 }
51resource(825) myrect { 1 };
52
53// becomes $"0000803F000000400000404000008040"
54resource(826) (raw) myrect { 1, 2, 3, 4 };
55
56// becomes { 1.00000, 2.00000, 3.00000, 4.00000 }
57resource(827) #'RECT' (raw) myrect { 1, 2, 3, 4 };
58resource(828) #'RECT' $"0000803F000000400000404000008040";
59
60//resource(829) myrect { left = 1, 2, 3, 4, 5 };  // too many fields
61//resource(829) myrect { dude = 1, 2, 3, 4, 5 };  // unknown field
62//resource(829) myrect { (float) top = 1, 2, 3, 4 };  // unknown type top
63
64enum { NoConflict = 100 };
65type #'RAWT' NoConflict { int32 a };
66
67// Types are not identified by their type_code, but by their name, so the
68// size of typ3 should be 5, even though typ1 and 2 have the same code.
69type #'same' typ1 { int8 x };
70type #'same' typ2 { int32 x };
71type #'diff' typ3 { typ1 a, typ2 b };
72resource(830) typ3 { typ1 { 1 }, typ2 { 2 } };
73resource(831) typ3 { b = typ2 { 1 }, a = typ1 { 2 } };
74resource(832) typ3 { b = typ2 1, a = typ1 2 };
75resource(833) typ3 { typ1 1, typ2 2 };
76//resource(834) typ3 { typ2 { 1 }, typ1 { 2 } };          // invalid cast
77//resource(834) typ3 { a = typ2 { 1 }, b = typ1 { 2 } };  // invalid cast
78//resource(834) typ3 { a = { 1 }, b = { 2 } };            // invalid cast
79
80// Size of this type's data should still be 8, even though the default
81// value for one of the fields is an int8.
82type #'RAWT' rect2 { float a, float b = (int8) 12 };
83resource(835) rect2 { 1 };
84
85type #'cmpd' compound { int16 a = 100, int16 b = 0x80 };
86type #'nest' nested { compound c = compound { 16, 32 }, int8 i = 4 };
87type #'nst2' nested2 { compound c, int8 i };
88resource(840) compound { };
89resource(841) compound;
90resource(842) nested { compound { }, 1 };
91resource(843) nested2 { compound, 1 };
92resource(844) nested;
93resource(845) nested2;
94
95type #'CSTR' strings { string a, string b = "yo" };
96resource(850) strings;
97resource(851) strings { a = "long", b = "longer" };
98resource(852) strings { b = "long" };
99//resource(859) (string) strings { "long", "longer" };  // invalid cast
100
101type #'RAWT' msgs { archive BBitmap a };
102resource(860) msgs;
103resource(861) msgs { a = archive BBitmap { "field" = "value" } };
104
105type #'MSGG' msgs2 { message m = message('yeah') { "fld" = "val" } };
106resource(862) msgs2;
107
108// When you decompile these, it only sees the first message.
109type #'RAWT' msgs3 { message m, archive BBitmap a };
110type #'zzzz' msgs4
111{
112	message m = message { "f" = "v" },
113	message n = message { "v" = "f" }
114};
115resource(863) msgs3;
116resource(864) msgs4;
117
118type #'zzzz' msgs5 { int8 x, message m, message n };
119resource(865) msgs5;
120resource(866) msgs5 { 4, message('yoyo') { "f" = "v" } };
121
122type #'what' onefield { int32 flags };
123resource(870) onefield 100;
124
125type ye_olde_raw { int32 a };
126resource(871) ye_olde_raw 64;
127
128//type #'what' sometype { UnKnOwN x };      // unknown type
129//type #'what' B_INT8_TYPE { int8 x };      // duplicate type (built-in)
130//type #'RECT' myrect { float x };          // duplicate type
131//type #'RAWT' whoops { float x = "wrong" } // invalid cast
132//type #'jump' jump { int8 x, jump j };     // unknown type jump
133
134//resource(890) tooSoon 123;         // unknown type (must
135//type #'soon' tooSoon { int32 x };  // be defined first)
136
137//resource(890) UnKnOwN { 123 };                // unknown type
138//resource(890) (UnKnOwN) { 123 };              // unknown type
139//resource(890) message('blah') { UnKnOwN x };  // unknown type
140//resource(890) myraw { 123 };                  // invalid cast
141//resource(890) (myrect) { 123 };               // invalid cast
142
143//------------------------------------------------------------------------------
144
145enum {
146	R_Point = 100,
147	R_Rect = 100,
148	R_Color = 100,
149};
150
151resource(R_Point) point { -8.30573e+26, -1.0977e+37 };
152resource(880) point;
153
154resource(R_Rect) rect { 0.0, 0.0, -1.0, -1.0 };
155resource(881) rect;
156
157resource(R_Color) rgb_color { 0xaa, 0xbb, 0x88, 0x80 };
158resource(882) rgb_color;
159
160resource app_signature "application/x-vnd.vendor.appname";
161resource app_flags;
162
163resource app_version;
164resource large_icon;
165resource mini_icon;
166
167resource file_types message
168{
169	"types" = "text/plain",
170	"types" = "text/x-source-code"
171};
172
173//------------------------------------------------------------------------------
174
175type #'CSTR' notfixed1 { string s };
176resource(901) notfixed1;                    // empty string
177resource(902) notfixed1 "hi";               // "hi"
178resource(903) notfixed1 "hellotherepeeps";  // "hellotherepeeps"
179
180type #'CSTR' notfixed2 { string s = "hello" };
181resource(904) notfixed2;                    // "hello"
182resource(905) notfixed2 "hi";               // "hi"
183resource(906) notfixed2 "hellotherepeeps";  // "hellotherepeeps"
184
185type notfixed3 { array a };
186resource(907) notfixed3;                          // 0 bytes
187resource(908) notfixed3 array {                   // 3 bytes
188	(uint8) 0x01, (uint8) 0x02, (uint8) 0x03 };
189
190type #'CSTR' fixed1 { string s[10] };
191resource(910) fixed1;                      // 10 null bytes
192resource(911) fixed1 "hello";              // 5 chars, 5 nulls
193resource(912) fixed1 "hellotherepeeps";    // 9 chars, 1 null
194
195type #'CSTR' fixed2 { string s[10] = "hello" };
196resource(913) fixed2;                      // 5 chars, 5 nulls
197resource(914) fixed2 "hi";                 // 2 chars, 8 nulls
198resource(915) fixed2 "hellotherepeeps";    // 9 chars, 1 null
199
200type #'CSTR' fixed3 { string s[2] = "hello" };
201resource(916) fixed3;                      // 1 char, 1 null
202resource(917) fixed3 "woot";               // 1 char, 1 null
203
204type #'BYTE' fixed4 { int32 i[1] = 1026 };
205resource(921) fixed4;                      // one byte with value 2
206resource(922) fixed4 1027;                 // one byte with value 3
207
208type #'BYTE' fixed5 { int32 i[1] };
209resource(923) fixed5;                      // one byte with value 0
210resource(924) fixed5 1026;                 // one byte with value 2
211
212type fixed6 { int32 i[8] };
213resource(925) fixed6;                      // eight bytes with value 0
214resource(926) fixed6 0xDEADBEEF;           // EFBEADDE00000000
215
216type fixed7 { int32 i[4] };               // int32 is already 4 bytes,
217resource(927) fixed7;                      // so the [4] is ignored
218resource(928) fixed7 1234;
219
220type fixed8 { array a[3] };
221resource(930) fixed8;                      // 000000
222resource(931) fixed8 array {               // 112200
223	(uint8) 0x11, (uint8) 0x22 };
224resource(932) fixed8 array {               // 112233
225	(uint8) 0x11, (uint8) 0x22,
226	(uint8) 0x33, (uint8) 0x44 };
227
228type fixed9 { array a[3] = array {
229	(uint8) 0x11, (uint8) 0x22, (uint8) 0x33 } };
230resource(933) fixed9;                      // 112233
231resource(934) fixed9 array {               // 778800
232	(uint8) 0x77, (uint8) 0x88 };
233resource(935) fixed9 array {               // 667788
234	(uint8) 0x66, (uint8) 0x77,
235	(uint8) 0x88, (uint8) 0x99 };
236
237type fixed10 { message msg[2] };
238resource(936) fixed10;
239
240type fixed11 { fixed10 f[1] };
241resource(937) fixed11;
242
243//type fixed0 { string s[0] };  // invalid size
244