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/>.
22 //#ifdef DEBUG_GPS_CONVERSION
25 #include "flight/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)
36 uint32_t result = GPS_coord_to_degrees("diediedie");
40 typedef struct gpsConversionExpectation_s {
43 } gpsConversionExpectation_t;
45 TEST(GpsConversionTest, GPSCoordToDegrees_NMEA_Values)
47 const gpsConversionExpectation_t gpsConversionExpectations[] = {
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},
62 uint8_t testIterationCount = sizeof(gpsConversionExpectations) / sizeof(gpsConversionExpectation_t);
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);
71 uint32_t result = GPS_coord_to_degrees(expectation->coord);
72 EXPECT_EQ(result, expectation->degrees);