~azzar1/unity/fix-839717-5.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <gtest/gtest.h>
#include <UnityCore/GLibWrapper.h>
#include <UnityCore/RatingsFilter.h>

using namespace std;
using namespace unity::dash;
using namespace unity;

namespace
{

class TestRatingsFilter : public ::testing::Test
{
public:
  TestRatingsFilter()
    : model_(dee_sequence_model_new())
  {
    dee_model_set_schema(model_, "s", "s", "s", "s", "a{sv}", "b", "b", "b", NULL);

    AddIters();
  }

  void AddIters()
  {
    GVariantBuilder b;
    g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
    g_variant_builder_add(&b, "{sv}", "rating", g_variant_new("d", 0.6));

    iter_ = dee_model_append(model_,
                             "ratings",
                             "Ratings0",
                             "gtk-apply",
                             "ratings",
                             g_variant_builder_end(&b),
                             TRUE,
                             TRUE,
                             FALSE);
  }

  glib::Object<DeeModel> model_;
  DeeModelIter* iter_;
};

TEST_F(TestRatingsFilter, TestConstruction)
{
  RatingsFilter::Ptr ratings(new RatingsFilter(model_, iter_));
  EXPECT_FLOAT_EQ(ratings->rating, 0.6);
}

TEST_F(TestRatingsFilter, TestSetting)
{
  RatingsFilter::Ptr ratings(new RatingsFilter(model_, iter_));
  ratings->rating = 1.0f;

  GVariant* row_value = dee_model_get_value(model_, iter_, FilterColumn::RENDERER_STATE);

  GVariantIter iter;
  g_variant_iter_init(&iter, row_value);

  char* key = NULL;
  GVariant* value = NULL;
  float rating = 0.0f;
  while (g_variant_iter_loop(&iter, "{sv}", &key, &value))
  {
    if (g_strcmp0(key, "rating") == 0)
    {
      rating = g_variant_get_double(value);
      break;
    }
  }

  EXPECT_FLOAT_EQ(ratings->rating, rating);
  EXPECT_TRUE(ratings->filtering);

  g_variant_unref(row_value);
}


}