summaryrefslogtreecommitdiff
path: root/src/tests/elementary/spec/efl_test_range_display.c
blob: f072e02c1023c58f646f51e315fc305ba7da57f0 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Efl_Ui.h>
#include "efl_ui_spec_suite.h"
#include "suite_helpers.h"

/* spec-meta-start
      {"test-interface":"Efl.Ui.Range_Display",
       "test-widgets": ["Efl.Ui.Spin", "Efl.Ui.Progressbar", "Efl.Ui.Slider", "Efl.Ui.Spin_Button"]}
   spec-meta-end */

EFL_START_TEST(value_setting_limits)
{
   efl_ui_range_limits_set(widget, -20.0, 20.0);
   efl_ui_range_value_set(widget, 10.0);

   EXPECT_ERROR_START;
   efl_ui_range_value_set(widget, -25.0);
   EXPECT_ERROR_END;
   ck_assert(efl_ui_range_value_get(widget) == 10.0);

   EXPECT_ERROR_START;
   efl_ui_range_value_set(widget, 25.0);
   EXPECT_ERROR_END;
   ck_assert(efl_ui_range_value_get(widget) == 10.0);
}
EFL_END_TEST

EFL_START_TEST(limit_setting)
{
   double min, max;

   efl_ui_range_limits_set(widget, -20.0, 20.0);
   efl_ui_range_limits_get(widget, &min, &max);
   ck_assert(min == -20.0);
   ck_assert(max == 20.0);
   EXPECT_ERROR_START;
   efl_ui_range_limits_set(widget, -20.0, -20.0);
   EXPECT_ERROR_END;
   efl_ui_range_limits_get(widget, &min, &max);
   ck_assert(min == -20.0);
   ck_assert(max == 20.0);

   EXPECT_ERROR_START;
   efl_ui_range_limits_set(widget, 2.0, -20.0);
   EXPECT_ERROR_END;
   efl_ui_range_limits_get(widget, &min, &max);
   ck_assert(min == -20.0);
   ck_assert(max == 20.0);

   EXPECT_ERROR_START;
   efl_ui_range_limits_set(widget, 25.0, 20.0);
   EXPECT_ERROR_END;
   efl_ui_range_limits_get(widget, &min, &max);
   ck_assert(min == -20.0);
   ck_assert(max == 20.0);

   efl_ui_range_limits_set(widget, -25.0, -20.0);
   efl_ui_range_limits_get(widget, &min, &max);
   ck_assert(min == -25.0);
   ck_assert(max == -20.0);

   efl_ui_range_limits_set(widget, 20.0, 25.0);
   efl_ui_range_limits_get(widget, &min, &max);
   ck_assert(min == 20.0);
   ck_assert(max == 25.0);
}
EFL_END_TEST

EFL_START_TEST(value_setting)
{
   double i;
   efl_ui_range_limits_set(widget, -20.0, 20.0);
   for (i = -20.0; i <= 20.0; ++i)
     {
        efl_ui_range_value_set(widget, i);
        ck_assert(efl_ui_range_value_get(widget) == i);
     }
}
EFL_END_TEST

static void
_set_flag(void *data, const Efl_Event *ev)
{
   Eina_Bool *b = data;

   ck_assert_int_eq(*b, EINA_FALSE);
   *b = EINA_TRUE;
   ck_assert_ptr_eq(ev->info, NULL);
}

EFL_START_TEST (range_display_value_events)
{
   Eina_Bool changed = EINA_FALSE, min_reached = EINA_FALSE, max_reached = EINA_FALSE;

   efl_ui_range_limits_set(widget, -3.0, 3.0);
   efl_ui_range_value_set(widget, 0.0);
   efl_event_callback_add(widget, EFL_UI_RANGE_EVENT_CHANGED, _set_flag, &changed);
   efl_event_callback_add(widget, EFL_UI_RANGE_EVENT_MIN_REACHED, _set_flag, &min_reached);
   efl_event_callback_add(widget, EFL_UI_RANGE_EVENT_MAX_REACHED, _set_flag, &max_reached);

   efl_ui_range_value_set(widget, 1.0);
   ck_assert_int_eq(changed, EINA_TRUE);
   ck_assert_int_eq(min_reached, EINA_FALSE);
   ck_assert_int_eq(max_reached, EINA_FALSE);
   changed = EINA_FALSE;
   min_reached = EINA_FALSE;
   max_reached = EINA_FALSE;

   efl_ui_range_value_set(widget, 3.0);
   ck_assert_int_eq(changed, EINA_TRUE);
   ck_assert_int_eq(min_reached, EINA_FALSE);
   ck_assert_int_eq(max_reached, EINA_TRUE);
   changed = EINA_FALSE;
   min_reached = EINA_FALSE;
   max_reached = EINA_FALSE;

   efl_ui_range_value_set(widget, -3.0);
   ck_assert_int_eq(changed, EINA_TRUE);
   ck_assert_int_eq(min_reached, EINA_TRUE);
   ck_assert_int_eq(max_reached, EINA_FALSE);
   changed = EINA_FALSE;
   min_reached = EINA_FALSE;
   max_reached = EINA_FALSE;
}
EFL_END_TEST

void
efl_ui_range_display_behavior_test(TCase *tc)
{
   tcase_add_test(tc, value_setting_limits);
   tcase_add_test(tc, limit_setting);
   tcase_add_test(tc, value_setting);
   tcase_add_test(tc, range_display_value_events);
}