Back to index

unity  6.0.0
test_switcher_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 "SwitcherModel.h"
00024 #include "MockLauncherIcon.h"
00025 #include "AbstractLauncherIcon.h"
00026 
00027 #include <vector>
00028 
00029 
00030 using namespace unity::switcher;
00031 using unity::launcher::AbstractLauncherIcon;
00032 using unity::launcher::MockLauncherIcon;
00033 
00034 namespace
00035 {
00036 
00037 TEST(TestSwitcherModel, TestConstructor)
00038 {
00039   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00040   AbstractLauncherIcon::Ptr second(new MockLauncherIcon());
00041   std::vector<AbstractLauncherIcon::Ptr> icons;
00042   icons.push_back(first);
00043   icons.push_back(second);
00044 
00045   SwitcherModel::Ptr model(new SwitcherModel(icons));
00046 
00047   EXPECT_EQ(model->Size(), 2);
00048   EXPECT_EQ(model->Selection(), first);
00049   EXPECT_EQ(model->LastSelection(), first);
00050   EXPECT_EQ(model->SelectionIndex(), 0);
00051   EXPECT_EQ(model->LastSelectionIndex(), 0);
00052 }
00053 
00054 TEST(TestSwitcherModel, TestSelection)
00055 {
00056   std::vector<AbstractLauncherIcon::Ptr> icons;
00057   AbstractLauncherIcon::Ptr first(new MockLauncherIcon());
00058   AbstractLauncherIcon::Ptr second(new MockLauncherIcon());
00059   AbstractLauncherIcon::Ptr third(new MockLauncherIcon());
00060   AbstractLauncherIcon::Ptr fourth(new MockLauncherIcon());
00061 
00062   icons.push_back(first);
00063   icons.push_back(second);
00064   icons.push_back(third);
00065   icons.push_back(fourth);
00066 
00067   SwitcherModel::Ptr model(new SwitcherModel(icons));
00068 
00069   EXPECT_EQ(model->Size(), 4);
00070   EXPECT_EQ(model->Selection(), first);
00071 
00072   model->Next();
00073   EXPECT_EQ(model->Selection(), second);
00074   EXPECT_EQ(model->LastSelection(), first);
00075   model->Next();
00076   EXPECT_EQ(model->Selection(), third);
00077   EXPECT_EQ(model->LastSelection(), second);
00078   model->Next();
00079   EXPECT_EQ(model->Selection(), fourth);
00080   EXPECT_EQ(model->LastSelection(), third);
00081   model->Next();
00082   EXPECT_EQ(model->Selection(), first);
00083   EXPECT_EQ(model->LastSelection(), fourth);
00084   model->Next();
00085   EXPECT_EQ(model->Selection(), second);
00086   EXPECT_EQ(model->LastSelection(), first);
00087   model->Prev();
00088   EXPECT_EQ(model->Selection(), first);
00089   EXPECT_EQ(model->LastSelection(), second);
00090   model->Prev();
00091   EXPECT_EQ(model->Selection(), fourth);
00092   EXPECT_EQ(model->LastSelection(), first);
00093 
00094   model->Select(2);
00095   EXPECT_EQ(model->Selection(), third);
00096   EXPECT_EQ(model->LastSelection(), fourth);
00097 
00098   model->Select(first);
00099   EXPECT_EQ(model->Selection(), first);
00100   EXPECT_EQ(model->LastSelection(), third);
00101 }
00102 
00103 }