1/*
2 * Copyright (C) 2011 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "TestMain.h"
22
23#include <glib/gstdio.h>
24
25#if PLATFORM(GTK)
26#include <gtk/gtk.h>
27#endif
28
29uint32_t Test::s_webExtensionID = 0;
30
31void beforeAll();
32void afterAll();
33
34static GUniquePtr<char> testDataDirectory(g_dir_make_tmp("WebKitGLibTests-XXXXXX", nullptr));
35
36const char* Test::dataDirectory()
37{
38 return testDataDirectory.get();
39}
40
41static void registerGResource(void)
42{
43 GUniquePtr<char> resourcesPath(g_build_filename(WEBKIT_TEST_RESOURCES_DIR, "webkitglib-tests-resources.gresource", nullptr));
44 GResource* resource = g_resource_load(resourcesPath.get(), nullptr);
45 g_assert_nonnull(resource);
46
47 g_resources_register(resource);
48 g_resource_unref(resource);
49}
50
51static void removeNonEmptyDirectory(const char* directoryPath)
52{
53 GDir* directory = g_dir_open(directoryPath, 0, 0);
54 g_assert_nonnull(directory);
55 const char* fileName;
56 while ((fileName = g_dir_read_name(directory))) {
57 GUniquePtr<char> filePath(g_build_filename(directoryPath, fileName, nullptr));
58 if (g_file_test(filePath.get(), G_FILE_TEST_IS_DIR))
59 removeNonEmptyDirectory(filePath.get());
60 else
61 g_unlink(filePath.get());
62 }
63 g_dir_close(directory);
64 g_rmdir(directoryPath);
65}
66
67int main(int argc, char** argv)
68{
69 g_unsetenv("DBUS_SESSION_BUS_ADDRESS");
70#if PLATFORM(GTK)
71 gtk_test_init(&argc, &argv, nullptr);
72#else
73 g_test_init(&argc, &argv, nullptr);
74#endif
75 g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
76 g_setenv("WEBKIT_INJECTED_BUNDLE_PATH", WEBKIT_INJECTED_BUNDLE_PATH, FALSE);
77 g_setenv("LC_ALL", "C", TRUE);
78 g_setenv("GIO_USE_VFS", "local", TRUE);
79 g_setenv("GSETTINGS_BACKEND", "memory", TRUE);
80 // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
81 g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
82 g_test_bug_base("https://bugs.webkit.org/");
83
84 registerGResource();
85
86 beforeAll();
87 int returnValue = g_test_run();
88 afterAll();
89
90 removeNonEmptyDirectory(testDataDirectory.get());
91
92 return returnValue;
93}
94
95