Back to index

unity  6.0.0
test_launcher_model.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 Canonical Ltd.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as published
00006  * by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * version 3 along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>
00016  *
00017  * Authored by: Jason Smith <jason.smith@canonical.com>
00018  *
00019  */
00020 
00021 #include <gtest/gtest.h>
00022 
00023 #include "LauncherModel.h"
00024 #include "MockLauncherIcon.h"
00025 #include "AbstractLauncherIcon.h"
00026 
00027 #include <vector>
00028 
00029 
00030 using namespace unity::launcher;
00031 
00032 namespace
00033 {
00034 
00035 class EventListener
00036 {
00037   public:
00038     EventListener()
00039     {
00040       icon_added = false;
00041       icon_removed = false;
00042     }
00043 
00044     void OnIconAdded (AbstractLauncherIcon::Ptr icon)
00045     {
00046       icon_added = true;
00047     }
00048 
00049     void OnIconRemoved (AbstractLauncherIcon::Ptr icon)
00050     {
00051       icon_removed = true;
00052     }
00053 
00054     bool icon_added;
00055     bool icon_removed; 
00056 };
00057 //bool seen_result;
00058 
00059 TEST(TestLauncherModel, TestConstructor)
00060 {
00061   LauncherModel::Ptr model(new LauncherModel());
00062   EXPECT_EQ(model->Size(), 0);
00063 }
00064 
00065 TEST(TestLauncherModel, TestAdd)
00066 {
00067   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00068   LauncherModel::Ptr model(new LauncherModel());
00069 
00070   EXPECT_EQ(model->Size(), 0);
00071   model->AddIcon(first);
00072   EXPECT_EQ(model->Size(), 1);
00073 }
00074 
00075 TEST(TestLauncherModel, TestRemove)
00076 {
00077   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00078   LauncherModel::Ptr model(new LauncherModel());
00079 
00080   EXPECT_EQ(model->Size(), 0);
00081   model->AddIcon(first);
00082   EXPECT_EQ(model->Size(), 1);
00083   model->RemoveIcon(first);
00084   EXPECT_EQ(model->Size(), 0);
00085 }
00086 
00087 TEST(TestLauncherModel, TestAddSignal)
00088 {
00089   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00090   LauncherModel::Ptr model(new LauncherModel());
00091 
00092   EventListener *listener = new EventListener();
00093 
00094   model->icon_added.connect(sigc::mem_fun(listener, &EventListener::OnIconAdded));
00095   model->AddIcon(first);
00096   EXPECT_EQ(listener->icon_added, true);
00097 
00098   delete listener;
00099 }
00100 
00101 TEST(TestLauncherModel, TestRemoveSignal)
00102 {
00103   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00104   LauncherModel::Ptr model(new LauncherModel());
00105 
00106   EventListener *listener = new EventListener();
00107 
00108   model->icon_removed.connect(sigc::mem_fun(listener, &EventListener::OnIconRemoved));
00109   model->AddIcon(first);
00110   EXPECT_EQ(listener->icon_removed, false);
00111   model->RemoveIcon(first);
00112   EXPECT_EQ(listener->icon_removed, true);
00113 
00114   delete listener;
00115 }
00116 
00117 TEST(TestLauncherModel, TestSort)
00118 {
00119   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00120   AbstractLauncherIcon::Ptr second(new MockLauncherIcon());
00121   AbstractLauncherIcon::Ptr third(new MockLauncherIcon());
00122   AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());
00123 
00124   LauncherModel::Ptr model(new LauncherModel());
00125 
00126   third->SetSortPriority(0);
00127   model->AddIcon(third);
00128 
00129   first->SetSortPriority(-1);
00130   model->AddIcon(first);
00131 
00132   fourth->SetSortPriority(2);
00133   model->AddIcon(fourth);
00134 
00135   second->SetSortPriority(0);
00136   model->AddIcon(second);
00137 
00138   LauncherModel::iterator it;
00139   it = model->begin();
00140 
00141   EXPECT_EQ(first, *it);
00142   it++;
00143   EXPECT_EQ(second, *it);
00144   it++;
00145   EXPECT_EQ(third, *it);
00146   it++;
00147   EXPECT_EQ(fourth, *it);
00148 }
00149 
00150 TEST(TestLauncherModel, TestReorderBefore)
00151 {
00152   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00153   AbstractLauncherIcon::Ptr second(new MockLauncherIcon());
00154   AbstractLauncherIcon::Ptr third(new MockLauncherIcon());
00155   AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());
00156 
00157   LauncherModel::Ptr model(new LauncherModel());
00158 
00159   first->SetSortPriority(0);
00160   second->SetSortPriority(1);
00161   third->SetSortPriority(2);
00162   fourth->SetSortPriority(3);
00163 
00164   model->AddIcon(first);
00165   model->AddIcon(second);
00166   model->AddIcon(third);
00167   model->AddIcon(fourth);
00168 
00169   model->ReorderBefore(third, second, false);
00170 
00171   LauncherModel::iterator it;
00172   it = model->begin();
00173 
00174   EXPECT_EQ(first, *it);
00175   it++;
00176   EXPECT_EQ(third, *it);
00177   it++;
00178   EXPECT_EQ(second, *it);
00179   it++;
00180   EXPECT_EQ(fourth, *it);
00181 }
00182 
00183 TEST(TestLauncherModel, TestReorderSmart)
00184 {
00185   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00186   AbstractLauncherIcon::Ptr second(new MockLauncherIcon());
00187   AbstractLauncherIcon::Ptr third(new MockLauncherIcon());
00188   AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());
00189 
00190   LauncherModel::Ptr model(new LauncherModel());
00191 
00192   first->SetSortPriority(0);
00193   second->SetSortPriority(1);
00194   third->SetSortPriority(2);
00195   fourth->SetSortPriority(3);
00196 
00197   model->AddIcon(first);
00198   model->AddIcon(second);
00199   model->AddIcon(third);
00200   model->AddIcon(fourth);
00201 
00202   model->ReorderSmart(third, second, false);
00203 
00204   LauncherModel::iterator it;
00205   it = model->begin();
00206 
00207   EXPECT_EQ(first, *it);
00208   it++;
00209   EXPECT_EQ(third, *it);
00210   it++;
00211   EXPECT_EQ(second, *it);
00212   it++;
00213   EXPECT_EQ(fourth, *it);
00214 }
00215 
00216 }