@@ -31,6 +31,8 @@
3131#include "filter.h"
3232#include "multirangefilter.h"
3333#include "combinedfilteroption.h"
34+#include "checkoptionfilter.h"
35+#include "radiooptionfilter.h"
3436
3537void FiltersBindingsTest::initTestCase()
3638{
@@ -57,13 +59,28 @@ DeeModel* FiltersBindingsTest::createFilterModel()
5759}
5860
5961void FiltersBindingsTest::createMultiRangeFilter(DeeModel *model, const std::string &id, const std::string &name, int optionCount)
62+{
63+ createFilter(model, "filter-multirange", id, name, optionCount);
64+}
65+
66+void FiltersBindingsTest::createRadioOptionFilter(DeeModel *model, const std::string &id, const std::string &name, int optionCount)
67+{
68+ createFilter(model, "filter-radiooption", id, name, optionCount);
69+}
70+
71+void FiltersBindingsTest::createCheckOptionFilter(DeeModel *model, const std::string &id, const std::string &name, int optionCount)
72+{
73+ createFilter(model, "filter-checkoption", id, name, optionCount);
74+}
75+
76+void FiltersBindingsTest::createFilter(DeeModel *model, const std::string &renderer, const std::string &id, const std::string &name, int optionCount)
6077{
6178 GVariant* row[8];
6279
6380 row[0] = g_variant_new_string(id.c_str());
6481 row[1] = g_variant_new_string(name.c_str());
6582 row[2] = g_variant_new_string(""); // icon hint
66− row[3] = g_variant_new_string("filter-multirange"); // renderer
83+ row[3] = g_variant_new_string(renderer.c_str()); // renderer
6784
6885 GVariant *children[2];
6986 GVariant *key1 = g_variant_new_string("show-all-button");
@@ -211,6 +228,119 @@ void FiltersBindingsTest::testMultiRangeFilter()
211228
212229void FiltersBindingsTest::testCheckOptionFilter()
213230{
231+ auto model = createFilterModel();
232+
233+ createCheckOptionFilter(model, "f1", "Filter1", 3);
234+
235+ // create filter out of 1st row
236+ auto iter = dee_model_get_first_iter(DEE_MODEL(model));
237+ {
238+ auto core_filter = unity::dash::Filter::FilterFromIter(model, iter);
239+ QVERIFY(core_filter != nullptr);
240+ auto bind_filter = Filter::newFromUnityFilter(core_filter);
241+ auto check_filter = dynamic_cast<CheckOptionFilter*>(bind_filter);
242+ QVERIFY(check_filter != nullptr);
243+ auto options = check_filter->options();
244+ QCOMPARE(options->rowCount(), 3);
245+
246+ QVariant optvar = options->data(options->index(0));
247+ FilterOption* opt0 = optvar.value<FilterOption*>();
248+ QCOMPARE(opt0->id(), QString("opt0"));
249+
250+ optvar = options->data(options->index(1));
251+ FilterOption* opt1 = optvar.value<FilterOption*>();
252+ QCOMPARE(opt1->id(), QString("opt1"));
253+
254+ optvar = options->data(options->index(2));
255+ FilterOption* opt2 = optvar.value<FilterOption*>();
256+ QCOMPARE(opt2->id(), QString("opt2"));
257+
258+ QSignalSpy opt0spy(opt0, SIGNAL(activeChanged(bool)));
259+ QSignalSpy opt1spy(opt1, SIGNAL(activeChanged(bool)));
260+ QSignalSpy opt2spy(opt2, SIGNAL(activeChanged(bool)));
261+
262+ // test active property changes
263+ QCOMPARE(opt0->active(), false);
264+ QCOMPARE(opt1->active(), false);
265+ QCOMPARE(opt2->active(), false);
266+
267+ opt0->setActive(true);
268+ QCOMPARE(opt0spy.count(), 1);
269+ QCOMPARE(opt1spy.count(), 0);
270+ QCOMPARE(opt2spy.count(), 0);
271+ QCOMPARE(opt0->active(), true);
272+ QCOMPARE(opt1->active(), false);
273+ QCOMPARE(opt2->active(), false);
274+
275+ opt1->setActive(true);
276+ QCOMPARE(opt0spy.count(), 2);
277+ QCOMPARE(opt1spy.count(), 1);
278+ QCOMPARE(opt2spy.count(), 0);
279+ QCOMPARE(opt0->active(), false);
280+ QCOMPARE(opt1->active(), true);
281+ QCOMPARE(opt2->active(), false);
282+
283+ delete check_filter;
284+ }
285+}
286+
287+void FiltersBindingsTest::testRadioOptionFilter()
288+{
289+ auto model = createFilterModel();
290+
291+ createRadioOptionFilter(model, "f1", "Filter1", 3);
292+
293+ // create filter out of 1st row
294+ auto iter = dee_model_get_first_iter(DEE_MODEL(model));
295+ {
296+ auto core_filter = unity::dash::Filter::FilterFromIter(model, iter);
297+ QVERIFY(core_filter != nullptr);
298+ auto bind_filter = Filter::newFromUnityFilter(core_filter);
299+ auto radio_filter = dynamic_cast<RadioOptionFilter*>(bind_filter);
300+ QVERIFY(radio_filter != nullptr);
301+ auto options = radio_filter->options();
302+ QCOMPARE(options->rowCount(), 3);
303+
304+ QVariant optvar = options->data(options->index(0));
305+ FilterOption* opt0 = optvar.value<FilterOption*>();
306+ QCOMPARE(opt0->id(), QString("opt0"));
307+
308+ optvar = options->data(options->index(1));
309+ FilterOption* opt1 = optvar.value<FilterOption*>();
310+ QCOMPARE(opt1->id(), QString("opt1"));
311+
312+ optvar = options->data(options->index(2));
313+ FilterOption* opt2 = optvar.value<FilterOption*>();
314+ QCOMPARE(opt2->id(), QString("opt2"));
315+
316+ QSignalSpy opt0spy(opt0, SIGNAL(activeChanged(bool)));
317+ QSignalSpy opt1spy(opt1, SIGNAL(activeChanged(bool)));
318+ QSignalSpy opt2spy(opt2, SIGNAL(activeChanged(bool)));
319+
320+ // test active property changes
321+ QCOMPARE(opt0->active(), false);
322+ QCOMPARE(opt1->active(), false);
323+ QCOMPARE(opt2->active(), false);
324+
325+ opt0->setActive(true);
326+ QCOMPARE(opt0spy.count(), 1);
327+ QCOMPARE(opt1spy.count(), 0);
328+ QCOMPARE(opt2spy.count(), 0);
329+ QCOMPARE(opt0->active(), true);
330+ QCOMPARE(opt1->active(), false);
331+ QCOMPARE(opt2->active(), false);
332+
333+ opt1->setActive(true);
334+ QCOMPARE(opt0spy.count(), 2);
335+ QCOMPARE(opt1spy.count(), 1);
336+ QCOMPARE(opt2spy.count(), 0);
337+ QCOMPARE(opt0->active(), false);
338+ QCOMPARE(opt1->active(), true);
339+ QCOMPARE(opt2->active(), false);
340+
341+ delete radio_filter;
342+ }
343+
214344}
215345
216346QTEST_MAIN(FiltersBindingsTest)