summaryrefslogtreecommitdiff
path: root/tests
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2013-03-25 16:31:41 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2013-03-25 16:31:41 +0100
commit22994d1a656e21d9964e75fc7789b2e0fd8056d1 (patch)
treea320915a88e55df201508257135955acf270d6ae /tests
parente5c2bf72446614fe39fba69cf70d1b3296e970a2 (diff)
parent34e7dd24d7c29d481e5784b6a1d937f31e004fec (diff)
Merge with trunk
(bzr r3212.3.11)
Diffstat (limited to 'tests')
-rw-r--r--tests/autopilot/unity/tests/launcher/test_icon_behavior.py1
-rw-r--r--tests/autopilot/unity/tests/launcher/test_tooltips.py8
-rw-r--r--tests/data/applications/bzr-handle-patch.desktop2
-rw-r--r--tests/data/applications/kde4/afile.desktop2
-rw-r--r--tests/data/applications/no-icon.desktop2
-rw-r--r--tests/data/applications/ubuntu-software-center.desktop2
-rw-r--r--tests/data/applications/ubuntuone-installer.desktop2
-rw-r--r--tests/data/applications/update-manager.desktop2
-rw-r--r--tests/test_dbus_indicators.cpp2
-rw-r--r--tests/test_icon_loader.cpp147
-rw-r--r--tests/test_thumbnail_generator.cpp134
-rw-r--r--tests/test_utils.h21
12 files changed, 108 insertions, 217 deletions
diff --git a/tests/autopilot/unity/tests/launcher/test_icon_behavior.py b/tests/autopilot/unity/tests/launcher/test_icon_behavior.py
index da6e38cae..0f03b2d0f 100644
--- a/tests/autopilot/unity/tests/launcher/test_icon_behavior.py
+++ b/tests/autopilot/unity/tests/launcher/test_icon_behavior.py
@@ -70,6 +70,7 @@ class LauncherIconsTests(LauncherTestCase):
bfb = self.unity.launcher.model.get_bfb_icon()
self.mouse.move(bfb.center_x, bfb.center_y)
+ self.assertThat(lambda: bfb.get_tooltip(), Eventually(NotEquals(None)))
self.assertThat(bfb.get_tooltip().active, Eventually(Equals(True)))
self.unity.dash.ensure_visible()
self.addCleanup(self.unity.dash.ensure_hidden)
diff --git a/tests/autopilot/unity/tests/launcher/test_tooltips.py b/tests/autopilot/unity/tests/launcher/test_tooltips.py
index 09cd786e1..28d871aed 100644
--- a/tests/autopilot/unity/tests/launcher/test_tooltips.py
+++ b/tests/autopilot/unity/tests/launcher/test_tooltips.py
@@ -7,7 +7,7 @@
# by the Free Software Foundation.
from autopilot.matchers import Eventually
-from testtools.matchers import Equals
+from testtools.matchers import Equals, NotEquals
from time import sleep
from unity.tests.launcher import LauncherTestCase, _make_scenarios
@@ -37,8 +37,10 @@ class LauncherTooltipTests(LauncherTestCase):
a, b = 0, 1
while b < len(self.icons):
self.mouse.move(self.icons[b].center_x, self.icons[b].center_y)
- self.assertTrue(self.icons[b].get_tooltip().active)
- self.assertFalse(self.icons[a].get_tooltip().active)
+ self.assertThat(lambda: self.icons[b].get_tooltip(), Eventually(NotEquals(None)))
+ self.assertThat(self.icons[b].get_tooltip().active, Eventually(Equals(True)))
+ self.assertThat(lambda: self.icons[a].get_tooltip(), Eventually(NotEquals(None)))
+ self.assertThat(self.icons[a].get_tooltip().active, Eventually(Equals(False)))
a, b = a + 1, b + 1
b -= 1
diff --git a/tests/data/applications/bzr-handle-patch.desktop b/tests/data/applications/bzr-handle-patch.desktop
index 900e34d8d..2cc35de5e 100644
--- a/tests/data/applications/bzr-handle-patch.desktop
+++ b/tests/data/applications/bzr-handle-patch.desktop
@@ -2,7 +2,7 @@
Name=Bazaar
Comment=Apply Bazaar Bundle
Icon=bzr-icon-64
-Exec=bzr-handle-patch %f
+Exec=/bin/true
NoDisplay=true
Terminal=false
Type=Application
diff --git a/tests/data/applications/kde4/afile.desktop b/tests/data/applications/kde4/afile.desktop
index fa07d53e5..d368be5fe 100644
--- a/tests/data/applications/kde4/afile.desktop
+++ b/tests/data/applications/kde4/afile.desktop
@@ -6,7 +6,7 @@ X-AppInstall-Section=main
Name=gedit
GenericName=Text Editor
Comment=Edit text files
-Exec=gedit %U
+Exec=/bin/true
Terminal=false
Type=Application
StartupNotify=true
diff --git a/tests/data/applications/no-icon.desktop b/tests/data/applications/no-icon.desktop
index 4f2902fe2..6397c0229 100644
--- a/tests/data/applications/no-icon.desktop
+++ b/tests/data/applications/no-icon.desktop
@@ -1,7 +1,7 @@
[Desktop Entry]
Name=Default
Comment=Interactive viewer for a Default icon!
-Exec=gedit
+Exec=/bin/true
Terminal=false
Type=Application
Categories=GTK;Science;Graphics;
diff --git a/tests/data/applications/ubuntu-software-center.desktop b/tests/data/applications/ubuntu-software-center.desktop
index e8f860e07..453b63c7f 100644
--- a/tests/data/applications/ubuntu-software-center.desktop
+++ b/tests/data/applications/ubuntu-software-center.desktop
@@ -2,7 +2,7 @@
Name=Ubuntu Software Center
GenericName=Software Center
Comment=Lets you choose from thousands of applications available for Ubuntu
-Exec=/usr/bin/software-center %u
+Exec=/bin/true
Icon=softwarecenter
Terminal=false
Type=Application
diff --git a/tests/data/applications/ubuntuone-installer.desktop b/tests/data/applications/ubuntuone-installer.desktop
index 99c6a47b7..99c912954 100644
--- a/tests/data/applications/ubuntuone-installer.desktop
+++ b/tests/data/applications/ubuntuone-installer.desktop
@@ -1,7 +1,7 @@
[Desktop Entry]
Name=Ubuntu One
Comment=Configure and manage your Ubuntu One account
-Exec=ubuntuone-installer
+Exec=/bin/true
Icon=ubuntuone-installer
Terminal=false
Type=Application
diff --git a/tests/data/applications/update-manager.desktop b/tests/data/applications/update-manager.desktop
index 5f9f3a64f..c03774be2 100644
--- a/tests/data/applications/update-manager.desktop
+++ b/tests/data/applications/update-manager.desktop
@@ -2,7 +2,7 @@
Name=Update Manager
GenericName=Software Updates
Comment=Show and install available updates
-Exec=/usr/bin/update-manager
+Exec=/bin/true
Icon=update-manager
Terminal=false
Type=Application
diff --git a/tests/test_dbus_indicators.cpp b/tests/test_dbus_indicators.cpp
index f1406cf75..de8b4efbf 100644
--- a/tests/test_dbus_indicators.cpp
+++ b/tests/test_dbus_indicators.cpp
@@ -88,7 +88,7 @@ TEST_F(TestDBusIndicators, TestSync)
Utils::WaitUntil(sigc::mem_fun(this, &TestDBusIndicators::TriggerResync1Sent));
// We know the resync has been sent, but it may have not been processed
// so do one interation of the main loop more
- g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
+ g_main_context_iteration(NULL, TRUE);
EXPECT_EQ(dbus_indicators->GetIndicators().size(), 1);
EXPECT_EQ(dbus_indicators->GetIndicators().front()->GetEntries().size(), 2);
diff --git a/tests/test_icon_loader.cpp b/tests/test_icon_loader.cpp
index 509cdf541..8d02bf06e 100644
--- a/tests/test_icon_loader.cpp
+++ b/tests/test_icon_loader.cpp
@@ -21,6 +21,7 @@
#include <sigc++/sigc++.h>
#include "IconLoader.h"
+#include "test_utils.h"
using namespace testing;
using namespace unity;
@@ -45,8 +46,9 @@ struct LoadResult
{
glib::Object<GdkPixbuf> pixbuf;
bool got_callback;
+ bool disconnected;
- LoadResult() : pixbuf(NULL), got_callback(false) {}
+ LoadResult() : pixbuf(NULL), got_callback(false), disconnected(false) {}
void IconLoaded(std::string const& icon_name, int max_width, int max_height,
glib::Object<GdkPixbuf> const& buf)
{
@@ -56,6 +58,36 @@ struct LoadResult
}
};
+void CheckResults(std::vector<LoadResult> const& results)
+{
+ Utils::WaitUntilMSec([&results] {
+ bool got_all = true;
+ for (auto const& result : results)
+ {
+ got_all = (result.got_callback == !result.disconnected);
+
+ if (!got_all)
+ break;
+ }
+
+ return got_all;
+ });
+
+ for (auto const& result : results)
+ {
+ if (!result.disconnected)
+ {
+ ASSERT_TRUE(result.got_callback);
+ ASSERT_TRUE(IsValidPixbuf(result.pixbuf));
+ }
+ else
+ {
+ ASSERT_FALSE(result.got_callback);
+ }
+ }
+}
+
+
TEST(TestIconLoader, TestGetDefault)
{
// we need to initialize gtk
@@ -69,43 +101,26 @@ TEST(TestIconLoader, TestGetOneIcon)
{
LoadResult load_result;
IconLoader& icon_loader = IconLoader::GetDefault();
- volatile bool timeout_reached = false;
icon_loader.LoadFromIconName("gedit-icon", -1, 48, sigc::mem_fun(load_result,
&LoadResult::IconLoaded));
- guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));
- while (!timeout_reached && !load_result.got_callback)
- {
- g_main_context_iteration (NULL, TRUE);
- }
-
+ Utils::WaitUntilMSec(load_result.got_callback);
EXPECT_TRUE(load_result.got_callback);
EXPECT_TRUE(IsValidPixbuf(load_result.pixbuf));
-
- g_source_remove (tid);
}
TEST(TestIconLoader, TestGetAnnotatedIcon)
{
LoadResult load_result;
IconLoader& icon_loader = IconLoader::GetDefault();
- volatile bool timeout_reached = false;
-
icon_loader.LoadFromGIconString(". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'gedit-icon'%3E,%20'ribbon':%20%3C'foo'%3E%7D", -1, 48, sigc::mem_fun(load_result,
&LoadResult::IconLoaded));
- guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));
- while (!timeout_reached && !load_result.got_callback)
- {
- g_main_context_iteration (NULL, TRUE);
- }
-
+ Utils::WaitUntilMSec(load_result.got_callback);
EXPECT_TRUE(load_result.got_callback);
EXPECT_TRUE(IsValidPixbuf(load_result.pixbuf));
-
- g_source_remove (tid);
}
TEST(TestIconLoader, TestGetOneIconManyTimes)
@@ -113,7 +128,6 @@ TEST(TestIconLoader, TestGetOneIconManyTimes)
std::vector<LoadResult> results;
std::vector<int> handles;
IconLoader& icon_loader = IconLoader::GetDefault();
- volatile bool timeout_reached = false;
int i, load_count;
// 100 times should be good
@@ -133,52 +147,16 @@ TEST(TestIconLoader, TestGetOneIconManyTimes)
for (i = 0; i < load_count; i += 2)
{
icon_loader.DisconnectHandle(handles[i]);
+ results[i].disconnected = true;
}
- guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));
- int iterations = 0;
- while (!timeout_reached)
- {
- g_main_context_iteration (NULL, TRUE);
- bool all_loaded = true;
- bool any_loaded = false;
- for (i = 1; i < load_count; i += 2)
- {
- all_loaded &= results[i].got_callback;
- any_loaded |= results[i].got_callback;
- if (!all_loaded) break;
- }
- // count the number of iterations where we got some results
- if (any_loaded) iterations++;
- if (all_loaded) break;
- }
-
- EXPECT_FALSE(timeout_reached);
- // it's all loading the same icon, the results had to come in the same
- // main loop iteration (that's the desired behaviour)
- EXPECT_EQ(iterations, 1);
-
- for (i = 0; i < load_count; i++)
- {
- if (i % 2)
- {
- EXPECT_TRUE(results[i].got_callback);
- EXPECT_TRUE(IsValidPixbuf(results[i].pixbuf));
- }
- else
- {
- EXPECT_FALSE(results[i].got_callback);
- }
- }
-
- g_source_remove (tid);
+ CheckResults(results);
}
TEST(TestIconLoader, TestGetManyIcons)
{
std::vector<LoadResult> results;
IconLoader& icon_loader = IconLoader::GetDefault();
- volatile bool timeout_reached = false;
int i = 0;
int icon_count;
@@ -195,26 +173,7 @@ TEST(TestIconLoader, TestGetManyIcons)
if (i >= icon_count) break;
}
- guint tid = g_timeout_add (30000, TimeoutReached, (gpointer)(&timeout_reached));
- while (!timeout_reached)
- {
- g_main_context_iteration (NULL, TRUE);
- bool all_loaded = true;
- for (auto loader: results)
- {
- all_loaded &= loader.got_callback;
- if (!all_loaded) break;
- }
- if (all_loaded) break;
- }
-
- for (auto load_result: results)
- {
- EXPECT_TRUE(load_result.got_callback);
- EXPECT_TRUE(IsValidPixbuf(load_result.pixbuf));
- }
-
- g_source_remove (tid);
+ CheckResults(results);
}
TEST(TestIconLoader, TestCancelSome)
@@ -222,7 +181,6 @@ TEST(TestIconLoader, TestCancelSome)
std::vector<LoadResult> results;
std::vector<int> handles;
IconLoader& icon_loader = IconLoader::GetDefault();
- volatile bool timeout_reached = false;
int i = 0;
int icon_count;
@@ -245,35 +203,10 @@ TEST(TestIconLoader, TestCancelSome)
for (i = 0; i < icon_count; i += 2)
{
icon_loader.DisconnectHandle(handles[i]);
+ results[i].disconnected = true;
}
- guint tid = g_timeout_add (30000, TimeoutReached, (gpointer)(&timeout_reached));
- while (!timeout_reached)
- {
- g_main_context_iteration (NULL, TRUE);
- bool all_loaded = true;
- for (int i = 1; i < icon_count; i += 2)
- {
- all_loaded &= results[i].got_callback;
- if (!all_loaded) break;
- }
- if (all_loaded) break;
- }
-
- for (i = 0; i < icon_count; i++)
- {
- if (i % 2)
- {
- EXPECT_TRUE(results[i].got_callback);
- EXPECT_TRUE(IsValidPixbuf(results[i].pixbuf));
- }
- else
- {
- EXPECT_FALSE(results[i].got_callback);
- }
- }
-
- g_source_remove (tid);
+ CheckResults(results);
}
diff --git a/tests/test_thumbnail_generator.cpp b/tests/test_thumbnail_generator.cpp
index 239ee9b32..785730301 100644
--- a/tests/test_thumbnail_generator.cpp
+++ b/tests/test_thumbnail_generator.cpp
@@ -34,22 +34,14 @@ using namespace unity;
namespace
{
-gboolean TimeoutReached (gpointer data)
-{
- bool *b = static_cast<bool*>(data);
-
- *b = true;
-
- return FALSE;
-}
-
struct LoadResult
{
std::string return_string;
bool got_callback;
bool succeeded;
+ bool cancelled;
- LoadResult() : got_callback(false),succeeded(false) {}
+ LoadResult() : got_callback(false),succeeded(false), cancelled(false) {}
void ThumbnailReady(std::string const& result)
{
return_string = result;
@@ -66,6 +58,37 @@ struct LoadResult
}
};
+void CheckResults(std::vector<LoadResult> const& results)
+{
+ Utils::WaitUntilMSec([&results] {
+ bool got_all = true;
+ for (auto const& result : results)
+ {
+ got_all = (result.got_callback == !result.cancelled);
+
+ if (!got_all)
+ break;
+ }
+
+ return got_all;
+ });
+
+ for (auto const& result : results)
+ {
+ if (!result.cancelled)
+ {
+ ASSERT_TRUE(result.got_callback);
+ ASSERT_TRUE(result.succeeded);
+ glib::Object<GIcon> icon(g_icon_new_for_string(result.return_string.c_str(), nullptr));
+ ASSERT_TRUE(icon.IsType(G_TYPE_ICON));
+ }
+ else
+ {
+ ASSERT_FALSE(result.got_callback);
+ }
+ }
+}
+
TEST(TestThumbnailGenerator, TestNoURIThumbnail)
{
ThumbnailGenerator thumbnail_generator;
@@ -84,18 +107,11 @@ TEST(TestThumbnailGenerator, TestGetOneFileThumbnail)
thumb->ready.connect(sigc::mem_fun(load_result, &LoadResult::ThumbnailReady));
thumb->error.connect(sigc::mem_fun(load_result, &LoadResult::ThumbnailFailed));
- volatile bool timeout_reached = false;
- guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));
- while (!timeout_reached && !load_result.got_callback)
- {
- g_main_context_iteration (NULL, TRUE);
- }
+ Utils::WaitUntilMSec(load_result.got_callback);
EXPECT_TRUE(load_result.succeeded);
glib::Object<GIcon> icon(g_icon_new_for_string(load_result.return_string.c_str(), NULL));
EXPECT_TRUE(G_IS_ICON(icon.RawPtr()));
-
- g_source_remove (tid);
}
@@ -105,12 +121,12 @@ TEST(TestThumbnailGenerator, TestGetManyFileThumbnail)
ThumbnailGenerator thumbnail_generator;
const char* thumbs[] = { "file://" PKGDATADIR "/switcher_background.png" , "file://" PKGDATADIR "/star_highlight.png",
- "file://" PKGDATADIR "/switcher_round_rect.png", "file://" PKGDATADIR "/switcher_corner.png",
+ "file://" PKGDATADIR "/launcher_bfb.png", "file://" PKGDATADIR "/switcher_corner.png",
"file://" PKGDATADIR "/switcher_top.png", "file://" PKGDATADIR "/switcher_left.png",
"file://" PKGDATADIR "/dash_bottom_left_corner.png", "file://" PKGDATADIR "/dash_bottom_right_corner.png"};
std::vector<LoadResult> results;
- std::vector< ThumbnailNotifier::Ptr> notifiers;
+ std::vector<ThumbnailNotifier::Ptr> notifiers;
// 100 times should be good
int load_count = 100;
@@ -130,41 +146,10 @@ TEST(TestThumbnailGenerator, TestGetManyFileThumbnail)
for (int i = 0; i < load_count; i += 2)
{
notifiers[i]->Cancel();
+ results[i].cancelled = true;
}
-
- volatile bool timeout_reached = false;
- guint tid = g_timeout_add (30000, TimeoutReached, (gpointer)(&timeout_reached));
- while (!timeout_reached)
- {
- g_main_context_iteration (NULL, TRUE);
- bool all_loaded = true;
- bool any_loaded = false;
- for (int i = 1; i < load_count; i += 2)
- {
- all_loaded &= results[i].got_callback;
- any_loaded |= results[i].got_callback;
- if (!all_loaded) break;
- }
- if (all_loaded) break;
- }
-
- for (int i = 0; i < load_count; i++)
- {
- if (i % 2)
- {
- EXPECT_TRUE(results[i].got_callback);
- EXPECT_TRUE(results[i].succeeded);
- glib::Object<GIcon> icon(g_icon_new_for_string(results[i].return_string.c_str(), NULL));
- EXPECT_TRUE(G_IS_ICON(icon.RawPtr()));
- }
- else
- {
- EXPECT_FALSE(results[i].got_callback);
- }
- }
-
- g_source_remove (tid);
+ CheckResults(results);
}
@@ -179,18 +164,11 @@ TEST(TestThumbnailGenerator, TestGetOneGIcon)
thumb->ready.connect(sigc::mem_fun(load_result, &LoadResult::ThumbnailReady));
thumb->error.connect(sigc::mem_fun(load_result, &LoadResult::ThumbnailFailed));
- volatile bool timeout_reached = false;
- guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));
- while (!timeout_reached && !load_result.got_callback)
- {
- g_main_context_iteration (NULL, TRUE);
- }
+ Utils::WaitUntilMSec(load_result.got_callback);
EXPECT_TRUE(load_result.succeeded);
glib::Object<GIcon> icon(g_icon_new_for_string(load_result.return_string.c_str(), NULL));
EXPECT_TRUE(G_IS_ICON(icon.RawPtr()));
-
- g_source_remove (tid);
}
@@ -225,40 +203,10 @@ TEST(TestThumbnailGenerator, TestGetManyGIcon)
for (int i = 0; i < load_count; i += 2)
{
notifiers[i]->Cancel();
+ results[i].cancelled = true;
}
- volatile bool timeout_reached = false;
- guint tid = g_timeout_add (30000, TimeoutReached, (gpointer)(&timeout_reached));
- while (!timeout_reached)
- {
- g_main_context_iteration (NULL, TRUE);
- bool all_loaded = true;
- bool any_loaded = false;
- for (int i = 1; i < load_count; i += 2)
- {
- all_loaded &= results[i].got_callback;
- any_loaded |= results[i].got_callback;
- if (!all_loaded) break;
- }
- if (all_loaded) break;
- }
-
- for (int i = 0; i < load_count; i++)
- {
- if (i % 2)
- {
- EXPECT_TRUE(results[i].got_callback);
- EXPECT_TRUE(results[i].succeeded);
- glib::Object<GIcon> icon(g_icon_new_for_string(results[i].return_string.c_str(), NULL));
- EXPECT_TRUE(G_IS_ICON(icon.RawPtr()));
- }
- else
- {
- EXPECT_FALSE(results[i].got_callback);
- }
- }
-
- g_source_remove (tid);
+ CheckResults(results);
}
diff --git a/tests/test_utils.h b/tests/test_utils.h
index c31a393bb..c41b91e2d 100644
--- a/tests/test_utils.h
+++ b/tests/test_utils.h
@@ -21,20 +21,27 @@ public:
WaitUntilMSec(success, max_wait * 1000);
}
- static void WaitUntilMSec(std::function<bool()> const& check_function, bool result = true, unsigned max_wait = 500)
+ static void WaitUntilMSec(std::function<bool()> const& check_function, bool expected_result = true, unsigned max_wait = 500)
{
ASSERT_NE(check_function, nullptr);
bool timeout_reached = false;
guint32 timeout_id = ScheduleTimeout(&timeout_reached, max_wait);
+ bool result;
- while (check_function() != result && !timeout_reached)
- g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
+ while (!timeout_reached)
+ {
+ result = check_function();
+ if (result == expected_result)
+ break;
+
+ g_main_context_iteration(NULL, TRUE);
+ }
- if (check_function() == result)
+ if (result == expected_result)
g_source_remove(timeout_id);
- EXPECT_EQ(check_function(), result);
+ EXPECT_EQ(result, expected_result);
}
static void WaitUntil(std::function<bool()> const& check_function, bool result = true, unsigned max_wait = 10)
@@ -58,7 +65,7 @@ public:
guint32 timeout_id = ScheduleTimeout(&timeout_reached, timeout_duration);
while (!timeout_reached)
- g_main_context_iteration(g_main_context_get_thread_default(), TRUE);
+ g_main_context_iteration(NULL, TRUE);
g_source_remove(timeout_id);
}
@@ -66,7 +73,7 @@ public:
private:
static gboolean TimeoutCallback(gpointer data)
{
- *(bool*)data = true;
+ *static_cast<bool*>(data) = true;
return FALSE;
};
};