Call CloseDevice() before DeleteIORequest(), and don't call
[AROS.git] / test / icon / render.c
blob0a0d28556d9ffc2ba61c800b04e56e56296f7b44
1 /*
2 * Copyright (C) 2011, 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 no 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 <string.h> /* For memcmp() */
17 #include "testframe.h"
19 #include "icon.inc"
21 int main(int argc, char **argv)
23 struct DiskObject *icon;
24 struct Screen *screen;
25 LONG frameless;
26 struct Rectangle emboss = {};
28 TESTING_BEGINS();
30 TEST_START("Make Test Icon")
31 LONG ispal = 0xdeadcafe;
32 icon = GetDiskObject(NULL);
33 VERIFY_NEQ(icon, NULL);
34 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalFrameless, &frameless, TAG_END), 1, -1);
35 VERIFY_RET(IconControl(NULL, ICONCTRLA_GetGlobalEmbossRect, &emboss, TAG_END), 1, -1);
36 if (frameless)
37 emboss.MinX = emboss.MinY = emboss.MaxX = emboss.MaxY = 0;
38 VERIFY_RET(IconControl(icon, ICONCTRLA_SetWidth, test_width, TAG_END), 1, -1);
39 VERIFY_RET(IconControl(icon, ICONCTRLA_SetHeight, test_height, TAG_END), 1, -1);
40 VERIFY_RET(IconControl(icon, ICONCTRLA_SetPaletteSize1, test_palsize, TAG_END), 1, -1);
41 VERIFY_RET(IconControl(icon, ICONCTRLA_SetTransparentColor1, 0, TAG_END), 1, -1);
42 VERIFY_RET(IconControl(icon, ICONCTRLA_SetPalette1, &test_pal[0], TAG_END), 1, -1);
43 VERIFY_RET(IconControl(icon, ICONCTRLA_SetImageData1, &test_img[0], TAG_END), 1, -1);
44 VERIFY_RET(IconControl(icon, ICONCTRLA_IsPaletteMapped, &ispal, TAG_END), 1, -1);
45 VERIFY_NEQ(ispal, 0);
46 TEST_END();
48 TEST_START("LayoutIcon(icon, screen, TAG_END)");
49 UWORD dummypens[] = { ~0 };
50 int i;
52 screen = OpenScreenTags(NULL,
53 SA_Depth, test_depth,
54 SA_Type, CUSTOMSCREEN,
55 SA_ShowTitle, FALSE,
56 SA_Title, "Icon",
57 SA_Quiet, TRUE,
58 SA_Left, 0,
59 SA_Top, 0,
60 SA_Colors, test_colorspec,
61 SA_Width, test_width * 2,
62 SA_Height, test_height * 2,
63 SA_Pens, dummypens,
64 TAG_END);
65 VERIFY_NEQ(screen, NULL);
66 /* Allocate *precisely* the pens we want */
67 for (i = 0; i < test_palsize; i++) {
68 ObtainPen(screen->ViewPort.ColorMap, i,
69 test_pal[i].red ? 0xffffffff : 0,
70 test_pal[i].green ? 0xffffffff : 0,
71 test_pal[i].blue ? 0xffffffff : 0,
72 0);
75 VERIFY_RET(LayoutIcon(icon, screen, OBP_Precision, PRECISION_EXACT, TAG_END), TRUE, 0);
76 TEST_END();
78 TEST_START("DrawIconState(&screen->RastPort, icon, NULL, 0, 0, 0, NULL)");
79 UWORD x, y;
80 int i;
81 UBYTE *pixel, s_img[test_width * test_height], t_img[test_width * test_height];
82 const UBYTE *pp, *i2p;
83 struct TagItem tags[] = {
84 { ICONDRAWA_Frameless, TRUE, },
85 { ICONDRAWA_Borderless, TRUE, },
86 { ICONDRAWA_EraseBackground, FALSE, },
87 { TAG_DONE }
90 /* Draw a solid block of '7' behind the icon */
91 SetAPen(&screen->RastPort, 7);
92 RectFill(&screen->RastPort, 0, 0, test_width*2 - 1, test_height*2 - 1);
94 DrawIconStateA(&screen->RastPort, icon, NULL, 0, 0, 0, tags);
96 /* Verify that the icon was written correctly.
97 * All the '4' colors should be '7'
99 pixel = t_img;
100 pp = test_img;
101 for (y = 0; y < test_height; y++)
102 for (x = 0; x < test_width; x++, pixel++, pp++)
103 *pixel = (*pp == 4) ? 7 : *pp;
105 pixel = s_img;
106 for (y = 0; y < test_height; y++)
107 for (x = 0; x < test_width; x++, pixel++)
108 *pixel = (UBYTE)ReadPixel(&screen->RastPort, x, y);
110 pixel = t_img;
111 pp = s_img;
112 i2p = s_img; /* Icon to Pen color mapping */
113 for (y = 0; y < test_height; y++) {
114 for (x = 0; x < test_width; x++, pixel++, pp++) {
115 *pixel = i2p[*pixel];
116 if (*pp != *pixel) {
117 Printf("%ldx%ld: != %ld, got %ld\n", x, y, *pixel, *pp);
118 VERIFY_EQ(*pp, *pixel);
123 for (i = 0; i < test_palsize; i++) {
124 Printf("Icon %ld = Pen %ld\n", i, i2p[i]);
127 VERIFY_EQ(memcmp(s_img, t_img, sizeof(t_img)), 0);
128 TEST_END();
130 TEST_START("Cleanup");
131 int i;
132 for (i = 0; i < test_palsize; i++) {
133 ReleasePen(screen->ViewPort.ColorMap, i);
136 FreeDiskObject(icon);
137 CloseScreen(screen);
138 TEST_END();
140 TESTING_ENDS();
142 return 0;