5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <QtCore/QDir>
22 #include <QtCore/QDebug>
23 #include <QApplication>
26 #include <gtest/gtest.h>
31 #include "targets/simu/simulcd.h"
35 void doPaint_480x272(QPainter
& p
)
37 QRgb rgb
= qRgb(0, 0, 0);
38 p
.setBackground(QBrush(rgb
));
39 p
.eraseRect(0, 0, LCD_W
, LCD_H
);
41 uint16_t previousColor
= 0xFF;
42 for (int y
=0; y
<LCD_H
; y
++) {
43 for (int x
=0; x
<LCD_W
; x
++) {
44 #if defined(PCBX10) && !defined(SIMU)
45 uint16_t color
= simuLcdBuf
[(LCD_W
-1-x
)+LCD_W
*(LCD_H
-1-y
)]; // color in RGB565
47 uint16_t color
= simuLcdBuf
[x
+LCD_W
*y
]; // color in RGB565
50 if (color
!= previousColor
) {
51 previousColor
= color
;
52 RGB_SPLIT(color
, r
, g
, b
);
53 rgb
= qRgb(r
<<3, g
<<2, b
<<3);
55 p
.setBrush(QBrush(rgb
));
63 bool checkScreenshot_480x272(const QString
& test
)
66 QImage
buffer(LCD_W
, LCD_H
, QImage::Format_RGB32
);
69 QString
filename(QString("%1_%2x%3.png").arg(test
).arg(LCD_W
).arg(LCD_H
));
70 QImage
reference(TESTS_PATH
"/tests/" + filename
);
72 if (buffer
== reference
) {
76 QString
filename(QString("%1_%2x%3.png").arg(test
).arg(LCD_W
).arg(LCD_H
));
77 buffer
.save("/tmp/" + filename
);
83 TEST(Lcd_480x272
, vline
)
85 lcd
->clear(TEXT_BGCOLOR
);
86 for (int x
=0; x
<100; x
+=2) {
87 lcdDrawSolidVerticalLine(x
, x
/2, 12, TEXT_COLOR
);
89 EXPECT_TRUE(checkScreenshot_480x272("vline"));
92 TEST(Lcd_480x272
, primitives
)
94 lcd
->clear(TEXT_BGCOLOR
);
95 lcdDrawText(8, 8, "The quick brown fox jumps over the lazy dog", CURVE_AXIS_COLOR
|NO_FONTCACHE
);
96 lcdDrawText(5, 5, "The quick brown fox jumps over the lazy dog", TEXT_COLOR
|NO_FONTCACHE
);
98 lcdDrawFilledRect(10, 30, 30, 30, SOLID
, TITLE_BGCOLOR
);
99 lcdDrawFilledRect(50, 30, 30, 30, DOTTED
, TEXT_COLOR
);
100 lcdDrawFilledRect(90, 30, 30, 30, SOLID
, ROUND
|TITLE_BGCOLOR
);
101 lcdDrawRect(130, 30, 30, 30, 1, SOLID
, TITLE_BGCOLOR
);
102 lcdDrawRect(170, 30, 30, 30, 2, SOLID
, TITLE_BGCOLOR
);
103 lcdDrawRect(210, 30, 30, 30, 5, SOLID
, TITLE_BGCOLOR
);
105 lcdDrawVerticalLine(10, 70, 100, SOLID
, TITLE_BGCOLOR
);
106 lcdDrawVerticalLine(15, 70, 90, SOLID
, TITLE_BGCOLOR
);
107 lcdDrawVerticalLine(20, 70, 80, SOLID
, TITLE_BGCOLOR
);
108 lcdDrawVerticalLine(25, 70, 70, SOLID
, TITLE_BGCOLOR
);
110 lcdDrawHorizontalLine(30, 70, 100, SOLID
, TEXT_COLOR
);
111 lcdDrawHorizontalLine(30, 75, 90, SOLID
, TEXT_COLOR
);
112 lcdDrawHorizontalLine(30, 80, 80, SOLID
, TEXT_COLOR
);
113 lcdDrawHorizontalLine(30, 85, 70, SOLID
, TEXT_COLOR
);
116 EXPECT_TRUE(checkScreenshot_480x272("primitives"));
119 TEST(Lcd_480x272
, transparency
)
121 lcd
->clear(TEXT_BGCOLOR
);
122 lcdDrawText(8, 8, "The quick brown fox jumps over the lazy dog", TEXT_COLOR
|OPACITY(4)|NO_FONTCACHE
);
123 lcdDrawText(5, 5, "The quick brown fox jumps over the lazy dog", TEXT_COLOR
|OPACITY(12)|NO_FONTCACHE
);
125 lcdDrawFilledRect(10, 30, 30, 30, SOLID
, TITLE_BGCOLOR
|OPACITY(8));
126 lcdDrawFilledRect(50, 30, 30, 30, DOTTED
, TEXT_COLOR
|OPACITY(10));
127 lcdDrawFilledRect(90, 30, 30, 30, SOLID
, ROUND
|TITLE_BGCOLOR
|OPACITY(12));
128 lcdDrawRect(130, 30, 30, 30, 1, SOLID
, TITLE_BGCOLOR
|OPACITY(8));
129 lcdDrawRect(170, 30, 30, 30, 2, SOLID
, TITLE_BGCOLOR
|OPACITY(8));
130 lcdDrawRect(210, 30, 30, 30, 5, SOLID
, TITLE_BGCOLOR
|OPACITY(8));
132 lcdDrawVerticalLine(10, 70, 100, SOLID
, TITLE_BGCOLOR
|OPACITY(2));
133 lcdDrawVerticalLine(15, 70, 90, SOLID
, TITLE_BGCOLOR
|OPACITY(6));
134 lcdDrawVerticalLine(20, 70, 80, SOLID
, TITLE_BGCOLOR
|OPACITY(10));
135 lcdDrawVerticalLine(25, 70, 70, SOLID
, TITLE_BGCOLOR
|OPACITY(OPACITY_MAX
));
137 lcdDrawHorizontalLine(30, 70, 100, SOLID
, TEXT_COLOR
|OPACITY(2));
138 lcdDrawHorizontalLine(30, 75, 90, SOLID
, TEXT_COLOR
|OPACITY(6));
139 lcdDrawHorizontalLine(30, 80, 80, SOLID
, TEXT_COLOR
|OPACITY(10));
140 lcdDrawHorizontalLine(30, 85, 70, SOLID
, TEXT_COLOR
|OPACITY(OPACITY_MAX
));
143 for(int n
=0; n
<10; n
++) {
144 int x
= 120 + n
* 20;
146 int color
= COLOR(n
/2 + 5);
148 lcdDrawFilledRect(x
, y
, size
, size
, SOLID
, color
|OPACITY(8));
152 EXPECT_TRUE(checkScreenshot_480x272("transparency"));
155 TEST(Lcd_480x272
, fonts
)
158 lcd
->clear(TEXT_BGCOLOR
);
160 lcdDrawText(8, 8, "The quick brown fox jumps over the lazy dog", TEXT_COLOR
|OPACITY(4));
161 lcdDrawText(5, 5, "The quick brown fox jumps over the lazy dog", TEXT_COLOR
|OPACITY(12));
163 lcdDrawText(10, 200, "The quick", TEXT_COLOR
|VERTICAL
|NO_FONTCACHE
);
164 lcdDrawText(30, 200, "The quick brown fox", TEXT_COLOR
|VERTICAL
|NO_FONTCACHE
);
165 // lcdDrawText(50, 200, "The quick brown fox jumps over the lazy dog", TEXT_COLOR|VERTICAL|NO_FONTCACHE);
167 lcdDrawText(8, 208, "The quick brown fox jumps over the lazy dog", TITLE_BGCOLOR
|OPACITY(4));
168 lcdDrawText(5, 205, "The quick brown fox jumps over the lazy dog", TITLE_BGCOLOR
|OPACITY(12));
170 EXPECT_TRUE(checkScreenshot_480x272("fonts"));