mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 00:05:33 +03:00
Add first unit test for some code in serial.c. Fix compiler warnings in
other tests.
This commit is contained in:
parent
8a9d2e3708
commit
b0b1eaf9c7
10 changed files with 164 additions and 61 deletions
|
@ -71,17 +71,17 @@ TEST(AltitudeHoldTest, IsThrustFacingDownwards)
|
|||
// given
|
||||
|
||||
inclinationExpectation_t inclinationExpectations[] = {
|
||||
{ { 0, 0 }, DOWNWARDS_THRUST },
|
||||
{ { 799, 799 }, DOWNWARDS_THRUST },
|
||||
{ { 800, 799 }, UPWARDS_THRUST },
|
||||
{ { 799, 800 }, UPWARDS_THRUST },
|
||||
{ { 800, 800 }, UPWARDS_THRUST },
|
||||
{ { 801, 801 }, UPWARDS_THRUST },
|
||||
{ { -799, -799 }, DOWNWARDS_THRUST },
|
||||
{ { -800, -799 }, UPWARDS_THRUST },
|
||||
{ { -799, -800 }, UPWARDS_THRUST },
|
||||
{ { -800, -800 }, UPWARDS_THRUST },
|
||||
{ { -801, -801 }, UPWARDS_THRUST }
|
||||
{ {{ 0, 0 }}, DOWNWARDS_THRUST },
|
||||
{ {{ 799, 799 }}, DOWNWARDS_THRUST },
|
||||
{ {{ 800, 799 }}, UPWARDS_THRUST },
|
||||
{ {{ 799, 800 }}, UPWARDS_THRUST },
|
||||
{ {{ 800, 800 }}, UPWARDS_THRUST },
|
||||
{ {{ 801, 801 }}, UPWARDS_THRUST },
|
||||
{ {{ -799, -799 }}, DOWNWARDS_THRUST },
|
||||
{ {{ -800, -799 }}, UPWARDS_THRUST },
|
||||
{ {{ -799, -800 }}, UPWARDS_THRUST },
|
||||
{ {{ -800, -800 }}, UPWARDS_THRUST },
|
||||
{ {{ -801, -801 }}, UPWARDS_THRUST }
|
||||
};
|
||||
uint8_t testIterationCount = sizeof(inclinationExpectations) / sizeof(inclinationExpectation_t);
|
||||
|
||||
|
@ -105,18 +105,18 @@ typedef struct inclinationAngleExpectations_s {
|
|||
TEST(AltitudeHoldTest, TestCalculateTiltAngle)
|
||||
{
|
||||
inclinationAngleExpectations_t inclinationAngleExpectations[] = {
|
||||
{ {0, 0}, 0},
|
||||
{ {1, 0}, 1},
|
||||
{ {0, 1}, 1},
|
||||
{ {0, -1}, 1},
|
||||
{ {-1, 0}, 1},
|
||||
{ {-1, -2}, 2},
|
||||
{ {-2, -1}, 2},
|
||||
{ {1, 2}, 2},
|
||||
{ {2, 1}, 2}
|
||||
{ {{ 0, 0}}, 0},
|
||||
{ {{ 1, 0}}, 1},
|
||||
{ {{ 0, 1}}, 1},
|
||||
{ {{ 0, -1}}, 1},
|
||||
{ {{-1, 0}}, 1},
|
||||
{ {{-1, -2}}, 2},
|
||||
{ {{-2, -1}}, 2},
|
||||
{ {{ 1, 2}}, 2},
|
||||
{ {{ 2, 1}}, 2}
|
||||
};
|
||||
|
||||
rollAndPitchInclination_t inclination = {0, 0};
|
||||
rollAndPitchInclination_t inclination = {{0, 0}};
|
||||
uint16_t tilt_angle = calculateTiltAngle(&inclination);
|
||||
EXPECT_EQ(tilt_angle, 0);
|
||||
|
||||
|
|
73
src/test/unit/io_serial_unittest.cc
Normal file
73
src/test/unit/io_serial_unittest.cc
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* This file is part of Cleanflight.
|
||||
*
|
||||
* Cleanflight is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Cleanflight 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
extern "C" {
|
||||
#include "platform.h"
|
||||
|
||||
#include "drivers/serial.h"
|
||||
#include "io/serial.h"
|
||||
|
||||
void serialInit(serialConfig_t *initialSerialConfig);
|
||||
|
||||
}
|
||||
|
||||
#include "unittest_macros.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
//uint32_t testFeatureMask = 0;
|
||||
uint8_t cliMode = 0;
|
||||
|
||||
TEST(IoSerialTest, TestFindPortConfig)
|
||||
{
|
||||
// given
|
||||
serialConfig_t serialConfig;
|
||||
memset(&serialConfig, 0, sizeof(serialConfig));
|
||||
|
||||
// when
|
||||
serialInit(&serialConfig);
|
||||
|
||||
// and
|
||||
serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_MSP);
|
||||
|
||||
// then
|
||||
EXPECT_EQ(NULL, portConfig);
|
||||
}
|
||||
|
||||
|
||||
// STUBS
|
||||
|
||||
extern "C" {
|
||||
//
|
||||
//bool feature(uint32_t mask) {
|
||||
// return (mask & testFeatureMask);
|
||||
//}s
|
||||
|
||||
void delay(uint32_t) {}
|
||||
void cliEnter(serialPort_t *) {}
|
||||
void cliProcess(void) {}
|
||||
bool isSerialTransmitBufferEmpty(serialPort_t *) {
|
||||
return true;
|
||||
}
|
||||
void mspProcess(void) {}
|
||||
void systemResetToBootloader(void) {}
|
||||
|
||||
}
|
|
@ -418,6 +418,6 @@ int scaleRange(int x, int srcMin, int srcMax, int destMin, int destMax) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool failsafeHasTimerElapsed(void) { }
|
||||
bool failsafeHasTimerElapsed(void) { return false; }
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue