LCOV - code coverage report
Current view: top level - tests - vector-value.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 125 125 100.0 %
Date: 2024-05-11 21:41:31 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 40 80 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                 :            : #include "shumate/vector/shumate-vector-value-private.h"
       6                 :            : 
       7                 :            : static void
       8                 :          3 : test_vector_value_literal (void)
       9                 :            : {
      10                 :          6 :   g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
      11                 :          3 :   double number;
      12                 :          3 :   gboolean boolean;
      13                 :          3 :   const char *string;
      14                 :            : 
      15                 :          3 :   shumate_vector_value_unset (&value);
      16                 :            : 
      17                 :          3 :   shumate_vector_value_set_number (&value, 3.1415);
      18         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_number (&value, &number));
      19         [ -  + ]:          3 :   g_assert_cmpfloat (3.1415, ==, number);
      20                 :            : 
      21                 :          3 :   shumate_vector_value_set_boolean (&value, TRUE);
      22         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_boolean (&value, &boolean));
      23         [ -  + ]:          3 :   g_assert_true (boolean);
      24                 :            : 
      25                 :          3 :   shumate_vector_value_set_boolean (&value, FALSE);
      26         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_boolean (&value, &boolean));
      27         [ -  + ]:          3 :   g_assert_false (boolean);
      28                 :            : 
      29                 :          3 :   shumate_vector_value_set_string (&value, "Hello, world!");
      30         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_string (&value, &string));
      31         [ -  + ]:          3 :   g_assert_cmpstr ("Hello, world!", ==, string);
      32                 :          3 : }
      33                 :            : 
      34                 :            : 
      35                 :            : static void
      36                 :          3 : test_vector_value_from_gvalue (void)
      37                 :            : {
      38                 :          6 :   g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
      39                 :          3 :   g_auto(GValue) gvalue = G_VALUE_INIT;
      40                 :          3 :   double number;
      41                 :          3 :   gboolean boolean;
      42                 :          3 :   const char *string;
      43                 :            : 
      44                 :          3 :   shumate_vector_value_unset (&value);
      45                 :            : 
      46                 :          3 :   g_value_init (&gvalue, G_TYPE_DOUBLE);
      47                 :          3 :   g_value_set_double (&gvalue, 3.1415);
      48         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_set_from_g_value (&value, &gvalue));
      49         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_number (&value, &number));
      50         [ -  + ]:          3 :   g_assert_cmpfloat (3.1415, ==, number);
      51                 :          3 :   g_value_unset (&gvalue);
      52                 :            : 
      53                 :          3 :   g_value_init (&gvalue, G_TYPE_BOOLEAN);
      54                 :          3 :   g_value_set_boolean (&gvalue, TRUE);
      55         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_set_from_g_value (&value, &gvalue));
      56         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_boolean (&value, &boolean));
      57         [ -  + ]:          3 :   g_assert_true (boolean);
      58                 :            : 
      59                 :          3 :   g_value_set_boolean (&gvalue, FALSE);
      60                 :          3 :   shumate_vector_value_set_from_g_value (&value, &gvalue);
      61         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_boolean (&value, &boolean));
      62         [ -  + ]:          3 :   g_assert_false (boolean);
      63                 :          3 :   g_value_unset (&gvalue);
      64                 :            : 
      65                 :          3 :   g_value_init (&gvalue, G_TYPE_STRING);
      66                 :          3 :   g_value_set_string (&gvalue, "Hello, world!");
      67         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_set_from_g_value (&value, &gvalue));
      68         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_string (&value, &string));
      69         [ -  + ]:          3 :   g_assert_cmpstr ("Hello, world!", ==, string);
      70                 :          3 :   g_value_unset (&gvalue);
      71                 :          3 : }
      72                 :            : 
      73                 :            : static void
      74                 :          3 : test_vector_value_get_color (void)
      75                 :            : {
      76                 :          6 :   g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
      77                 :          3 :   GdkRGBA color, correct_color;
      78                 :            : 
      79                 :          3 :   gdk_rgba_parse (&correct_color, "goldenrod");
      80                 :          3 :   shumate_vector_value_set_string (&value, "goldenrod");
      81                 :            : 
      82         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_color (&value, &color));
      83         [ -  + ]:          3 :   g_assert_true (gdk_rgba_equal (&color, &correct_color));
      84                 :            : 
      85                 :            :   /* Try again to make sure caching works */
      86         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_get_color (&value, &color));
      87         [ -  + ]:          3 :   g_assert_true (gdk_rgba_equal (&color, &correct_color));
      88                 :            : 
      89                 :          3 :   shumate_vector_value_set_string (&value, "not a real color");
      90         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_get_color (&value, &color));
      91                 :            :   /* Try again to make sure caching works */
      92         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_get_color (&value, &color));
      93                 :          3 : }
      94                 :            : 
      95                 :            : 
      96                 :            : static void
      97                 :          3 : test_vector_value_equal (void)
      98                 :            : {
      99                 :          6 :   g_auto(ShumateVectorValue) value1 = SHUMATE_VECTOR_VALUE_INIT;
     100                 :          3 :   g_auto(ShumateVectorValue) value2 = SHUMATE_VECTOR_VALUE_INIT;
     101                 :          3 :   GdkRGBA color;
     102                 :            : 
     103                 :            :   /* Both are initialized to NULL so they should be equal */
     104         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_equal (&value1, &value2));
     105                 :            : 
     106                 :          3 :   shumate_vector_value_set_number (&value1, 1.0);
     107                 :          3 :   shumate_vector_value_set_number (&value2, 1.0);
     108         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_equal (&value1, &value2));
     109                 :            : 
     110                 :          3 :   shumate_vector_value_set_number (&value1, 1.0);
     111                 :          3 :   shumate_vector_value_set_number (&value2, 2.0);
     112         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_equal (&value1, &value2));
     113                 :            : 
     114                 :          3 :   shumate_vector_value_set_boolean (&value1, TRUE);
     115                 :          3 :   shumate_vector_value_set_boolean (&value2, TRUE);
     116         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_equal (&value1, &value2));
     117                 :            : 
     118                 :          3 :   shumate_vector_value_set_number (&value1, FALSE);
     119                 :          3 :   shumate_vector_value_set_number (&value2, TRUE);
     120         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_equal (&value1, &value2));
     121                 :            : 
     122                 :          3 :   shumate_vector_value_set_string (&value1, "Hello, world!");
     123                 :          3 :   shumate_vector_value_set_string (&value2, "Hello, world!");
     124         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_equal (&value1, &value2));
     125                 :            : 
     126                 :          3 :   shumate_vector_value_set_string (&value1, "Hello, world!");
     127                 :          3 :   shumate_vector_value_set_string (&value2, "Goodbye, world!");
     128         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_equal (&value1, &value2));
     129                 :            : 
     130                 :          3 :   gdk_rgba_parse (&color, "magenta");
     131                 :          3 :   shumate_vector_value_set_color (&value1, &color);
     132                 :          3 :   shumate_vector_value_set_color (&value2, &color);
     133         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_equal (&value1, &value2));
     134                 :            : 
     135                 :          3 :   shumate_vector_value_set_color (&value1, &color);
     136                 :          3 :   gdk_rgba_parse (&color, "purple");
     137                 :          3 :   shumate_vector_value_set_color (&value2, &color);
     138         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_equal (&value1, &value2));
     139                 :            : 
     140                 :          3 :   shumate_vector_value_set_string (&value1, "Hello, world!");
     141                 :          3 :   shumate_vector_value_set_number (&value2, 1.0);
     142         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_equal (&value1, &value2));
     143                 :            : 
     144                 :          3 :   shumate_vector_value_set_number (&value1, TRUE);
     145                 :          3 :   shumate_vector_value_set_boolean (&value2, 1.0);
     146         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_equal (&value1, &value2));
     147                 :            : 
     148                 :          3 :   shumate_vector_value_unset (&value1);
     149                 :          3 :   shumate_vector_value_set_number (&value2, 0.0);
     150         [ -  + ]:          3 :   g_assert_false (shumate_vector_value_equal (&value1, &value2));
     151                 :          3 : }
     152                 :            : 
     153                 :            : 
     154                 :            : static void
     155                 :          3 : test_vector_value_copy (void)
     156                 :            : {
     157                 :          6 :   g_auto(ShumateVectorValue) value1 = SHUMATE_VECTOR_VALUE_INIT;
     158                 :          3 :   g_auto(ShumateVectorValue) value2 = SHUMATE_VECTOR_VALUE_INIT;
     159                 :          3 :   GdkRGBA color;
     160                 :            : 
     161                 :          3 :   shumate_vector_value_copy (&value1, &value2);
     162         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_equal (&value1, &value2));
     163                 :            : 
     164                 :          3 :   gdk_rgba_parse (&color, "red");
     165                 :          3 :   shumate_vector_value_set_color (&value1, &color);
     166                 :          3 :   shumate_vector_value_copy (&value1, &value2);
     167         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_equal (&value1, &value2));
     168                 :            : 
     169                 :          3 :   shumate_vector_value_set_string (&value1, "Hello, world!");
     170                 :          3 :   shumate_vector_value_copy (&value1, &value2);
     171         [ -  + ]:          3 :   g_assert_true (shumate_vector_value_equal (&value1, &value2));
     172                 :          3 : }
     173                 :            : 
     174                 :            : int
     175                 :          3 : main (int argc, char *argv[])
     176                 :            : {
     177                 :          3 :   g_test_init (&argc, &argv, NULL);
     178                 :            : 
     179                 :          3 :   g_test_add_func ("/vector/value/literal", test_vector_value_literal);
     180                 :          3 :   g_test_add_func ("/vector/value/from-gvalue", test_vector_value_from_gvalue);
     181                 :          3 :   g_test_add_func ("/vector/value/get-color", test_vector_value_get_color);
     182                 :          3 :   g_test_add_func ("/vector/value/equal", test_vector_value_equal);
     183                 :          3 :   g_test_add_func ("/vector/value/copy", test_vector_value_copy);
     184                 :            : 
     185                 :          3 :   return g_test_run ();
     186                 :            : }

Generated by: LCOV version 1.14