LCOV - code coverage report
Current view: top level - tests - data-source-request.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 38 38 100.0 %
Date: 2024-05-11 21:41:31 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 42 50.0 %

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

Generated by: LCOV version 1.14