1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#undef G_DISABLE_ASSERT
#include <gtk/gtk.h>
#include <shumate/shumate.h>
static void
test_data_source_request_data (void)
{
g_autoptr(ShumateDataSourceRequest) req = shumate_data_source_request_new (1, 2, 3);
const char *data1 = "Hello, world!";
const char *data2 = "Goodbye!";
g_autoptr(GBytes) bytes1 = g_bytes_new_static (data1, strlen (data1));
g_autoptr(GBytes) bytes2 = g_bytes_new_static (data2, strlen (data2));
g_assert_cmpint (shumate_data_source_request_get_x (req), ==, 1);
g_assert_cmpint (shumate_data_source_request_get_y (req), ==, 2);
g_assert_cmpint (shumate_data_source_request_get_zoom_level (req), ==, 3);
shumate_data_source_request_emit_data (req, bytes1, FALSE);
g_assert_true (g_bytes_equal (bytes1, shumate_data_source_request_get_data (req)));
g_assert_false (shumate_data_source_request_is_completed (req));
shumate_data_source_request_emit_data (req, bytes2, FALSE);
g_assert_true (g_bytes_equal (bytes2, shumate_data_source_request_get_data (req)));
g_assert_false (shumate_data_source_request_is_completed (req));
shumate_data_source_request_emit_data (req, bytes1, TRUE);
g_assert_true (g_bytes_equal (bytes1, shumate_data_source_request_get_data (req)));
g_assert_true (shumate_data_source_request_is_completed (req));
}
static void
test_data_source_request_error (void)
{
g_autoptr(ShumateDataSourceRequest) req = shumate_data_source_request_new (1, 2, 3);
const char *data1 = "Hello, world!";
g_autoptr(GBytes) bytes1 = g_bytes_new_static (data1, strlen (data1));
g_autoptr(GError) error = g_error_new (G_IO_ERROR, G_IO_ERROR_EXISTS, "Error!");
g_assert_false (shumate_data_source_request_is_completed (req));
shumate_data_source_request_emit_data (req, bytes1, FALSE);
g_assert_true (g_bytes_equal (bytes1, shumate_data_source_request_get_data (req)));
g_assert_false (shumate_data_source_request_is_completed (req));
shumate_data_source_request_emit_error (req, error);
g_assert_true (shumate_data_source_request_is_completed (req));
g_assert_null (shumate_data_source_request_get_data (req));
g_assert_cmpstr (shumate_data_source_request_get_error (req)->message, ==, "Error!");
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/data-source-request/data", test_data_source_request_data);
g_test_add_func ("/data-source-request/error", test_data_source_request_error);
return g_test_run ();
}
|