Main Page
Namespaces
Namespace List
Namespace Members
All
b
c
d
f
h
o
s
t
Functions
Typedefs
Classes
Class List
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
~
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
w
x
~
Variables
b
c
d
e
f
g
i
l
m
r
s
t
v
Typedefs
Enumerations
Enumerator
Files
File List
File Members
All
_
a
c
f
g
l
m
p
r
t
Functions
Variables
Macros
test
test_string.cpp
Go to the documentation of this file.
1
// Bring in my package's API, which is what I'm testing
2
#include <
socketcan_interface/string.h
>
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
}
main
int main(int argc, char **argv)
Definition:
test_string.cpp:50
can::Frame
Definition:
interface.h:62
can::tostring
std::string tostring(const Header &h, bool lc)
Definition:
string.cpp:78
can::Header::fullid
unsigned int fullid() const
Definition:
interface.h:31
can::Header::is_extended
unsigned int is_extended
frame uses 29 bit CAN identifier
Definition:
interface.h:26
string.h
can::Header::is_rtr
unsigned int is_rtr
frame is a remote transfer request
Definition:
interface.h:25
TEST
TEST(StringTest, stringconversion)
Definition:
test_string.cpp:8
can::toframe
Frame toframe(const std::string &s)
Definition:
string.cpp:119
can::Header::is_error
unsigned int is_error
marks an error frame (only used internally)
Definition:
interface.h:24
can::Frame::isValid
bool isValid() const
Definition:
interface.h:68
socketcan_interface
Author(s): Mathias Lüdtke
autogenerated on Wed Mar 2 2022 00:52:25