1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-23 00:05:17 +03:00

Code formatting

This commit is contained in:
Bertrand Songis 2016-03-05 15:44:42 +01:00
parent 8e2c280e4a
commit 3b8c5bbeb1
10 changed files with 2627 additions and 2751 deletions

View file

@ -1,27 +1,12 @@
/* /*
* Authors (alphabetical order) * Copyright (C) OpenTX
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
* *
* opentx is based on code named * Based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, * th9x - http://code.google.com/p/th9x
* er9x by Erez Raviv: http://code.google.com/p/er9x/, * er9x - http://code.google.com/p/er9x
* and the original (and ongoing) project by * gruvin9x - http://code.google.com/p/gruvin9x
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ *
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
@ -31,7 +16,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*
*/ */
#include "gtests.h" #include "gtests.h"

View file

@ -1,164 +1,148 @@
/* /*
* Authors (alphabetical order) * Copyright (C) OpenTX
* - Andre Bernet <bernet.andre@gmail.com> *
* - Andreas Weitl * Based on code named
* - Bertrand Songis <bsongis@gmail.com> * th9x - http://code.google.com/p/th9x
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com> * er9x - http://code.google.com/p/er9x
* - Cameron Weeks <th9xer@gmail.com> * gruvin9x - http://code.google.com/p/gruvin9x
* - Erez Raviv *
* - Gabriel Birkus * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
* - Jean-Pierre Parisy *
* - Karl Szmutny * This program is free software; you can redistribute it and/or modify
* - Michael Blandford * it under the terms of the GNU General Public License version 2 as
* - Michal Hlavinka * published by the Free Software Foundation.
* - Pat Mackenzie *
* - Philip Moss * This program is distributed in the hope that it will be useful,
* - Rob Thomson * but WITHOUT ANY WARRANTY; without even the implied warranty of
* - Romolo Manfredini <romolo.manfredini@gmail.com> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* - Thomas Husterer * GNU General Public License for more details.
* */
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, #include "gtests.h"
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by #if !defined(PCBSKY9X)
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ TEST(Eeprom, 100_random_writes)
* {
* This program is free software; you can redistribute it and/or modify eepromFile = NULL; // in memory
* it under the terms of the GNU General Public License version 2 as RlcFile f;
* published by the Free Software Foundation. uint8_t buf[1000];
* uint8_t buf2[1000];
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of storageFormat();
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. for(int i=0; i<100; i++) {
* int size = rand()%800;
*/ for(int j=0; j<size; j++) {
buf[j] = rand() < (RAND_MAX/10000*i) ? 0 : (j&0xff);
#include "gtests.h" }
f.writeRlc(5, 5, buf, size, 100);
#if !defined(PCBSKY9X) // printf("size=%4d red=%4d\n\n\n", size, f.size());
TEST(Eeprom, 100_random_writes) f.openRd(5);
{ uint16_t n = f.readRlc(buf2,size+1);
eepromFile = NULL; // in memory EXPECT_EQ(n, size);
RlcFile f; EXPECT_EQ(memcmp(buf, buf2, size), 0);
uint8_t buf[1000]; }
uint8_t buf2[1000]; }
storageFormat(); TEST(Eeprom, test2)
{
for(int i=0; i<100; i++) { eepromFile = NULL; // in memory
int size = rand()%800; RlcFile f;
for(int j=0; j<size; j++) { uint8_t buf[1000];
buf[j] = rand() < (RAND_MAX/10000*i) ? 0 : (j&0xff);
} storageFormat();
f.writeRlc(5, 5, buf, size, 100);
// printf("size=%4d red=%4d\n\n\n", size, f.size()); for(int i=0; i<1000; i++) buf[i]='6'+i%4;
f.openRd(5);
uint16_t n = f.readRlc(buf2,size+1); f.writeRlc(6, 6, buf, 300, 100);
EXPECT_EQ(n, size);
EXPECT_EQ(memcmp(buf, buf2, size), 0); f.openRd(6);
} uint16_t sz=0;
} for(int i=0; i<500; i++){
uint8_t b;
TEST(Eeprom, test2) uint16_t n=f.readRlc(&b,1);
{ if(n) EXPECT_EQ(b, ('6'+sz%4));
eepromFile = NULL; // in memory sz+=n;
RlcFile f; }
uint8_t buf[1000]; EXPECT_EQ(sz, 300);
}
storageFormat();
TEST(Eeprom, storageCheckImmediately)
for(int i=0; i<1000; i++) buf[i]='6'+i%4; {
eepromFile = NULL; // in memory
f.writeRlc(6, 6, buf, 300, 100); // RlcFile f;
uint8_t buf[1000];
f.openRd(6);
uint16_t sz=0; storageFormat();
for(int i=0; i<500; i++){
uint8_t b; for(int i=0; i<1000; i++) buf[i]='6'+i%4;
uint16_t n=f.readRlc(&b,1);
if(n) EXPECT_EQ(b, ('6'+sz%4)); theFile.writeRlc(6, 6, buf, 300, false);
sz+=n;
} storageCheck(true);
EXPECT_EQ(sz, 300);
} theFile.openRd(6);
uint16_t sz=0;
TEST(Eeprom, storageCheckImmediately) for(int i=0; i<500; i++){
{ uint8_t b;
eepromFile = NULL; // in memory uint16_t n=theFile.readRlc(&b,1);
// RlcFile f; if(n) EXPECT_EQ(b, ('6'+sz%4));
uint8_t buf[1000]; sz+=n;
}
storageFormat(); EXPECT_EQ(sz, 300);
}
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
TEST(Eeprom, copy)
theFile.writeRlc(6, 6, buf, 300, false); {
eepromFile = NULL; // in memory
storageCheck(true);
uint8_t buf[1000];
theFile.openRd(6);
uint16_t sz=0; storageFormat();
for(int i=0; i<500; i++){
uint8_t b; for(int i=0; i<1000; i++) buf[i]='6'+i%4;
uint16_t n=theFile.readRlc(&b,1);
if(n) EXPECT_EQ(b, ('6'+sz%4)); theFile.writeRlc(5, 6, buf, 300, true);
sz+=n;
} theFile.copy(6, 5);
EXPECT_EQ(sz, 300);
} theFile.openRd(6);
uint16_t sz=0;
TEST(Eeprom, copy) for(int i=0; i<500; i++){
{ uint8_t b;
eepromFile = NULL; // in memory uint16_t n=theFile.readRlc(&b,1);
if(n) EXPECT_EQ(b, ('6'+sz%4));
uint8_t buf[1000]; sz+=n;
}
storageFormat(); EXPECT_EQ(sz, 300);
}
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
TEST(Eeprom, rm)
theFile.writeRlc(5, 6, buf, 300, true); {
eepromFile = NULL; // in memory
theFile.copy(6, 5);
uint8_t buf[1000];
theFile.openRd(6);
uint16_t sz=0; storageFormat();
for(int i=0; i<500; i++){
uint8_t b; for(int i=0; i<1000; i++) buf[i]='6'+i%4;
uint16_t n=theFile.readRlc(&b,1);
if(n) EXPECT_EQ(b, ('6'+sz%4)); theFile.writeRlc(5, 6, buf, 300, true);
sz+=n;
} EXPECT_EQ(EFile::exists(5), true);
EXPECT_EQ(sz, 300);
} EFile::rm(5);
TEST(Eeprom, rm) EXPECT_EQ(EFile::exists(5), false);
{
eepromFile = NULL; // in memory theFile.openRd(5);
uint16_t sz=0;
uint8_t buf[1000]; for(int i=0; i<500; i++){
uint8_t b;
storageFormat(); uint16_t n=theFile.readRlc(&b,1);
if(n) EXPECT_EQ(b, ('6'+sz%4));
for(int i=0; i<1000; i++) buf[i]='6'+i%4; sz+=n;
}
theFile.writeRlc(5, 6, buf, 300, true); EXPECT_EQ(sz, 0);
}
EXPECT_EQ(EFile::exists(5), true); #endif
EFile::rm(5);
EXPECT_EQ(EFile::exists(5), false);
theFile.openRd(5);
uint16_t sz=0;
for(int i=0; i<500; i++){
uint8_t b;
uint16_t n=theFile.readRlc(&b,1);
if(n) EXPECT_EQ(b, ('6'+sz%4));
sz+=n;
}
EXPECT_EQ(sz, 0);
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,69 +1,53 @@
/* /*
* Authors (alphabetical order) * Copyright (C) OpenTX
* - Andre Bernet <bernet.andre@gmail.com> *
* - Andreas Weitl * Based on code named
* - Bertrand Songis <bsongis@gmail.com> * th9x - http://code.google.com/p/th9x
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com> * er9x - http://code.google.com/p/er9x
* - Cameron Weeks <th9xer@gmail.com> * gruvin9x - http://code.google.com/p/gruvin9x
* - Erez Raviv *
* - Gabriel Birkus * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
* - Jean-Pierre Parisy *
* - Karl Szmutny * This program is free software; you can redistribute it and/or modify
* - Michael Blandford * it under the terms of the GNU General Public License version 2 as
* - Michal Hlavinka * published by the Free Software Foundation.
* - Pat Mackenzie *
* - Philip Moss * This program is distributed in the hope that it will be useful,
* - Rob Thomson * but WITHOUT ANY WARRANTY; without even the implied warranty of
* - Romolo Manfredini <romolo.manfredini@gmail.com> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* - Thomas Husterer * GNU General Public License for more details.
* */
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, #include <QtGui/QApplication>
* er9x by Erez Raviv: http://code.google.com/p/er9x/, #include "gtests.h"
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ int32_t lastAct = 0;
* uint16_t anaInValues[NUM_STICKS+NUM_POTS] = { 0 };
* This program is free software; you can redistribute it and/or modify uint16_t anaIn(uint8_t chan)
* it under the terms of the GNU General Public License version 2 as {
* published by the Free Software Foundation. if (chan < NUM_STICKS+NUM_POTS)
* return anaInValues[chan];
* This program is distributed in the hope that it will be useful, else
* but WITHOUT ANY WARRANTY; without even the implied warranty of return 0;
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the }
* GNU General Public License for more details.
* static char _zchar2stringResult[200];
*/ const char * zchar2string(const char * zstring, int size)
{
#include <QtGui/QApplication> if (size > (int)sizeof(_zchar2stringResult) ) {
#include "gtests.h" return 0;
}
int32_t lastAct = 0; zchar2str(_zchar2stringResult, zstring, size);
uint16_t anaInValues[NUM_STICKS+NUM_POTS] = { 0 }; return _zchar2stringResult;
uint16_t anaIn(uint8_t chan) }
{
if (chan < NUM_STICKS+NUM_POTS) int main(int argc, char **argv)
return anaInValues[chan]; {
else QCoreApplication app(argc, argv);
return 0; simuInit();
} StartEepromThread(NULL);
menuLevel = 0;
static char _zchar2stringResult[200]; menuHandlers[0] = menuMainView;
const char * zchar2string(const char * zstring, int size) ::testing::InitGoogleTest(&argc, argv);
{ return RUN_ALL_TESTS();
if (size > (int)sizeof(_zchar2stringResult) ) { }
return 0;
}
zchar2str(_zchar2stringResult, zstring, size);
return _zchar2stringResult;
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
simuInit();
StartEepromThread(NULL);
menuLevel = 0;
menuHandlers[0] = menuMainView;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View file

@ -1,5 +1,25 @@
#ifndef __GTESTS_H /*
#define __GTESTS_H * Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _GTESTS_H_
#define _GTESTS_H_
#include <QtCore/QString> #include <QtCore/QString>
#include <math.h> #include <math.h>
@ -71,4 +91,4 @@ inline void TELEMETRY_RESET()
bool checkScreenshot(QString test); bool checkScreenshot(QString test);
#endif #endif // _GTESTS_H_

View file

@ -1,477 +1,461 @@
/* /*
* Authors (alphabetical order) * Copyright (C) OpenTX
* - Andre Bernet <bernet.andre@gmail.com> *
* - Andreas Weitl * Based on code named
* - Bertrand Songis <bsongis@gmail.com> * th9x - http://code.google.com/p/th9x
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com> * er9x - http://code.google.com/p/er9x
* - Cameron Weeks <th9xer@gmail.com> * gruvin9x - http://code.google.com/p/gruvin9x
* - Erez Raviv *
* - Gabriel Birkus * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
* - Jean-Pierre Parisy *
* - Karl Szmutny * This program is free software; you can redistribute it and/or modify
* - Michael Blandford * it under the terms of the GNU General Public License version 2 as
* - Michal Hlavinka * published by the Free Software Foundation.
* - Pat Mackenzie *
* - Philip Moss * This program is distributed in the hope that it will be useful,
* - Rob Thomson * but WITHOUT ANY WARRANTY; without even the implied warranty of
* - Romolo Manfredini <romolo.manfredini@gmail.com> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* - Thomas Husterer * GNU General Public License for more details.
* */
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, #include <QtCore/QDir>
* er9x by Erez Raviv: http://code.google.com/p/er9x/, #include <QtCore/QDebug>
* and the original (and ongoing) project by #include <QtGui/QApplication>
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ #include <QtGui/QPainter>
* #include <math.h>
* This program is free software; you can redistribute it and/or modify #include <gtest/gtest.h>
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. #define SWAP_DEFINED
* #include "opentx.h"
* This program is distributed in the hope that it will be useful, #include "location.h"
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the void doPaint(QPainter & p)
* GNU General Public License for more details. {
* QRgb rgb = qRgb(161, 161, 161);
*/
p.setBackground(QBrush(rgb));
#include <QtCore/QDir> p.eraseRect(0, 0, LCD_W, LCD_H);
#include <QtCore/QDebug>
#include <QtGui/QApplication> if (1) {
#include <QtGui/QPainter> #if !defined(PCBTARANIS)
#include <math.h> rgb = qRgb(0, 0, 0);
#include <gtest/gtest.h> p.setPen(rgb);
p.setBrush(QBrush(rgb));
#define SWAP_DEFINED #endif
#include "opentx.h"
#include "location.h" #if defined(PCBTARANIS)
unsigned int previousDepth = 0xFF;
void doPaint(QPainter & p) #endif
{
QRgb rgb = qRgb(161, 161, 161); for (int y=0; y<LCD_H; y++) {
#if defined(PCBTARANIS)
p.setBackground(QBrush(rgb)); unsigned int idx = (y/2) * LCD_W;
p.eraseRect(0, 0, LCD_W, LCD_H); #else
unsigned int idx = (y/8) * LCD_W;
if (1) { unsigned int mask = (1 << (y%8));
#if !defined(PCBTARANIS) #endif
rgb = qRgb(0, 0, 0); for (int x=0; x<LCD_W; x++, idx++) {
p.setPen(rgb); #if !defined(PCBTARANIS)
p.setBrush(QBrush(rgb)); if (simuLcdBuf[idx] & mask) {
#endif p.drawPoint(x, y);
}
#if defined(PCBTARANIS) #else
unsigned int previousDepth = 0xFF; unsigned int z = (y & 1) ? (simuLcdBuf[idx] >> 4) : (simuLcdBuf[idx] & 0x0F);
#endif if (z) {
if (z != previousDepth) {
for (int y=0; y<LCD_H; y++) { previousDepth = z;
#if defined(PCBTARANIS) rgb = qRgb(161-(z*161)/15, 161-(z*161)/15, 161-(z*161)/15);
unsigned int idx = (y/2) * LCD_W; p.setPen(rgb);
#else p.setBrush(QBrush(rgb));
unsigned int idx = (y/8) * LCD_W; }
unsigned int mask = (1 << (y%8)); p.drawPoint(x, y);
#endif }
for (int x=0; x<LCD_W; x++, idx++) { #endif
#if !defined(PCBTARANIS) }
if (simuLcdBuf[idx] & mask) { }
p.drawPoint(x, y); }
} }
#else
unsigned int z = (y & 1) ? (simuLcdBuf[idx] >> 4) : (simuLcdBuf[idx] & 0x0F); bool checkScreenshot(const QString & test)
if (z) { {
if (z != previousDepth) { lcdRefresh();
previousDepth = z; QImage buffer(LCD_W, LCD_H, QImage::Format_RGB32);
rgb = qRgb(161-(z*161)/15, 161-(z*161)/15, 161-(z*161)/15); QPainter p(&buffer);
p.setPen(rgb); doPaint(p);
p.setBrush(QBrush(rgb)); QString filename(QString("%1_%2x%3.png").arg(test).arg(LCD_W).arg(LCD_H));
} buffer.save("/tmp/" + filename);
p.drawPoint(x, y); QFile screenshot("/tmp/" + filename);
} if (!screenshot.open(QIODevice::ReadOnly))
#endif return false;
} QFile reference( TESTS_PATH "/tests/" + filename);
} if (!reference.open(QIODevice::ReadOnly))
} return false;
} if (reference.readAll() != screenshot.readAll())
return false;
bool checkScreenshot(const QString & test) screenshot.remove();
{ return true;
lcdRefresh(); }
QImage buffer(LCD_W, LCD_H, QImage::Format_RGB32);
QPainter p(&buffer); TEST(outdezNAtt, test_unsigned)
doPaint(p); {
QString filename(QString("%1_%2x%3.png").arg(test).arg(LCD_W).arg(LCD_H)); lcdClear();
buffer.save("/tmp/" + filename); lcdDrawNumber(0, 0, 65530, LEFT|UNSIGN);
QFile screenshot("/tmp/" + filename); EXPECT_TRUE(checkScreenshot("unsigned")) << "Unsigned numbers will be bad displayed";
if (!screenshot.open(QIODevice::ReadOnly)) }
return false;
QFile reference( TESTS_PATH "/tests/" + filename); #if defined(CPUARM)
if (!reference.open(QIODevice::ReadOnly)) TEST(outdezNAtt, testBigNumbers)
return false; {
if (reference.readAll() != screenshot.readAll()) lcdClear();
return false; lcdDrawNumber(0, 0, 1234567, LEFT);
screenshot.remove(); lcdDrawNumber(0, FH, -1234567, LEFT);
return true; EXPECT_TRUE(checkScreenshot("big_numbers"));
} }
#endif // #if defined(CPUARM)
TEST(outdezNAtt, test_unsigned)
{
lcdClear(); TEST(Lcd, Invers_0_0)
lcdDrawNumber(0, 0, 65530, LEFT|UNSIGN); {
EXPECT_TRUE(checkScreenshot("unsigned")) << "Unsigned numbers will be bad displayed"; lcdClear();
} lcdDrawText(0, 0, "Test", INVERS);
EXPECT_TRUE(checkScreenshot("invers_0_0"));
#if defined(CPUARM) }
TEST(outdezNAtt, testBigNumbers)
{ TEST(Lcd, Invers_0_1)
lcdClear(); {
lcdDrawNumber(0, 0, 1234567, LEFT); lcdClear();
lcdDrawNumber(0, FH, -1234567, LEFT); lcdDrawText(0, 1, "Test", INVERS);
EXPECT_TRUE(checkScreenshot("big_numbers")); EXPECT_TRUE(checkScreenshot("invers_0_1"));
} }
#endif // #if defined(CPUARM)
TEST(Lcd, Prec2_Left)
{
TEST(Lcd, Invers_0_0) lcdClear();
{ lcdDrawNumber(0, 0, 2, PREC2|LEFT);
lcdClear(); EXPECT_TRUE(checkScreenshot("prec2_left"));
lcdDrawText(0, 0, "Test", INVERS); }
EXPECT_TRUE(checkScreenshot("invers_0_0"));
} TEST(Lcd, Prec2_Right)
{
TEST(Lcd, Invers_0_1) lcdClear();
{ lcdDrawNumber(LCD_W, LCD_H-FH, 2, PREC2);
lcdClear(); EXPECT_TRUE(checkScreenshot("prec2_right"));
lcdDrawText(0, 1, "Test", INVERS); }
EXPECT_TRUE(checkScreenshot("invers_0_1"));
} #if defined(CPUARM)
TEST(Lcd, Prec1_Dblsize_Invers)
TEST(Lcd, Prec2_Left) {
{ lcdClear();
lcdClear(); lcdDrawNumber(LCD_W, 10, 51, PREC1|DBLSIZE|INVERS);
lcdDrawNumber(0, 0, 2, PREC2|LEFT); EXPECT_TRUE(checkScreenshot("prec1_dblsize_invers"));
EXPECT_TRUE(checkScreenshot("prec2_left")); }
} #endif
TEST(Lcd, Prec2_Right) TEST(Lcd, Line_Wrap)
{ {
lcdClear(); lcdClear();
lcdDrawNumber(LCD_W, LCD_H-FH, 2, PREC2); lcdDrawText(LCD_W-10, 0, "TEST");
EXPECT_TRUE(checkScreenshot("prec2_right")); EXPECT_TRUE(checkScreenshot("line_wrap"));
} }
#if defined(CPUARM) TEST(Lcd, DblsizeBottomRight)
TEST(Lcd, Prec1_Dblsize_Invers) {
{ lcdClear();
lcdClear(); lcdDrawText(LCD_W-20, LCD_H-16, "TEST", DBLSIZE);
lcdDrawNumber(LCD_W, 10, 51, PREC1|DBLSIZE|INVERS); EXPECT_TRUE(checkScreenshot("dblsize_bottom_right"));
EXPECT_TRUE(checkScreenshot("prec1_dblsize_invers")); }
}
#endif #if defined(CPUARM)
TEST(Lcd, Smlsize_drawStringWithIndex)
TEST(Lcd, Line_Wrap) {
{ lcdClear();
lcdClear(); drawStringWithIndex(0, 0, "FM", 0, SMLSIZE);
lcdDrawText(LCD_W-10, 0, "TEST"); EXPECT_TRUE(checkScreenshot("smlsize_drawstringwithindex"));
EXPECT_TRUE(checkScreenshot("line_wrap")); }
} #endif
TEST(Lcd, DblsizeBottomRight) TEST(Lcd, vline)
{ {
lcdClear(); lcdClear();
lcdDrawText(LCD_W-20, LCD_H-16, "TEST", DBLSIZE); for (int x=0; x<100; x+=2) {
EXPECT_TRUE(checkScreenshot("dblsize_bottom_right")); lcdDrawSolidVerticalLine(x, x/2, 12);
} }
EXPECT_TRUE(checkScreenshot("vline"));
#if defined(CPUARM) }
TEST(Lcd, Smlsize_drawStringWithIndex)
{ #if defined(CPUARM)
lcdClear(); TEST(Lcd, vline_x_lt0)
drawStringWithIndex(0, 0, "FM", 0, SMLSIZE); {
EXPECT_TRUE(checkScreenshot("smlsize_drawstringwithindex")); lcdClear();
} lcdDrawSolidVerticalLine(50, -10, 12);
#endif lcdDrawSolidVerticalLine(100, -10, 1);
EXPECT_TRUE(checkScreenshot("vline_lt0"));
TEST(Lcd, vline) }
{ #endif
lcdClear();
for (int x=0; x<100; x+=2) { #if defined(CPUARM)
lcdDrawSolidVerticalLine(x, x/2, 12); TEST(Lcd, Smlsize)
} {
EXPECT_TRUE(checkScreenshot("vline")); lcdClear();
} lcdDrawText(0, 0, "TESTgy,", SMLSIZE);
lcdDrawText(10, 22, "TESTgy,", SMLSIZE|INVERS);
#if defined(CPUARM) lcdDrawFilledRect(8, 40, 100, 20);
TEST(Lcd, vline_x_lt0) lcdDrawText(10, 42, "TESTgy,", SMLSIZE);
{
lcdClear(); bool invert = false;
lcdDrawSolidVerticalLine(50, -10, 12); for(int i=0; i<3; i++) {
lcdDrawSolidVerticalLine(100, -10, 1); lcdDrawText(40+(4*i), 0+(4*i), "ABC", SMLSIZE|(invert?INVERS:0));
EXPECT_TRUE(checkScreenshot("vline_lt0")); invert = !invert;
} }
#endif
EXPECT_TRUE(checkScreenshot("smlsize"));
#if defined(CPUARM) }
TEST(Lcd, Smlsize)
{ TEST(Lcd, Stdsize)
lcdClear(); {
lcdDrawText(0, 0, "TESTgy,", SMLSIZE); lcdClear();
lcdDrawText(10, 22, "TESTgy,", SMLSIZE|INVERS); lcdDrawText(0, 0, "TEST", 0);
lcdDrawFilledRect(8, 40, 100, 20); lcdDrawText(10, 22, "TEST", INVERS);
lcdDrawText(10, 42, "TESTgy,", SMLSIZE); lcdDrawFilledRect(8, 40, 100, 20);
lcdDrawText(10, 42, "TEST", 0);
bool invert = false;
for(int i=0; i<3; i++) { bool invert = false;
lcdDrawText(40+(4*i), 0+(4*i), "ABC", SMLSIZE|(invert?INVERS:0)); for(int i=0; i<3; i++) {
invert = !invert; lcdDrawText(40+(4*i), 0+(4*i), "ABC", (invert?INVERS:0));
} invert = !invert;
}
EXPECT_TRUE(checkScreenshot("smlsize"));
} EXPECT_TRUE(checkScreenshot("stdsize"));
}
TEST(Lcd, Stdsize)
{ TEST(Lcd, Midsize)
lcdClear(); {
lcdDrawText(0, 0, "TEST", 0); lcdClear();
lcdDrawText(10, 22, "TEST", INVERS); lcdDrawText(0, 0, "TEST", MIDSIZE);
lcdDrawFilledRect(8, 40, 100, 20); lcdDrawText(10, 22, "TEST", MIDSIZE|INVERS);
lcdDrawText(10, 42, "TEST", 0); lcdDrawFilledRect(8, 40, 100, 20);
lcdDrawText(10, 42, "TEST", MIDSIZE);
bool invert = false;
for(int i=0; i<3; i++) { bool invert = false;
lcdDrawText(40+(4*i), 0+(4*i), "ABC", (invert?INVERS:0)); for(int i=0; i<3; i++) {
invert = !invert; lcdDrawText(40+(4*i), 0+(4*i), "ABC", MIDSIZE|(invert?INVERS:0));
} invert = !invert;
}
EXPECT_TRUE(checkScreenshot("stdsize"));
} EXPECT_TRUE(checkScreenshot("midsize"));
}
TEST(Lcd, Midsize)
{ TEST(Lcd, Dblsize)
lcdClear(); {
lcdDrawText(0, 0, "TEST", MIDSIZE); lcdClear();
lcdDrawText(10, 22, "TEST", MIDSIZE|INVERS); lcdDrawText(2, 10, "TST", DBLSIZE);
lcdDrawFilledRect(8, 40, 100, 20); lcdDrawText(42, 10, "TST", DBLSIZE|INVERS);
lcdDrawText(10, 42, "TEST", MIDSIZE); lcdDrawFilledRect(80, 8, 46, 24);
lcdDrawText(82, 10, "TST", DBLSIZE);
bool invert = false;
for(int i=0; i<3; i++) { bool invert = false;
lcdDrawText(40+(4*i), 0+(4*i), "ABC", MIDSIZE|(invert?INVERS:0)); for(int i=0; i<3; i++) {
invert = !invert; lcdDrawText(10+(4*i), 30+(4*i), "ABC", DBLSIZE|(invert?INVERS:0));
} invert = !invert;
}
EXPECT_TRUE(checkScreenshot("midsize"));
} EXPECT_TRUE(checkScreenshot("dblsize"));
}
TEST(Lcd, Dblsize) #endif
{
lcdClear(); #if defined(PCBTARANIS)
lcdDrawText(2, 10, "TST", DBLSIZE); TEST(Lcd, DrawSwitch)
lcdDrawText(42, 10, "TST", DBLSIZE|INVERS); {
lcdDrawFilledRect(80, 8, 46, 24); lcdClear();
lcdDrawText(82, 10, "TST", DBLSIZE); putsSwitches(0, 10, SWSRC_SA0, 0);
putsSwitches(30, 10, SWSRC_SA0, SMLSIZE);
bool invert = false; // putsSwitches(60, 10, SWSRC_SA0, MIDSIZE); missing arrows in this font
for(int i=0; i<3; i++) { putsSwitches(90, 10, SWSRC_SA0, DBLSIZE);
lcdDrawText(10+(4*i), 30+(4*i), "ABC", DBLSIZE|(invert?INVERS:0)); EXPECT_TRUE(checkScreenshot("drawswitch"));
invert = !invert; }
} #endif
EXPECT_TRUE(checkScreenshot("dblsize")); #if defined(PCBTARANIS)
} TEST(Lcd, BMPWrapping)
#endif {
lcdClear();
#if defined(PCBTARANIS) uint8_t bitmap[2+40*40/2];
TEST(Lcd, DrawSwitch) lcdLoadBitmap(bitmap, TESTS_PATH "/tests/plane.bmp", 40, 40);
{ lcdDrawBitmap(200, 0, bitmap);
lcdClear(); lcdDrawBitmap(200, 60, bitmap);
putsSwitches(0, 10, SWSRC_SA0, 0); lcdDrawBitmap(240, 60, bitmap); // x too big
putsSwitches(30, 10, SWSRC_SA0, SMLSIZE); lcdDrawBitmap(20, 200, bitmap); // y too big
// putsSwitches(60, 10, SWSRC_SA0, MIDSIZE); missing arrows in this font EXPECT_TRUE(checkScreenshot("bmpwrapping"));
putsSwitches(90, 10, SWSRC_SA0, DBLSIZE); }
EXPECT_TRUE(checkScreenshot("drawswitch")); #endif
}
#endif #if defined(PCBTARANIS)
TEST(Lcd, lcdDrawHorizontalLine)
#if defined(PCBTARANIS) {
TEST(Lcd, BMPWrapping) lcdClear();
{ lcdDrawHorizontalLine(0, 10, LCD_W, DOTTED);
lcdClear(); lcdDrawHorizontalLine(0, 20, LCD_W, SOLID);
uint8_t bitmap[2+40*40/2]; lcdDrawHorizontalLine(50, 30, LCD_W, 0xEE); //too wide
lcdLoadBitmap(bitmap, TESTS_PATH "/tests/plane.bmp", 40, 40); lcdDrawHorizontalLine(50, LCD_H + 10, 20, SOLID); //too low
lcdDrawBitmap(200, 0, bitmap); lcdDrawHorizontalLine(250, 30, LCD_W, SOLID); //x outside display
lcdDrawBitmap(200, 60, bitmap); EXPECT_TRUE(checkScreenshot("lcdDrawHorizontalLine"));
lcdDrawBitmap(240, 60, bitmap); // x too big }
lcdDrawBitmap(20, 200, bitmap); // y too big #endif
EXPECT_TRUE(checkScreenshot("bmpwrapping"));
} #if defined(PCBTARANIS)
#endif TEST(Lcd, lcdDrawVerticalLine)
{
#if defined(PCBTARANIS) lcdClear();
TEST(Lcd, lcdDrawHorizontalLine) lcdDrawVerticalLine(10, 0, LCD_H, DOTTED);
{ lcdDrawVerticalLine(20, 0, LCD_H, SOLID);
lcdClear(); lcdDrawVerticalLine(30, 30, LCD_H, 0xEE); //too high
lcdDrawHorizontalLine(0, 10, LCD_W, DOTTED); lcdDrawVerticalLine(40, LCD_H + 10, 20, SOLID); //too low
lcdDrawHorizontalLine(0, 20, LCD_W, SOLID); lcdDrawVerticalLine(250, LCD_H + 10, LCD_H, SOLID); //x outside display
lcdDrawHorizontalLine(50, 30, LCD_W, 0xEE); //too wide EXPECT_TRUE(checkScreenshot("lcdDrawVerticalLine"));
lcdDrawHorizontalLine(50, LCD_H + 10, 20, SOLID); //too low }
lcdDrawHorizontalLine(250, 30, LCD_W, SOLID); //x outside display #endif
EXPECT_TRUE(checkScreenshot("lcdDrawHorizontalLine"));
} template <int padding> class TestBuffer
#endif {
private:
#if defined(PCBTARANIS) uint8_t * buf;
TEST(Lcd, lcdDrawVerticalLine) uint32_t size;
{ public:
lcdClear(); TestBuffer(uint32_t size) : buf(0), size(size) {
lcdDrawVerticalLine(10, 0, LCD_H, DOTTED); buf = new uint8_t[size + padding * 2];
lcdDrawVerticalLine(20, 0, LCD_H, SOLID); memset(buf, 0xA5, padding);
lcdDrawVerticalLine(30, 30, LCD_H, 0xEE); //too high memset(buf+padding, 0x00, size);
lcdDrawVerticalLine(40, LCD_H + 10, 20, SOLID); //too low memset(buf+padding+size, 0x5A, padding);
lcdDrawVerticalLine(250, LCD_H + 10, LCD_H, SOLID); //x outside display };
EXPECT_TRUE(checkScreenshot("lcdDrawVerticalLine")); ~TestBuffer() { if (buf) delete[] buf; };
} uint8_t * buffer() { return buf + padding; };
#endif void leakCheck() const {
uint8_t paddingCompareBuf[padding];
template <int padding> class TestBuffer memset(paddingCompareBuf, 0xA5, padding);
{ if (memcmp(buf, paddingCompareBuf, padding) != 0) {
private: ADD_FAILURE() << "buffer leaked low";
uint8_t * buf; };
uint32_t size; memset(paddingCompareBuf, 0x5A, padding);
public: if (memcmp(buf+padding+size, paddingCompareBuf, padding) != 0) {
TestBuffer(uint32_t size) : buf(0), size(size) { ADD_FAILURE() << "buffer leaked high";
buf = new uint8_t[size + padding * 2]; }
memset(buf, 0xA5, padding); };
memset(buf+padding, 0x00, size); };
memset(buf+padding+size, 0x5A, padding);
}; #if defined(PCBTARANIS)
~TestBuffer() { if (buf) delete[] buf; }; TEST(Lcd, lcdDrawBitmapLoadAndDisplay)
uint8_t * buffer() { return buf + padding; }; {
void leakCheck() const { lcdClear();
uint8_t paddingCompareBuf[padding]; // Test proper BMP files, they should display correctly
memset(paddingCompareBuf, 0xA5, padding); {
if (memcmp(buf, paddingCompareBuf, padding) != 0) { TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(7, 32));
ADD_FAILURE() << "buffer leaked low"; EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/4b_7x32.bmp", 7, 32) != NULL);
}; bitmap.leakCheck();
memset(paddingCompareBuf, 0x5A, padding); lcdDrawBitmap(10, 2, bitmap.buffer());
if (memcmp(buf+padding+size, paddingCompareBuf, padding) != 0) { }
ADD_FAILURE() << "buffer leaked high"; {
} TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(6, 32));
}; EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/1b_6x32.bmp", 6, 32) != NULL);
}; bitmap.leakCheck();
lcdDrawBitmap(20, 2, bitmap.buffer());
#if defined(PCBTARANIS) }
TEST(Lcd, lcdDrawBitmapLoadAndDisplay) {
{ TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(31, 31));
lcdClear(); EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/4b_31x31.bmp", 31, 31) != NULL);
// Test proper BMP files, they should display correctly bitmap.leakCheck();
{ lcdDrawBitmap(30, 2, bitmap.buffer());
TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(7, 32)); }
EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/4b_7x32.bmp", 7, 32) != NULL); {
bitmap.leakCheck(); TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(39, 32));
lcdDrawBitmap(10, 2, bitmap.buffer()); EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/1b_39x32.bmp", 39, 32) != NULL);
} bitmap.leakCheck();
{ lcdDrawBitmap(70, 2, bitmap.buffer());
TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(6, 32)); }
EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/1b_6x32.bmp", 6, 32) != NULL); {
bitmap.leakCheck(); TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(20, 20));
lcdDrawBitmap(20, 2, bitmap.buffer()); EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/4b_20x20.bmp", 20, 20) != NULL);
} bitmap.leakCheck();
{ lcdDrawBitmap(120, 2, bitmap.buffer());
TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(31, 31)); }
EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/4b_31x31.bmp", 31, 31) != NULL); EXPECT_TRUE(checkScreenshot("lcdDrawBitmapLoadAndDisplay"));
bitmap.leakCheck();
lcdDrawBitmap(30, 2, bitmap.buffer()); // Test various bad BMP files, they should not display
} {
{ TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(LCD_W+1, 32));
TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(39, 32)); EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), "", LCD_W+1, 32) == NULL) << "to wide";
EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/1b_39x32.bmp", 39, 32) != NULL); bitmap.leakCheck();
bitmap.leakCheck(); }
lcdDrawBitmap(70, 2, bitmap.buffer()); {
} TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(10, 10));
{ EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/1b_39x32.bmp", 10, 10) == NULL) << "to small buffer";
TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(20, 20)); bitmap.leakCheck();
EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/4b_20x20.bmp", 20, 20) != NULL); }
bitmap.leakCheck(); }
lcdDrawBitmap(120, 2, bitmap.buffer()); #endif
}
EXPECT_TRUE(checkScreenshot("lcdDrawBitmapLoadAndDisplay")); #if defined(PCBTARANIS)
TEST(Lcd, lcdDrawLine)
// Test various bad BMP files, they should not display {
{ int start, length, xOffset;
TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(LCD_W+1, 32)); uint8_t pattern;
EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), "", LCD_W+1, 32) == NULL) << "to wide";
bitmap.leakCheck(); lcdClear();
}
{ start = 5;
TestBuffer<1000> bitmap(BITMAP_BUFFER_SIZE(10, 10)); pattern = SOLID;
EXPECT_TRUE(lcdLoadBitmap(bitmap.buffer(), TESTS_PATH "/tests/1b_39x32.bmp", 10, 10) == NULL) << "to small buffer"; length = 40;
bitmap.leakCheck(); xOffset = 0;
} lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
} lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
#endif
start = 10;
#if defined(PCBTARANIS) pattern = DOTTED;
TEST(Lcd, lcdDrawLine) length = 40;
{ xOffset = 0;
int start, length, xOffset; lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
uint8_t pattern; lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
lcdClear(); start = 55;
pattern = SOLID;
start = 5; length = -40;
pattern = SOLID; xOffset = 80;
length = 40; lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
xOffset = 0; lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0); start = 50;
pattern = DOTTED;
start = 10; length = -40;
pattern = DOTTED; xOffset = 80;
length = 40; lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
xOffset = 0; lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0);
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0); // 45 deg lines
lcdDrawLine( 35, 40, 45, 40, SOLID, FORCE );
start = 55; lcdDrawLine( 40, 35, 40, 45, SOLID, FORCE );
pattern = SOLID;
length = -40; lcdDrawLine( 20, 40, 40, 20, SOLID, FORCE );
xOffset = 80; lcdDrawLine( 40, 20, 60, 40, SOLID, FORCE );
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0); lcdDrawLine( 60, 40, 40, 60, SOLID, FORCE );
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0); lcdDrawLine( 40, 60, 20, 40, SOLID, FORCE );
start = 50; lcdDrawLine( 31, 39, 39, 31, SOLID, FORCE );
pattern = DOTTED; lcdDrawLine( 41, 31, 49, 39, SOLID, FORCE );
length = -40; lcdDrawLine( 49, 41, 41, 49, SOLID, FORCE );
xOffset = 80; lcdDrawLine( 39, 49, 31, 41, SOLID, FORCE );
lcdDrawLine(start+(length>0?1:-1)+xOffset, start, start+(length>0?1:-1)+xOffset+length, start, pattern, 0);
lcdDrawLine(start+xOffset, start+(length>0?1:-1), start+xOffset, start+(length>0?1:-1)+length, pattern, 0); // slanted lines
lcdDrawLine( 150, 10, 190, 10, SOLID, FORCE );
// 45 deg lines lcdDrawLine( 150, 10, 190, 20, SOLID, FORCE );
lcdDrawLine( 35, 40, 45, 40, SOLID, FORCE ); lcdDrawLine( 150, 10, 190, 30, SOLID, FORCE );
lcdDrawLine( 40, 35, 40, 45, SOLID, FORCE ); lcdDrawLine( 150, 10, 190, 40, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 50, SOLID, FORCE );
lcdDrawLine( 20, 40, 40, 20, SOLID, FORCE );
lcdDrawLine( 40, 20, 60, 40, SOLID, FORCE ); lcdDrawLine( 150, 10, 190, 50, SOLID, FORCE );
lcdDrawLine( 60, 40, 40, 60, SOLID, FORCE ); lcdDrawLine( 150, 10, 180, 50, SOLID, FORCE );
lcdDrawLine( 40, 60, 20, 40, SOLID, FORCE ); lcdDrawLine( 150, 10, 170, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 160, 50, SOLID, FORCE );
lcdDrawLine( 31, 39, 39, 31, SOLID, FORCE ); lcdDrawLine( 150, 10, 150, 50, SOLID, FORCE );
lcdDrawLine( 41, 31, 49, 39, SOLID, FORCE );
lcdDrawLine( 49, 41, 41, 49, SOLID, FORCE ); EXPECT_TRUE(checkScreenshot("lcdDrawLine"));
lcdDrawLine( 39, 49, 31, 41, SOLID, FORCE ); }
#endif
// slanted lines
lcdDrawLine( 150, 10, 190, 10, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 20, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 30, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 40, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 190, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 180, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 170, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 160, 50, SOLID, FORCE );
lcdDrawLine( 150, 10, 150, 50, SOLID, FORCE );
EXPECT_TRUE(checkScreenshot("lcdDrawLine"));
}
#endif

