/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. * History:
  26. * ================================================================
  27. * 2009-10-03 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #include "ftk.h"
  31. int main(int argc, char* argv[])
  32. {
  33. FtkColor color = {0};
  34. ftk_init(argc, argv);
  35. FtkWidget* thiz = FTK_ZALLOC(sizeof(FtkWidget));
  36. FtkCanvas* canvas = ftk_canvas_create(240, 320, &color);
  37. ftk_widget_init(thiz, 1, 100, 0, 0, 0, 0, 0);
  38. ftk_widget_set_canvas(thiz, canvas);
  39. ftk_widget_resize(thiz, 240, 320);
  40. ftk_widget_move(thiz, 200, 100);
  41. assert(ftk_widget_left(thiz) == 200);
  42. assert(ftk_widget_top(thiz) == 100);
  43. assert(ftk_widget_width(thiz) == 240);
  44. assert(ftk_widget_height(thiz) == 320);
  45. assert(ftk_widget_type(thiz) == 1);
  46. assert(ftk_widget_id(thiz) == 100);
  47. assert(ftk_widget_top_abs(thiz) == 100);
  48. assert(ftk_widget_left_abs(thiz) == 200);
  49. ftk_widget_set_insensitive(thiz, 1);
  50. assert(ftk_widget_is_insensitive(thiz));
  51. ftk_widget_set_insensitive(thiz, 0);
  52. assert(!ftk_widget_is_insensitive(thiz));
  53. assert(!ftk_widget_is_visible(thiz));
  54. assert(!ftk_widget_is_focused(thiz));
  55. ftk_widget_set_focused(thiz, 1);
  56. assert(ftk_widget_is_focused(thiz));
  57. assert(ftk_widget_parent(thiz) == NULL);
  58. assert(ftk_widget_child(thiz) == NULL);
  59. assert(ftk_widget_next(thiz) == NULL);
  60. assert(ftk_widget_toplevel(thiz) == thiz);
  61. assert(ftk_widget_lookup(thiz, 100) == thiz);
  62. FtkWidget* child1 = calloc(1, sizeof(FtkWidget));
  63. FtkWidget* child2 = calloc(1, sizeof(FtkWidget));
  64. ftk_widget_init(child1, 1, 200, 0, 0, 0, 0, 0);
  65. ftk_widget_init(child2, 1, 300, 0, 0, 0, 0, 0);
  66. ftk_widget_move(thiz, 0, 0);
  67. ftk_widget_move(child1, 0, 0);
  68. ftk_widget_move(child2, 100, 100);
  69. ftk_widget_resize(thiz, 320, 480);
  70. ftk_widget_resize(child1, 100, 100);
  71. ftk_widget_resize(child2, 100, 100);
  72. ftk_widget_append_child(thiz, child1);
  73. ftk_widget_append_child(thiz, child2);
  74. assert(ftk_widget_next(child1) == child2);
  75. assert(ftk_widget_prev(child1) == NULL);
  76. assert(ftk_widget_next(child2) == NULL);
  77. assert(ftk_widget_prev(child2) == child1);
  78. assert(ftk_widget_child(thiz) == child1);
  79. assert(ftk_widget_next(child1) == child2);
  80. assert(ftk_widget_lookup(thiz, 200) == child1);
  81. assert(ftk_widget_lookup(thiz, 300) == child2);
  82. assert(ftk_widget_find_target(thiz, 50, 50, 0) == child1);
  83. assert(ftk_widget_find_target(thiz, 150, 150, 0) == child2);
  84. ftk_canvas_destroy(canvas);
  85. ftk_widget_unref(thiz);
  86. return 0;
  87. }