Back to index

unity  6.0.0
test_ratings_filter.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <UnityCore/GLibWrapper.h>
00003 #include <UnityCore/RatingsFilter.h>
00004 
00005 using namespace std;
00006 using namespace unity::dash;
00007 using namespace unity;
00008 
00009 namespace
00010 {
00011 
00012 class TestRatingsFilter : public ::testing::Test
00013 {
00014 public:
00015   TestRatingsFilter()
00016     : model_(dee_sequence_model_new())
00017   {
00018     dee_model_set_schema(model_, "s", "s", "s", "s", "a{sv}", "b", "b", "b", NULL);
00019 
00020     AddIters();
00021   }
00022 
00023   void AddIters()
00024   {
00025     GVariantBuilder b;
00026     g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
00027     g_variant_builder_add(&b, "{sv}", "rating", g_variant_new("d", 0.6));
00028 
00029     iter_ = dee_model_append(model_,
00030                              "ratings",
00031                              "Ratings0",
00032                              "gtk-apply",
00033                              "ratings",
00034                              g_variant_builder_end(&b),
00035                              TRUE,
00036                              TRUE,
00037                              FALSE);
00038   }
00039 
00040   glib::Object<DeeModel> model_;
00041   DeeModelIter* iter_;
00042 };
00043 
00044 TEST_F(TestRatingsFilter, TestConstruction)
00045 {
00046   RatingsFilter::Ptr ratings(new RatingsFilter(model_, iter_));
00047   EXPECT_FLOAT_EQ(ratings->rating, 0.6);
00048 }
00049 
00050 TEST_F(TestRatingsFilter, TestSetting)
00051 {
00052   RatingsFilter::Ptr ratings(new RatingsFilter(model_, iter_));
00053   ratings->rating = 1.0f;
00054 
00055   GVariant* row_value = dee_model_get_value(model_, iter_, FilterColumn::RENDERER_STATE);
00056 
00057   GVariantIter iter;
00058   g_variant_iter_init(&iter, row_value);
00059 
00060   char* key = NULL;
00061   GVariant* value = NULL;
00062   float rating = 0.0f;
00063   while (g_variant_iter_loop(&iter, "{sv}", &key, &value))
00064   {
00065     if (g_strcmp0(key, "rating") == 0)
00066     {
00067       rating = g_variant_get_double(value);
00068       break;
00069     }
00070   }
00071 
00072   EXPECT_FLOAT_EQ(ratings->rating, rating);
00073   EXPECT_TRUE(ratings->filtering);
00074 
00075   g_variant_unref(row_value);
00076 }
00077 
00078 
00079 }