MRPT  2.0.1
static_string_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
13 
14 using namespace mrpt::typemeta;
15 
16 TEST(StaticString, ctor)
17 {
18  constexpr string_literal<3> a = "foo";
19  (void)(a);
20 
21  constexpr auto b = literal("foo");
22  (void)(b);
23 }
24 
25 TEST(StaticString, concat_literals)
26 {
27  constexpr auto a = literal("foo");
28  constexpr auto b = literal("bar");
29  // In GCC7 these ones can be "constexpr", but that fails in MSVC 2017 (!)
30  auto ab = a + b;
31 
32  static_assert(ab.size() == 6, "***");
33  EXPECT_EQ(ab[0], 'f');
34  EXPECT_EQ(ab[5], 'r');
35 }
36 
37 TEST(StaticString, concat_multi)
38 {
39  constexpr auto a = literal("foo");
40  constexpr auto b = literal("bar");
41  auto ab = a + b;
42  auto ba = b + a;
43 
44  // test sstring + literal:
45  auto abc = ab + literal("more");
46  static_assert(abc.size() == (6 + 4), "***");
47 
48  // test sstring + sstring:
49  auto abba = ab + ba;
50  static_assert(abba.size() == 2 * 6, "***");
51 
52  // Test c_str():
53  const char* s = abba.c_str();
54  const char* s2 = static_cast<const char*>(abba);
55  EXPECT_EQ(s, s2);
56 
57  // Test cast to "const char*" () operator:
58  const char* s3 = static_cast<const char*>(a);
59  EXPECT_EQ(a.c_str(), s3);
60 }
61 
63 {
64  constexpr auto a = num_to_string<13>::value;
65  (void)(a);
66 }
constexpr auto literal(const char(&lit)[N_PLUS_1]) -> string_literal< N_PLUS_1 - 1 >
Definition: static_string.h:46
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
TEST(StaticString, ctor)
constexpr string representation of a number.
Definition: num_to_string.h:44



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020