aboutsummaryrefslogtreecommitdiff
path: root/tests/check-hildon-picker-button.c
blob: ab37f03b0adb5497d9e1290c596804602ca559f9 (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
/*
 * This file is a part of hildon tests
 *
 * Copyright (C) 2009 Nokia Corporation, all rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <stdlib.h>
#include <string.h>
#include <check.h>
#include "test_suites.h"
#include "check_utils.h"
#include <hildon/hildon.h>

static HildonButton *button = NULL;
static HildonTouchSelector *selector = NULL;
static GtkWindow *window = NULL;

static void
fx_setup ()
{
    int argc = 0;

    gtk_init (&argc, NULL);

    window = GTK_WINDOW (hildon_window_new());

    fail_if (!HILDON_IS_WINDOW(window),
	     "hildon-picker-button: Window creation failed.");

    button = HILDON_BUTTON (hildon_picker_button_new (HILDON_SIZE_AUTO,
                              HILDON_BUTTON_ARRANGEMENT_VERTICAL));
    selector = HILDON_TOUCH_SELECTOR (hildon_touch_selector_new_text ());

    hildon_touch_selector_append_text (selector, "Row one");
    hildon_touch_selector_append_text (selector, "Row two");
    hildon_touch_selector_append_text (selector, "Row three");
    hildon_touch_selector_append_text (selector, "Row four");

    hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button), selector);

    gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (button));
    gtk_widget_show (GTK_WIDGET (button));

    show_test_window (GTK_WIDGET (window));
}

static void
fx_teardown ()
{
    gtk_widget_destroy (GTK_WIDGET (window));
}

/**
   Purpose: test that programmatic changes in the selector update the
   value displayed in the button.

   Checks for:

   - Initial value must be empty.
   - Programmatically selecting an item in the selector should show it in the button.
   - Updating the contents of a selected row should update the displayed value accordingly.

*/
START_TEST (test_hildon_picker_button_value)
{
    const gchar *value;
    GtkTreeIter iter;
    GtkTreeModel *model;
    const gchar *new_value = "Something different";

    /* Test 1: getting initial value. */
    value = hildon_button_get_value (button);
    fail_if (strcmp (value, "") != 0,
             "hildon-picker-button: default value wrong: `%s'",
             value);

    /* Test 2: Selecting a particular row. */
    hildon_touch_selector_set_active (selector, 0, 1);
    value = hildon_button_get_value (button);
    fail_if (strcmp (value, "Row two") != 0,
             "hildon-picker-button: switched to second row in the selector, "
             "but button displays `%s'.", value);

    /* Test 3: Modifying a selected row. */
    model = hildon_touch_selector_get_model (selector, 0);
    hildon_touch_selector_get_selected (selector, 0, &iter);
    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                        0, new_value, -1);
    value = hildon_button_get_value (button);
    fail_if (strcmp (value, new_value) != 0,
             "hildon-picker-button: set the currently selected row to `%s' "
             "but button displays `%s'.", new_value, value);

}
END_TEST

Suite *create_hildon_picker_button_suite (void)
{
    Suite *s = suite_create ("HildonPickerButton");

    TCase *tc1 = tcase_create ("hildon_picker_button");
    tcase_add_checked_fixture (tc1, fx_setup, fx_teardown);
    tcase_add_test (tc1, test_hildon_picker_button_value);
    suite_add_tcase (s, tc1);

    return s;
}