~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to tests/test_glib_cancellable.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-04-26 12:41:09 UTC
  • Revision ID: mail@3v1n0.net-20130426124109-t3b2shjah2omiqa2
Unity: Remove all the views, but the Shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
 
/*
3
 
 * Copyright (C) 2013 Canonical Ltd
4
 
 *
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.
8
 
 *
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.
13
 
 *
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/>.
16
 
 *
17
 
 * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
18
 
 */
19
 
 
20
 
#include <gmock/gmock.h>
21
 
#include <UnityCore/GLibWrapper.h>
22
 
 
23
 
using namespace unity::glib;
24
 
 
25
 
namespace
26
 
{
27
 
 
28
 
TEST(TestGLibCancellable, Construction)
29
 
{
30
 
  Cancellable cancellable;
31
 
  Error error;
32
 
  ASSERT_TRUE(cancellable.Get().IsType(G_TYPE_CANCELLABLE));
33
 
  EXPECT_FALSE(cancellable.IsCancelled());
34
 
  EXPECT_FALSE(cancellable.IsCancelled(error));
35
 
}
36
 
 
37
 
TEST(TestGLibCancellable, Destruction)
38
 
{
39
 
  Object<GCancellable> canc_obj;
40
 
  {
41
 
    Cancellable cancellable;
42
 
    canc_obj = cancellable.Get();
43
 
  }
44
 
 
45
 
  EXPECT_TRUE(g_cancellable_is_cancelled(canc_obj));
46
 
}
47
 
 
48
 
TEST(TestGLibCancellable, Cancel)
49
 
{
50
 
  Cancellable cancellable;
51
 
 
52
 
  cancellable.Cancel();
53
 
  EXPECT_TRUE(cancellable.IsCancelled());
54
 
}
55
 
 
56
 
TEST(TestGLibCancellable, CancelWithError)
57
 
{
58
 
  Cancellable cancellable;
59
 
  Error error;
60
 
 
61
 
  cancellable.Cancel();
62
 
  EXPECT_TRUE(cancellable.IsCancelled(error));
63
 
  EXPECT_FALSE(error.Message().empty());
64
 
}
65
 
 
66
 
TEST(TestGLibCancellable, Reset)
67
 
{
68
 
  Cancellable cancellable;
69
 
 
70
 
  cancellable.Cancel();
71
 
  ASSERT_TRUE(cancellable.IsCancelled());
72
 
 
73
 
  auto obj = cancellable.Get();
74
 
  cancellable.Reset();
75
 
  EXPECT_FALSE(cancellable.IsCancelled());
76
 
  EXPECT_EQ(obj, cancellable.Get());
77
 
}
78
 
 
79
 
TEST(TestGLibCancellable, Renew)
80
 
{
81
 
  Cancellable cancellable;
82
 
 
83
 
  cancellable.Cancel();
84
 
  ASSERT_TRUE(cancellable.IsCancelled());
85
 
 
86
 
  auto obj = cancellable.Get();
87
 
  cancellable.Renew();
88
 
  EXPECT_FALSE(cancellable.IsCancelled());
89
 
  EXPECT_NE(obj, cancellable.Get());
90
 
}
91
 
 
92
 
TEST(TestGLibCancellable, OperatorGCancellable)
93
 
{
94
 
  Cancellable cancellable;
95
 
 
96
 
  EXPECT_EQ(g_cancellable_is_cancelled(cancellable), cancellable.IsCancelled());
97
 
 
98
 
  g_cancellable_cancel(cancellable);
99
 
  EXPECT_EQ(g_cancellable_is_cancelled(cancellable), cancellable.IsCancelled());
100
 
}
101
 
 
102
 
TEST(TestGLibCancellable, Equality)
103
 
{
104
 
  Cancellable cancellable;
105
 
 
106
 
  ASSERT_EQ(cancellable.Get(), cancellable);
107
 
  ASSERT_EQ(cancellable.Get().RawPtr(), cancellable);
108
 
}
109
 
 
110
 
TEST(TestGLibCancellable, NotEquality)
111
 
{
112
 
  Cancellable cancellable1;
113
 
  Cancellable cancellable2;
114
 
 
115
 
  ASSERT_NE(cancellable1, cancellable2);
116
 
  ASSERT_NE(cancellable1.Get(), cancellable2);
117
 
  ASSERT_NE(cancellable1.Get().RawPtr(), cancellable2);
118
 
}
119
 
 
120
 
} // Namespace