Revert "Device/Driver/LX: Add small delay after baud rate change"
[xcsoar.git] / test / src / TestCSVLine.cpp
blob689c62a965c4ce85ce5b944d721ef9b99617905b
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "IO/CSVLine.hpp"
24 #include "TestUtil.hpp"
26 #include <cstring>
27 #include <string>
29 static void
30 Test1()
32 CSVLine line("1,2,x,4,5,6,7,8,9,10");
34 // Test read(int)
35 ok1(line.Read(-1) == 1);
37 // Test rest()
38 const auto rest = line.Rest();
39 ok1(std::string(rest.begin(), rest.end()) == "2,x,4,5,6,7,8,9,10");
41 // Test skip()
42 ok1(line.Skip() == 1);
44 // Test skip(int)
45 line.Skip(3);
46 ok1(line.Read(-1) == 6);
48 // Test read_first_char()
49 ok1(line.ReadFirstChar() == '7');
51 // Test read(char)
52 char temp[10];
53 line.Read(temp, 10);
54 ok1(strcmp(temp, "8") == 0);
56 // Test read_compare(char)
57 ok1(line.ReadCompare("9"));
59 // Test read(long)
60 ok1(line.Read(-1l) == 10l);
62 // Test default-value at line-end
63 ok1(line.Read(11) == 11);
65 // Test default-value at line-end
66 int temp_int;
67 ok1(!line.ReadChecked(temp_int));
70 static void
71 Test2()
73 CSVLine line("A0,4.5555,4.5555,42,0,1.337,42.42,42,xxx");
75 // Test read_hex()
76 ok1(line.ReadHex(-1) == 160);
78 // Test read(double)
79 ok1(equals(fixed(line.Read(0.0)), 4.5555));
81 // Test read(fixed)
82 ok1(equals(line.Read(fixed(0)), 4.5555));
84 // Test read(bool)
85 ok1(line.Read(false) == true);
86 ok1(line.Read(false) == false);
88 // Test read_checked()
89 double temp_double;
90 ok1(line.ReadChecked(temp_double) && equals(fixed(temp_double), 1.337));
92 fixed temp_fixed;
93 ok1(line.ReadChecked(temp_fixed) && equals(temp_fixed, 42.42));
95 int temp_int;
96 ok1(line.ReadChecked(temp_int) && temp_int == 42);
97 ok1(!line.ReadChecked(temp_int) && temp_int == 42);
101 main(int argc, char **argv)
103 plan_tests(19);
105 Test1();
106 Test2();
108 return exit_status();