dsp3000_parser_utest.cpp
Go to the documentation of this file.
1 
3 #include "kvh/dsp3000_parser.h"
4 #include "gtest/gtest.h"
5 
6 TEST(KvhDsp3000Parser, normalInput)
7 {
8  char input[] = " 0.015733 1\r\n";
9 
10  ParseDsp3000Data parsed_data(parse_dsp3000(input, sizeof(input) - 1));
11  EXPECT_EQ(true, parsed_data.did_parser_succeed);
12  EXPECT_EQ(0, parsed_data.new_buffer_length);
13  EXPECT_FLOAT_EQ(0.015733, parsed_data.value);
14  EXPECT_EQ(true, parsed_data.is_sensor_data_valid);
15 }
16 
17 TEST(KvhDsp3000Parser, normalInputButNoSpace)
18 {
19  char input[] = "0.015733 1\r\n";
20 
21  ParseDsp3000Data parsed_data(parse_dsp3000(input, sizeof(input) - 1));
22  EXPECT_EQ(false, parsed_data.did_parser_succeed);
23  EXPECT_EQ(0, parsed_data.new_buffer_length);
24 }
25 
26 TEST(KvhDsp3000Parser, normalInputButNoSpaceAndEnd)
27 {
28  char input[] = "0.015733 1";
29 
30  ParseDsp3000Data parsed_data(parse_dsp3000(input, sizeof(input) - 1));
31  EXPECT_EQ(false, parsed_data.did_parser_succeed);
32  EXPECT_EQ(sizeof(input) - 1, parsed_data.new_buffer_length);
33 }
34 
35 TEST(KvhDsp3000Parser, onlyValue)
36 {
37  int constexpr DATA_LEN = 17;
38  static char const *const DATA = " 0.015733 ";
39  char input[DATA_LEN + 1];
40 
41  memcpy(input, DATA, DATA_LEN + 1);
42  ParseDsp3000Data parsed_data(parse_dsp3000(input, DATA_LEN));
43  EXPECT_EQ(false, parsed_data.did_parser_succeed);
44  EXPECT_EQ(DATA_LEN, parsed_data.new_buffer_length);
45  ASSERT_LT(parsed_data.new_buffer_length, sizeof(input));
46  ASSERT_GE(parsed_data.new_buffer_length, 0);
47  input[parsed_data.new_buffer_length] = '\0';
48  EXPECT_STREQ(DATA, input);
49 }
50 
51 TEST(KvhDsp3000Parser, onlyValid)
52 {
53  char input[] = " 1\r\n";
54 
55  ParseDsp3000Data parsed_data(parse_dsp3000(input, sizeof(input) - 1));
56  EXPECT_EQ(false, parsed_data.did_parser_succeed);
57  EXPECT_EQ(0, parsed_data.new_buffer_length);
58 }
59 
60 TEST(KvhDsp3000Parser, onlyValidThenNormal)
61 {
62  static char const *const EXPECTED_INTERMEDIATE_DATA = " 0.015733 1\r\n";
63  char input[] = " 1\r\n 0.015733 1\r\n";
64 
65  ParseDsp3000Data const parsed_data_valid(parse_dsp3000(input, sizeof(input) - 1));
66  EXPECT_EQ(false, parsed_data_valid.did_parser_succeed);
67  EXPECT_EQ(strlen(EXPECTED_INTERMEDIATE_DATA), parsed_data_valid.new_buffer_length);
68  ASSERT_LT(parsed_data_valid.new_buffer_length, sizeof(input));
69  ASSERT_GE(parsed_data_valid.new_buffer_length, 0);
70  input[parsed_data_valid.new_buffer_length] = '\0';
71  ASSERT_STREQ(input, EXPECTED_INTERMEDIATE_DATA);
72  ParseDsp3000Data const parsed_data_normal(parse_dsp3000(input, parsed_data_valid.new_buffer_length));
73  EXPECT_EQ(true, parsed_data_normal.did_parser_succeed);
74  EXPECT_EQ(0, parsed_data_normal.new_buffer_length);
75  EXPECT_FLOAT_EQ(0.015733, parsed_data_normal.value);
76  EXPECT_EQ(true, parsed_data_normal.is_sensor_data_valid);
77 }
78 
79 int main(int argc, char **argv)
80 {
81  testing::InitGoogleTest(&argc, argv);
82  return RUN_ALL_TESTS();
83 }
ParseDsp3000Data parse_dsp3000(char *buffer, int buffer_size)
Copyright Autonomous Solutions Inc. 2016.
Definition: dsp3000_parser.h:8
int main(int argc, char **argv)
TEST(KvhDsp3000Parser, normalInput)
Copyright Autonomous Solutions Inc. 2016.


kvh_drivers
Author(s): Jeff Schmidt, Geoffrey Viola
autogenerated on Mon Jun 10 2019 13:45:24