char_array_formatter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3  */
4 
5 #include <gtest/gtest.h>
7 
8 using uavcan::Array;
17 
19 {
21  A8 a;
22 
24  ASSERT_STREQ("", f.getArray().c_str());
25 
26  f.write("Don't %s.", "Panic");
27  ASSERT_STREQ("Don't Panic.", f.getArray().c_str());
28 
29  f.write(" abc%idef ", 123);
30  ASSERT_STREQ("Don't Panic. abc123def ", f.getArray().c_str());
31 
32  f.write("%g", 0.0);
33  ASSERT_STREQ("Don't Panic. abc123def 0", f.getArray().c_str());
34 
35  a.clear();
36  ASSERT_STREQ("", f.getArray().c_str());
37 
38  f.write("123456789");
39  ASSERT_STREQ("123456789", f.getArray().c_str());
40 }
41 
42 #if !defined(UAVCAN_CPP_VERSION) || !defined(UAVCAN_CPP11)
43 # error UAVCAN_CPP_VERSION
44 #endif
45 
46 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
47 
49 {
51  A8 a;
52 
54 
55  f.write(
56  "%% char='%*' double='%*' long='%*' unsigned long='%*' int='%s' long double='%*' bool='%*' const char='%*' %%",
57  '%', -12.3456, -123456789123456789L, 987654321, -123456789, 0.000000001L, true, "Don't Panic.");
58 
59  static const std::string Reference =
60  "% char='%' double='-12.3456' long='-123456789123456789' unsigned long='987654321' int='-123456789' "
61  "long double='1e-09' bool='1' const char='Don't Pani"; // few chars truncated!
62 
63  ASSERT_STREQ(Reference.c_str(), f.getArray().c_str());
64 
65  a.clear();
66 
67  f.write("");
68  ASSERT_STREQ("", f.getArray().c_str());
69 
70  f.write("%%"); // Nothing to format --> "%%" is not expanded
71  ASSERT_STREQ("%%", f.getArray().c_str());
72 
73  f.write("%*", "Test", 123, true); // Extra args ignored
74  ASSERT_STREQ("%%Test", f.getArray().c_str());
75 
76  f.write("%% %* %* %% %*", true); // Insufficient args are OK; second "%%" is not expanded
77  ASSERT_STREQ("%%Test% 1 %* %% %*", f.getArray().c_str());
78 }
79 
80 #endif
uavcan::SignednessSigned
@ SignednessSigned
Definition: integer_spec.hpp:17
TEST
TEST(CharArrayFormatter, Basic)
Definition: char_array_formatter.cpp:18
uavcan::ArrayModeStatic
@ ArrayModeStatic
Definition: array.hpp:35
f
f
uavcan::Array
Definition: array.hpp:424
uavcan::CharArrayFormatter
Definition: char_array_formatter.hpp:25
uavcan::ArrayModeDynamic
@ ArrayModeDynamic
Definition: array.hpp:35
uavcan::CastModeTruncate
@ CastModeTruncate
Definition: type_util.hpp:17
uavcan::IntegerSpec
Definition: integer_spec.hpp:24
uavcan::SignednessUnsigned
@ SignednessUnsigned
Definition: integer_spec.hpp:17
char_array_formatter.hpp
uavcan::CastModeSaturate
@ CastModeSaturate
Definition: type_util.hpp:17


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:02