updated reference website link
[betaflight.git] / src / test / unit / gps_conversion_unittest.cc
blob78e3e51ac70309b321351340ab975a5484613dc2
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdint.h>
20 #include <limits.h>
22 //#ifdef DEBUG_GPS_CONVERSION
24 extern "C" {
25 #include "common/gps_conversion.h"
28 #include "unittest_macros.h"
29 #include "gtest/gtest.h"
31 // See http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
33 TEST(GpsConversionTest, GPSCoordToDegrees_BadString)
35 // expect
36 uint32_t result = GPS_coord_to_degrees("diediedie");
37 EXPECT_EQ(result, 0);
40 typedef struct gpsConversionExpectation_s {
41 const char *coord;
42 uint32_t degrees;
43 } gpsConversionExpectation_t;
45 TEST(GpsConversionTest, GPSCoordToDegrees_NMEA_Values)
47 const gpsConversionExpectation_t gpsConversionExpectations[] = {
48 {"0.0", 0},
49 {"000.0", 0},
50 {"00000.0000", 0},
51 {"0.0001", 16}, // smallest value
52 {"25599.9999", 2566666650UL}, // largest value
53 {"25599.99999", 2566666650UL}, // too many fractional digits
54 {"25699.9999", 16666650UL}, // overflowed without detection
55 {"5128.3727", 514728783UL},
56 {"5321.6802", 533613366UL},
57 {"00630.3372", 65056200UL},
60 // expect
62 uint8_t testIterationCount = sizeof(gpsConversionExpectations) / sizeof(gpsConversionExpectation_t);
64 // expect
66 for (uint8_t index = 0; index < testIterationCount; index ++) {
67 const gpsConversionExpectation_t *expectation = &gpsConversionExpectations[index];
68 #ifdef DEBUG_GPS_CONVERSION
69 printf("iteration: %d\n", index);
70 #endif
71 uint32_t result = GPS_coord_to_degrees(expectation->coord);
72 EXPECT_EQ(result, expectation->degrees);