1 /*******************************************************************************
2  * Copyright (c) 2000, 2015 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *     Red Hat Inc. - Bug 462631
11  * Port to the D programming language:
12  *     alice <stigma@disroot.org>
13  *******************************************************************************/
14 module tests.PaletteData;
15 
16 import java.lang.exceptions;
17 
18 import org.eclipse.swt.graphics.PaletteData;
19 import org.eclipse.swt.graphics.RGB;
20 
21 /**
22  * Automated Test Suite for class org.eclipse.swt.graphics.PaletteData
23  *
24  * @see org.eclipse.swt.graphics.PaletteData
25  */
26 
27 @("test_Constructor$Lorg_eclipse_swt_graphics_RGB")
28 unittest
29 {
30     /* SWT extension: allow null and zero length arrays
31     try {
32         new PaletteData(cast(RGB[])null);
33         assert(false, "No exception thrown for rgb is null");
34     } catch (IllegalArgumentException e) {
35     }
36     */
37 
38     PaletteData data = new PaletteData([]);
39     assert(false == data.isDirect, ":a:");
40 
41     data = new PaletteData([null, null]);
42     assert(false == data.isDirect, ":b:");
43 
44     data = new PaletteData(new RGB(0, 0, 0), new RGB(255, 255, 255));
45     assert(false == data.isDirect, ":c:");
46 }
47 
48 @("test_ConstructorIII")
49 unittest
50 {
51     PaletteData data = new PaletteData(0, 0, 0);
52     assert(data.isDirect, ":a:");
53 
54     data = new PaletteData(-1, -1, -1);
55     assert(data.isDirect, ":b:");
56 
57     data = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
58     assert(data.isDirect, ":c:");
59 }
60 
61 @("test_getPixelLorg_eclipse_swt_graphics_RGB")
62 unittest
63 {
64     // indexed palette tests
65     RGB[] rgbs = [new RGB(0, 0, 0), new RGB(255, 255, 255), new RGB(50, 100, 150)];
66     PaletteData data = new PaletteData(rgbs);
67 
68     try {
69         data.getPixel(null);
70         assert(false, "No exception thrown for indexed palette with rgb == null");
71     } catch (IllegalArgumentException e) {
72     }
73 
74     try {
75         data.getPixel(new RGB(0, 0, 1));
76         assert(false, "No exception thrown for rgb not found");
77     } catch (IllegalArgumentException e) {
78     }
79 
80     assert((rgbs.length-1) == data.getPixel(rgbs[$ - 1]), ":a:");
81 
82     // direct palette tests
83     RGB rgb = new RGB(0x32, 0x64, 0x96);
84     data = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
85 
86     try {
87         data.getPixel(null);
88         assert(false, "No exception thrown for indexed palette with rgb == null");
89     } catch (IllegalArgumentException e) {
90     }
91 
92     assert(0x326496 == data.getPixel(rgb), ":b:");
93 }
94 
95 @("test_getRGBI")
96 unittest
97 {
98     // indexed palette tests
99     RGB[] rgbs = [new RGB(0, 0, 0), new RGB(255, 255, 255), new RGB(50, 100, 150)];
100     PaletteData data = new PaletteData(rgbs);
101 
102     try {
103         data.getRGB(cast(int)rgbs.length);
104         assert(false, "No exception thrown for nonexistent pixel");
105     } catch (IllegalArgumentException e) {
106     }
107 
108     assert(rgbs[$ - 1] == data.getRGB(cast(int)(rgbs.length) - 1), ":a:");
109 
110     // direct palette tests
111     RGB rgb = new RGB(0x32, 0x64, 0x96);
112     data = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
113 
114     assert(rgb == data.getRGB(0x326496));
115 }
116 
117 @("test_getRGBs")
118 unittest
119 {
120 	// indexed palette tests
121 	RGB[] rgbs = [new RGB(0, 0, 0), new RGB(255, 255, 255)];
122 	PaletteData data = new PaletteData(rgbs);
123 
124 	assert(rgbs == data.getRGBs(), ":a:");
125 
126 	// direct palette tests
127 	data = new PaletteData(0xff0000, 0x00ff00, 0x0000ff);
128 
129     assert(data.getRGBs() == null, ":b:");
130 }