Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / wtf / OptionalTest.cpp
blob7974637fce57ece4ce8a8c4b62cbc0fb18e8ad88
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.
5 #include "config.h"
6 #include "wtf/Optional.h"
8 #include <gtest/gtest.h>
10 namespace WTF {
11 namespace {
13 struct IntBox {
14 IntBox(int n) : number(n) { }
15 int number;
18 class DestructionNotifier {
19 public:
20 DestructionNotifier(bool& flag) : m_flag(flag) { }
21 ~DestructionNotifier() { m_flag = true; }
22 private:
23 bool& m_flag;
26 TEST(OptionalTest, BooleanTest)
28 Optional<int> optional;
29 EXPECT_FALSE(optional);
30 optional.emplace(0);
31 EXPECT_TRUE(optional);
34 TEST(OptionalTest, Dereference)
36 Optional<int> optional;
37 optional.emplace(1);
38 EXPECT_EQ(1, *optional);
40 Optional<IntBox> optionalIntbox;
41 optionalIntbox.emplace(42);
42 EXPECT_EQ(42, optionalIntbox->number);
45 TEST(OptionalTest, DestructorCalled)
47 // Destroying a disengaged optional shouldn't do anything.
49 Optional<DestructionNotifier> optional;
52 // Destroying an engaged optional should call the destructor.
53 bool isDestroyed = false;
55 Optional<DestructionNotifier> optional;
56 optional.emplace(isDestroyed);
57 EXPECT_FALSE(isDestroyed);
59 EXPECT_TRUE(isDestroyed);
62 } // namespace
63 } // namespace WTF