APM:Libraries
libraries
AP_GPS
tests
test_gps.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2016 Intel Corporation. All rights reserved.
3
*
4
* This file is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This file is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
#include <AP_gtest.h>
18
19
#include <
AP_GPS/AP_GPS_NMEA.h
>
20
21
const
AP_HAL::HAL
&
hal
=
AP_HAL::get_HAL
();
22
23
class
AP_GPS_NMEA_Test
24
{
25
public
:
26
int32_t
parse_decimal_100
(
const
char
*p)
const
27
{
28
return
AP_GPS_NMEA::_parse_decimal_100
(p);
29
}
30
};
31
32
TEST
(
AP_GPS_NMEA
,
parse_decimal_100
)
33
{
34
AP_GPS_NMEA_Test
test;
35
36
/* Positive numbers with possible round/truncate */
37
ASSERT_EQ(100, test.
parse_decimal_100
(
"1.0"
));
38
ASSERT_EQ(100, test.
parse_decimal_100
(
"1.00"
));
39
ASSERT_EQ(100, test.
parse_decimal_100
(
"1.001"
));
40
ASSERT_EQ(101, test.
parse_decimal_100
(
"1.006"
));
41
42
/* Positive numbers with possible round/truncate with + signal */
43
ASSERT_EQ(100, test.
parse_decimal_100
(
"+1.0"
));
44
ASSERT_EQ(100, test.
parse_decimal_100
(
"+1.00"
));
45
ASSERT_EQ(100, test.
parse_decimal_100
(
"+1.001"
));
46
ASSERT_EQ(101, test.
parse_decimal_100
(
"+1.006"
));
47
48
/* Positive numbers in (0, 1) range, with possible round/truncate */
49
ASSERT_EQ(0, test.
parse_decimal_100
(
"0.0"
));
50
ASSERT_EQ(0, test.
parse_decimal_100
(
"0.00"
));
51
ASSERT_EQ(0, test.
parse_decimal_100
(
"0.001"
));
52
ASSERT_EQ(1, test.
parse_decimal_100
(
"0.006"
));
53
54
/* Negative numbers with possible round/truncate */
55
ASSERT_EQ(-100, test.
parse_decimal_100
(
"-1.0"
));
56
ASSERT_EQ(-100, test.
parse_decimal_100
(
"-1.00"
));
57
ASSERT_EQ(-100, test.
parse_decimal_100
(
"-1.001"
));
58
ASSERT_EQ(-101, test.
parse_decimal_100
(
"-1.006"
));
59
60
/* Integer numbers */
61
ASSERT_EQ(100, test.
parse_decimal_100
(
"1"
));
62
ASSERT_EQ(-100, test.
parse_decimal_100
(
"-1"
));
63
}
64
65
AP_GTEST_MAIN()
AP_GPS_NMEA_Test
Definition:
test_gps.cpp:23
AP_GPS_NMEA
Definition:
AP_GPS_NMEA.h:51
AP_HAL::HAL
Definition:
HAL.h:26
AP_HAL::get_HAL
const HAL & get_HAL()
Definition:
HAL_ChibiOS_Class.cpp:234
AP_GPS_NMEA.h
NMEA protocol parser.
TEST
TEST(AP_GPS_NMEA, parse_decimal_100)
Definition:
test_gps.cpp:32
AP_GPS_NMEA::_parse_decimal_100
static int32_t _parse_decimal_100(const char *p)
Definition:
AP_GPS_NMEA.cpp:135
AP_GPS_NMEA_Test::parse_decimal_100
int32_t parse_decimal_100(const char *p) const
Definition:
test_gps.cpp:26
hal
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition:
test_gps.cpp:21
Generated on Sun Jun 17 2018 14:18:48 for APM:Libraries by
1.8.13