[gupnp/wip/phako/libsoup3] tests: Add test for folder serving with locale



commit c7ea1c13d1e5452f71dbe5bf172ff9ef1f0c317c
Author: Jens Georg <mail jensge org>
Date:   Sun Dec 26 15:04:35 2021 +0100

    tests: Add test for folder serving with locale

 tests/data/locale/test.de/index.html.de |   1 +
 tests/data/locale/test.fr/index.html.fr |   1 +
 tests/data/locale/test/index.html       |   1 +
 tests/test-context.c                    | 129 ++++++++++++++++++++++++++++++++
 4 files changed, 132 insertions(+)
---
diff --git a/tests/data/locale/test.de/index.html.de b/tests/data/locale/test.de/index.html.de
new file mode 100644
index 0000000..7673daa
--- /dev/null
+++ b/tests/data/locale/test.de/index.html.de
@@ -0,0 +1 @@
+de
diff --git a/tests/data/locale/test.fr/index.html.fr b/tests/data/locale/test.fr/index.html.fr
new file mode 100644
index 0000000..527e861
--- /dev/null
+++ b/tests/data/locale/test.fr/index.html.fr
@@ -0,0 +1 @@
+fr
diff --git a/tests/data/locale/test/index.html b/tests/data/locale/test/index.html
new file mode 100644
index 0000000..4ad96d5
--- /dev/null
+++ b/tests/data/locale/test/index.html
@@ -0,0 +1 @@
+default
diff --git a/tests/test-context.c b/tests/test-context.c
index 3cd1d1b..64310f4 100644
--- a/tests/test-context.c
+++ b/tests/test-context.c
@@ -637,6 +637,132 @@ test_gupnp_context_http_language_serve_file ()
         g_object_unref (session);
 }
 
+void
+test_gupnp_context_http_language_serve_folder ()
+{
+        GError *error = NULL;
+        GUPnPContext *context = create_context (0, &error);
+        DefaultCallbackData d = { .bytes = NULL, .loop = NULL };
+
+        d.loop = g_main_loop_new (NULL, FALSE);
+
+        GSList *uris =
+                soup_server_get_uris (gupnp_context_get_server (context));
+        gupnp_context_host_path (context, DATA_PATH "/locale/test", "/foo");
+        SoupSession *session = soup_session_new ();
+        char *base = g_uri_to_string (uris->data);
+        char *new_uri =
+                g_uri_resolve_relative (base, "foo/", G_URI_FLAGS_NONE, &error);
+        g_free (base);
+
+        SoupMessage *msg = soup_message_new (SOUP_METHOD_GET, new_uri);
+        soup_session_set_accept_language (session, NULL);
+
+        soup_session_send_and_read_async (session,
+                                          msg,
+                                          G_PRIORITY_DEFAULT,
+                                          NULL,
+                                          soup_message_default_callback,
+                                          &d);
+        g_main_loop_run (d.loop);
+
+        SoupMessageHeaders *hdrs = soup_message_get_response_headers (msg);
+        g_assert_cmpint (soup_message_get_status (msg), ==, SOUP_STATUS_OK);
+        g_assert_null (soup_message_headers_get_one (hdrs, "Content-Language"));
+        g_assert_nonnull (d.bytes);
+        g_assert_cmpmem (g_bytes_get_data (d.bytes, NULL),
+                         g_bytes_get_size (d.bytes),
+                         "default\n",
+                         8);
+        g_bytes_unref (d.bytes);
+
+        g_object_unref (msg);
+        msg = soup_message_new (SOUP_METHOD_GET, new_uri);
+        soup_session_set_accept_language (session, "de");
+        soup_session_send_and_read_async (session,
+                                          msg,
+                                          G_PRIORITY_DEFAULT,
+                                          NULL,
+                                          soup_message_default_callback,
+                                          &d);
+        g_main_loop_run (d.loop);
+
+        hdrs = soup_message_get_response_headers (msg);
+        g_assert_cmpint (soup_message_get_status (msg), ==, SOUP_STATUS_OK);
+        g_assert_cmpstr (
+                soup_message_headers_get_one (hdrs, "Content-Language"),
+                ==,
+                "de");
+        g_assert_nonnull (d.bytes);
+        g_assert_cmpmem (g_bytes_get_data (d.bytes, NULL),
+                         g_bytes_get_size (d.bytes),
+                         "de\n",
+                         3);
+        g_bytes_unref (d.bytes);
+
+
+        g_object_unref (msg);
+        msg = soup_message_new (SOUP_METHOD_GET, new_uri);
+        soup_session_set_accept_language (session, "fr");
+        soup_session_send_and_read_async (session,
+                                          msg,
+                                          G_PRIORITY_DEFAULT,
+                                          NULL,
+                                          soup_message_default_callback,
+                                          &d);
+        g_main_loop_run (d.loop);
+
+        hdrs = soup_message_get_response_headers (msg);
+        g_assert_cmpint (soup_message_get_status (msg), ==, SOUP_STATUS_OK);
+        g_assert_cmpstr (
+                soup_message_headers_get_one (hdrs, "Content-Language"),
+                ==,
+                "fr");
+        g_assert_nonnull (d.bytes);
+        g_assert_cmpmem (g_bytes_get_data (d.bytes, NULL),
+                         g_bytes_get_size (d.bytes),
+                         "fr\n",
+                         3);
+        g_bytes_unref (d.bytes);
+
+        g_object_unref (msg);
+        msg = soup_message_new (SOUP_METHOD_GET, new_uri);
+        soup_session_set_accept_language (session, "it");
+        soup_session_send_and_read_async (session,
+                                          msg,
+                                          G_PRIORITY_DEFAULT,
+                                          NULL,
+                                          soup_message_default_callback,
+                                          &d);
+        g_main_loop_run (d.loop);
+
+        hdrs = soup_message_get_response_headers (msg);
+        g_assert_cmpint (soup_message_get_status (msg), ==, SOUP_STATUS_OK);
+        g_assert_cmpstr (
+                soup_message_headers_get_one (hdrs, "Content-Language"),
+                ==,
+                "en");
+        g_assert_nonnull (d.bytes);
+        g_assert_cmpmem (g_bytes_get_data (d.bytes, NULL),
+                         g_bytes_get_size (d.bytes),
+                         "default\n",
+                         8);
+        g_bytes_unref (d.bytes);
+
+        g_object_unref (msg);
+
+        g_free (new_uri);
+        g_object_unref (context);
+        g_slist_free_full (uris, (GDestroyNotify) g_uri_unref);
+
+        // Make sure the source teardown handlers get run so we don't confuse valgrind
+        g_timeout_add (500, (GSourceFunc)g_main_loop_quit, d.loop);
+        g_main_loop_run (d.loop);
+        g_main_loop_unref (d.loop);
+        g_object_unref (session);
+}
+
+
 int main (int argc, char *argv[]) {
         g_test_init (&argc, &argv, NULL);
         g_test_add_func ("/context/http/ranged-requests",
@@ -653,6 +779,9 @@ int main (int argc, char *argv[]) {
         g_test_add_func ("/context/http/language/serve-file",
                          test_gupnp_context_http_language_serve_file);
 
+        g_test_add_func ("/context/http/language/serve-folder",
+                         test_gupnp_context_http_language_serve_folder);
+
         g_test_add_func ("/context/utility/rewrite_uri",
                          test_gupnp_context_rewrite_uri);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]