Back to index

unity  6.0.0
test_favorite_store_private.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: Andrea Azzarone <azzaronea@gmail.com>
00018  *
00019  */
00020 
00021 #include <gtest/gtest.h>
00022  
00023 #include "FavoriteStorePrivate.h"
00024 
00025 using namespace unity;
00026 
00027 TEST(TestFavoriteStorePrivate, TestGetNewbies)
00028 {
00029   std::list<std::string> old;
00030   std::list<std::string> fresh;
00031   std::vector<std::string> result;
00032   
00033   old.push_back("a");
00034   old.push_back("b");
00035   old.push_back("c");
00036   old.push_back("d");
00037   
00038   // No change.
00039   fresh.push_back("a");
00040   fresh.push_back("b");
00041   fresh.push_back("c");
00042   fresh.push_back("d");
00043   
00044   result = internal::impl::GetNewbies(old, fresh);
00045   
00046   EXPECT_TRUE(result.empty());
00047   
00048   // Permutation.
00049   fresh.clear();
00050   result.clear();
00051   fresh.push_back("a");
00052   fresh.push_back("c");
00053   fresh.push_back("b");
00054   fresh.push_back("d");
00055   
00056   result = internal::impl::GetNewbies(old, fresh);
00057   
00058   EXPECT_TRUE(result.empty());
00059   
00060   // a b c d -> a c b
00061   fresh.clear();
00062   result.clear();
00063   fresh.push_back("a");
00064   fresh.push_back("c");
00065   fresh.push_back("b");
00066   
00067   result = internal::impl::GetNewbies(old, fresh);
00068         
00069   EXPECT_TRUE(result.empty());
00070   
00071   // a b c d -> a b c d e f
00072   fresh.clear();
00073   result.clear();
00074   fresh.push_back("a");
00075   fresh.push_back("b");
00076   fresh.push_back("c");
00077   fresh.push_back("d");
00078   fresh.push_back("e");
00079   fresh.push_back("f");
00080   
00081   result = internal::impl::GetNewbies(old, fresh);
00082   
00083   EXPECT_EQ(result.size(), 2);
00084   EXPECT_EQ(result[0], "e");
00085   EXPECT_EQ(result[1], "f");
00086   
00087   // a b c d -> a b c e f
00088   fresh.clear();
00089   result.clear();
00090   fresh.push_back("a");
00091   fresh.push_back("b");
00092   fresh.push_back("c");
00093   fresh.push_back("e");
00094   fresh.push_back("f");
00095   
00096   result = internal::impl::GetNewbies(old, fresh);
00097   
00098   EXPECT_EQ(result.size(), 2);
00099   EXPECT_EQ(result[0], "e");
00100   EXPECT_EQ(result[1], "f");
00101 }
00102 
00103 TEST(TestFavoriteStorePrivate, TestGetSignalAddedInfo)
00104 {
00105   std::list<std::string> favs;
00106   std::vector<std::string> newbies;
00107   std::string position;
00108   bool before;
00109   
00110   favs.push_back("a");
00111   favs.push_back("b");
00112   favs.push_back("c");
00113   favs.push_back("d");
00114   favs.push_back("e");
00115   
00116   // b c d e -> a b c d e
00117   newbies.push_back("a");
00118   internal::impl::GetSignalAddedInfo(favs, newbies, "a", position, before);
00119   EXPECT_TRUE(before);
00120   EXPECT_EQ(position, "b");
00121   
00122   // a c d e -> a b c d e
00123   newbies.clear();
00124   newbies.push_back("b");
00125   internal::impl::GetSignalAddedInfo(favs, newbies, "b", position, before);
00126   EXPECT_FALSE(before);
00127   EXPECT_EQ(position, "a");
00128   
00129   // a b d e -> a b c d e
00130   newbies.clear();
00131   newbies.push_back("c");
00132   internal::impl::GetSignalAddedInfo(favs, newbies, "c", position, before);
00133   EXPECT_FALSE(before);
00134   EXPECT_EQ(position, "b");
00135   
00136   // a b c e -> a b c d e
00137   newbies.clear();
00138   newbies.push_back("d");
00139   internal::impl::GetSignalAddedInfo(favs, newbies, "d", position, before);
00140   EXPECT_FALSE(before);
00141   EXPECT_EQ(position, "c");
00142   
00143   // a b c d -> a b c d e
00144   newbies.clear();
00145   newbies.push_back("e");
00146   internal::impl::GetSignalAddedInfo(favs, newbies, "e", position, before);
00147   EXPECT_FALSE(before);
00148   EXPECT_EQ(position, "d");
00149   
00150   // -> b a c
00151   favs.clear();
00152   favs.push_back("b");
00153   favs.push_back("a");
00154   favs.push_back("c");
00155   newbies.clear();
00156   newbies.push_back("a");
00157   newbies.push_back("b");
00158   newbies.push_back("c");
00159   
00160   internal::impl::GetSignalAddedInfo(favs, newbies, "b", position, before);
00161   EXPECT_TRUE(before);
00162   EXPECT_EQ(position, "");
00163   
00164   internal::impl::GetSignalAddedInfo(favs, newbies, "a", position, before);
00165   EXPECT_FALSE(before);
00166   EXPECT_EQ(position, "b");
00167   
00168   internal::impl::GetSignalAddedInfo(favs, newbies, "c", position, before);
00169   EXPECT_FALSE(before);
00170   EXPECT_EQ(position, "a");
00171 }
00172 
00173 
00174 TEST(TestFavoriteStorePrivate, TestGetRemoved)
00175 {
00176   std::list<std::string> old;
00177   std::list<std::string> fresh;
00178   std::vector<std::string> result;
00179   
00180   old.push_back("a");
00181   old.push_back("b");
00182   old.push_back("c");
00183   old.push_back("d");
00184   
00185   // No change.
00186   fresh.push_back("a");
00187   fresh.push_back("b");
00188   fresh.push_back("c");
00189   fresh.push_back("d");
00190   
00191   result = internal::impl::GetRemoved(old, fresh);
00192   
00193   EXPECT_TRUE(result.empty());
00194   
00195   // Permutation.
00196   fresh.clear();
00197   result.clear();
00198   fresh.push_back("a");
00199   fresh.push_back("c");
00200   fresh.push_back("b");
00201   fresh.push_back("d");
00202   
00203   result = internal::impl::GetRemoved(old, fresh);
00204   
00205   EXPECT_TRUE(result.empty());
00206   
00207   // a b c d -> b c
00208   fresh.clear();
00209   result.clear();
00210   fresh.push_back("b");
00211   fresh.push_back("c");
00212   
00213   result = internal::impl::GetRemoved(old, fresh);
00214   
00215   EXPECT_EQ(result.size(), 2);
00216   EXPECT_EQ(result[0], "a");
00217   EXPECT_EQ(result[1], "d");
00218   
00219   // a b c d -> a e f d
00220   fresh.clear();
00221   result.clear();
00222   fresh.push_back("a");
00223   fresh.push_back("e");
00224   fresh.push_back("f");
00225   fresh.push_back("d");
00226   
00227   
00228   result = internal::impl::GetRemoved(old, fresh);
00229   
00230   EXPECT_EQ(result.size(), 2);
00231   EXPECT_EQ(result[0], "b");
00232   EXPECT_EQ(result[1], "c");
00233 }
00234   
00235 
00236 TEST(TestFavoriteStorePrivate, TestNeedToBeReorderedBasic)
00237 {
00238   std::list<std::string> old;
00239   std::list<std::string> fresh;
00240   
00241   old.push_back("a");
00242   old.push_back("b");
00243   old.push_back("c");
00244   old.push_back("d");
00245   
00246   // No change.
00247   fresh.push_back("a");
00248   fresh.push_back("b");
00249   fresh.push_back("c");
00250   fresh.push_back("d");
00251   
00252   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00253   
00254   // Permutation.
00255   fresh.clear();
00256   fresh.push_back("a");
00257   fresh.push_back("c");
00258   fresh.push_back("b");
00259   fresh.push_back("d");
00260   
00261   EXPECT_TRUE(internal::impl::NeedToBeReordered(old, fresh));
00262   
00263   // Empty.
00264   fresh.clear();
00265   
00266   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00267 }
00268  
00269 TEST(TestFavoriteStorePrivate, TestNeedToBeReorderedLess)
00270 {
00271   std::list<std::string> old;
00272   std::list<std::string> fresh;
00273   
00274   old.push_back("a");
00275   old.push_back("b");
00276   old.push_back("c");
00277   old.push_back("d");
00278    
00279   // a b c d -> a b c
00280   fresh.clear();
00281   fresh.push_back("a");
00282   fresh.push_back("b");
00283   fresh.push_back("c");
00284   
00285   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00286   
00287   // a b c d ->  b c d
00288   fresh.clear();
00289   fresh.push_back("b");
00290   fresh.push_back("c");
00291   fresh.push_back("d");
00292   
00293   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00294   
00295   // a b c d -> a b d
00296   fresh.clear();
00297   fresh.push_back("a");
00298   fresh.push_back("b");
00299   fresh.push_back("d");
00300   
00301   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00302   
00303   // a b c d -> a
00304   fresh.clear();
00305   fresh.push_back("a");
00306   
00307   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00308   
00309   // a b c d ->  a d b
00310   fresh.clear();
00311   fresh.push_back("a");
00312   fresh.push_back("d");
00313   fresh.push_back("b");
00314   
00315   EXPECT_TRUE(internal::impl::NeedToBeReordered(old, fresh));
00316   
00317   // a b c d ->  b a c
00318   fresh.clear();
00319   fresh.push_back("b");
00320   fresh.push_back("a");
00321   fresh.push_back("c");
00322   
00323   EXPECT_TRUE(internal::impl::NeedToBeReordered(old, fresh));
00324 }
00325 
00326 TEST(TestFavoriteStorePrivate, TestNeedToBeReorderedPlus)
00327 {
00328   std::list<std::string> old;
00329   std::list<std::string> fresh;
00330   
00331   old.push_back("a");
00332   old.push_back("b");
00333   old.push_back("c");
00334   old.push_back("d");
00335    
00336   // All new elements.
00337   fresh.clear();
00338   fresh.push_back("e");
00339   fresh.push_back("f");
00340   fresh.push_back("g");
00341   fresh.push_back("h");
00342   
00343   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00344   
00345   // a b c d -> a b c d e
00346   fresh.clear();
00347   fresh.push_back("a");
00348   fresh.push_back("b");
00349   fresh.push_back("c");
00350   fresh.push_back("d");
00351   fresh.push_back("e");
00352   
00353   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00354   
00355   // a b c d -> a b e c d
00356   fresh.clear();
00357   fresh.push_back("a");
00358   fresh.push_back("b");
00359   fresh.push_back("e");
00360   fresh.push_back("c");
00361   fresh.push_back("d");
00362   
00363   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00364   
00365   // a b c d -> a b e d c
00366   fresh.clear();
00367   fresh.push_back("a");
00368   fresh.push_back("b");
00369   fresh.push_back("e");
00370   fresh.push_back("d");
00371   fresh.push_back("c");
00372   
00373   EXPECT_TRUE(internal::impl::NeedToBeReordered(old, fresh));
00374   
00375   // a b c d -> f a b c d
00376   fresh.clear();
00377   fresh.push_back("f");
00378   fresh.push_back("a");
00379   fresh.push_back("b");
00380   fresh.push_back("c");
00381   fresh.push_back("d");
00382   
00383   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00384 }
00385 
00386 TEST(TestFavoriteStorePrivate, TestNeedToBeReorderedMixed)
00387 {
00388   std::list<std::string> old;
00389   std::list<std::string> fresh;
00390   
00391   old.push_back("a");
00392   old.push_back("b");
00393   old.push_back("c");
00394   old.push_back("d");
00395   
00396   // a b c d -> b f c g h
00397   fresh.clear();
00398   fresh.push_back("b");
00399   fresh.push_back("f");
00400   fresh.push_back("c");
00401   fresh.push_back("g");
00402   fresh.push_back("h");
00403   
00404   EXPECT_FALSE(internal::impl::NeedToBeReordered(old, fresh));
00405   
00406   
00407   // a b c d -> c f b g h
00408   fresh.clear();
00409   fresh.push_back("c");
00410   fresh.push_back("f");
00411   fresh.push_back("b");
00412   fresh.push_back("g");
00413   fresh.push_back("h");
00414   
00415   EXPECT_TRUE(internal::impl::NeedToBeReordered(old, fresh));
00416 }
00417