Verified Commit b205a460 authored by James Westman's avatar James Westman
Browse files

tests: Make TestTileServer an object

This will help with more complicated network tile source tests in the
parent 6e012a72
......@@ -37,7 +37,8 @@ on_tile_filled (GObject *object, GAsyncResult *res, gpointer user_data)
static void
test_network_tile_source_tile (void)
g_autofree char *uri = testserver_start ();
g_autoptr(TestTileServer) server = test_tile_server_new ();
g_autofree char *uri = test_tile_server_start (server);
g_autoptr(ShumateMapSource) source = create_tile_source (uri);
g_autoptr(ShumateTile) tile = shumate_tile_new_full (0, 0, 256, 0);
g_autoptr(GMainLoop) loop = NULL;
......@@ -4,6 +4,48 @@
#include <libsoup/soup.h>
#include <gdk/gdk.h>
#include "test-tile-server.h"
struct _TestTileServer
GObject parent_instance;
SoupServer *server;
G_DEFINE_TYPE (TestTileServer, test_tile_server, G_TYPE_OBJECT)
TestTileServer *
test_tile_server_new (void)
return g_object_new (TEST_TYPE_TILE_SERVER, NULL);
static void
test_tile_server_finalize (GObject *object)
TestTileServer *self = (TestTileServer *)object;
g_clear_object (&self->server);
G_OBJECT_CLASS (test_tile_server_parent_class)->finalize (object);
static void
test_tile_server_class_init (TestTileServerClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = test_tile_server_finalize;
static void
test_tile_server_init (TestTileServer *self)
self->server = soup_server_new (NULL, NULL);
static cairo_status_t
write_func (void *bytearray, const unsigned char *data, unsigned int length)
......@@ -51,18 +93,16 @@ server_callback (SoupServer *server,
char *
testserver_start (void)
test_tile_server_start (TestTileServer *self)
SoupServer *server = soup_server_new (NULL, NULL);
g_autoptr(GError) error = NULL;
g_autoptr(GSList) uris = NULL;
soup_server_add_handler (self->server, NULL, server_callback, generate_image (), (GDestroyNotify) g_bytes_unref);
soup_server_add_handler (server, NULL, server_callback, generate_image (), (GDestroyNotify) g_bytes_unref);
soup_server_listen_local (server, 0, 0, &error);
soup_server_listen_local (self->server, 0, 0, &error);
g_assert_no_error (error);
uris = soup_server_get_uris (server);
uris = soup_server_get_uris (self->server);
g_assert_true (g_slist_length (uris) >= 1);
return soup_uri_to_string (uris->data, FALSE);
char *testserver_start (void);
#pragma once
#include <glib-object.h>
#define TEST_TYPE_TILE_SERVER (test_tile_server_get_type())
G_DECLARE_FINAL_TYPE (TestTileServer, test_tile_server, TEST, TILE_SERVER, GObject)
TestTileServer *test_tile_server_new (void);
char *test_tile_server_start (TestTileServer *self);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment