Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: Source/wtf/OptionalTest.cpp

Issue 1129793005: Replace OwnPtr with WTF::Optional for optional recorders. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: merge with master Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "wtf/Optional.h"
7
8 #include <gtest/gtest.h>
9
10 namespace WTF {
11 namespace {
12
13 struct IntBox {
14 IntBox(int n) : number(n) { }
15 int number;
16 };
17
18 class DestructionNotifier {
19 public:
20 DestructionNotifier(bool& flag) : m_flag(flag) { }
21 ~DestructionNotifier() { m_flag = true; }
22 private:
23 bool& m_flag;
24 };
25
26 TEST(OptionalTest, BooleanTest)
27 {
28 Optional<int> optional;
29 EXPECT_FALSE(optional);
30 optional.emplace(0);
31 EXPECT_TRUE(optional);
32 }
33
34 TEST(OptionalTest, Dereference)
35 {
36 Optional<int> optional;
37 optional.emplace(1);
38 EXPECT_EQ(1, *optional);
39
40 Optional<IntBox> optionalIntbox;
41 optionalIntbox.emplace(42);
42 EXPECT_EQ(42, optionalIntbox->number);
43 }
44
45 TEST(OptionalTest, DestructorCalled)
46 {
47 // Destroying a disengaged optional shouldn't do anything.
48 {
49 Optional<DestructionNotifier> optional;
50 }
51
52 // Destroying an engaged optional should call the destructor.
53 bool isDestroyed = false;
54 {
55 Optional<DestructionNotifier> optional;
56 optional.emplace(isDestroyed);
57 EXPECT_FALSE(isDestroyed);
58 }
59 EXPECT_TRUE(isDestroyed);
60 }
61
62 } // namespace
63 } // namespace WTF
OLDNEW
« Source/wtf/Optional.h ('K') | « Source/wtf/Optional.h ('k') | Source/wtf/TypeTraits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698