blob: 348d7ddfae57cbe36fc9a3a1fe1189b941f68402 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18#include <string>
19
20#include "Maybe.h"
21
22namespace aapt {
23
24struct Dummy {
25 Dummy() {
26 std::cerr << "Constructing Dummy " << (void *) this << std::endl;
27 }
28
29 Dummy(const Dummy& rhs) {
30 std::cerr << "Copying Dummy " << (void *) this << " from " << (const void*) &rhs << std::endl;
31 }
32
33 Dummy(Dummy&& rhs) {
34 std::cerr << "Moving Dummy " << (void *) this << " from " << (void*) &rhs << std::endl;
35 }
36
37 ~Dummy() {
38 std::cerr << "Destroying Dummy " << (void *) this << std::endl;
39 }
40};
41
42TEST(MaybeTest, MakeNothing) {
43 Maybe<int> val = make_nothing<int>();
44 EXPECT_FALSE(val);
45
46 Maybe<std::string> val2 = make_nothing<std::string>();
47 EXPECT_FALSE(val2);
48
49 val2 = make_nothing<std::string>();
50 EXPECT_FALSE(val2);
51}
52
53TEST(MaybeTest, MakeSomething) {
54 Maybe<int> val = make_value(23);
55 ASSERT_TRUE(val);
56 EXPECT_EQ(23, val.value());
57
58 Maybe<std::string> val2 = make_value(std::string("hey"));
59 ASSERT_TRUE(val2);
60 EXPECT_EQ(std::string("hey"), val2.value());
61}
62
63TEST(MaybeTest, Lifecycle) {
64 Maybe<Dummy> val = make_nothing<Dummy>();
65
66 Maybe<Dummy> val2 = make_value(Dummy());
67}
68
69} // namespace aapt