Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / tests / lcd_480x272.cpp
blob769fccc5fb341f8f12c26ae15c724b404070c241
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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>
24 #include <QPainter>
25 #include <math.h>
26 #include <gtest/gtest.h>
28 #define SWAP_DEFINED
29 #include "opentx.h"
30 #include "location.h"
31 #include "targets/simu/simulcd.h"
33 #if defined(COLORLCD)
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
46 #else
47 uint16_t color = simuLcdBuf[x+LCD_W*y]; // color in RGB565
48 #endif
49 if (color) {
50 if (color != previousColor) {
51 previousColor = color;
52 RGB_SPLIT(color, r, g, b);
53 rgb = qRgb(r<<3, g<<2, b<<3);
54 p.setPen(rgb);
55 p.setBrush(QBrush(rgb));
57 p.drawPoint(x, y);
63 bool checkScreenshot_480x272(const QString & test)
65 lcdRefresh();
66 QImage buffer(LCD_W, LCD_H, QImage::Format_RGB32);
67 QPainter p(&buffer);
68 doPaint_480x272(p);
69 QString filename(QString("%1_%2x%3.png").arg(test).arg(LCD_W).arg(LCD_H));
70 QImage reference(TESTS_PATH "/" + filename);
72 if (buffer == reference) {
73 return true;
75 else {
76 QString filename(QString("%1_%2x%3.png").arg(test).arg(LCD_W).arg(LCD_H));
77 buffer.save("/tmp/" + filename);
78 return false;
83 TEST(Lcd_480x272, vline)
85 loadFonts();
86 lcd->clear(TEXT_BGCOLOR);
87 for (int x=0; x<100; x+=2) {
88 lcdDrawSolidVerticalLine(x, x/2, 12, TEXT_COLOR);
90 EXPECT_TRUE(checkScreenshot_480x272("vline"));
93 TEST(Lcd_480x272, primitives)
95 loadFonts();
96 lcd->clear(TEXT_BGCOLOR);
97 lcdDrawText(8, 8, "The quick brown fox jumps over the lazy dog", CURVE_AXIS_COLOR|NO_FONTCACHE);
98 lcdDrawText(5, 5, "The quick brown fox jumps over the lazy dog", TEXT_COLOR|NO_FONTCACHE);
100 lcdDrawFilledRect(10, 30, 30, 30, SOLID, TITLE_BGCOLOR);
101 lcdDrawFilledRect(50, 30, 30, 30, DOTTED, TEXT_COLOR);
102 lcdDrawFilledRect(90, 30, 30, 30, SOLID, ROUND|TITLE_BGCOLOR);
103 lcdDrawRect(130, 30, 30, 30, 1, SOLID, TITLE_BGCOLOR);
104 lcdDrawRect(170, 30, 30, 30, 2, SOLID, TITLE_BGCOLOR);
105 lcdDrawRect(210, 30, 30, 30, 5, SOLID, TITLE_BGCOLOR);
107 lcdDrawVerticalLine(10, 70, 100, SOLID, TITLE_BGCOLOR);
108 lcdDrawVerticalLine(15, 70, 90, SOLID, TITLE_BGCOLOR);
109 lcdDrawVerticalLine(20, 70, 80, SOLID, TITLE_BGCOLOR);
110 lcdDrawVerticalLine(25, 70, 70, SOLID, TITLE_BGCOLOR);
112 lcdDrawHorizontalLine(30, 70, 100, SOLID, TEXT_COLOR);
113 lcdDrawHorizontalLine(30, 75, 90, SOLID, TEXT_COLOR);
114 lcdDrawHorizontalLine(30, 80, 80, SOLID, TEXT_COLOR);
115 lcdDrawHorizontalLine(30, 85, 70, SOLID, TEXT_COLOR);
118 EXPECT_TRUE(checkScreenshot_480x272("primitives"));
121 TEST(Lcd_480x272, transparency)
123 loadFonts();
124 lcd->clear(TEXT_BGCOLOR);
125 lcdDrawText(8, 8, "The quick brown fox jumps over the lazy dog", TEXT_COLOR|OPACITY(4)|NO_FONTCACHE);
126 lcdDrawText(5, 5, "The quick brown fox jumps over the lazy dog", TEXT_COLOR|OPACITY(12)|NO_FONTCACHE);
128 lcdDrawFilledRect(10, 30, 30, 30, SOLID, TITLE_BGCOLOR|OPACITY(8));
129 lcdDrawFilledRect(50, 30, 30, 30, DOTTED, TEXT_COLOR|OPACITY(10));
130 lcdDrawFilledRect(90, 30, 30, 30, SOLID, ROUND|TITLE_BGCOLOR|OPACITY(12));
131 lcdDrawRect(130, 30, 30, 30, 1, SOLID, TITLE_BGCOLOR|OPACITY(8));
132 lcdDrawRect(170, 30, 30, 30, 2, SOLID, TITLE_BGCOLOR|OPACITY(8));
133 lcdDrawRect(210, 30, 30, 30, 5, SOLID, TITLE_BGCOLOR|OPACITY(8));
135 lcdDrawVerticalLine(10, 70, 100, SOLID, TITLE_BGCOLOR|OPACITY(2));
136 lcdDrawVerticalLine(15, 70, 90, SOLID, TITLE_BGCOLOR|OPACITY(6));
137 lcdDrawVerticalLine(20, 70, 80, SOLID, TITLE_BGCOLOR|OPACITY(10));
138 lcdDrawVerticalLine(25, 70, 70, SOLID, TITLE_BGCOLOR|OPACITY(OPACITY_MAX));
140 lcdDrawHorizontalLine(30, 70, 100, SOLID, TEXT_COLOR|OPACITY(2));
141 lcdDrawHorizontalLine(30, 75, 90, SOLID, TEXT_COLOR|OPACITY(6));
142 lcdDrawHorizontalLine(30, 80, 80, SOLID, TEXT_COLOR|OPACITY(10));
143 lcdDrawHorizontalLine(30, 85, 70, SOLID, TEXT_COLOR|OPACITY(OPACITY_MAX));
146 for(int n=0; n<10; n++) {
147 int x = 120 + n * 20;
148 int y = 80 + n * 10;
149 int color = COLOR(n/2 + 5);
150 int size = 100;
151 lcdDrawFilledRect(x, y, size, size, SOLID, color|OPACITY(8));
155 EXPECT_TRUE(checkScreenshot_480x272("transparency"));
158 TEST(Lcd_480x272, fonts)
160 loadFonts();
161 loadFontCache();
162 lcd->clear(TEXT_BGCOLOR);
164 lcdDrawText(8, 8, "The quick brown fox jumps over the lazy dog", TEXT_COLOR|OPACITY(4));
165 lcdDrawText(5, 5, "The quick brown fox jumps over the lazy dog", TEXT_COLOR|OPACITY(12));
167 lcdDrawText(10, 200, "The quick", TEXT_COLOR|VERTICAL|NO_FONTCACHE);
168 lcdDrawText(30, 200, "The quick brown fox", TEXT_COLOR|VERTICAL|NO_FONTCACHE);
169 // lcdDrawText(50, 200, "The quick brown fox jumps over the lazy dog", TEXT_COLOR|VERTICAL|NO_FONTCACHE);
171 lcdDrawText(8, 208, "The quick brown fox jumps over the lazy dog", TITLE_BGCOLOR|OPACITY(4));
172 lcdDrawText(5, 205, "The quick brown fox jumps over the lazy dog", TITLE_BGCOLOR|OPACITY(12));
174 EXPECT_TRUE(checkScreenshot_480x272("fonts"));
178 #endif