Back to index

unity  6.0.0
test_results.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/Results.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.resultsmodel";
00016 static const unsigned int n_rows = 200;
00017 
00018 static void WaitForSynchronize(Results& model)
00019 {
00020   ::Utils::WaitForModelSynchronize<Result>(model, n_rows);
00021 }
00022 
00023 TEST(TestResults, TestConstruction)
00024 {
00025   Results model;
00026   model.swarm_name = swarm_name;
00027 }
00028 
00029 TEST(TestResults, TestSynchronization)
00030 {
00031   Results model;
00032   model.swarm_name = swarm_name;
00033 
00034   WaitForSynchronize(model);
00035   EXPECT_EQ(model.count, n_rows);
00036 }
00037 
00038 TEST(TestResults, TestRowsValid)
00039 {
00040   Results model;
00041   model.swarm_name = swarm_name;
00042 
00043   WaitForSynchronize(model);
00044 
00045   for (unsigned int i = 0; i < n_rows; i++)
00046   {
00047     Result adaptor = model.RowAtIndex(i);
00048 
00049     unity::glib::String tmp(g_strdup_printf("Result%d", i));
00050     string value = tmp.Str();
00051     EXPECT_EQ(adaptor.uri, value);
00052     EXPECT_EQ(adaptor.icon_hint, value);
00053     EXPECT_EQ(adaptor.category_index, i);
00054     EXPECT_EQ(adaptor.mimetype, value);
00055     EXPECT_EQ(adaptor.name, value);
00056     EXPECT_EQ(adaptor.comment, value);
00057     EXPECT_EQ(adaptor.dnd_uri, value);
00058   }
00059 }
00060 
00061 // We're testing the model's ability to store and retrieve random pointers
00062 TEST(TestResults, TestSetGetRenderer)
00063 {
00064   Results model;
00065   model.swarm_name = swarm_name;
00066 
00067   WaitForSynchronize(model);
00068 
00069   for (unsigned int i = 0; i < n_rows; i++)
00070   {
00071     Result adaptor = model.RowAtIndex(i);
00072 
00073     char* value = g_strdup_printf("Renderer%d", i);
00074     adaptor.set_renderer<char*>(value);
00075   }
00076 
00077   for (unsigned int i = 0; i < n_rows; i++)
00078   {
00079     Result adaptor = model.RowAtIndex(i);
00080 
00081     unity::glib::String value(adaptor.renderer<char*>());
00082     unity::glib::String renderer(g_strdup_printf("Renderer%d", i));
00083 
00084     EXPECT_EQ(value.Str(), renderer.Str());
00085   }
00086 }
00087 
00088 }