Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 38873bf

Browse files
cuiyanxgrgustaf
authored andcommitted
[tests] Add test case for GFX APIs (#1646)
Signed-off-by: Cui Yan <yanx.cui@intel.com>
1 parent da04539 commit 38873bf

File tree

2 files changed

+593
-0
lines changed

2 files changed

+593
-0
lines changed

tests/test-gfx-negative-manual.js

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
// Copyright (c) 2017, Intel Corporation.
2+
3+
// Software Requirements:
4+
// ST7735.js module
5+
// Hardware Requirements:
6+
// A SPI LCD screen(ST7735)
7+
// Wiring:
8+
// For SPI LCD screen(ST7735):
9+
// Wire VCC on SPI LCD screen(ST7735) to Vcc(3.3v) on the Arduino 101
10+
// Wire GND on SPI LCD screen(ST7735) to GND on the Arduino 101
11+
// Wire LED+ on SPI LCD screen(ST7735) to Vcc(3.3v) on the Arduino 101
12+
// Wire LED- on SPI LCD screen(ST7735) to GND on the Arduino 101
13+
// Wire CS on SPI LCD screen(ST7735) to IO4 on the Arduino 101
14+
// Wire RST on SPI LCD screen(ST7735) to IO7 on the Arduino 101
15+
// Wire DC(AO) on SPI LCD screen(ST7735) to IO8 on the Arduino 101
16+
// Wire SDA on SPI LCD screen(ST7735) to IO11 on the Arduino 101
17+
// Wire SCL on SPI LCD screen(ST7735) to IO13 on the Arduino 101
18+
19+
console.log("Test GFX APIs with SPI LCD screen(ST7735)");
20+
21+
var LCD = require("ST7735.js");
22+
var gfxLib = require("gfx");
23+
24+
try {
25+
var GFX = gfxLib.init(LCD.width, LCD.height, LCD.initScreen, LCD.drawCB);
26+
GFX.drawPixel(0, 0, [0xF8, 0x00]);
27+
} catch (e) {
28+
console.log("\n" + e.name + " : " + e.message);
29+
console.log("init(width, height, screen, draw): ");
30+
console.log("expected result: Expected a function");
31+
}
32+
33+
GFX = gfxLib.init(LCD.width, LCD.height, LCD.initScreen, LCD.drawCB, LCD);
34+
console.log("\ninit(width, height, screen, draw, optional): ");
35+
console.log("expected result: screen init successful");
36+
37+
// Color init
38+
var BLACK = [0x00, 0x00];
39+
var BLUE = [0x00, 0x1F];
40+
var RED = [0xF8, 0x00];
41+
var GREEN = [0x07, 0xE0];
42+
var CYAN = [0x07, 0xFF];
43+
var MAGENTA = [0xF8, 0x1F];
44+
var YELLOW = [0xFF, 0xE0];
45+
var WHITE = [0xFF, 0xFF];
46+
47+
var x = 0;
48+
var y = 0;
49+
var width = 0;
50+
var height = 0;
51+
var radius = 0;
52+
53+
var backGround = function(color) {
54+
for (var i = 0; i < 16; i++) {
55+
x = 4 * i;
56+
y = 5 * i;
57+
width = 128 - 8 * i;
58+
height = 160 - 10 * i;
59+
GFX.drawRect(x, y, width, height, color, 5);
60+
}
61+
}
62+
63+
var drawCircular = function(x, y, radius, color) {
64+
for (var i = -radius; i <= radius; i++) {
65+
for (var j = -radius; j <= radius; j++) {
66+
if ((i * i + j * j) <= radius * radius) {
67+
GFX.drawPixel(x + i, y + j, color);
68+
}
69+
}
70+
}
71+
}
72+
73+
var valueArray;
74+
var screenCount = 0;
75+
var screenTimer = setInterval(function () {
76+
screenCount++;
77+
78+
if (screenCount === 1) {
79+
backGround(BLACK);
80+
81+
valueArray = [
82+
[0, 0, 160, 160],
83+
[0, 0, 128, 200],
84+
[-100, 0, 128, 160],
85+
[0, -100, 128, 160]
86+
];
87+
for (var k = 0; k < valueArray.length; k++) {
88+
try {
89+
GFX.fillRect(valueArray[k][0], valueArray[k][1],
90+
valueArray[k][2], valueArray[k][3], WHITE);
91+
} catch (e) {
92+
console.log("\n" + e.name + " : " + e.message);
93+
console.log("fillRect(x, y, width, height, color): ");
94+
console.log("expected result: throw out error");
95+
}
96+
}
97+
}
98+
99+
if (screenCount === 2) {
100+
backGround(BLACK);
101+
102+
valueArray = [
103+
[0, 0, 5, "top left corner"],
104+
[128, 0, 5, "top right corner"],
105+
[0, 160, 5, "lower left corner"],
106+
[128, 160, 5, "lower right corner"]
107+
];
108+
for (var k = 0; k < valueArray.length; k++) {
109+
drawCircular(valueArray[k][0], valueArray[k][1],
110+
valueArray[k][2], WHITE);
111+
112+
console.log("\ndrawPixel(x, y, color): doodle and no error");
113+
console.log("expected result: draw circular in " +
114+
valueArray[k][3] + " outside of the screen");
115+
}
116+
}
117+
118+
if (screenCount === 3) {
119+
backGround(BLACK);
120+
121+
valueArray = [
122+
[30, -100, 200, 1],
123+
[50, 100, 200, 1],
124+
[70, -100, 300, 1],
125+
[-50, -50, 300, 1],
126+
[160, -50, 300, 1]
127+
];
128+
for (var k = 0; k < valueArray.length; k++) {
129+
GFX.drawVLine(valueArray[k][0], valueArray[k][1],
130+
valueArray[k][2], WHITE, valueArray[k][3]);
131+
132+
console.log("\ndrawVLine(x, y, height, color, size): " +
133+
"doodle and no error");
134+
console.log("expected result: draw vertical line " +
135+
"outside of the screen");
136+
}
137+
}
138+
139+
if (screenCount === 4) {
140+
backGround(BLACK);
141+
142+
valueArray = [
143+
[-100, 30, 200, 1],
144+
[50, 100, 200, 1],
145+
[-100, 70, 300, 1],
146+
[-50, -50, 300, 1],
147+
[-50, 200, 300, 1]
148+
];
149+
for (var k = 0; k < valueArray.length; k++) {
150+
GFX.drawHLine(valueArray[k][0], valueArray[k][1],
151+
valueArray[k][2], WHITE, valueArray[k][3]);
152+
153+
console.log("\ndrawHLine(x, y, width, color, size): " +
154+
"doodle and no error");
155+
console.log("expected result: draw horizontal line " +
156+
"outside of the screen");
157+
}
158+
}
159+
160+
if (screenCount === 5) {
161+
backGround(BLACK);
162+
163+
valueArray = [
164+
[-50, -50, 50, 50],
165+
[60, 60, 200, 200],
166+
[-100, -70, 300, 300],
167+
[-100, 10, 10, 100],
168+
[50, 300, 300, 100]
169+
];
170+
for (var k = 0; k < valueArray.length; k++) {
171+
GFX.drawLine(valueArray[k][0], valueArray[k][1],
172+
valueArray[k][2], valueArray[k][3], WHITE);
173+
174+
console.log("\ndrawLine(x0, y0, x1, y1, color): " +
175+
"doodle and no error");
176+
console.log("expected result: draw oblique line " +
177+
"outside of the screen");
178+
}
179+
}
180+
181+
if (screenCount === 6) {
182+
backGround(BLACK);
183+
184+
valueArray = [
185+
[50, -50, 50, 100],
186+
[50, 210, 50, 100],
187+
[-50, 50, 100, 50],
188+
[178, 50, 100, 50],
189+
[40, -60, 70, 280],
190+
[-60, 40, 70, 248],
191+
[-10, -10, 148, 180]
192+
];
193+
for (var k = 0; k < valueArray.length; k++) {
194+
GFX.drawRect(valueArray[k][0], valueArray[k][1],
195+
valueArray[k][2], valueArray[k][3], WHITE);
196+
197+
console.log("\ndrawRect(x, y, width, height, color): " +
198+
"doodle and no error");
199+
console.log("expected result: draw hollow rectangle " +
200+
"outside of the screen");
201+
}
202+
}
203+
204+
if (screenCount === 7) {
205+
var charCount = 0;
206+
var charTimer = setInterval(function () {
207+
if (charCount < 15) {
208+
backGround(BLACK);
209+
GFX.drawChar(0, 0, "I", WHITE, charCount + 1);
210+
} else {
211+
console.log("\ndrawChar(x, y, char, color, size): ");
212+
console.log("expected result: gradually enlarged");
213+
214+
clearInterval(charTimer);
215+
}
216+
217+
charCount++;
218+
}, 1000);
219+
}
220+
221+
if (screenCount === 11) {
222+
var stringCount = 0;
223+
var stringTimer = setInterval(function () {
224+
if (stringCount < 15) {
225+
backGround(BLACK);
226+
GFX.drawString(0, 0, "ZJS", WHITE, stringCount + 1);
227+
} else {
228+
console.log("\ndrawString(x, y, str, color, size): ");
229+
console.log("expected result: gradually enlarged");
230+
231+
clearInterval(stringTimer);
232+
}
233+
234+
stringCount++;
235+
}, 1000);
236+
}
237+
238+
if (screenCount === 15) {
239+
console.log("\nTesting completed");
240+
241+
backGround(BLACK);
242+
clearInterval(screenTimer);
243+
}
244+
}, 5000);

0 commit comments

Comments
 (0)