Back to index

unity  6.0.0
test_categories.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <glib-object.h>
00003 
00004 #include <UnityCore/GLibWrapper.h>
00005 #include <UnityCore/Categories.h>
00006 
00007 #include "test_utils.h"
00008 
00009 using namespace std;
00010 using namespace unity::dash;
00011 
00012 namespace
00013 {
00014 
00015 static const string swarm_name = "com.canonical.test.categoriesmodel";
00016 static const unsigned int n_rows = 5;
00017 
00018 static void WaitForSynchronize(Categories& model)
00019 {
00020   ::Utils::WaitForModelSynchronize<Category>(model, n_rows);
00021 }
00022 
00023 TEST(TestCategories, TestConstruction)
00024 {
00025   Categories model;
00026   model.swarm_name = swarm_name;
00027 }
00028 
00029 TEST(TestCategories, TestSynchronization)
00030 {
00031   Categories model;
00032   model.swarm_name = swarm_name;
00033 
00034   WaitForSynchronize(model);
00035   EXPECT_EQ(model.count, n_rows);
00036 }
00037 
00038 TEST(TestCategories, TestRowsValid)
00039 {
00040   Categories model;
00041   model.swarm_name = swarm_name;
00042 
00043   WaitForSynchronize(model);
00044 
00045   for (unsigned int i = 0; i < n_rows; i++)
00046   {
00047     Category adaptor = model.RowAtIndex(i);
00048 
00049     unity::glib::String tmp(g_strdup_printf("Category%d", i));
00050     string value = tmp.Str();
00051     EXPECT_EQ(adaptor.name, value);
00052     EXPECT_EQ(adaptor.icon_hint, "gtk-apply");
00053     EXPECT_EQ(adaptor.index, i);
00054     EXPECT_EQ(adaptor.renderer_name, "grid");
00055   }
00056 }
00057 
00058 // We're testing the model's ability to store and retrieve random pointers
00059 TEST(TestCategories, TestSetGetRenderer)
00060 {
00061   Categories model;
00062   model.swarm_name = swarm_name;
00063 
00064   WaitForSynchronize(model);
00065 
00066   for (unsigned int i = 0; i < n_rows; i++)
00067   {
00068     Category adaptor = model.RowAtIndex(i);
00069 
00070     char* value = g_strdup_printf("Renderer%d", i);
00071     adaptor.set_renderer<char*>(value);
00072   }
00073 
00074   for (unsigned int i = 0; i < n_rows; i++)
00075   {
00076     Category adaptor = model.RowAtIndex(i);
00077 
00078     unity::glib::String value(adaptor.renderer<char*>());
00079     unity::glib::String renderer(g_strdup_printf("Renderer%d", i));
00080 
00081     EXPECT_EQ(value.Str(), renderer.Str());
00082   }
00083 }
00084 
00085 }