"Fossies" - the Fresh Open Source Software Archive

Member "gtk+-3.24.12/testsuite/gtk/adjustment.c" (3 Jan 2019, 5077 Bytes) of package /linux/misc/gtk+-3.24.12.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* GTK - The GIMP Toolkit
    2  * Copyright (C) 2014 Red Hat, Inc.
    3  *
    4  * This library is free software; you can redistribute it and/or
    5  * modify it under the terms of the GNU Lesser General Public
    6  * License as published by the Free Software Foundation; either
    7  * version 2 of the License, or (at your option) any later version.
    8  *
    9  * This library is distributed in the hope that it will be useful,
   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12  * Lesser General Public License for more details.
   13  *
   14  * You should have received a copy of the GNU Lesser General Public
   15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
   16  */
   17 
   18 #include <gtk/gtk.h>
   19 
   20 static void
   21 test_basic (void)
   22 {
   23   GtkAdjustment *a;
   24 
   25   a = gtk_adjustment_new (2.0, 0.0, 100.0, 1.0, 5.0, 10.0);
   26   
   27   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 2.0);
   28   g_assert_cmpfloat (gtk_adjustment_get_lower (a), ==, 0.0);
   29   g_assert_cmpfloat (gtk_adjustment_get_upper (a), ==, 100.0);
   30   g_assert_cmpfloat (gtk_adjustment_get_step_increment (a), ==, 1.0);
   31   g_assert_cmpfloat (gtk_adjustment_get_page_increment (a), ==, 5.0);
   32   g_assert_cmpfloat (gtk_adjustment_get_page_size (a), ==, 10.0);
   33   g_assert_cmpfloat (gtk_adjustment_get_minimum_increment (a), ==, 1.0);
   34 
   35   gtk_adjustment_set_value (a, 50.0);
   36   gtk_adjustment_set_lower (a, 20.0);
   37   gtk_adjustment_set_upper (a, 75.5);
   38   gtk_adjustment_set_step_increment (a, 2.2);
   39   gtk_adjustment_set_page_increment (a, 1.5);
   40   gtk_adjustment_set_page_size (a, 10.0);
   41 
   42   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 50.0);
   43   g_assert_cmpfloat (gtk_adjustment_get_lower (a), ==, 20.0);
   44   g_assert_cmpfloat (gtk_adjustment_get_upper (a), ==, 75.5);
   45   g_assert_cmpfloat (gtk_adjustment_get_step_increment (a), ==, 2.2);
   46   g_assert_cmpfloat (gtk_adjustment_get_page_increment (a), ==, 1.5);
   47   g_assert_cmpfloat (gtk_adjustment_get_page_size (a), ==, 10.0);
   48   g_assert_cmpfloat (gtk_adjustment_get_minimum_increment (a), ==, 1.5);
   49 
   50   g_object_unref (a);
   51 }
   52 
   53 static gint changed_count;
   54 static gint value_changed_count;
   55 
   56 static void
   57 changed_cb (GtkAdjustment *a)
   58 {
   59   changed_count++;
   60 }
   61 
   62 static void
   63 value_changed_cb (GtkAdjustment *a)
   64 {
   65   value_changed_count++;
   66 }
   67 
   68 static void
   69 test_signals (void)
   70 {
   71   GtkAdjustment *a;
   72 
   73   a = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
   74 
   75   g_signal_connect (a, "changed", G_CALLBACK (changed_cb), NULL);
   76   g_signal_connect (a, "value-changed", G_CALLBACK (value_changed_cb), NULL);
   77 
   78 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
   79   changed_count = value_changed_count = 0;
   80   gtk_adjustment_changed (a);
   81   g_assert_cmpint (changed_count, ==, 1);  
   82   g_assert_cmpint (value_changed_count, ==, 0);  
   83 
   84   changed_count = value_changed_count = 0;
   85   gtk_adjustment_value_changed (a);
   86   g_assert_cmpint (changed_count, ==, 0);  
   87   g_assert_cmpint (value_changed_count, ==, 1);  
   88 G_GNUC_END_IGNORE_DEPRECATIONS
   89 
   90   changed_count = value_changed_count = 0;
   91   gtk_adjustment_configure (a, 0.0, 0.0, 100.0, 1.0, 5.0, 0.0);
   92   g_assert_cmpint (changed_count, ==, 1);  
   93   g_assert_cmpint (value_changed_count, ==, 0);  
   94 
   95   changed_count = value_changed_count = 0;
   96   gtk_adjustment_set_value (a, 50.0);
   97   gtk_adjustment_set_lower (a, 20.0);
   98   gtk_adjustment_set_upper (a, 75.5);
   99   gtk_adjustment_set_step_increment (a, 2.2);
  100   gtk_adjustment_set_page_increment (a, 1.5);
  101   gtk_adjustment_set_page_size (a, 10.0);
  102   g_assert_cmpint (changed_count, ==, 5);  
  103   g_assert_cmpint (value_changed_count, ==, 1);  
  104 
  105   g_object_unref (a); 
  106 }
  107 
  108 static void
  109 test_clamp (void)
  110 {
  111   GtkAdjustment *a;
  112 
  113   a = gtk_adjustment_new (2.0, 0.0, 100.0, 1.0, 5.0, 10.0);
  114 
  115   gtk_adjustment_set_value (a, -10.0);
  116   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 0.0);
  117 
  118   gtk_adjustment_set_value (a, 200.0);
  119   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 90.0);
  120 
  121   gtk_adjustment_set_value (a, 99.0);
  122   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 90.0);
  123 
  124   gtk_adjustment_configure (a, 0.0, 0.0, 10.0, 1.0, 5.0, 20.0);
  125   
  126   gtk_adjustment_set_value (a, 5.0);
  127   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 0.0);
  128 
  129   g_object_unref (a);
  130 }
  131 
  132 static void
  133 test_clamp_page (void)
  134 {
  135   GtkAdjustment *a;
  136 
  137   a = gtk_adjustment_new (20.0, 0.0, 100.0, 1.0, 5.0, 10.0);
  138 
  139   gtk_adjustment_clamp_page (a, 50.0, 55.0);
  140   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 45.0);
  141 
  142   gtk_adjustment_clamp_page (a, 52.0, 58.0);
  143   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 48.0);
  144 
  145   gtk_adjustment_clamp_page (a, 48.0, 50.0);
  146   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 48.0);
  147 
  148   gtk_adjustment_clamp_page (a, 30.0, 50.0);
  149   g_assert_cmpfloat (gtk_adjustment_get_value (a), ==, 30.0);
  150 
  151   g_object_unref (a);
  152 }
  153 
  154 int
  155 main (int   argc,
  156       char *argv[])
  157 {
  158   gtk_test_init (&argc, &argv);
  159 
  160   g_test_add_func ("/adjustment/basic", test_basic);
  161   g_test_add_func ("/adjustment/signals", test_signals);
  162   g_test_add_func ("/adjustment/clamp", test_clamp);
  163   g_test_add_func ("/adjustment/clamp_page", test_clamp_page);
  164 
  165   return g_test_run();
  166 }