Back to index

unity  6.0.0
test_launcher_entry_remote.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2012 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Marco Trevisan (TreviƱo) <3v1n0@ubuntu.com>
00018  */
00019 
00020 #include <gmock/gmock.h>
00021 
00022 #include "LauncherEntryRemote.h"
00023 
00024 using namespace std;
00025 using namespace unity;
00026 using namespace testing;
00027 
00028 namespace
00029 {
00030 
00031 GVariant* BuildVariantParameters(std::string const& app_uri = "app_uri",
00032                                  std::string const& emblem = "emblem",
00033                                  bool emblem_visible = false,
00034                                  long long count = 0,
00035                                  bool count_visible = false,
00036                                  double progress = 0.0f,
00037                                  bool progress_visible = false,
00038                                  bool urgent = false,
00039                                  std::string const& quicklist_path = "/my/quicklist/path")
00040 {
00041   GVariantBuilder b;
00042 
00043   g_variant_builder_init(&b, G_VARIANT_TYPE ("a{sv}"));
00044   g_variant_builder_add(&b, "{sv}", "emblem", g_variant_new_string(emblem.c_str()));
00045   g_variant_builder_add(&b, "{sv}", "emblem-visible", g_variant_new_boolean(emblem_visible));
00046   g_variant_builder_add(&b, "{sv}", "count", g_variant_new_int64(count));
00047   g_variant_builder_add(&b, "{sv}", "count-visible", g_variant_new_boolean(count_visible));
00048   g_variant_builder_add(&b, "{sv}", "progress", g_variant_new_double(progress));
00049   g_variant_builder_add(&b, "{sv}", "progress-visible", g_variant_new_boolean(progress_visible));
00050   g_variant_builder_add(&b, "{sv}", "urgent", g_variant_new_boolean(urgent));
00051   g_variant_builder_add(&b, "{sv}", "quicklist", g_variant_new_string(quicklist_path.c_str()));
00052 
00053   return g_variant_new("(sa{sv})", app_uri.c_str(), &b);
00054 }
00055 
00056 TEST(TestLauncherEntryRemote, DummyConstruction)
00057 {
00058   LauncherEntryRemote entry("TestName", nullptr);
00059 
00060   EXPECT_EQ(entry.DBusName(), "TestName");
00061   EXPECT_TRUE(entry.AppUri().empty());
00062   EXPECT_TRUE(entry.Emblem().empty());
00063   EXPECT_EQ(entry.Count(), 0);
00064   EXPECT_EQ(entry.Progress(), 0.0f);
00065   EXPECT_THAT(entry.Quicklist().RawPtr(), IsNull());
00066   EXPECT_FALSE(entry.EmblemVisible());
00067   EXPECT_FALSE(entry.CountVisible());
00068   EXPECT_FALSE(entry.ProgressVisible());
00069   EXPECT_FALSE(entry.Urgent());
00070 }
00071 
00072 TEST(TestLauncherEntryRemote, Construction)
00073 {
00074   LauncherEntryRemote entry("TestName", BuildVariantParameters());
00075 
00076   EXPECT_EQ(entry.DBusName(), "TestName");
00077   EXPECT_EQ(entry.AppUri(), "app_uri");
00078   EXPECT_EQ(entry.Emblem(), "emblem");
00079   EXPECT_EQ(entry.Count(), 0);
00080   EXPECT_EQ(entry.Progress(), 0.0f);
00081   EXPECT_THAT(entry.Quicklist().RawPtr(), NotNull());
00082   EXPECT_FALSE(entry.EmblemVisible());
00083   EXPECT_FALSE(entry.CountVisible());
00084   EXPECT_FALSE(entry.ProgressVisible());
00085   EXPECT_FALSE(entry.Urgent());
00086 }
00087 
00088 TEST(TestLauncherEntryRemote, CustomConstruction)
00089 {
00090   GVariant* parameters;
00091   parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
00092                                       true, true, "/My/DBus/Menu/For/QL");
00093   LauncherEntryRemote entry("CustomName", parameters);
00094 
00095   EXPECT_EQ(entry.DBusName(), "CustomName");
00096   EXPECT_EQ(entry.AppUri(), "Uri");
00097   EXPECT_EQ(entry.Emblem(), "TestEmblem");
00098   EXPECT_EQ(entry.Count(), 55);
00099   EXPECT_EQ(entry.Progress(), 31.12f);
00100   EXPECT_THAT(entry.Quicklist().RawPtr(), NotNull());
00101   EXPECT_TRUE(entry.EmblemVisible());
00102   EXPECT_TRUE(entry.CountVisible());
00103   EXPECT_TRUE(entry.ProgressVisible());
00104   EXPECT_TRUE(entry.Urgent());
00105 }
00106 
00107 TEST(TestLauncherEntryRemote, UpdateFromOther)
00108 {
00109   LauncherEntryRemote entry1("Entry1", BuildVariantParameters("AppURI1"));
00110 
00111   ASSERT_EQ(entry1.DBusName(), "Entry1");
00112   ASSERT_EQ(entry1.AppUri(), "AppURI1");
00113   auto old_ql1 = entry1.Quicklist();
00114   ASSERT_THAT(old_ql1.RawPtr(), NotNull());
00115 
00116   GVariant* parameters;
00117   parameters = BuildVariantParameters("Uri2", "TestEmblem", false, 5, true, 0.12f,
00118                                       true, false, "/My/DBus/Menu/For/QL");
00119 
00120   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00121   ASSERT_EQ(entry2->AppUri(), "Uri2");
00122 
00123   entry1.Update(entry2);
00124 
00125   EXPECT_EQ(entry1.DBusName(), "Entry2");
00126   EXPECT_EQ(entry1.AppUri(), "AppURI1");
00127   EXPECT_EQ(entry1.Emblem(), "TestEmblem");
00128   EXPECT_EQ(entry1.Count(), 5);
00129   EXPECT_EQ(entry1.Progress(), 0.12f);
00130   EXPECT_THAT(entry1.Quicklist().RawPtr(), NotNull());
00131   EXPECT_NE(old_ql1, entry1.Quicklist());
00132   EXPECT_FALSE(entry1.EmblemVisible());
00133   EXPECT_TRUE(entry1.CountVisible());
00134   EXPECT_TRUE(entry1.ProgressVisible());
00135   EXPECT_FALSE(entry1.Urgent());
00136 }
00137 
00138 TEST(TestLauncherEntryRemote, UpdateFromVariantIter)
00139 {
00140   LauncherEntryRemote entry1("Entry1", BuildVariantParameters("AppURI1"));
00141 
00142   ASSERT_EQ(entry1.DBusName(), "Entry1");
00143   ASSERT_EQ(entry1.AppUri(), "AppURI1");
00144   auto old_ql1 = entry1.Quicklist();
00145   ASSERT_THAT(old_ql1.RawPtr(), NotNull());
00146 
00147   GVariant* parameters;
00148   parameters = BuildVariantParameters("Uri2", "TestEmblem", false, 5, true, 0.12f,
00149                                       true, false, "/My/DBus/Menu/For/QL");
00150 
00151   gchar* app_uri;
00152   GVariantIter* prop_iter;
00153   g_variant_get(parameters, "(&sa{sv})", &app_uri, &prop_iter);
00154   entry1.Update(prop_iter);
00155   g_variant_iter_free(prop_iter);
00156 
00157   EXPECT_EQ(entry1.DBusName(), "Entry1");
00158   EXPECT_EQ(entry1.AppUri(), "AppURI1");
00159   EXPECT_EQ(entry1.Emblem(), "TestEmblem");
00160   EXPECT_EQ(entry1.Count(), 5);
00161   EXPECT_EQ(entry1.Progress(), 0.12f);
00162   EXPECT_THAT(entry1.Quicklist().RawPtr(), NotNull());
00163   EXPECT_NE(old_ql1, entry1.Quicklist());
00164   EXPECT_FALSE(entry1.EmblemVisible());
00165   EXPECT_TRUE(entry1.CountVisible());
00166   EXPECT_TRUE(entry1.ProgressVisible());
00167   EXPECT_FALSE(entry1.Urgent());
00168 }
00169 
00170 TEST(TestLauncherEntryRemote, ChangeDBusName)
00171 {
00172   LauncherEntryRemote entry("Entry", BuildVariantParameters("AppURI"));
00173 
00174   bool name_changed = false;
00175   std::string old_name;
00176   entry.dbus_name_changed.connect([&] (LauncherEntryRemote*, std::string s) {
00177     name_changed = true;
00178     old_name = s;
00179   });
00180 
00181   auto old_ql = entry.Quicklist();
00182   ASSERT_THAT(old_ql.RawPtr(), NotNull());
00183   ASSERT_EQ(entry.DBusName(), "Entry");
00184 
00185   entry.SetDBusName("NewEntryName");
00186   ASSERT_EQ(entry.DBusName(), "NewEntryName");
00187 
00188   EXPECT_THAT(entry.Quicklist().RawPtr(), IsNull());
00189   EXPECT_NE(old_ql, entry.Quicklist());
00190 
00191   EXPECT_TRUE(name_changed);
00192   EXPECT_EQ(old_name, "Entry");
00193 }
00194 
00195 TEST(TestLauncherEntryRemote, EmblemChangedSignal)
00196 {
00197   GVariant* parameters;
00198   parameters = BuildVariantParameters("Uri", "TestEmblem1", true, 55, true, 31.12f,
00199                                       true, true, "/My/DBus/Menu/For/QL");
00200 
00201   LauncherEntryRemote entry1("Entry1", parameters);
00202 
00203   bool value_changed = false;
00204   entry1.emblem_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
00205 
00206   parameters = BuildVariantParameters("Uri", "TestEmblem2", true, 55, true, 31.12f,
00207                                       true, true, "/My/DBus/Menu/For/QL");
00208 
00209   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00210 
00211   ASSERT_EQ(entry1.Emblem(), "TestEmblem1");
00212 
00213   entry1.Update(entry2);
00214 
00215   EXPECT_TRUE(value_changed);
00216   EXPECT_EQ(entry1.Emblem(), "TestEmblem2");
00217 }
00218 
00219 TEST(TestLauncherEntryRemote, CountChangedSignal)
00220 {
00221   GVariant* parameters;
00222   parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
00223                                       true, true, "/My/DBus/Menu/For/QL");
00224 
00225   LauncherEntryRemote entry1("Entry1", parameters);
00226 
00227   bool value_changed = false;
00228   entry1.count_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
00229 
00230   parameters = BuildVariantParameters("Uri", "TestEmblem", true, 155, true, 31.12f,
00231                                       true, true, "/My/DBus/Menu/For/QL");
00232 
00233   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00234 
00235   ASSERT_EQ(entry1.Count(), 55);
00236 
00237   entry1.Update(entry2);
00238 
00239   EXPECT_TRUE(value_changed);
00240   EXPECT_EQ(entry1.Count(), 155);
00241 }
00242 
00243 TEST(TestLauncherEntryRemote, ProgressChangedSignal)
00244 {
00245   GVariant* parameters;
00246   parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 0.12f,
00247                                       true, true, "/My/DBus/Menu/For/QL");
00248 
00249   LauncherEntryRemote entry1("Entry1", parameters);
00250 
00251   bool value_changed = false;
00252   entry1.progress_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
00253 
00254   parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
00255                                       true, true, "/My/DBus/Menu/For/QL");
00256 
00257   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00258 
00259   ASSERT_EQ(entry1.Progress(), 0.12f);
00260 
00261   entry1.Update(entry2);
00262 
00263   EXPECT_TRUE(value_changed);
00264   EXPECT_EQ(entry1.Progress(), 31.12f);
00265 }
00266 
00267 TEST(TestLauncherEntryRemote, QuicklistChangedSignal)
00268 {
00269   GVariant* parameters;
00270   parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
00271                                       true, true, "/My/DBus/Menu/For/QL1");
00272 
00273   LauncherEntryRemote entry1("Entry1", parameters);
00274 
00275   bool value_changed = false;
00276   entry1.quicklist_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
00277 
00278   parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
00279                                       true, true, "/My/DBus/Menu/For/QL2");
00280 
00281   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00282 
00283   auto old_ql1 = entry1.Quicklist();
00284   ASSERT_THAT(old_ql1.RawPtr(), NotNull());
00285 
00286   entry1.Update(entry2);
00287 
00288   EXPECT_TRUE(value_changed);
00289   EXPECT_NE(entry1.Quicklist(), old_ql1);
00290   EXPECT_EQ(entry1.Quicklist(), entry2->Quicklist());
00291 }
00292 
00293 TEST(TestLauncherEntryRemote, EmblemVisibilityChanged)
00294 {
00295   GVariant* parameters;
00296   parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, true, 31.12f,
00297                                       true, true, "/My/DBus/Menu/For/QL");
00298 
00299   LauncherEntryRemote entry1("Entry1", parameters);
00300 
00301   bool value_changed = false;
00302   entry1.emblem_visible_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
00303 
00304   parameters = BuildVariantParameters("Uri", "TestEmblem", true, 55, true, 31.12f,
00305                                       true, true, "/My/DBus/Menu/For/QL");
00306 
00307   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00308 
00309   ASSERT_FALSE(entry1.EmblemVisible());
00310 
00311   entry1.Update(entry2);
00312 
00313   EXPECT_TRUE(value_changed);
00314   EXPECT_TRUE(entry1.EmblemVisible());
00315 }
00316 
00317 TEST(TestLauncherEntryRemote, CountVisibilityChanged)
00318 {
00319   GVariant* parameters;
00320   parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
00321                                       true, true, "/My/DBus/Menu/For/QL");
00322 
00323   LauncherEntryRemote entry1("Entry1", parameters);
00324 
00325   bool value_changed = false;
00326   entry1.count_visible_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
00327 
00328   parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, true, 31.12f,
00329                                       true, true, "/My/DBus/Menu/For/QL");
00330 
00331   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00332 
00333   ASSERT_FALSE(entry1.CountVisible());
00334 
00335   entry1.Update(entry2);
00336 
00337   EXPECT_TRUE(value_changed);
00338   EXPECT_TRUE(entry1.CountVisible());
00339 }
00340 
00341 TEST(TestLauncherEntryRemote, ProgressVisibilityChanged)
00342 {
00343   GVariant* parameters;
00344   parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
00345                                       false, true, "/My/DBus/Menu/For/QL");
00346 
00347   LauncherEntryRemote entry1("Entry1", parameters);
00348 
00349   bool value_changed = false;
00350   entry1.progress_visible_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
00351 
00352   parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
00353                                       true, true, "/My/DBus/Menu/For/QL");
00354 
00355   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00356 
00357   ASSERT_FALSE(entry1.ProgressVisible());
00358 
00359   entry1.Update(entry2);
00360 
00361   EXPECT_TRUE(value_changed);
00362   EXPECT_TRUE(entry1.ProgressVisible());
00363 }
00364 
00365 TEST(TestLauncherEntryRemote, UrgentChanged)
00366 {
00367   GVariant* parameters;
00368   parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
00369                                       false, false, "/My/DBus/Menu/For/QL");
00370 
00371   LauncherEntryRemote entry1("Entry1", parameters);
00372 
00373   bool value_changed = false;
00374   entry1.urgent_changed.connect([&] (LauncherEntryRemote*) { value_changed = true; });
00375 
00376   parameters = BuildVariantParameters("Uri", "TestEmblem", false, 55, false, 31.12f,
00377                                       false, true, "/My/DBus/Menu/For/QL");
00378 
00379   LauncherEntryRemote::Ptr entry2(new LauncherEntryRemote("Entry2", parameters));
00380 
00381   ASSERT_FALSE(entry1.Urgent());
00382 
00383   entry1.Update(entry2);
00384 
00385   EXPECT_TRUE(value_changed);
00386   EXPECT_TRUE(entry1.Urgent());
00387 }
00388 
00389 } // Namespace