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 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"
21 int main(int argc
, char **argv
)
23 struct DiskObject
*icon
;
24 struct Screen
*screen
;
26 struct Rectangle emboss
= {};
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);
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);
48 TEST_START("LayoutIcon(icon, screen, TAG_END)");
49 UWORD dummypens
[] = { ~0 };
52 screen
= OpenScreenTags(NULL
,
54 SA_Type
, CUSTOMSCREEN
,
60 SA_Colors
, test_colorspec
,
61 SA_Width
, test_width
* 2,
62 SA_Height
, test_height
* 2,
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,
75 VERIFY_RET(LayoutIcon(icon
, screen
, OBP_Precision
, PRECISION_EXACT
, TAG_END
), TRUE
, 0);
78 TEST_START("DrawIconState(&screen->RastPort, icon, NULL, 0, 0, 0, NULL)");
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
, },
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'
101 for (y
= 0; y
< test_height
; y
++)
102 for (x
= 0; x
< test_width
; x
++, pixel
++, pp
++)
103 *pixel
= (*pp
== 4) ? 7 : *pp
;
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
);
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
];
117 Printf("(%ld,%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);
130 TEST_START("Cleanup");
132 for (i
= 0; i
< test_palsize
; i
++) {
133 ReleasePen(screen
->ViewPort
.ColorMap
, i
);
136 FreeDiskObject(icon
);