test_string.cpp
Go to the documentation of this file.
1 // Bring in my package's API, which is what I'm testing
3 
4 // Bring in gtest
5 #include <gtest/gtest.h>
6 
7 
8 TEST(StringTest, stringconversion)
9 {
10  const std::string s1("123#1234567812345678");
11  can::Frame f1 = can::toframe(s1);
12  EXPECT_EQ(s1, can::tostring(f1, true));
13 
14  const std::string s2("1337#1234567812345678");
15  can::Frame f2 = can::toframe(s2);
16  EXPECT_FALSE(f2.isValid());
17 
18  const std::string s3("80001337#1234567812345678");
19  const std::string s4("00001337#1234567812345678");
20 
21  can::Frame f3 = can::toframe(s3);
22  EXPECT_EQ(f3.fullid(), 0x80001337);
23  EXPECT_TRUE(f3.isValid());
24  EXPECT_TRUE(f3.is_extended);
25  EXPECT_EQ(s4, can::tostring(f3, true)); // 8000 is converted to 0000
26 
27  can::Frame f4 = can::toframe(s4);
28  EXPECT_EQ(f4.fullid(), 0x80001337);
29  EXPECT_TRUE(f4.isValid());
30  EXPECT_TRUE(f4.is_extended);
31  EXPECT_EQ(s4, can::tostring(f4, true));
32 
33  const std::string s5("20001337#1234567812345678");
34  can::Frame f5 = can::toframe(s5);
35  EXPECT_EQ(f5.fullid(), 0xA0001337);
36  EXPECT_TRUE(f5.isValid());
37  EXPECT_TRUE(f5.is_error);
38  EXPECT_EQ(s5, can::tostring(f5, true));
39 
40  const std::string s6("40001337#1234567812345678");
41  can::Frame f6 = can::toframe(s6);
42  EXPECT_EQ(f6.fullid(), 0xC0001337);
43  EXPECT_TRUE(f6.isValid());
44  EXPECT_TRUE(f6.is_rtr);
45  EXPECT_EQ(s6, can::tostring(f6, true));
46 
47 }
48 
49 // Run all the tests that were declared with TEST()
50 int main(int argc, char **argv){
51 testing::InitGoogleTest(&argc, argv);
52 return RUN_ALL_TESTS();
53 }
bool isValid() const
Definition: interface.h:68
std::string tostring(const Header &h, bool lc)
Definition: string.cpp:78
unsigned int is_error
marks an error frame (only used internally)
Definition: interface.h:24
unsigned int fullid() const
Definition: interface.h:31
int main(int argc, char **argv)
Definition: test_string.cpp:50
Frame toframe(const std::string &s)
Definition: string.cpp:119
unsigned int is_extended
frame uses 29 bit CAN identifier
Definition: interface.h:26
TEST(StringTest, stringconversion)
Definition: test_string.cpp:8
unsigned int is_rtr
frame is a remote transfer request
Definition: interface.h:25


socketcan_interface
Author(s): Mathias Lüdtke
autogenerated on Mon Feb 28 2022 23:28:00