Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/plugin/PlaceholderTest.cpp

Issue 29323611: Issue #1234, #2058 - Rewrite log facility, improving thread implementation
Patch Set: rebase only Created July 27, 2016, 9:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/plugin/ActiveQueueTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include <gtest/gtest.h>
18 #include "../../src/plugin/ActiveQueue.h"
19 #include <ostream>
20 #include <memory>
21
22 // The C compiler version for VS2012 is 17.00
23 #if defined(_MSC_VER) && _MSC_VER <= 1700
24 #define DELETED
25 #else
26 #define DELETED =delete
27 #endif
28
29 /**
30 * Class with only a copy constructor for an instantiation test.
31 */
32 template<class T>
33 struct MinimalCopy
34 {
35 T value;
36
37 MinimalCopy() DELETED;
38 MinimalCopy(MinimalCopy&&) DELETED;
39 MinimalCopy& operator=(const MinimalCopy&) DELETED;
40 MinimalCopy& operator=(MinimalCopy&&) DELETED;
41
42 MinimalCopy(T x)
43 : value(x)
44 {}
45
46 MinimalCopy(const MinimalCopy& t)
47 : value(t.value)
48 {}
49 };
50
51 /**
52 * Class with only a move constructor for an instantiation test.
53 */
54 template<class T>
55 struct MinimalMove
56 {
57 std::unique_ptr<int> a; // Not really needed, but illustrative
58 T value;
59
60 MinimalMove() DELETED;
61 MinimalMove(const MinimalMove&) DELETED;
62 MinimalMove& operator=(const MinimalMove&) DELETED;
63 MinimalMove& operator=(MinimalMove&&) DELETED;
64
65 MinimalMove(T x)
66 : a(nullptr), value(x)
67 {}
68
69 MinimalMove(MinimalMove&& x)
70 : a(std::move(x.a)), value(std::move(x.value))
71 {}
72 };
73
74 /*
75 * These are mostly a compilation tests.
76 * They check that the Placeholder only needs a single constructor, copy or move , to instantiate.
77 *
78 * For VS2012, using C++03 syntax, failure to instantiate the 'Placeholder' temp late
79 * will show up as a link error for one of declared-but-not-defined members.
80 * Using C++11 syntax, it will show up as a compile error.
81 *
82 * Extra blocks in test code illustrate the anticipated use of 'Placeholder'.
83 */
84
85 /*
86 * Placeholder works with simple intrinsic types.
87 */
88 TEST(Placeholder, Int)
89 {
90 Placeholder<int> x;
91 {
92 x.Construct(42);
93 }
94 {
95 ASSERT_EQ(42, x.Object());
96 }
97 }
98
99 /*
100 * Placeholder works with only a copy constructor.
101 */
102 TEST(Placeholder, MinimalCopy)
103 {
104 typedef MinimalCopy<int> T;
105 Placeholder<T> x;
106 {
107 T a(42);
108 x.Construct(a); // Can't use a temporary because MinimalCopy has no move con structor (arbitrarily)
109 }
110 int y = 1;
111 {
112 y = x.Object().value;
113 }
114 ASSERT_EQ(42, y);
115 }
116
117 TEST(Placeholder, MinimalMove)
118 {
119 typedef MinimalMove<int> T;
120 Placeholder<T> x;
121 {
122 x.Construct(std::move(T(42)));
123 }
124 int y = 1;
125 {
126 y = x.Object().value;
127 }
128 ASSERT_EQ(42, y);
129 }
130
131 TEST(Placeholder, MinimalMoveParameter)
132 {
133 typedef MinimalMove<int> T;
134 Placeholder<T> x;
135 {
136 x.Construct(std::move(T(42)));
137 }
138 int y = 1;
139 {
140 y = [&](T&& t)
141 {
142 return t.value;
143 }(std::move(x.Object()));
144 }
145 ASSERT_EQ(42, y);
146 }
147
OLDNEW
« no previous file with comments | « test/plugin/ActiveQueueTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld