void InputEventsWestonTest::SetUp()
{
  WestonTest::SetUp();
  
  clientLibrary.Load();
  eglLibrary.Load();
  xkbCommonLibrary.Load();
  
  xkbContext.reset(CXKBKeymap::CreateXKBContext(xkbCommonLibrary),
                   boost::bind(&IDllXKBCommon::xkb_context_unref,
                               &xkbCommonLibrary, _1));
  keymap.reset(new CXKBKeymap(
                 xkbCommonLibrary, 
                 CXKBKeymap::CreateXKBKeymapFromNames(xkbCommonLibrary,
                                                      xkbContext.get(),
                                                      "evdev",
                                                      "pc105",
                                                      "us",
                                                      "",
                                                      "")));
  
  display.reset(new xw::Display(clientLibrary));
  queue.reset(CreateEventQueue());
  registry.reset(new xw::Registry(clientLibrary,
                                  display->GetWlDisplay(),
                                  *this));
  loop.reset(new xwe::Loop(listener, *queue));

  /* Wait for the seat, shell, compositor to appear */
  WaitForSynchronize();
  
  ASSERT_TRUE(input.get() != NULL);
  ASSERT_TRUE(compositor.get() != NULL);
  ASSERT_TRUE(shell.get() != NULL);
  ASSERT_TRUE(xbmcWayland.get() != NULL);
  
  /* Wait for input devices to appear etc */
  WaitForSynchronize();
  
  surface.reset(new xw::Surface(clientLibrary,
                                compositor->CreateSurface()));
  shellSurface.reset(new xw::ShellSurface(clientLibrary,
                                          shell->CreateShellSurface(
                                            surface->GetWlSurface())));
  openGLSurface.reset(new xw::OpenGLSurface(eglLibrary,
                                            surface->GetWlSurface(),
                                            SurfaceWidth,
                                            SurfaceHeight));

  wl_shell_surface_set_toplevel(shellSurface->GetWlShellSurface());
  surface->Commit();
}
TEST_F(TestScopeFilter, TestFilterCheckOption)
{
    Filters::Ptr filters = scope_->filters;
    WaitForSynchronize(filters, 4);

    CheckOptionFilter::Ptr filter = static_pointer_cast<CheckOptionFilter>(filters->FilterAtIndex(0));
    EXPECT_EQ(filter->id, "categories");
    EXPECT_EQ(filter->name, "Categories");
    EXPECT_EQ(filter->icon_hint, "");
    EXPECT_EQ(filter->renderer_name, "filter-checkoption");
    EXPECT_TRUE(filter->visible);
    EXPECT_FALSE(filter->collapsed);
    EXPECT_FALSE(filter->filtering);

    CheckOptionFilter::CheckOptions options = filter->options;
    EXPECT_EQ(options.size(), (unsigned int)3);

    EXPECT_EQ(options[0]->id, "cat0");
    EXPECT_EQ(options[0]->name, "Category 0");
    EXPECT_EQ(options[0]->icon_hint, "gtk-cdrom");
    EXPECT_FALSE(options[0]->active);

    EXPECT_EQ(options[1]->id, "cat1");
    EXPECT_EQ(options[1]->name, "Category 1");
    EXPECT_EQ(options[1]->icon_hint, "gtk-directory");
    EXPECT_FALSE(options[1]->active);

    EXPECT_EQ(options[2]->id, "cat2");
    EXPECT_EQ(options[2]->name, "Category 2");
    EXPECT_EQ(options[2]->icon_hint, "gtk-clear");
    EXPECT_FALSE(options[2]->active);
}
TEST_F(TestScopeFilter, TestFilterMultiRange)
{
    Filters::Ptr filters = scope_->filters;
    WaitForSynchronize(filters, 4);

    MultiRangeFilter::Ptr filter = static_pointer_cast<MultiRangeFilter>(filters->FilterAtIndex(3));
    EXPECT_EQ(filter->id, "size");
    EXPECT_EQ(filter->name, "Size");
    EXPECT_EQ(filter->icon_hint, "");
    std::string tmp = filter->renderer_name;
    EXPECT_EQ(filter->renderer_name, "filter-multirange");
    EXPECT_TRUE(filter->visible);
    EXPECT_TRUE(filter->collapsed);
    EXPECT_FALSE(filter->filtering);

    MultiRangeFilter::Options options = filter->options;
    EXPECT_EQ(options.size(), (unsigned int)4);

    EXPECT_EQ(options[0]->id, "1MB");
    EXPECT_EQ(options[0]->name, "1MB");
    EXPECT_EQ(options[0]->icon_hint, "");
    EXPECT_FALSE(options[0]->active);

    EXPECT_EQ(options[1]->id, "10MB");
    EXPECT_EQ(options[1]->name, "10MB");
    EXPECT_EQ(options[1]->icon_hint, "");
    EXPECT_FALSE(options[1]->active);

    EXPECT_EQ(options[2]->id, "100MB");
    EXPECT_EQ(options[2]->name, "100MB");
    EXPECT_EQ(options[2]->icon_hint, "");
    EXPECT_FALSE(options[2]->active);
}
TEST_F(TestScopeFilter, TestFilterRadioOption)
{
    Filters::Ptr filters = scope_->filters;
    WaitForSynchronize(filters, 4);

    RadioOptionFilter::Ptr filter = static_pointer_cast<RadioOptionFilter>(filters->FilterAtIndex(1));
    EXPECT_EQ(filter->id, "when");
    EXPECT_EQ(filter->name, "When");
    EXPECT_EQ(filter->icon_hint, "");
    EXPECT_EQ(filter->renderer_name, "filter-radiooption");
    EXPECT_TRUE(filter->visible);
    EXPECT_FALSE(filter->collapsed);
    EXPECT_FALSE(filter->filtering);

    RadioOptionFilter::RadioOptions options = filter->options;
    EXPECT_EQ(options.size(), (unsigned int)3);

    EXPECT_EQ(options[0]->id, "today");
    EXPECT_EQ(options[0]->name, "Today");
    EXPECT_EQ(options[0]->icon_hint, "");
    EXPECT_FALSE(options[0]->active);

    EXPECT_EQ(options[1]->id, "yesterday");
    EXPECT_EQ(options[1]->name, "Yesterday");
    EXPECT_EQ(options[1]->icon_hint, "");
    EXPECT_FALSE(options[1]->active);

    EXPECT_EQ(options[2]->id, "lastweek");
    EXPECT_EQ(options[2]->name, "Last Week");
    EXPECT_EQ(options[2]->icon_hint, "");
    EXPECT_FALSE(options[2]->active);
}
TEST_F(TestScopeFilter, TestFilterRadioOptionLogic)
{
    Filters::Ptr filters = scope_->filters;
    WaitForSynchronize(filters, 4);

    RadioOptionFilter::Ptr filter = static_pointer_cast<RadioOptionFilter>(filters->FilterAtIndex(1));
    RadioOptionFilter::RadioOptions options = filter->options;

    EXPECT_FALSE (filter->filtering);
    EXPECT_FALSE (options[0]->active);
    EXPECT_FALSE (options[1]->active);
    EXPECT_FALSE (options[2]->active);

    options[0]->active = true;
    options[0]->active = false;
    EXPECT_FALSE (filter->filtering);
    EXPECT_FALSE (options[0]->active);
    EXPECT_FALSE (options[1]->active);
    EXPECT_FALSE (options[2]->active);

    options[0]->active = true;
    EXPECT_TRUE (filter->filtering);
    EXPECT_TRUE (options[0]->active);
    EXPECT_FALSE (options[1]->active);
    EXPECT_FALSE (options[2]->active);

    options[1]->active = true;
    EXPECT_TRUE (filter->filtering);
    EXPECT_FALSE (options[0]->active);
    EXPECT_TRUE (options[1]->active);
    EXPECT_FALSE (options[2]->active);

    options[2]->active = true;
    EXPECT_TRUE (filter->filtering);
    EXPECT_FALSE (options[0]->active);
    EXPECT_FALSE (options[1]->active);
    EXPECT_TRUE (options[2]->active);

    filter->Clear();
    EXPECT_FALSE (filter->filtering);
    EXPECT_FALSE (options[0]->active);
    EXPECT_FALSE (options[1]->active);
    EXPECT_FALSE (options[2]->active);
}
TEST_F(TestScopeFilter, TestFilterRatings)
{
    Filters::Ptr filters = scope_->filters;
    WaitForSynchronize(filters, 4);

    RatingsFilter::Ptr filter = static_pointer_cast<RatingsFilter>(filters->FilterAtIndex(2));
    EXPECT_EQ(filter->id, "ratings");
    EXPECT_EQ(filter->name, "Ratings");
    EXPECT_EQ(filter->icon_hint, "");
    std::string tmp = filter->renderer_name;
    EXPECT_EQ(filter->renderer_name, "filter-ratings");
    EXPECT_TRUE(filter->visible);
    EXPECT_FALSE(filter->collapsed);
    EXPECT_FALSE(filter->filtering);

    EXPECT_FLOAT_EQ(filter->rating, 0.0f);
    filter->rating = 0.5f;
    EXPECT_FLOAT_EQ(filter->rating, 0.5f);
}