PageRenderTime 436ms CodeModel.GetById 152ms app.highlight 8ms RepoModel.GetById 203ms app.codeStats 0ms

/src/test/widget_test.c

http://ftk.googlecode.com/
C | 94 lines | 58 code | 7 blank | 29 comment | 23 complexity | 885d6660b281e27062e98a86fa1a56f9 MD5 | raw file
 1/*
 2 * File: widget_test.c    
 3 * Author:  Li XianJing <xianjimli@hotmail.com>
 4 * Brief:   
 5 *
 6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
 7 *
 8 * Licensed under the Academic Free License version 2.1
 9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25/*
26 * History:
27 * ================================================================
28 * 2009-10-03 Li XianJing <xianjimli@hotmail.com> created
29 *
30 */
31#include "ftk.h"
32
33int main(int argc, char* argv[])
34{
35	FtkColor color = {0};
36	ftk_init(argc, argv);
37	FtkWidget* thiz = FTK_ZALLOC(sizeof(FtkWidget));
38	FtkCanvas* canvas = ftk_canvas_create(240, 320, &color);
39	ftk_widget_init(thiz, 1, 100, 0, 0, 0, 0, 0);
40	ftk_widget_set_canvas(thiz, canvas);
41	ftk_widget_resize(thiz, 240, 320);
42	ftk_widget_move(thiz, 200, 100);
43	assert(ftk_widget_left(thiz) == 200);
44	assert(ftk_widget_top(thiz) == 100);
45	assert(ftk_widget_width(thiz) == 240);
46	assert(ftk_widget_height(thiz) == 320);
47	assert(ftk_widget_type(thiz) == 1);
48	assert(ftk_widget_id(thiz) == 100);
49	assert(ftk_widget_top_abs(thiz) == 100);
50	assert(ftk_widget_left_abs(thiz) == 200);
51	ftk_widget_set_insensitive(thiz, 1);
52	assert(ftk_widget_is_insensitive(thiz));
53	ftk_widget_set_insensitive(thiz, 0);
54	assert(!ftk_widget_is_insensitive(thiz));
55	assert(!ftk_widget_is_visible(thiz));
56	assert(!ftk_widget_is_focused(thiz));
57	ftk_widget_set_focused(thiz, 1);	
58	assert(ftk_widget_is_focused(thiz));
59	assert(ftk_widget_parent(thiz) == NULL);
60	assert(ftk_widget_child(thiz) == NULL);
61	assert(ftk_widget_next(thiz) == NULL);
62	assert(ftk_widget_toplevel(thiz) == thiz);
63	assert(ftk_widget_lookup(thiz, 100) == thiz);
64
65	FtkWidget* child1 = calloc(1, sizeof(FtkWidget));
66	FtkWidget* child2 = calloc(1, sizeof(FtkWidget));
67	ftk_widget_init(child1, 1, 200, 0, 0, 0, 0, 0);
68	ftk_widget_init(child2, 1, 300, 0, 0, 0, 0, 0);
69
70	ftk_widget_move(thiz, 0, 0);
71	ftk_widget_move(child1, 0, 0);
72	ftk_widget_move(child2, 100, 100);
73	ftk_widget_resize(thiz, 320, 480);
74	ftk_widget_resize(child1, 100, 100);
75	ftk_widget_resize(child2, 100, 100);
76
77	ftk_widget_append_child(thiz, child1);
78	ftk_widget_append_child(thiz, child2);
79	assert(ftk_widget_next(child1) == child2);
80	assert(ftk_widget_prev(child1) == NULL);
81	assert(ftk_widget_next(child2) == NULL);
82	assert(ftk_widget_prev(child2) == child1);
83	assert(ftk_widget_child(thiz) == child1);
84	assert(ftk_widget_next(child1) == child2);
85	assert(ftk_widget_lookup(thiz, 200) == child1);
86	assert(ftk_widget_lookup(thiz, 300) == child2);
87
88	assert(ftk_widget_find_target(thiz, 50, 50, 0) == child1);
89	assert(ftk_widget_find_target(thiz, 150, 150, 0) == child2);
90
91	ftk_canvas_destroy(canvas);
92	ftk_widget_unref(thiz);
93	return 0;
94}