2
* Copyright 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Ted Gould <ted.gould@canonical.com>
20
#include <gtest/gtest.h>
21
#include <glib/gstdio.h>
23
#include <upstart-app-launch.h>
25
class FailureTest : public ::testing::Test
28
GTestDBus * testbus = NULL;
31
virtual void SetUp() {
32
testbus = g_test_dbus_new(G_TEST_DBUS_NONE);
33
g_test_dbus_up(testbus);
36
virtual void TearDown() {
37
g_test_dbus_down(testbus);
38
g_clear_object(&testbus);
42
static gboolean pause_helper (gpointer pmainloop) {
43
g_main_loop_quit(static_cast<GMainLoop *>(pmainloop));
44
return G_SOURCE_REMOVE;
47
void pause (guint time) {
49
GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
50
g_timeout_add(time, pause_helper, mainloop);
52
g_main_loop_run(mainloop);
54
g_main_loop_unref(mainloop);
57
while (g_main_pending()) {
58
g_main_iteration(TRUE);
64
failed_observer (const gchar * appid, upstart_app_launch_app_failed_t reason, gpointer user_data)
66
if (reason == UPSTART_APP_LAUNCH_APP_FAILED_CRASH) {
67
std::string * last = static_cast<std::string *>(user_data);
73
TEST_F(FailureTest, CrashTest)
75
g_setenv("EXIT_STATUS", "-100", TRUE);
76
g_setenv("JOB", "application-click", TRUE);
77
g_setenv("INSTANCE", "foo", TRUE);
79
std::string last_observer;
80
ASSERT_TRUE(upstart_app_launch_observer_add_app_failed(failed_observer, &last_observer));
83
ASSERT_TRUE(g_spawn_command_line_sync(APP_FAILED_TOOL, NULL, NULL, NULL, NULL));
86
EXPECT_EQ("foo", last_observer);
88
last_observer.clear();
89
g_unsetenv("EXIT_STATUS");
90
g_setenv("EXIT_SIGNAL", "KILL", TRUE);
93
ASSERT_TRUE(g_spawn_command_line_sync(APP_FAILED_TOOL, NULL, NULL, NULL, NULL));
96
EXPECT_EQ("foo", last_observer);
98
ASSERT_TRUE(upstart_app_launch_observer_delete_app_failed(failed_observer, &last_observer));
103
TEST_F(FailureTest, LegacyTest)
105
g_setenv("EXIT_STATUS", "-100", TRUE);
106
g_setenv("JOB", "application-legacy", TRUE);
107
g_setenv("INSTANCE", "foo-1234", TRUE);
109
std::string last_observer;
110
ASSERT_TRUE(upstart_app_launch_observer_add_app_failed(failed_observer, &last_observer));
113
ASSERT_TRUE(g_spawn_command_line_sync(APP_FAILED_TOOL, NULL, NULL, NULL, NULL));
116
EXPECT_EQ("foo", last_observer);
118
ASSERT_TRUE(upstart_app_launch_observer_delete_app_failed(failed_observer, &last_observer));
124
failed_start_observer (const gchar * appid, upstart_app_launch_app_failed_t reason, gpointer user_data)
126
if (reason == UPSTART_APP_LAUNCH_APP_FAILED_START_FAILURE) {
127
std::string * last = static_cast<std::string *>(user_data);
133
TEST_F(FailureTest, StartTest)
135
g_setenv("JOB", "application-click", TRUE);
136
g_setenv("INSTANCE", "foo", TRUE);
137
g_unsetenv("EXIT_STATUS");
138
g_unsetenv("EXIT_SIGNAL");
140
std::string last_observer;
141
ASSERT_TRUE(upstart_app_launch_observer_add_app_failed(failed_start_observer, &last_observer));
143
ASSERT_TRUE(g_spawn_command_line_sync(APP_FAILED_TOOL, NULL, NULL, NULL, NULL));
146
EXPECT_EQ("foo", last_observer);
148
ASSERT_TRUE(upstart_app_launch_observer_delete_app_failed(failed_start_observer, &last_observer));