aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-16 21:23:57 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-16 21:23:57 -0600
commit2e9d3bb48946ccebf49cff64ab5de67e5714e1e3 (patch)
treeaa8fc3b514a49b58dc797a2083af5f6417adf0f5
parent6f2e235e660094f6ec27a0a099428ac3fe852ff7 (diff)
downloadayatana-indicator-datetime-2e9d3bb48946ccebf49cff64ab5de67e5714e1e3.tar.gz
ayatana-indicator-datetime-2e9d3bb48946ccebf49cff64ab5de67e5714e1e3.tar.bz2
ayatana-indicator-datetime-2e9d3bb48946ccebf49cff64ab5de67e5714e1e3.zip
get timezone, clock tests running again with Settings & State
-rw-r--r--include/datetime/actions-live.h7
-rw-r--r--include/datetime/actions.h2
-rw-r--r--src/actions-live.cpp9
-rw-r--r--src/actions.cpp6
-rw-r--r--tests/geoclue-fixture.h48
-rw-r--r--tests/test-clock.cc168
-rw-r--r--tests/test-dbus-fixture.h14
-rw-r--r--tests/test-timezones.cc21
8 files changed, 91 insertions, 184 deletions
diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h
index 2059a4d..3d04660 100644
--- a/include/datetime/actions-live.h
+++ b/include/datetime/actions-live.h
@@ -36,15 +36,14 @@ namespace datetime {
class LiveActions: public Actions
{
public:
- LiveActions(std::shared_ptr<State>& state): Actions(state) {}
+ LiveActions(const std::shared_ptr<State>& state): Actions(state) {}
~LiveActions() =default;
void open_desktop_settings();
void open_phone_settings();
- void open_phone_clock();
- void open_phone_planner();
+ void open_phone_clock_app();
+ void open_planner();
void open_planner_at(const DateTime&);
- void open_calendar_at(const DateTime&);
void open_appointment(const std::string& uid);
void set_location(const std::string& zone, const std::string& name);
void set_calendar_date(const DateTime&);
diff --git a/include/datetime/actions.h b/include/datetime/actions.h
index ed45c3c..a4c6017 100644
--- a/include/datetime/actions.h
+++ b/include/datetime/actions.h
@@ -51,7 +51,7 @@ public:
std::shared_ptr<State> state() { return m_state; }
protected:
- Actions(std::shared_ptr<State>& state);
+ Actions(const std::shared_ptr<State>& state);
virtual ~Actions();
private:
diff --git a/src/actions-live.cpp b/src/actions-live.cpp
index 08e1466..c699aff 100644
--- a/src/actions-live.cpp
+++ b/src/actions-live.cpp
@@ -39,12 +39,12 @@ void LiveActions::open_phone_settings()
g_message("%s", G_STRFUNC);
}
-void LiveActions::open_phone_clock()
+void LiveActions::open_phone_clock_app()
{
g_message("%s", G_STRFUNC);
}
-void LiveActions::open_phone_planner()
+void LiveActions::open_planner()
{
g_message("%s", G_STRFUNC);
}
@@ -54,11 +54,6 @@ void LiveActions::open_planner_at(const DateTime&)
g_message("%s", G_STRFUNC);
}
-void LiveActions::open_calendar_at(const DateTime&)
-{
- g_message("%s", G_STRFUNC);
-}
-
void LiveActions::open_appointment(const std::string& uid)
{
g_message("%s - %s", G_STRFUNC, uid.c_str());
diff --git a/src/actions.cpp b/src/actions.cpp
index 52ee1eb..0df7d53 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -130,7 +130,7 @@ GVariant* create_default_header_state()
return g_variant_builder_end(&b);
}
-GVariant* create_calendar_state(std::shared_ptr<State>& state)
+GVariant* create_calendar_state(const std::shared_ptr<State>& state)
{
gboolean days[32] = { 0 };
for(const auto& appt : state->planner->thisMonth.get())
@@ -138,7 +138,7 @@ GVariant* create_calendar_state(std::shared_ptr<State>& state)
GVariantBuilder day_builder;
g_variant_builder_init(&day_builder, G_VARIANT_TYPE("ai"));
- for (int i=0; i<G_N_ELEMENTS(days); i++)
+ for (guint i=0; i<G_N_ELEMENTS(days); i++)
if (days[i])
g_variant_builder_add(&day_builder, "i", i);
@@ -165,7 +165,7 @@ GVariant* create_calendar_state(std::shared_ptr<State>& state)
****
***/
-Actions::Actions(std::shared_ptr<State>& state):
+Actions::Actions(const std::shared_ptr<State>& state):
m_state(state),
m_actions(g_simple_action_group_new())
{
diff --git a/tests/geoclue-fixture.h b/tests/geoclue-fixture.h
index 890204a..7e29018 100644
--- a/tests/geoclue-fixture.h
+++ b/tests/geoclue-fixture.h
@@ -33,8 +33,10 @@ class GeoclueFixture : public GlibFixture
DbusTestService * service = nullptr;
DbusTestDbusMock * mock = nullptr;
- DbusTestDbusMockObject * obj_master = nullptr;
- DbusTestDbusMockObject * obj_client = nullptr;
+ DbusTestDbusMockObject * obj_geo = nullptr;
+ DbusTestDbusMockObject * obj_geo_m = nullptr;
+ DbusTestDbusMockObject * obj_geo_mc = nullptr;
+ DbusTestDbusMockObject * obj_geo_addr = nullptr;
const std::string timezone_1 = "America/Denver";
void SetUp ()
@@ -42,25 +44,31 @@ class GeoclueFixture : public GlibFixture
super::SetUp();
GError * error = nullptr;
- const gchar * const client_path = "/org/freedesktop/Geoclue/Master/client0";
+ const auto master_path = "/org/freedesktop/Geoclue/Master";
+ const auto client_path = "/org/freedesktop/Geoclue/Master/client0";
GString * gstr = g_string_new (nullptr);
service = dbus_test_service_new (nullptr);
mock = dbus_test_dbus_mock_new ("org.freedesktop.Geoclue.Master");
- obj_master = dbus_test_dbus_mock_get_object (mock,
- "/org/freedesktop/Geoclue/Master",
- "org.freedesktop.Geoclue.Master",
- nullptr);
+ auto interface = "org.freedesktop.Geoclue.Master";
+ obj_geo_m = dbus_test_dbus_mock_get_object (mock, master_path, interface, nullptr);
g_string_printf (gstr, "ret = '%s'", client_path);
- dbus_test_dbus_mock_object_add_method (mock, obj_master, nullptr, "Create", nullptr, G_VARIANT_TYPE_OBJECT_PATH, gstr->str, &error);
+ dbus_test_dbus_mock_object_add_method (mock, obj_geo_m, "Create", nullptr, G_VARIANT_TYPE_OBJECT_PATH, gstr->str, &error);
- obj_client = dbus_test_dbus_mock_get_object (mock, client_path, "org.freedesktop.Geoclue.MasterClient", nullptr);
- dbus_test_dbus_mock_object_add_method (mock, obj_client, nullptr, "SetRequirements", G_VARIANT_TYPE("(iibi)"), nullptr, "", &error);
- dbus_test_dbus_mock_object_add_method (mock, obj_client, nullptr, "AddressStart", nullptr, nullptr, "", &error);
- dbus_test_dbus_mock_object_add_method (mock, obj_client, "org.freedesktop.Geoclue", "AddReference", nullptr, nullptr, "", &error);
+ interface = "org.freedesktop.Geoclue.MasterClient";
+ obj_geo_mc = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr);
+ dbus_test_dbus_mock_object_add_method (mock, obj_geo_mc, "SetRequirements", G_VARIANT_TYPE("(iibi)"), nullptr, "", &error);
+ dbus_test_dbus_mock_object_add_method (mock, obj_geo_mc, "AddressStart", nullptr, nullptr, "", &error);
+
+ interface = "org.freedesktop.Geoclue";
+ obj_geo = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr);
+ dbus_test_dbus_mock_object_add_method (mock, obj_geo, "AddReference", nullptr, nullptr, "", &error);
g_string_printf (gstr, "ret = (1385238033, {'timezone': '%s'}, (3, 0.0, 0.0))", timezone_1.c_str());
- dbus_test_dbus_mock_object_add_method (mock, obj_client, "org.freedesktop.Geoclue.Address", "GetAddress", nullptr, G_VARIANT_TYPE("(ia{ss}(idd))"), gstr->str, &error);
+
+ interface = "org.freedesktop.Geoclue.Address";
+ obj_geo_addr = dbus_test_dbus_mock_get_object (mock, client_path, interface, nullptr);
+ dbus_test_dbus_mock_object_add_method (mock, obj_geo_addr, "GetAddress", nullptr, G_VARIANT_TYPE("(ia{ss}(idd))"), gstr->str, &error);
dbus_test_service_add_task(service, DBUS_TEST_TASK(mock));
dbus_test_service_start_tasks(service);
@@ -101,11 +109,11 @@ private:
struct EmitAddressChangedData
{
DbusTestDbusMock * mock = nullptr;
- DbusTestDbusMockObject * obj_client = nullptr;
+ DbusTestDbusMockObject * obj_geo_addr = nullptr;
std::string timezone;
- EmitAddressChangedData(DbusTestDbusMock * mock_,
- DbusTestDbusMockObject * obj_client_,
- const std::string& timezone_): mock(mock_), obj_client(obj_client_), timezone(timezone_) {}
+ EmitAddressChangedData(DbusTestDbusMock* mock_,
+ DbusTestDbusMockObject* obj_geo_addr_,
+ const std::string& timezone_): mock(mock_), obj_geo_addr(obj_geo_addr_), timezone(timezone_) {}
};
static gboolean emit_address_changed_idle (gpointer gdata)
@@ -114,8 +122,8 @@ private:
auto fmt = g_strdup_printf ("(1385238033, {'timezone': '%s'}, (3, 0.0, 0.0))", data->timezone.c_str());
GError * error = nullptr;
- dbus_test_dbus_mock_object_emit_signal(data->mock, data->obj_client,
- "org.freedesktop.Geoclue.Address",
+ dbus_test_dbus_mock_object_emit_signal(data->mock, data->obj_geo_addr,
+ //"org.freedesktop.Geoclue.Address",
"AddressChanged",
G_VARIANT_TYPE("(ia{ss}(idd))"),
g_variant_new_parsed (fmt),
@@ -135,7 +143,7 @@ public:
void setGeoclueTimezoneOnIdle (const std::string& newZone)
{
- g_timeout_add (50, emit_address_changed_idle, new EmitAddressChangedData(mock, obj_client, newZone.c_str()));
+ g_timeout_add (50, emit_address_changed_idle, new EmitAddressChangedData(mock, obj_geo_addr, newZone.c_str()));
}
};
diff --git a/tests/test-clock.cc b/tests/test-clock.cc
index 7d3a35e..142ccad 100644
--- a/tests/test-clock.cc
+++ b/tests/test-clock.cc
@@ -20,95 +20,56 @@
#include <datetime/clock.h>
#include <datetime/timezones.h>
-#include "glib-fixture.h"
+#include "test-dbus-fixture.h"
/***
****
***/
-using unity::indicator::datetime::Clock;
-using unity::indicator::datetime::LiveClock;
-using unity::indicator::datetime::Timezones;
+using namespace unity::indicator::datetime;
-class ClockFixture: public GlibFixture
+class ClockFixture: public TestDBusFixture
{
private:
-
- typedef GlibFixture super;
-
- static void
- on_bus_opened(GObject* /*object*/, GAsyncResult* res, gpointer gself)
- {
- auto self = static_cast<ClockFixture*>(gself);
-
- GError * err = 0;
- self->system_bus = g_bus_get_finish(res, &err);
- g_assert_no_error(err);
-
- g_main_loop_quit(self->loop);
- }
-
- static void
- on_bus_closed(GObject* /*object*/, GAsyncResult* res, gpointer gself)
- {
- auto self = static_cast<ClockFixture*>(gself);
-
- GError * err = 0;
- g_dbus_connection_close_finish(self->system_bus, res, &err);
- g_assert_no_error(err);
-
- g_main_loop_quit(self->loop);
- }
-
- protected:
-
- GTestDBus * test_dbus;
- GDBusConnection * system_bus;
-
- virtual void SetUp()
- {
- super::SetUp();
-
- // pull up a test dbus
- test_dbus = g_test_dbus_new(G_TEST_DBUS_NONE);
- g_test_dbus_up(test_dbus);
- const char * address = g_test_dbus_get_bus_address(test_dbus);
- g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, TRUE);
- g_debug("test_dbus's address is %s", address);
-
- // wait for the GDBusConnection before returning
- g_bus_get(G_BUS_TYPE_SYSTEM, nullptr, on_bus_opened, this);
- g_main_loop_run(loop);
- }
-
- virtual void TearDown()
- {
- // close the system bus
- g_dbus_connection_close(system_bus, nullptr, on_bus_closed, this);
- g_main_loop_run(loop);
- g_clear_object(&system_bus);
-
- // tear down the test dbus
- g_test_dbus_down(test_dbus);
- g_clear_object(&test_dbus);
-
- super::TearDown();
- }
+ typedef TestDBusFixture super;
public:
-
void emitPrepareForSleep()
{
g_dbus_connection_emit_signal(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr),
- NULL,
- "/org/freedesktop/login1", // object path
- "org.freedesktop.login1.Manager", // interface
- "PrepareForSleep", // signal name
- g_variant_new("(b)", FALSE),
- NULL);
+ NULL,
+ "/org/freedesktop/login1", // object path
+ "org.freedesktop.login1.Manager", // interface
+ "PrepareForSleep", // signal name
+ g_variant_new("(b)", FALSE),
+ NULL);
}
};
+/**
+ * Confirm that normal time passing doesn't trigger a skew event.
+ * that idling changing the clock's time triggers a skew event
+ */
+TEST_F(ClockFixture, IdleDoesNotTriggerSkew)
+{
+ std::shared_ptr<Timezones> zones(new Timezones);
+ zones->timezone.set("America/New_York");
+ LiveClock clock(zones);
+ wait_msec(500); // wait for the bus to set up
+
+ bool skewed = false;
+ clock.skewDetected.connect([&skewed](){
+ skewed = true;
+ g_warn_if_reached();
+ return G_SOURCE_REMOVE;
+ });
+
+ const unsigned int intervalSec = 3;
+ clock.skewTestIntervalSec.set(intervalSec);
+ wait_msec(intervalSec * 2.5 * 1000);
+ EXPECT_FALSE(skewed);
+}
+
/***
****
***/
@@ -120,37 +81,6 @@ TEST_F(ClockFixture, HelloFixture)
std::shared_ptr<Timezones> zones(new Timezones);
zones->timezone.set("America/New_York");
LiveClock clock(zones);
-
-#if 0
- GTimeZone * tz_nyc = g_time_zone_new(file_timezone.c_str());
- GDateTime * now_nyc = g_date_time_new_now(tz_nyc);
- GDateTime * now = clock.localtime();
- EXPECT_EQ(g_date_time_get_utc_offset(now_nyc), g_date_time_get_utc_offset(now));
- EXPECT_LE(abs(g_date_time_difference(now_nyc,now)), G_USEC_PER_SEC);
- g_date_time_unref(now);
- g_date_time_unref(now_nyc);
- g_time_zone_unref(tz_nyc);
-
- /// change the timezones!
- clock.skewDetected.connect([this](){
- g_main_loop_quit(loop);
- });
- file_timezone = "America/Los_Angeles";
- g_idle_add([](gpointer str){
- set_file(static_cast<const char*>(str));
- return G_SOURCE_REMOVE;
- }, const_cast<char*>(file_timezone.c_str()));
- g_main_loop_run(loop);
-
- GTimeZone * tz_la = g_time_zone_new(file_timezone.c_str());
- GDateTime * now_la = g_date_time_new_now(tz_la);
- now = clock.localtime();
- EXPECT_EQ(g_date_time_get_utc_offset(now_la), g_date_time_get_utc_offset(now));
- EXPECT_LE(abs(g_date_time_difference(now_la,now)), G_USEC_PER_SEC);
- g_date_time_unref(now);
- g_date_time_unref(now_la);
- g_time_zone_unref(tz_la);
-#endif
}
@@ -159,10 +89,6 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew)
std::shared_ptr<Timezones> zones(new Timezones);
zones->timezone.set("America/New_York");
LiveClock clock(zones);
- //std::string file_timezone = "America/New_York";
- //set_file(file_timezone);
- //std::shared_ptr<TimezoneDetector> detector(new TimezoneDetector(TIMEZONE_FILE));
- //LiveClock clock(detector);
auto tz_nyc = g_time_zone_new("America/New_York");
auto now_nyc = g_date_time_new_now(tz_nyc);
@@ -213,30 +139,6 @@ TEST_F(ClockFixture, SleepTriggersSkew)
return G_SOURCE_REMOVE;
}, this);
- wait_msec(1000);
+ g_main_loop_run(loop);
EXPECT_TRUE(skewed);
}
-
-/**
- * Confirm that normal time passing doesn't trigger a skew event.
- * that idling changing the clock's time triggers a skew event
- */
-TEST_F(ClockFixture, IdleDoesNotTriggerSkew)
-{
- std::shared_ptr<Timezones> zones(new Timezones);
- zones->timezone.set("America/New_York");
- LiveClock clock(zones);
- wait_msec(500); // wait for the bus to set up
-
- bool skewed = false;
- clock.skewDetected.connect([&skewed](){
- skewed = true;
- g_warn_if_reached();
- return G_SOURCE_REMOVE;
- });
-
- const unsigned int intervalSec = 4;
- clock.skewTestIntervalSec.set(intervalSec);
- wait_msec(intervalSec * 2.5 * 1000);
- EXPECT_FALSE(skewed);
-}
diff --git a/tests/test-dbus-fixture.h b/tests/test-dbus-fixture.h
index fc7ab5a..db06be2 100644
--- a/tests/test-dbus-fixture.h
+++ b/tests/test-dbus-fixture.h
@@ -86,15 +86,17 @@ class TestDBusFixture: public GlibFixture
virtual void TearDown ()
{
+ wait_msec();
+
// close the system bus
- g_dbus_connection_close (system_bus, nullptr, on_bus_closed, this);
- g_main_loop_run (loop);
- g_clear_object (&system_bus);
+ g_dbus_connection_close(system_bus, nullptr, on_bus_closed, this);
+ g_main_loop_run(loop);
+ g_clear_object(&system_bus);
// tear down the test dbus
- g_test_dbus_down (test_dbus);
- g_clear_object (&test_dbus);
+ g_test_dbus_down(test_dbus);
+ g_clear_object(&test_dbus);
- super::TearDown ();
+ super::TearDown();
}
};
diff --git a/tests/test-timezones.cc b/tests/test-timezones.cc
index d3c8e3a..3f02761 100644
--- a/tests/test-timezones.cc
+++ b/tests/test-timezones.cc
@@ -19,12 +19,15 @@
#include "geoclue-fixture.h"
+#include <datetime/settings.h>
#include <datetime/timezones-live.h>
+#include <memory> // std::shared_ptr
+
#include <cstdio> // fopen()
#include <unistd.h> // sync()
-using unity::indicator::datetime::LiveTimezones;
+using namespace unity::indicator::datetime;
typedef GeoclueFixture TimezonesFixture;
@@ -49,7 +52,8 @@ TEST_F(TimezonesFixture, ManagerTest)
std::string timezone_geo = "America/Denver";
set_file(timezone_file);
- LiveTimezones z(TIMEZONE_FILE);
+ std::shared_ptr<Settings> settings(new Settings);
+ LiveTimezones z(settings, TIMEZONE_FILE);
wait_msec(500); // wait for the bus to get set up
EXPECT_EQ(timezone_file, z.timezone.get());
auto zones = z.timezones.get();
@@ -71,13 +75,13 @@ TEST_F(TimezonesFixture, ManagerTest)
g_main_loop_quit(loop);
});
- g_idle_add([](gpointer gz) {
- auto az = static_cast<LiveTimezones*>(gz);
- g_message("geolocation was %d", (int)az->geolocationEnabled.get());
+ g_idle_add([](gpointer s_in) {
+ auto s = static_cast<Settings*>(s_in);
+ g_message("geolocation was %d", (int)s->show_detected_location.get());
g_message("turning geolocation on");
- az->geolocationEnabled.set(true);
+ s->show_detected_location.set(true);
return G_SOURCE_REMOVE;
- }, &z);
+ }, settings.get());
// turn on geoclue during the idle... this should add timezone_1 to the 'timezones' property
g_main_loop_run(loop);
@@ -115,9 +119,6 @@ TEST_F(TimezonesFixture, ManagerTest)
EXPECT_EQ(2, zones.size());
EXPECT_EQ(1, zones.count(timezone_file));
EXPECT_EQ(1, zones.count(timezone_geo));
-
-
-
}