1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2013 Canonical Ltd
5
* This program 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.
9
* This program 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.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by: Marco Trevisan <marco.trevisan@canonical.com>
20
#include <gmock/gmock.h>
21
#include <UnityCore/GLibWrapper.h>
23
using namespace unity::glib;
28
TEST(TestGLibCancellable, Construction)
30
Cancellable cancellable;
32
ASSERT_TRUE(cancellable.Get().IsType(G_TYPE_CANCELLABLE));
33
EXPECT_FALSE(cancellable.IsCancelled());
34
EXPECT_FALSE(cancellable.IsCancelled(error));
37
TEST(TestGLibCancellable, Destruction)
39
Object<GCancellable> canc_obj;
41
Cancellable cancellable;
42
canc_obj = cancellable.Get();
45
EXPECT_TRUE(g_cancellable_is_cancelled(canc_obj));
48
TEST(TestGLibCancellable, Cancel)
50
Cancellable cancellable;
53
EXPECT_TRUE(cancellable.IsCancelled());
56
TEST(TestGLibCancellable, CancelWithError)
58
Cancellable cancellable;
62
EXPECT_TRUE(cancellable.IsCancelled(error));
63
EXPECT_FALSE(error.Message().empty());
66
TEST(TestGLibCancellable, Reset)
68
Cancellable cancellable;
71
ASSERT_TRUE(cancellable.IsCancelled());
73
auto obj = cancellable.Get();
75
EXPECT_FALSE(cancellable.IsCancelled());
76
EXPECT_EQ(obj, cancellable.Get());
79
TEST(TestGLibCancellable, Renew)
81
Cancellable cancellable;
84
ASSERT_TRUE(cancellable.IsCancelled());
86
auto obj = cancellable.Get();
88
EXPECT_FALSE(cancellable.IsCancelled());
89
EXPECT_NE(obj, cancellable.Get());
92
TEST(TestGLibCancellable, OperatorGCancellable)
94
Cancellable cancellable;
96
EXPECT_EQ(g_cancellable_is_cancelled(cancellable), cancellable.IsCancelled());
98
g_cancellable_cancel(cancellable);
99
EXPECT_EQ(g_cancellable_is_cancelled(cancellable), cancellable.IsCancelled());
102
TEST(TestGLibCancellable, Equality)
104
Cancellable cancellable;
106
ASSERT_EQ(cancellable.Get(), cancellable);
107
ASSERT_EQ(cancellable.Get().RawPtr(), cancellable);
110
TEST(TestGLibCancellable, NotEquality)
112
Cancellable cancellable1;
113
Cancellable cancellable2;
115
ASSERT_NE(cancellable1, cancellable2);
116
ASSERT_NE(cancellable1.Get(), cancellable2);
117
ASSERT_NE(cancellable1.Get().RawPtr(), cancellable2);