View file

@ -1,184 +1,168 @@
/* /*
* Authors (alphabetical order) * Copyright (C) OpenTX
* - Andre Bernet <bernet.andre@gmail.com> *
* - Andreas Weitl * Based on code named
* - Bertrand Songis <bsongis@gmail.com> * th9x - http://code.google.com/p/th9x
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com> * er9x - http://code.google.com/p/er9x
* - Cameron Weeks <th9xer@gmail.com> * gruvin9x - http://code.google.com/p/gruvin9x
* - Erez Raviv *
* - Gabriel Birkus * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
* - Jean-Pierre Parisy *
* - Karl Szmutny * This program is free software; you can redistribute it and/or modify
* - Michael Blandford * it under the terms of the GNU General Public License version 2 as
* - Michal Hlavinka * published by the Free Software Foundation.
* - Pat Mackenzie *
* - Philip Moss * This program is distributed in the hope that it will be useful,
* - Rob Thomson * but WITHOUT ANY WARRANTY; without even the implied warranty of
* - Romolo Manfredini <romolo.manfredini@gmail.com> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* - Thomas Husterer * GNU General Public License for more details.
* */
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, #include <math.h>
* er9x by Erez Raviv: http://code.google.com/p/er9x/, #include "gtests.h"
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ #if defined(LUA)
*
* This program is free software; you can redistribute it and/or modify #define SWAP_DEFINED
* it under the terms of the GNU General Public License version 2 as #include "opentx.h"
* published by the Free Software Foundation.
* extern const char * zchar2string(const char * zstring, int size);
* This program is distributed in the hope that it will be useful, #define EXPECT_ZSTREQ(c_string, z_string) EXPECT_STREQ(c_string, zchar2string(z_string, sizeof(z_string)))
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ::testing::AssertionResult __luaExecStr(const char * str)
* GNU General Public License for more details. {
* extern lua_State * L;
*/ if (!L) luaInit();
if (!L) return ::testing::AssertionFailure() << "No Lua state!";
#include <math.h> if (luaL_dostring(L, str)) {
#include "gtests.h" return ::testing::AssertionFailure() << "lua error: " << lua_tostring(L, -1);
}
#if defined(LUA) return ::testing::AssertionSuccess();
}
#define SWAP_DEFINED
#include "opentx.h" #define luaExecStr(test) EXPECT_TRUE(__luaExecStr(test))
extern const char * zchar2string(const char * zstring, int size); TEST(Lua, testSetModelInfo)
#define EXPECT_ZSTREQ(c_string, z_string) EXPECT_STREQ(c_string, zchar2string(z_string, sizeof(z_string))) {
luaExecStr("info = model.getInfo()");
::testing::AssertionResult __luaExecStr(const char * str) // luaExecStr("print('model name: '..info.name..' id: '..info.id)");
{ luaExecStr("info.name = 'modelA'");
extern lua_State * L; luaExecStr("model.setInfo(info)");
if (!L) luaInit(); // luaExecStr("print('model name: '..info.name..' id: '..info.id)");
if (!L) return ::testing::AssertionFailure() << "No Lua state!"; EXPECT_ZSTREQ("modelA", g_model.header.name);
if (luaL_dostring(L, str)) {
return ::testing::AssertionFailure() << "lua error: " << lua_tostring(L, -1); luaExecStr("info.name = 'Model 1'");
} luaExecStr("model.setInfo(info)");
return ::testing::AssertionSuccess(); // luaExecStr("print('model name: '..info.name..' id: '..info.id)");
} EXPECT_ZSTREQ("Model 1", g_model.header.name);
}
#define luaExecStr(test) EXPECT_TRUE(__luaExecStr(test))
TEST(Lua, testPanicProtection)
TEST(Lua, testSetModelInfo) {
{ bool passed = false;
luaExecStr("info = model.getInfo()"); PROTECT_LUA() {
// luaExecStr("print('model name: '..info.name..' id: '..info.id)"); PROTECT_LUA() {
luaExecStr("info.name = 'modelA'"); //simulate panic
luaExecStr("model.setInfo(info)"); longjmp(global_lj->b, 1);
// luaExecStr("print('model name: '..info.name..' id: '..info.id)"); }
EXPECT_ZSTREQ("modelA", g_model.header.name); else {
//we should come here
luaExecStr("info.name = 'Model 1'"); passed = true;
luaExecStr("model.setInfo(info)"); }
// luaExecStr("print('model name: '..info.name..' id: '..info.id)"); UNPROTECT_LUA();
EXPECT_ZSTREQ("Model 1", g_model.header.name); }
} else {
// an not here
TEST(Lua, testPanicProtection) // TRACE("testLuaProtection: test 1 FAILED");
{ FAIL() << "Failed test 1";
bool passed = false; }
PROTECT_LUA() { UNPROTECT_LUA()
PROTECT_LUA() {
//simulate panic EXPECT_EQ(passed, true);
longjmp(global_lj->b, 1);
} passed = false;
else {
//we should come here PROTECT_LUA() {
passed = true; PROTECT_LUA() {
} int a = 5;
UNPROTECT_LUA(); a = a; // avoids the warning
} }
else { else {
// an not here //we should not come here
// TRACE("testLuaProtection: test 1 FAILED"); // TRACE("testLuaProtection: test 2 FAILED");
FAIL() << "Failed test 1"; FAIL() << "Failed test 2";
} }
UNPROTECT_LUA() UNPROTECT_LUA()
//simulate panic
EXPECT_EQ(passed, true); longjmp(global_lj->b, 1);
}
passed = false; else {
// we should come here
PROTECT_LUA() { passed = true;
PROTECT_LUA() { }
int a = 5; UNPROTECT_LUA()
a = a; // avoids the warning
} EXPECT_EQ(passed, true);
else { }
//we should not come here
// TRACE("testLuaProtection: test 2 FAILED"); TEST(Lua, testModelInputs)
FAIL() << "Failed test 2"; {
} MODEL_RESET();
UNPROTECT_LUA() luaExecStr("noInputs = model.getInputsCount(0)");
//simulate panic luaExecStr("if noInputs > 0 then error('getInputsCount()') end");
longjmp(global_lj->b, 1);
} // add one line on Input4
else { luaExecStr("model.insertInput(3, 0, {name='test1', source=MIXSRC_Thr, weight=56, offset=3, switch=2})");
// we should come here EXPECT_EQ(3, (int)g_model.expoData[0].chn);
passed = true; EXPECT_ZSTREQ("test1", g_model.expoData[0].name);
} EXPECT_EQ(MIXSRC_Thr, g_model.expoData[0].srcRaw);
UNPROTECT_LUA() EXPECT_EQ(56, g_model.expoData[0].weight);
EXPECT_EQ(3, g_model.expoData[0].offset);
EXPECT_EQ(passed, true); EXPECT_EQ(2, g_model.expoData[0].swtch);
}
// add another one before existing line on Input4
TEST(Lua, testModelInputs) luaExecStr("model.insertInput(3, 0, {name='test2', source=MIXSRC_Rud, weight=-56})");
{ EXPECT_EQ(3, (int)g_model.expoData[0].chn);
MODEL_RESET(); EXPECT_ZSTREQ("test2", g_model.expoData[0].name);
luaExecStr("noInputs = model.getInputsCount(0)"); EXPECT_EQ(MIXSRC_Rud, g_model.expoData[0].srcRaw);
luaExecStr("if noInputs > 0 then error('getInputsCount()') end"); EXPECT_EQ(-56, g_model.expoData[0].weight);
EXPECT_EQ(0, g_model.expoData[0].offset);
// add one line on Input4 EXPECT_EQ(0, g_model.expoData[0].swtch);
luaExecStr("model.insertInput(3, 0, {name='test1', source=MIXSRC_Thr, weight=56, offset=3, switch=2})");
EXPECT_EQ(3, (int)g_model.expoData[0].chn); EXPECT_EQ(3, (int)g_model.expoData[1].chn);
EXPECT_ZSTREQ("test1", g_model.expoData[0].name); EXPECT_ZSTREQ("test1", g_model.expoData[1].name);
EXPECT_EQ(MIXSRC_Thr, g_model.expoData[0].srcRaw); EXPECT_EQ(MIXSRC_Thr, g_model.expoData[1].srcRaw);
EXPECT_EQ(56, g_model.expoData[0].weight); EXPECT_EQ(56, g_model.expoData[1].weight);
EXPECT_EQ(3, g_model.expoData[0].offset); EXPECT_EQ(3, g_model.expoData[1].offset);
EXPECT_EQ(2, g_model.expoData[0].swtch); EXPECT_EQ(2, g_model.expoData[1].swtch);
// add another one before existing line on Input4 // add another line after existing lines on Input4
luaExecStr("model.insertInput(3, 0, {name='test2', source=MIXSRC_Rud, weight=-56})"); luaExecStr("model.insertInput(3, model.getInputsCount(3), {name='test3', source=MIXSRC_Ail, weight=100})");
EXPECT_EQ(3, (int)g_model.expoData[0].chn); EXPECT_EQ(3, (int)g_model.expoData[0].chn);
EXPECT_ZSTREQ("test2", g_model.expoData[0].name); EXPECT_ZSTREQ("test2", g_model.expoData[0].name);
EXPECT_EQ(MIXSRC_Rud, g_model.expoData[0].srcRaw); EXPECT_EQ(MIXSRC_Rud, g_model.expoData[0].srcRaw);
EXPECT_EQ(-56, g_model.expoData[0].weight); EXPECT_EQ(-56, g_model.expoData[0].weight);
EXPECT_EQ(0, g_model.expoData[0].offset); EXPECT_EQ(0, g_model.expoData[0].offset);
EXPECT_EQ(0, g_model.expoData[0].swtch); EXPECT_EQ(0, g_model.expoData[0].swtch);
EXPECT_EQ(3, (int)g_model.expoData[1].chn); EXPECT_EQ(3, (int)g_model.expoData[1].chn);
EXPECT_ZSTREQ("test1", g_model.expoData[1].name); EXPECT_ZSTREQ("test1", g_model.expoData[1].name);
EXPECT_EQ(MIXSRC_Thr, g_model.expoData[1].srcRaw); EXPECT_EQ(MIXSRC_Thr, g_model.expoData[1].srcRaw);
EXPECT_EQ(56, g_model.expoData[1].weight); EXPECT_EQ(56, g_model.expoData[1].weight);
EXPECT_EQ(3, g_model.expoData[1].offset); EXPECT_EQ(3, g_model.expoData[1].offset);
EXPECT_EQ(2, g_model.expoData[1].swtch); EXPECT_EQ(2, g_model.expoData[1].swtch);
// add another line after existing lines on Input4 EXPECT_EQ(3, (int)g_model.expoData[2].chn);
luaExecStr("model.insertInput(3, model.getInputsCount(3), {name='test3', source=MIXSRC_Ail, weight=100})"); EXPECT_ZSTREQ("test3", g_model.expoData[2].name);
EXPECT_EQ(3, (int)g_model.expoData[0].chn); EXPECT_EQ(MIXSRC_Ail, g_model.expoData[2].srcRaw);
EXPECT_ZSTREQ("test2", g_model.expoData[0].name); EXPECT_EQ(100, g_model.expoData[2].weight);
EXPECT_EQ(MIXSRC_Rud, g_model.expoData[0].srcRaw); EXPECT_EQ(0, g_model.expoData[2].offset);
EXPECT_EQ(-56, g_model.expoData[0].weight); EXPECT_EQ(0, g_model.expoData[2].swtch);
EXPECT_EQ(0, g_model.expoData[0].offset);
EXPECT_EQ(0, g_model.expoData[0].swtch); // verify number of lines for Input4
luaExecStr("noInputs = model.getInputsCount(3)");
EXPECT_EQ(3, (int)g_model.expoData[1].chn); luaExecStr("if noInputs ~= 3 then error('getInputsCount()') end");
EXPECT_ZSTREQ("test1", g_model.expoData[1].name);
EXPECT_EQ(MIXSRC_Thr, g_model.expoData[1].srcRaw); }
EXPECT_EQ(56, g_model.expoData[1].weight);
EXPECT_EQ(3, g_model.expoData[1].offset); #endif // #if defined(LUA)
EXPECT_EQ(2, g_model.expoData[1].swtch);
EXPECT_EQ(3, (int)g_model.expoData[2].chn);
EXPECT_ZSTREQ("test3", g_model.expoData[2].name);
EXPECT_EQ(MIXSRC_Ail, g_model.expoData[2].srcRaw);
EXPECT_EQ(100, g_model.expoData[2].weight);
EXPECT_EQ(0, g_model.expoData[2].offset);
EXPECT_EQ(0, g_model.expoData[2].swtch);
// verify number of lines for Input4
luaExecStr("noInputs = model.getInputsCount(3)");
luaExecStr("if noInputs ~= 3 then error('getInputsCount()') end");
}
#endif // #if defined(LUA)

