lazy_constructor.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 
9 TEST(LazyConstructor, Basic)
10 {
11  using ::uavcan::LazyConstructor;
12 
13  LazyConstructor<std::string> a;
14  LazyConstructor<std::string> b;
15 
16  ASSERT_FALSE(a);
17  ASSERT_FALSE(b.isConstructed());
18 
19  /*
20  * Construction
21  */
22  a.destroy(); // no-op
23  a.construct();
24  b.construct<const char*>("Hello world");
25 
26  ASSERT_TRUE(a);
27  ASSERT_TRUE(b.isConstructed());
28 
29  ASSERT_NE(*a, *b);
30  ASSERT_STRNE(a->c_str(), b->c_str());
31 
32  ASSERT_EQ(*a, "");
33  ASSERT_EQ(*b, "Hello world");
34 
35  /*
36  * Copying
37  */
38  a = b; // Assignment operator performs destruction and immediate copy construction
39  ASSERT_EQ(*a, *b);
40  ASSERT_EQ(*a, "Hello world");
41 
42  LazyConstructor<std::string> c(a); // Copy constructor call is forwarded to std::string
43 
44  ASSERT_EQ(*c, *a);
45 
46  *a = "123";
47  ASSERT_NE(*c, *a);
48  ASSERT_EQ(*c, *b);
49 
50  *c = "456";
51  ASSERT_NE(*a, *c);
52  ASSERT_NE(*b, *a);
53  ASSERT_NE(*c, *b);
54 
55  /*
56  * Destruction
57  */
58  ASSERT_TRUE(c);
59  c.destroy();
60  ASSERT_FALSE(c);
61 }
lazy_constructor.hpp
TEST
TEST(LazyConstructor, Basic)
Definition: lazy_constructor.cpp:9


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