Back to index

unity  6.0.0
test_filter.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <glib-object.h>
00003 #include <UnityCore/GLibWrapper.h>
00004 #include <UnityCore/Filter.h>
00005 
00006 using namespace std;
00007 using namespace unity::dash;
00008 using namespace unity;
00009 
00010 namespace
00011 {
00012 
00013 class TestFilter : public ::testing::Test
00014 {
00015 public:
00016   TestFilter()
00017     : model_(dee_sequence_model_new())
00018   {
00019     dee_model_set_schema(model_, "s", "s", "s", "s", "a{sv}", "b", "b", "b", NULL);
00020 
00021     AddIters();
00022   }
00023 
00024   void AddIters()
00025   {
00026     GVariantBuilder b;
00027     g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
00028     GVariant* hints = g_variant_builder_end(&b);
00029 
00030     iter0_ = dee_model_append(model_,
00031                               "ratings",
00032                               "Ratings0",
00033                               "gtk-apply",
00034                               "ratings",
00035                               hints,
00036                               TRUE,
00037                               TRUE,
00038                               FALSE);
00039 
00040     iter1_ = dee_model_append(model_,
00041                               "ratings",
00042                               "Ratings1",
00043                               "gtk-apply",
00044                               "ratings",
00045                               hints,
00046                               TRUE,
00047                               TRUE,
00048                               FALSE);
00049 
00050     iter2_ = dee_model_append(model_,
00051                               "ratings",
00052                               "Ratings2",
00053                               "gtk-apply",
00054                               "ratings",
00055                               hints,
00056                               TRUE,
00057                               TRUE,
00058                               FALSE);
00059   }
00060 
00061   glib::Object<DeeModel> model_;
00062   DeeModelIter* iter0_;
00063   DeeModelIter* iter1_;
00064   DeeModelIter* iter2_;
00065 };
00066 
00067 class FilterRecorder : public Filter
00068 {
00069 public:
00070   FilterRecorder(DeeModel* model, DeeModelIter* iter)
00071     : Filter(model, iter)
00072     , removed_(false)
00073     , updated_(false)
00074   {
00075     removed.connect(sigc::mem_fun(this, &FilterRecorder::OnRemoved));
00076   }
00077 
00078   void Update(Filter::Hints& hints)
00079   {
00080     updated_ = true;
00081   }
00082 
00083   void OnRemoved()
00084   {
00085     removed_ = true;
00086   }
00087 
00088   void Clear()
00089   {}
00090 
00091   bool removed_;
00092   bool updated_;
00093 };
00094 
00095 TEST_F(TestFilter, TestConstruction)
00096 {
00097   FilterRecorder filter(model_, iter0_);
00098 }
00099 
00100 TEST_F(TestFilter, TestConnect)
00101 {
00102   g_debug("a");
00103   FilterRecorder recorder(model_, iter0_);
00104   g_debug("b");
00105 
00106   EXPECT_EQ(recorder.id, "ratings");
00107   EXPECT_EQ(recorder.name, "Ratings0");
00108   EXPECT_EQ(recorder.icon_hint, "gtk-apply");
00109   EXPECT_EQ(recorder.renderer_name, "ratings");
00110   EXPECT_TRUE(recorder.visible);
00111   EXPECT_TRUE(recorder.collapsed);
00112   EXPECT_FALSE(recorder.filtering);
00113 }
00114 
00115 TEST_F(TestFilter, TestChanged)
00116 {
00117   FilterRecorder recorder(model_, iter1_);
00118 
00119   dee_model_set_value(model_, iter1_, 0, g_variant_new("s", "checkbox"));
00120   dee_model_set_value(model_, iter1_, 7, g_variant_new("b", TRUE));
00121 
00122   EXPECT_EQ(recorder.updated_, true);
00123   EXPECT_EQ(recorder.id, "checkbox");
00124   EXPECT_EQ(recorder.name, "Ratings1");
00125   EXPECT_EQ(recorder.icon_hint, "gtk-apply");
00126   EXPECT_EQ(recorder.renderer_name, "ratings");
00127   EXPECT_TRUE(recorder.visible);
00128   EXPECT_TRUE(recorder.collapsed);
00129   EXPECT_TRUE(recorder.filtering);
00130 }
00131 
00132 TEST_F(TestFilter, TestRemoved)
00133 {
00134   FilterRecorder recorder(model_, iter1_);
00135 
00136   dee_model_remove(model_, iter2_);
00137   EXPECT_EQ(recorder.removed_, false);
00138 
00139   dee_model_remove(model_, iter0_);
00140   EXPECT_EQ(recorder.removed_, false);
00141 
00142   dee_model_remove(model_, iter1_);
00143   EXPECT_EQ(recorder.removed_, true);
00144 }
00145 
00146 }