File diff suppressed because it is too large Load diff

View file

@ -1,27 +1,12 @@
/* /*
* Authors (alphabetical order) * Copyright (C) OpenTX
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
* *
* opentx is based on code named * Based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, * th9x - http://code.google.com/p/th9x
* er9x by Erez Raviv: http://code.google.com/p/er9x/, * er9x - http://code.google.com/p/er9x
* and the original (and ongoing) project by * gruvin9x - http://code.google.com/p/gruvin9x
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ *
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
@ -31,7 +16,6 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*
*/ */
#include "gtests.h" #include "gtests.h"

View file

@ -1,255 +1,239 @@
/* /*
* Authors (alphabetical order) * Copyright (C) OpenTX
* - Andre Bernet <bernet.andre@gmail.com> *
* - Andreas Weitl * Based on code named
* - Bertrand Songis <bsongis@gmail.com> * th9x - http://code.google.com/p/th9x
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com> * er9x - http://code.google.com/p/er9x
* - Cameron Weeks <th9xer@gmail.com> * gruvin9x - http://code.google.com/p/gruvin9x
* - Erez Raviv *
* - Gabriel Birkus * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
* - Jean-Pierre Parisy *
* - Karl Szmutny * This program is free software; you can redistribute it and/or modify
* - Michael Blandford * it under the terms of the GNU General Public License version 2 as
* - Michal Hlavinka * published by the Free Software Foundation.
* - Pat Mackenzie *
* - Philip Moss * This program is distributed in the hope that it will be useful,
* - Rob Thomson * but WITHOUT ANY WARRANTY; without even the implied warranty of
* - Romolo Manfredini <romolo.manfredini@gmail.com> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* - Thomas Husterer * GNU General Public License for more details.
* */
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, #include "gtests.h"
* er9x by Erez Raviv: http://code.google.com/p/er9x/, #include "opentx.h"
* and the original (and ongoing) project by #include "timers.h"
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
* #if !defined(CPUARM)
* This program is free software; you can redistribute it and/or modify #undef timerSet
* it under the terms of the GNU General Public License version 2 as void timerSet(int idx, int16_t val)
* published by the Free Software Foundation. {
* TimerState & timerState = timersStates[idx];
* This program is distributed in the hope that it will be useful, timerState.state = TMR_OFF; // is changed to RUNNING dep from mode
* but WITHOUT ANY WARRANTY; without even the implied warranty of timerState.val = val;
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the timerState.val_10ms = 0 ;
* GNU General Public License for more details. }
* #endif // #if !defined(CPUARM)
*/
#if defined(ACCURAT_THROTTLE_TIMER)
#include "gtests.h" #define THR_100 128 // approximately 10% full throttle
#include "opentx.h" #define THR_50 64 // approximately 10% full throttle
#include "timers.h" #define THR_10 13 // approximately 10% full throttle
#else
#if !defined(CPUARM) #define THR_100 32 // approximately 10% full throttle
#undef timerSet #define THR_50 16 // approximately 10% full throttle
void timerSet(int idx, int16_t val) #define THR_10 3 // approximately 10% full throttle
{ #endif
TimerState & timerState = timersStates[idx];
timerState.state = TMR_OFF; // is changed to RUNNING dep from mode
timerState.val = val; #define TEST_AB_EQUAL(a, b) if (a != b) { return ::testing::AssertionFailure() << \
timerState.val_10ms = 0 ; #a "= " << (uint32_t)a << ", " << #b "= " << (uint32_t)b; };
}
#endif // #if !defined(CPUARM) void initModelTimer(uint32_t idx, uint8_t mode, int16_t start = 0)
{
#if defined(ACCURAT_THROTTLE_TIMER) g_model.timers[0].mode = mode;
#define THR_100 128 // approximately 10% full throttle g_model.timers[0].start = start;
#define THR_50 64 // approximately 10% full throttle g_model.timers[0].countdownBeep = COUNTDOWN_SILENT;
#define THR_10 13 // approximately 10% full throttle g_model.timers[0].minuteBeep = 0;
#else g_model.timers[0].spare = 0;
#define THR_100 32 // approximately 10% full throttle #if defined(CPUARM) || defined(CPUM2560)
#define THR_50 16 // approximately 10% full throttle g_model.timers[0].persistent = 0;
#define THR_10 3 // approximately 10% full throttle g_model.timers[0].value = 0;
#endif #endif
}
#define TEST_AB_EQUAL(a, b) if (a != b) { return ::testing::AssertionFailure() << \ /*
#a "= " << (uint32_t)a << ", " << #b "= " << (uint32_t)b; }; Run timers for n seconds and test the end state
*/
void initModelTimer(uint32_t idx, uint8_t mode, int16_t start = 0) ::testing::AssertionResult evalTimersForNSecondsAndTest(unsigned int n, uint8_t throttle, uint32_t idx, uint8_t state, int value)
{ {
g_model.timers[0].mode = mode; unsigned int noLoops = n * 100;
g_model.timers[0].start = start; while (noLoops--) {
g_model.timers[0].countdownBeep = COUNTDOWN_SILENT; evalTimers(throttle, 1);
g_model.timers[0].minuteBeep = 0; }
g_model.timers[0].spare = 0; TEST_AB_EQUAL(timersStates[idx].state, state);
#if defined(CPUARM) || defined(CPUM2560) TEST_AB_EQUAL(timersStates[idx].val, value);
g_model.timers[0].persistent = 0; return ::testing::AssertionSuccess();
g_model.timers[0].value = 0; }
#endif
} TEST(Timers, timerReset)
{
/* initModelTimer(0, TMRMODE_THR_REL, 200);
Run timers for n seconds and test the end state timerReset(0);
*/ EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 200));
::testing::AssertionResult evalTimersForNSecondsAndTest(unsigned int n, uint8_t throttle, uint32_t idx, uint8_t state, int value)
{ initModelTimer(1, TMRMODE_THR_REL, 0);
unsigned int noLoops = n * 100; timerReset(1);
while (noLoops--) { EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 1, TMR_OFF, 0));
evalTimers(throttle, 1); }
}
TEST_AB_EQUAL(timersStates[idx].state, state); #if defined(CPUARM)
TEST_AB_EQUAL(timersStates[idx].val, value); TEST(Timers, timerSet)
return ::testing::AssertionSuccess(); {
} timerSet(0, 500);
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 500));
TEST(Timers, timerReset)
{ timerSet(1, 300);
initModelTimer(0, TMRMODE_THR_REL, 200); EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 1, TMR_OFF, 300));
timerReset(0); }
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 200));
TEST(Timers, timerGreaterThan9hours)
initModelTimer(1, TMRMODE_THR_REL, 0); {
timerReset(1); initModelTimer(0, TMRMODE_ABS, 0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 1, TMR_OFF, 0)); timerSet(0, 0);
} // test with 24 hours
EXPECT_TRUE(evalTimersForNSecondsAndTest(24*3600, THR_100, 0, TMR_RUNNING, 24*3600));
#if defined(CPUARM) }
TEST(Timers, timerSet) #endif // #if defined(CPUARM)
{
timerSet(0, 500); #if defined(CPUARM) || defined(CPUM2560)
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 500)); TEST(Timers, saveRestoreTimers)
{
timerSet(1, 300); g_model.timers[0].persistent = 1;
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 1, TMR_OFF, 300)); g_model.timers[1].persistent = 1;
} timerSet(0, 500);
timerSet(1, 1500);
TEST(Timers, timerGreaterThan9hours) saveTimers();
{ EXPECT_EQ(g_model.timers[0].value, 500);
initModelTimer(0, TMRMODE_ABS, 0); EXPECT_EQ(g_model.timers[1].value, 1500);
timerSet(0, 0); EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 500));
// test with 24 hours EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 1, TMR_OFF, 1500));
EXPECT_TRUE(evalTimersForNSecondsAndTest(24*3600, THR_100, 0, TMR_RUNNING, 24*3600));
} timerReset(0);
#endif // #if defined(CPUARM) timerReset(1);
restoreTimers();
#if defined(CPUARM) || defined(CPUM2560) EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 500));
TEST(Timers, saveRestoreTimers) EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 1, TMR_OFF, 1500));
{ }
g_model.timers[0].persistent = 1; #endif
g_model.timers[1].persistent = 1;
timerSet(0, 500); TEST(Timers, timerOff)
timerSet(1, 1500); {
saveTimers(); initModelTimer(0, TMRMODE_NONE, 0);
EXPECT_EQ(g_model.timers[0].value, 500); timerReset(0);
EXPECT_EQ(g_model.timers[1].value, 1500);
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 500)); EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 0));
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 1, TMR_OFF, 1500)); EXPECT_TRUE(evalTimersForNSecondsAndTest(10, THR_100, 0, TMR_OFF, 0));
}
timerReset(0);
timerReset(1); TEST(Timers, timerAbsolute)
restoreTimers(); {
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 500)); initModelTimer(0, TMRMODE_ABS, 0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 1, TMR_OFF, 1500)); timerReset(0);
}
#endif EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, 1));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 101));
TEST(Timers, timerOff) EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 201));
{
initModelTimer(0, TMRMODE_NONE, 0); // max timer value test
timerReset(0); timerSet(0, TIMER_MAX-10);
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, TIMER_MAX-9));
EXPECT_TRUE(evalTimersForNSecondsAndTest(0, THR_100, 0, TMR_OFF, 0)); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, TIMER_MAX));
EXPECT_TRUE(evalTimersForNSecondsAndTest(10, THR_100, 0, TMR_OFF, 0));
} // test down-running
g_model.timers[0].start = 200;
TEST(Timers, timerAbsolute) timerReset(0);
{ EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, 199));
initModelTimer(0, TMRMODE_ABS, 0); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 99));
timerReset(0); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_NEGATIVE, -1));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_STOPPED, -101));
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, 1));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 101)); #if !defined(CPUARM)
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 201)); // min timer value test
timerSet(0, TIMER_MIN+10);
// max timer value test EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, TIMER_MIN+9));
timerSet(0, TIMER_MAX-10); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, TIMER_MIN));
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, TIMER_MAX-9)); #endif
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, TIMER_MAX)); }
// test down-running TEST(Timers, timerThrottle)
g_model.timers[0].start = 200; {
timerReset(0); initModelTimer(0, TMRMODE_THR, 0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, 199)); timerReset(0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 99));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_NEGATIVE, -1)); EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_RUNNING, 0));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_STOPPED, -101)); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 100));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_RUNNING, 200));
#if !defined(CPUARM) EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 200));
// min timer value test
timerSet(0, TIMER_MIN+10); // test down-running
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, TIMER_MIN+9)); g_model.timers[0].start = 200;
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, TIMER_MIN)); timerReset(0);
#endif EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, 199));
} EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_RUNNING, 199));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 99));
TEST(Timers, timerThrottle) EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_50, 0, TMR_NEGATIVE, -1));
{ EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_STOPPED,-101));
initModelTimer(0, TMRMODE_THR, 0); }
timerReset(0);
TEST(Timers, timerThrottleRelative)
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_RUNNING, 0)); {
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 100)); initModelTimer(0, TMRMODE_THR_REL, 0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_RUNNING, 200));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 200)); timerReset(0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_RUNNING, 0));
// test down-running EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 100));
g_model.timers[0].start = 200; EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_50, 0, TMR_RUNNING, 150)); // 50% throttle == 50s
timerReset(0); #if defined(ACCURAT_THROTTLE_TIMER)
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, 199)); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_RUNNING, 160)); // 10% throttle == 10s
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_RUNNING, 199)); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 160));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 99)); #else
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_50, 0, TMR_NEGATIVE, -1)); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_RUNNING, 159)); // 10% throttle == 10s
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_STOPPED,-101)); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 159));
} #endif
TEST(Timers, timerThrottleRelative) // test down-running
{ initModelTimer(0, TMRMODE_THR_REL, 200);
initModelTimer(0, TMRMODE_THR_REL, 0); timerReset(0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, 199));
timerReset(0); EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_RUNNING, 199));
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_RUNNING, 0)); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 99));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 100)); EXPECT_TRUE(evalTimersForNSecondsAndTest(200, THR_50, 0, TMR_NEGATIVE, -1)); // 50% throttle == 100s
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_50, 0, TMR_RUNNING, 150)); // 50% throttle == 50s #if defined(ACCURAT_THROTTLE_TIMER)
#if defined(ACCURAT_THROTTLE_TIMER) EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_NEGATIVE,-11)); // 10% throttle == 10s
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_RUNNING, 160)); // 10% throttle == 10s EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_STOPPED,-111));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 160)); #else
#else EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_NEGATIVE,-10)); // 10% throttle == 10s
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_RUNNING, 159)); // 10% throttle == 10s EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_STOPPED,-110));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 159)); #endif
#endif }
// test down-running TEST(Timers, timerThrottleTriggered)
initModelTimer(0, TMRMODE_THR_REL, 200); {
timerReset(0); initModelTimer(0, TMRMODE_THR_TRG, 0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, THR_100, 0, TMR_RUNNING, 199));
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_RUNNING, 199)); timerReset(0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 99)); EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_OFF, 0));
EXPECT_TRUE(evalTimersForNSecondsAndTest(200, THR_50, 0, TMR_NEGATIVE, -1)); // 50% throttle == 100s EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10-1, 0, TMR_OFF, 0)); // below threshold
#if defined(ACCURAT_THROTTLE_TIMER) EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_50, 0, TMR_RUNNING, 100));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_NEGATIVE,-11)); // 10% throttle == 10s EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 200));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_STOPPED,-111)); EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 300));
#else
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10, 0, TMR_NEGATIVE,-10)); // 10% throttle == 10s // test down-running
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_STOPPED,-110)); initModelTimer(0, TMRMODE_THR_TRG, 200);
#endif timerReset(0);
} EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_OFF, 200));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10-1, 0, TMR_OFF, 200)); // below threshold
TEST(Timers, timerThrottleTriggered) EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 100));
{ EXPECT_TRUE(evalTimersForNSecondsAndTest(101, THR_50, 0, TMR_NEGATIVE, -1));
initModelTimer(0, TMRMODE_THR_TRG, 0); EXPECT_TRUE(evalTimersForNSecondsAndTest(10, 0, 0, TMR_NEGATIVE,-11));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_STOPPED,-111));
timerReset(0); }
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_OFF, 0));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10-1, 0, TMR_OFF, 0)); // below threshold
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_50, 0, TMR_RUNNING, 100));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 200));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_RUNNING, 300));
// test down-running
initModelTimer(0, TMRMODE_THR_TRG, 200);
timerReset(0);
EXPECT_TRUE(evalTimersForNSecondsAndTest(1, 0, 0, TMR_OFF, 200));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_10-1, 0, TMR_OFF, 200)); // below threshold
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, THR_100, 0, TMR_RUNNING, 100));
EXPECT_TRUE(evalTimersForNSecondsAndTest(101, THR_50, 0, TMR_NEGATIVE, -1));
EXPECT_TRUE(evalTimersForNSecondsAndTest(10, 0, 0, TMR_NEGATIVE,-11));
EXPECT_TRUE(evalTimersForNSecondsAndTest(100, 0, 0, TMR_STOPPED,-111));
}