aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-07-26 23:35:38 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-07-26 23:35:38 -0500
commitfcd77b806a8826d5f694f78c63943d0f768ef6ec (patch)
tree22738c06ae6599e729ad386bc3126772dda13299 /tests
parenta7e8b219e8a9301249301cff6fbe989670d4e312 (diff)
downloadayatana-indicator-datetime-fcd77b806a8826d5f694f78c63943d0f768ef6ec.tar.gz
ayatana-indicator-datetime-fcd77b806a8826d5f694f78c63943d0f768ef6ec.tar.bz2
ayatana-indicator-datetime-fcd77b806a8826d5f694f78c63943d0f768ef6ec.zip
refactor the Notifications / sound / awake code
Diffstat (limited to 'tests')
-rw-r--r--tests/manual-test-snap.cpp11
-rw-r--r--tests/test-snap.cpp74
2 files changed, 53 insertions, 32 deletions
diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp
index cc24a67..7d4403d 100644
--- a/tests/manual-test-snap.cpp
+++ b/tests/manual-test-snap.cpp
@@ -22,13 +22,13 @@
#include <datetime/settings-live.h>
#include <datetime/snap.h>
#include <datetime/timezones-live.h>
+#include <notifications/notifications.h>
#include <glib.h>
using namespace unity::indicator::datetime;
-#define TIMEZONE_FILE ("/etc/timezone")
-
+namespace uin = unity::indicator::notifications;
/***
****
@@ -94,11 +94,12 @@ int main(int argc, const char* argv[])
auto settings = std::make_shared<LiveSettings>();
settings->alarm_volume.set(volume);
- auto timezones = std::make_shared<LiveTimezones>(settings, TIMEZONE_FILE);
- auto clock = std::make_shared<LiveClock>(timezones);
- Snap snap (clock, settings);
+
+ auto notification_engine = std::make_shared<uin::Engine>("indicator-datetime-service");
+ Snap snap (notification_engine, settings);
snap(a, show, dismiss);
g_main_loop_run(loop);
+
g_main_loop_unref(loop);
return 0;
}
diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp
index f9e7a66..9a049fa 100644
--- a/tests/test-snap.cpp
+++ b/tests/test-snap.cpp
@@ -21,11 +21,11 @@
#include <datetime/dbus-shared.h>
#include <datetime/settings.h>
#include <datetime/snap.h>
-#include <datetime/timezones.h>
-#include <libdbustest/dbus-test.h>
+#include <notifications/dbus-shared.h>
+#include <notifications/notifications.h>
-#include <libnotify/notify.h>
+#include <libdbustest/dbus-test.h>
#include <glib.h>
@@ -37,6 +37,11 @@ using namespace unity::indicator::datetime;
****
***/
+namespace
+{
+ static constexpr char const * APP_NAME {"indicator-datetime-service"};
+}
+
using namespace unity::indicator::datetime;
class SnapFixture: public GlibFixture
@@ -60,18 +65,19 @@ protected:
static constexpr char const * POWERD_METHOD_REQUEST_SYS_STATE {"requestSysState"};
static constexpr char const * POWERD_METHOD_CLEAR_SYS_STATE {"clearSysState"};
- static constexpr int NOTIFY_ID {1234};
+ static constexpr int FIRST_NOTIFY_ID {1000};
static constexpr int NOTIFICATION_CLOSED_EXPIRED {1};
static constexpr int NOTIFICATION_CLOSED_DISMISSED {2};
static constexpr int NOTIFICATION_CLOSED_API {3};
static constexpr int NOTIFICATION_CLOSED_UNDEFINED {4};
- static constexpr char const * APP_NAME {"indicator-datetime-service"};
-
- static constexpr char const * METHOD_NOTIFY {"Notify"};
+ static constexpr char const * METHOD_CLOSE {"CloseNotification"};
static constexpr char const * METHOD_GET_CAPS {"GetCapabilities"};
static constexpr char const * METHOD_GET_INFO {"GetServerInformation"};
+ static constexpr char const * METHOD_NOTIFY {"Notify"};
+
+ static constexpr char const * SIGNAL_CLOSED {"NotificationClosed"};
static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"};
@@ -118,7 +124,8 @@ protected:
NOTIFY_INTERFACE,
&error);
g_assert_no_error(error);
-
+
+ // METHOD_GET_INFO
str = g_strdup("ret = ('mock-notify', 'test vendor', '1.0', '1.1')");
dbus_test_dbus_mock_object_add_method(notify_mock,
notify_obj,
@@ -130,7 +137,14 @@ protected:
g_assert_no_error (error);
g_free (str);
- str = g_strdup_printf ("ret = %d", NOTIFY_ID);
+ // METHOD_NOTIFY
+ str = g_strdup_printf("try:\n"
+ " self.NextNotifyId\n"
+ "except AttributeError:\n"
+ " self.NextNotifyId = %d\n"
+ "ret = self.NextNotifyId\n"
+ "self.NextNotifyId += 1\n",
+ FIRST_NOTIFY_ID);
dbus_test_dbus_mock_object_add_method(notify_mock,
notify_obj,
METHOD_NOTIFY,
@@ -141,6 +155,21 @@ protected:
g_assert_no_error (error);
g_free (str);
+ // METHOD_CLOSE
+ str = g_strdup_printf("self.EmitSignal('%s', '%s', 'uu', [ args[0], %d ])",
+ NOTIFY_INTERFACE,
+ SIGNAL_CLOSED,
+ NOTIFICATION_CLOSED_API);
+ dbus_test_dbus_mock_object_add_method(notify_mock,
+ notify_obj,
+ METHOD_CLOSE,
+ G_VARIANT_TYPE("(u)"),
+ nullptr,
+ str,
+ &error);
+ g_assert_no_error (error);
+ g_free (str);
+
dbus_test_service_add_task(service, DBUS_TEST_TASK(notify_mock));
///
@@ -226,14 +255,10 @@ protected:
ASSERT_NE(nullptr, system_bus);
g_dbus_connection_set_exit_on_close(system_bus, FALSE);
g_object_add_weak_pointer(G_OBJECT(system_bus), (gpointer *)&system_bus);
-
- notify_init(APP_NAME);
}
virtual void TearDown()
{
- notify_uninit();
-
g_clear_object(&screen_mock);
g_clear_object(&powerd_mock);
g_clear_object(&notify_mock);
@@ -291,10 +316,8 @@ TEST_F(SnapFixture, InteractiveDuration)
static constexpr int duration_minutes = 120;
auto settings = std::make_shared<Settings>();
settings->alarm_duration.set(duration_minutes);
- auto timezones = std::make_shared<Timezones>();
- auto clock = std::make_shared<LiveClock>(timezones);
-
- Snap snap (clock, settings);
+ auto ne = std::make_shared<unity::indicator::notifications::Engine>(APP_NAME);
+ Snap snap (ne, settings);
make_interactive();
@@ -333,6 +356,7 @@ TEST_F(SnapFixture, InteractiveDuration)
const auto duration = std::chrono::minutes(duration_minutes);
EXPECT_EQ(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(), i32);
g_variant_unref(hints);
+ ne.reset();
}
/***
@@ -341,12 +365,9 @@ TEST_F(SnapFixture, InteractiveDuration)
TEST_F(SnapFixture, InhibitSleep)
{
- //static constexpr int duration_minutes = 120;
auto settings = std::make_shared<Settings>();
- //settings->alarm_duration.set(duration_minutes);
- auto timezones = std::make_shared<Timezones>();
- auto clock = std::make_shared<LiveClock>(timezones);
- auto snap = new Snap (clock, settings);
+ auto ne = std::make_shared<unity::indicator::notifications::Engine>(APP_NAME);
+ auto snap = new Snap (ne, settings);
make_interactive();
@@ -372,6 +393,7 @@ TEST_F(SnapFixture, InhibitSleep)
&error));
// force-close the snap
+ wait_msec(100);
delete snap;
wait_msec(100);
@@ -398,12 +420,9 @@ TEST_F(SnapFixture, InhibitSleep)
TEST_F(SnapFixture, ForceScreen)
{
- //static constexpr int duration_minutes = 120;
auto settings = std::make_shared<Settings>();
- //settings->alarm_duration.set(duration_minutes);
- auto timezones = std::make_shared<Timezones>();
- auto clock = std::make_shared<LiveClock>(timezones);
- auto snap = new Snap (clock, settings);
+ auto ne = std::make_shared<unity::indicator::notifications::Engine>(APP_NAME);
+ auto snap = new Snap (ne, settings);
make_interactive();
@@ -423,6 +442,7 @@ TEST_F(SnapFixture, ForceScreen)
g_assert_no_error(error);
// force-close the snap
+ wait_msec(100);
delete snap;
wait_msec(100);