Check for SYS/GL during library init. Reason is that
[AROS.git] / test / icon / diskobj.c
blob20549f67efe68626e1c8e338e0b02d02c9ce0131
1 /*
2 * Copyright (C) 2011-2014, The AROS Development Team. All rights reserved.
3 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
5 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
7 * Tests for icon.library that do not involve rendering to the screen.
9 * All 'draw' tests will be directed to a fake 3-bit planar bitmap
11 #include <proto/icon.h>
12 #include <proto/graphics.h>
13 #include <proto/intuition.h>
15 #include "testframe.h"
17 #include "icon.inc"
19 int main(int argc, char **argv)
21 struct DiskObject *icon;
23 TESTING_BEGINS();
25 TEST_START("GetDiskObject(NULL)");
26 icon = GetDiskObject(NULL);
27 VERIFY_NEQ(icon, NULL);
28 VERIFY_EQ(icon->do_Magic, 0);
29 VERIFY_EQ(icon->do_Version, 0);
30 VERIFY_EQ(icon->do_Gadget.LeftEdge, 0);
31 VERIFY_EQ(icon->do_Gadget.TopEdge, 0);
32 VERIFY_EQ(icon->do_Gadget.Width, 0);
33 VERIFY_EQ(icon->do_Gadget.Height, 0);
34 VERIFY_EQ(icon->do_Gadget.Flags, 0);
35 VERIFY_EQ(icon->do_Gadget.Activation, 0);
36 VERIFY_EQ(icon->do_Gadget.GadgetType, 0);
37 VERIFY_EQ(icon->do_Gadget.GadgetRender, NULL);
38 VERIFY_EQ(icon->do_Gadget.SelectRender, NULL);
39 VERIFY_EQ(icon->do_Gadget.GadgetText, NULL);
40 VERIFY_EQ(icon->do_Gadget.SpecialInfo, NULL);
41 VERIFY_EQ(icon->do_Gadget.GadgetID, 0);
42 VERIFY_EQ(icon->do_Gadget.UserData, NULL);
43 VERIFY_EQ(icon->do_Type, 0);
44 VERIFY_EQ(icon->do_DefaultTool, NULL);
45 VERIFY_EQ(icon->do_ToolTypes, NULL);
46 VERIFY_EQ(icon->do_CurrentX, 0);
47 VERIFY_EQ(icon->do_CurrentY, 0);
48 VERIFY_EQ(icon->do_ToolWindow, 0);
49 VERIFY_EQ(icon->do_StackSize, 0);
50 icon->do_Magic = WB_DISKMAGIC;
51 icon->do_Type = WBPROJECT;
52 icon->do_Version = (WB_DISKVERSION << 8) | WB_DISKREVISION;
53 icon->do_ToolTypes = (STRPTR *)test_tooltypes;
54 icon->do_DefaultTool = (STRPTR)test_defaulttool;
55 icon->do_CurrentX = NO_ICON_POSITION;
56 icon->do_CurrentY = NO_ICON_POSITION;
57 TEST_END();
59 /* Global properties */
61 TEST_START("IconControl(NULL, ICONCTRLA_{Set,Get}GlobalScreen, ...)");
62 struct Screen *screen = NULL;
64 /* Verify that GlobalScreen can be freed */
65 VERIFY_RET(IconControl(NULL, ICONCTRLA_SetGlobalScreen, NULL, TAG_END), 0, -1);
66 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalScreen, &screen, TAG_END), 1, -1);
67 VERIFY_EQ(screen, NULL);
69 /* Verify that GlobalScreen can be changed if freed */
70 VERIFY_RET(IconControl(NULL, ICONCTRLA_SetGlobalScreen, 0xcafebabe, TAG_END), 1, -1);
71 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalScreen, &screen, TAG_END), 1, -1);
72 VERIFY_EQ((APTR)screen, (APTR)0xcafebabe);
74 /* Verify that GlobalScreen can't be changed once set
76 VERIFY_RET(IconControl(NULL, ICONCTRLA_SetGlobalScreen, 0xdeadbeef, TAG_END), 0, -1);
77 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalScreen, &screen, TAG_END), 1, -1);
78 VERIFY_EQ((APTR)screen, (APTR)0xcafebabe);
80 VERIFY_RET(IconControl(NULL, ICONCTRLA_SetGlobalScreen, NULL, TAG_END), 1, -1);
81 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalScreen, &screen, TAG_END), 1, -1);
82 VERIFY_EQ((APTR)screen, (APTR)NULL);
83 TEST_END();
85 TEST_START("IconControl(NULL, ICONCTRLA_{Set,Get}GlobalPrecision, ...)");
86 LONG prec = 0x8eadbeef;
87 VERIFY_RET(IconControl(NULL, ICONCTRLA_SetGlobalPrecision, PRECISION_IMAGE, TAG_END), 1, -1);
88 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalPrecision, &prec, TAG_END), 1, -1);
89 VERIFY_EQ(prec, PRECISION_IMAGE);
90 VERIFY_RET(IconControl(NULL, ICONCTRLA_SetGlobalPrecision, PRECISION_ICON, TAG_END), 1, -1);
91 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalPrecision, &prec, TAG_END), 1, -1);
92 VERIFY_EQ(prec, PRECISION_ICON);
93 TEST_END();
95 TEST_START("IconControl(NULL, ICONCTRLA_{Set,Get}GlobalFrameless, ...)");
96 LONG frameless = 0xdeadbeef;
97 VERIFY_RET(IconControl(NULL, ICONCTRLA_SetGlobalFrameless, TRUE, TAG_END), 1, 0);
98 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalFrameless, &frameless, TAG_END), 1, -1);
99 VERIFY_EQ(frameless, TRUE);
100 VERIFY_RET(IconControl(NULL, ICONCTRLA_SetGlobalFrameless, FALSE, TAG_END), 1, 0);
101 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalFrameless, &frameless, TAG_END), 1, -1);
102 VERIFY_EQ(frameless, FALSE);
103 TEST_END();
105 /* Icon configuration */
106 TEST_START("IconControl(icon, ICONCTRLA_IsPaletteMapped (FALSE)");
107 LONG ispal = 0xdeadcafe;
108 VERIFY_RET(IconControl(icon, ICONCTRLA_IsPaletteMapped, &ispal, TAG_END), 1, -1);
109 VERIFY_EQ(ispal, 0);
110 TEST_END();
112 TEST_START("IconControl(icon, ICONCTRLA_{Set,Get}Width, ...)");
113 ULONG width = 0xdeadcafe;
114 VERIFY_RET(IconControl(icon, ICONCTRLA_GetWidth, &width, TAG_END), 0, -1);
115 VERIFY_EQ(width, 0xdeadcafe);
116 VERIFY_RET(IconControl(icon, ICONCTRLA_SetWidth, test_width, TAG_END), 1, -1);
117 VERIFY_RET(IconControl(icon, ICONCTRLA_GetWidth, &width, TAG_END), 1, -1);
118 VERIFY_EQ(width, test_width);
120 /* Verify that width <= 0 and width > 256 is invalid */
121 VERIFY_RET(IconControl(icon, ICONCTRLA_SetWidth, 0, TAG_END), 0, -1);
122 VERIFY_RET(IconControl(icon, ICONCTRLA_GetWidth, &width, TAG_END), 1, -1);
123 VERIFY_EQ(width, test_width);
124 VERIFY_RET(IconControl(icon, ICONCTRLA_SetWidth, 257, TAG_END), 0, -1);
125 VERIFY_RET(IconControl(icon, ICONCTRLA_GetWidth, &width, TAG_END), 1, -1);
126 VERIFY_EQ(width, test_width);
127 TEST_END();
129 TEST_START("IconControl(icon, ICONCTRLA_{Set,Get}Height, ...)");
130 ULONG height = 0xdeadcafe;
131 VERIFY_RET(IconControl(icon, ICONCTRLA_GetHeight, &height, TAG_END), 1, -1);
132 VERIFY_EQ(height, 0);
133 VERIFY_RET(IconControl(icon, ICONCTRLA_SetHeight, test_height, TAG_END), 1, -1);
134 VERIFY_RET(IconControl(icon, ICONCTRLA_GetHeight, &height, TAG_END), 1, -1);
135 VERIFY_EQ(height, test_height);
136 /* Verify that height <= 0 and height > 256 is invalid */
137 VERIFY_RET(IconControl(icon, ICONCTRLA_SetHeight, 0, TAG_END), 0, -1);
138 VERIFY_RET(IconControl(icon, ICONCTRLA_GetHeight, &height, TAG_END), 1, -1);
139 VERIFY_EQ(height, test_height);
140 VERIFY_RET(IconControl(icon, ICONCTRLA_SetHeight, 257, TAG_END), 0, -1);
141 VERIFY_RET(IconControl(icon, ICONCTRLA_GetHeight, &height, TAG_END), 1, -1);
142 VERIFY_EQ(height, test_height);
143 TEST_END();
145 TEST_START("IconControl(icon, ICONCTRLA_{Set,Get}PaletteSize1, ...)");
146 ULONG palsize = 0xdeadbeef;
147 VERIFY_RET(IconControl(icon, ICONCTRLA_GetPaletteSize1, &palsize, TAG_END), 1, -1);
148 VERIFY_EQ(palsize, 0);
149 VERIFY_RET(IconControl(icon, ICONCTRLA_SetPaletteSize1, test_palsize, TAG_END), 1, -1);
150 VERIFY_RET(IconControl(icon, ICONCTRLA_GetPaletteSize1, &palsize, TAG_END), 1, -1);
151 VERIFY_EQ(palsize, test_palsize);
152 /* Verify that palsize <= 0 and palsize > 256 is invalid */
153 VERIFY_RET(IconControl(icon, ICONCTRLA_SetPaletteSize1, 0, TAG_END), 0, -1);
154 VERIFY_RET(IconControl(icon, ICONCTRLA_GetPaletteSize1, &palsize, TAG_END), 1, -1);
155 VERIFY_EQ(palsize, 8);
156 VERIFY_RET(IconControl(icon, ICONCTRLA_SetPaletteSize1, 257, TAG_END), 0, -1);
157 VERIFY_RET(IconControl(icon, ICONCTRLA_GetPaletteSize1, &palsize, TAG_END), 1, -1);
158 VERIFY_EQ(palsize, 8);
159 TEST_END();
161 TEST_START("IconControl(icon, ICONCTRLA_{Set,Get}TransparentColor1, ...)");
162 LONG trans = 0xdeadcafe;
163 VERIFY_RET(IconControl(icon, ICONCTRLA_GetTransparentColor1, &trans, TAG_END), 1, -1);
164 VERIFY_EQ(trans, -1);
165 VERIFY_RET(IconControl(icon, ICONCTRLA_SetTransparentColor1, 3, TAG_END), 1, -1);
166 VERIFY_RET(IconControl(icon, ICONCTRLA_GetTransparentColor1, &trans, TAG_END), 1, -1);
167 VERIFY_EQ(trans, 3);
168 VERIFY_RET(IconControl(icon, ICONCTRLA_SetTransparentColor1, test_transcolor, TAG_END), 1, -1);
169 VERIFY_RET(IconControl(icon, ICONCTRLA_GetTransparentColor1, &trans, TAG_END), 1, -1);
170 VERIFY_EQ(trans, test_transcolor);
171 TEST_END();
173 TEST_START("IconControl(icon, ICONCTRLA_{Set,Get}Palette1, ...)");
174 struct ColorRegister *pal;
175 VERIFY_RET(IconControl(icon, ICONCTRLA_GetPalette1, &pal, TAG_END), 1, -1);
176 VERIFY_EQ(pal, NULL);
177 VERIFY_RET(IconControl(icon, ICONCTRLA_SetPalette1, &test_pal[0], TAG_END), 1, -1);
178 VERIFY_RET(IconControl(icon, ICONCTRLA_GetPalette1, &pal, TAG_END), 1, -1);
179 VERIFY_EQ(pal, &test_pal[0]);
180 TEST_END();
182 TEST_START("IconControl(icon, ICONCTRLA_{Set,Get}ImageData1, ...)");
183 struct ColorRegister *img;
184 VERIFY_RET(IconControl(icon, ICONCTRLA_GetImageData1, &img, TAG_END), 1, -1);
185 VERIFY_EQ(img, NULL);
186 VERIFY_RET(IconControl(icon, ICONCTRLA_SetImageData1, &test_img[0], TAG_END), 1, -1);
187 VERIFY_RET(IconControl(icon, ICONCTRLA_GetImageData1, &img, TAG_END), 1, -1);
188 VERIFY_EQ(img, (struct ColorRegister *)&test_img[0]);
189 TEST_END();
191 TEST_START("IconControl(icon, ICONCTRLA_IsPaletteMapped (TRUE)");
192 LONG ispal = 0xdeadcafe;
193 VERIFY_RET(IconControl(icon, ICONCTRLA_IsPaletteMapped, &ispal, TAG_END), 1, -1);
194 VERIFY_NEQ(ispal, 0);
195 TEST_END();
197 /* Test getting the default object for a non-existent icon */
198 TEST_START("Get Default Object");
199 BPTR file;
200 struct DiskObject *itmp;
202 DeleteDiskObject("T:diskobj.tmp");
203 DeleteFile("T:diskobj.tmp");
204 file = Open("T:diskobj.tmp", MODE_NEWFILE);
205 Write(file, "Hello World\n", 12);
206 Close(file);
207 itmp = GetDiskObjectNew("T:diskobj.tmp");
208 VERIFY_NEQ(itmp, NULL);
209 VERIFY_EQ(itmp->do_Type, WBPROJECT);
210 FreeDiskObject(itmp);
211 TEST_END();
213 /* Negative test saving to disk (no imagery data) */
214 TEST_START("PutDiskObject(..., icon)");
215 VERIFY_RET(PutDiskObject("T:diskobj.tmp", icon), 0,
216 ERROR_OBJECT_WRONG_TYPE);
217 TEST_END();
219 /* Test saving to disk */
220 TEST_START("PutDiskObject(..., icon)");
221 struct DiskObject *itmp, *isrc;
222 isrc = GetDiskObjectNew("SYS:");
223 VERIFY_NEQ(isrc, NULL);
224 icon->do_Gadget = isrc->do_Gadget;
225 VERIFY_NEQ(icon->do_Gadget.GadgetRender, NULL);
226 itmp = DupDiskObject(icon, ICONDUPA_DuplicateImages, TRUE,
227 ICONDUPA_DuplicateImageData, TRUE,
228 TAG_END);
229 FreeDiskObject(isrc);
230 FreeDiskObject(icon);
231 icon = itmp;
232 VERIFY_RET(PutDiskObject("T:diskobj.tmp", icon), 1, 0);
233 TEST_END();
235 TEST_START("FreeDiskObject()");
236 FreeDiskObject(icon);
237 TEST_END();
239 TESTING_ENDS();
241 return 0;