Gtests split into several source files
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - 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
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QPainter>
|
||||
#include <math.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define SWAP_DEFINED
|
||||
#include "opentx.h"
|
||||
|
||||
|
||||
#if defined(FRSKY) && !defined(FRSKY_SPORT)
|
||||
extern void frskyDProcessPacket(uint8_t *packet);
|
||||
TEST(FrSky, gpsNfuel)
|
||||
{
|
||||
g_model.frsky.usrProto = 1;
|
||||
frskyData.hub.gpsFix = 1;
|
||||
|
||||
uint8_t pkt1[] = { 0xfd, 0x07, 0x00, 0x5e, 0x14, 0x2c, 0x00, 0x5e, 0x1c, 0x03 };
|
||||
uint8_t pkt2[] = { 0xfd, 0x07, 0x00, 0x00, 0x5e, 0x13, 0x38, 0x0c, 0x5e, 0x1b };
|
||||
uint8_t pkt3[] = { 0xfd, 0x07, 0x00, 0xc9, 0x06, 0x5e, 0x23, 0x4e, 0x00, 0x5e };
|
||||
uint8_t pkt4[] = { 0xfd, 0x07, 0x00, 0x12, 0xef, 0x2e, 0x5e, 0x1a, 0x98, 0x26 };
|
||||
uint8_t pkt5[] = { 0xfd, 0x07, 0x00, 0x5e, 0x22, 0x45, 0x00, 0x5e, 0x11, 0x02 };
|
||||
uint8_t pkt6[] = { 0xfd, 0x07, 0x00, 0x00, 0x5e, 0x19, 0x93, 0x00, 0x5e, 0x04 };
|
||||
uint8_t pkt7[] = { 0xfd, 0x03, 0x00, 0x64, 0x00, 0x5e };
|
||||
frskyDProcessPacket(pkt1);
|
||||
frskyDProcessPacket(pkt2);
|
||||
frskyDProcessPacket(pkt3);
|
||||
frskyDProcessPacket(pkt4);
|
||||
frskyDProcessPacket(pkt5);
|
||||
frskyDProcessPacket(pkt6);
|
||||
frskyDProcessPacket(pkt7);
|
||||
EXPECT_EQ(frskyData.hub.gpsCourse_bp, 44);
|
||||
EXPECT_EQ(frskyData.hub.gpsCourse_ap, 03);
|
||||
EXPECT_EQ(frskyData.hub.gpsLongitude_bp / 100, 120);
|
||||
EXPECT_EQ(frskyData.hub.gpsLongitude_bp % 100, 15);
|
||||
EXPECT_EQ(frskyData.hub.gpsLongitude_ap, 0x2698);
|
||||
EXPECT_EQ(frskyData.hub.gpsLatitudeNS, 'N');
|
||||
EXPECT_EQ(frskyData.hub.gpsLongitudeEW, 'E');
|
||||
EXPECT_EQ(frskyData.hub.fuelLevel, 100);
|
||||
}
|
||||
|
||||
TEST(FrSky, dateNtime)
|
||||
{
|
||||
uint8_t pkt1[] = { 0xfd, 0x07, 0x00, 0x5e, 0x15, 0x0f, 0x07, 0x5e, 0x16, 0x0b };
|
||||
uint8_t pkt2[] = { 0xfd, 0x07, 0x00, 0x00, 0x5e, 0x17, 0x06, 0x12, 0x5e, 0x18 };
|
||||
uint8_t pkt3[] = { 0xfd, 0x03, 0x00, 0x32, 0x00, 0x5e };
|
||||
frskyDProcessPacket(pkt1);
|
||||
frskyDProcessPacket(pkt2);
|
||||
frskyDProcessPacket(pkt3);
|
||||
EXPECT_EQ(frskyData.hub.day, 15);
|
||||
EXPECT_EQ(frskyData.hub.month, 07);
|
||||
EXPECT_EQ(frskyData.hub.year, 11);
|
||||
EXPECT_EQ(frskyData.hub.hour, 06);
|
||||
EXPECT_EQ(frskyData.hub.min, 18);
|
||||
EXPECT_EQ(frskyData.hub.sec, 50);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(FRSKY_SPORT)
|
||||
extern bool checkSportPacket(uint8_t *packet);
|
||||
TEST(FrSkySPORT, checkCrc)
|
||||
{
|
||||
// uint8_t pkt[] = { 0x7E, 0x98, 0x10, 0x10, 0x00, 0x7D, 0x5E, 0x02, 0x00, 0x00, 0x5F };
|
||||
uint8_t pkt[] = { 0x7E, 0x98, 0x10, 0x10, 0x00, 0x7E, 0x02, 0x00, 0x00, 0x5F };
|
||||
EXPECT_EQ(checkSportPacket(pkt+1), true);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(FRSKY) && defined(CPUARM)
|
||||
TEST(FrSky, FrskyValueWithMinAveraging)
|
||||
{
|
||||
/*
|
||||
The following expected[] array is filled
|
||||
with values that correspond to 4 elements
|
||||
long averaging buffer.
|
||||
If length of averaging buffer is changed, this
|
||||
values must be adjusted
|
||||
*/
|
||||
uint8_t expected[] = { 10, 12, 17, 25, 35, 45, 55, 65, 75, 85, 92, 97, 100, 100, 100, 100, 100};
|
||||
int testPos = 0;
|
||||
//test of averaging
|
||||
FrskyValueWithMin testVal;
|
||||
testVal.value = 0;
|
||||
testVal.set(10);
|
||||
EXPECT_EQ(testVal.value, expected[testPos++]);
|
||||
for(int n=2; n<10; ++n) {
|
||||
testVal.set(n*10);
|
||||
EXPECT_EQ(testVal.value, expected[testPos++]);
|
||||
}
|
||||
for(int n=2; n<10; ++n) {
|
||||
testVal.set(100);
|
||||
EXPECT_EQ(testVal.value, expected[testPos++]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user