Mercurial > MadButterfly
comparison src/shape_stext.c @ 433:099941c3becf
Test cases for ratation on sh_stext
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 29 Jul 2009 16:35:03 +0800 |
parents | 9d5506968efb |
children | c02d2aa2c45e |
comparison
equal
deleted
inserted
replaced
432:331467b8e778 | 433:099941c3becf |
---|---|
851 _rdman_shape_stext_free((shape_t *)txt_o); | 851 _rdman_shape_stext_free((shape_t *)txt_o); |
852 free_font_face(face); | 852 free_font_face(face); |
853 } | 853 } |
854 | 854 |
855 static | 855 static |
856 void test_compute_styled_extents_n_scaled_font_rotate(void) { | |
857 sh_stext_t *txt_o; | |
858 co_aix *aggr; | |
859 mb_style_blk_t blks[2]; | |
860 mb_font_face_t *face; | |
861 mb_text_extents_t *ext; | |
862 int r; | |
863 | |
864 txt_o = (sh_stext_t *)rdman_shape_stext_new((redraw_man_t *)NULL, | |
865 "Hello World", 10, 15); | |
866 CU_ASSERT(txt_o != NULL); | |
867 | |
868 aggr = txt_o->shape.aggr; | |
869 aggr[0] = 1; | |
870 aggr[1] = 0; | |
871 aggr[2] = 0; | |
872 aggr[3] = 1; | |
873 aggr[4] = 1; | |
874 aggr[5] = 0; | |
875 | |
876 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | |
877 CU_ASSERT(face != NULL); | |
878 | |
879 blks[0].n_chars = 5; | |
880 blks[0].face = face; | |
881 blks[0].font_sz = 10; | |
882 | |
883 blks[1].n_chars = 4; | |
884 blks[1].face = face; | |
885 blks[1].font_sz = 15.5; | |
886 | |
887 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); | |
888 CU_ASSERT(r == OK); | |
889 | |
890 compute_styled_extents_n_scaled_font(txt_o); | |
891 | |
892 ext = &txt_o->extents; | |
893 CU_ASSERT(MBE_GET_HEIGHT(ext) > 47); | |
894 CU_ASSERT(MBE_GET_HEIGHT(ext) < 92); | |
895 CU_ASSERT(MBE_GET_WIDTH(ext) > 36); | |
896 CU_ASSERT(MBE_GET_WIDTH(ext) < 72); | |
897 CU_ASSERT(MBE_GET_X_ADV(ext) > 36); | |
898 CU_ASSERT(MBE_GET_X_ADV(ext) < 72); | |
899 CU_ASSERT(MBE_GET_Y_ADV(ext) > 36); | |
900 CU_ASSERT(MBE_GET_Y_ADV(ext) < 72); | |
901 | |
902 _rdman_shape_stext_free((shape_t *)txt_o); | |
903 free_font_face(face); | |
904 } | |
905 | |
906 static | |
856 void test_sh_stext_transform(void) { | 907 void test_sh_stext_transform(void) { |
857 sh_stext_t *txt_o; | 908 sh_stext_t *txt_o; |
858 mb_style_blk_t blks[2]; | 909 mb_style_blk_t blks[2]; |
859 co_aix *aggr; | 910 co_aix *aggr; |
860 mb_font_face_t *face; | 911 mb_font_face_t *face; |
932 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); | 983 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); |
933 CU_ASSERT(r == OK); | 984 CU_ASSERT(r == OK); |
934 | 985 |
935 sh_stext_transform((shape_t *)txt_o); | 986 sh_stext_transform((shape_t *)txt_o); |
936 | 987 |
988 move_cnt = 0; | |
937 sh_stext_draw((shape_t *)txt_o, NULL); | 989 sh_stext_draw((shape_t *)txt_o, NULL); |
938 CU_ASSERT(move_cnt == 2); | 990 CU_ASSERT(move_cnt == 2); |
939 CU_ASSERT(move_xys[0][0] == 200); | 991 CU_ASSERT(move_xys[0][0] == 200); |
940 CU_ASSERT(move_xys[0][1] == 50); | 992 CU_ASSERT(move_xys[0][1] == 50); |
941 CU_ASSERT(move_xys[1][0] >= 240 && move_xys[1][0] < 270); | 993 CU_ASSERT(move_xys[1][0] >= 240 && move_xys[1][0] < 270); |
942 CU_ASSERT(move_xys[1][1] == 50); | 994 CU_ASSERT(move_xys[1][1] == 50); |
995 | |
996 _rdman_shape_stext_free((shape_t *)txt_o); | |
997 free_font_face(face); | |
998 } | |
999 | |
1000 static | |
1001 void test_sh_stext_draw_rotate(void) { | |
1002 sh_stext_t *txt_o; | |
1003 mb_style_blk_t blks[2]; | |
1004 co_aix *aggr; | |
1005 mb_font_face_t *face; | |
1006 area_t *area; | |
1007 int r; | |
1008 | |
1009 txt_o = (sh_stext_t *)rdman_shape_stext_new(NULL, "hello world", 100, 50); | |
1010 CU_ASSERT(txt_o != NULL); | |
1011 | |
1012 aggr = txt_o->shape.aggr; | |
1013 aggr[0] = 2; | |
1014 aggr[1] = 0; | |
1015 aggr[2] = 0; | |
1016 aggr[3] = 1; | |
1017 aggr[4] = 1; | |
1018 aggr[5] = 0; | |
1019 | |
1020 face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); | |
1021 CU_ASSERT(face != NULL); | |
1022 | |
1023 blks[0].n_chars = 5; | |
1024 blks[0].face = face; | |
1025 blks[0].font_sz = 10; | |
1026 | |
1027 blks[1].n_chars = 6; | |
1028 blks[1].face = face; | |
1029 blks[1].font_sz = 15.5; | |
1030 | |
1031 r = sh_stext_set_style((shape_t *)txt_o, blks, 2); | |
1032 CU_ASSERT(r == OK); | |
1033 | |
1034 sh_stext_transform((shape_t *)txt_o); | |
1035 | |
1036 move_cnt = 0; | |
1037 sh_stext_draw((shape_t *)txt_o, NULL); | |
1038 CU_ASSERT(move_cnt == 2); | |
1039 CU_ASSERT(move_xys[0][0] == 200); | |
1040 CU_ASSERT(move_xys[0][1] == 150); | |
1041 CU_ASSERT(move_xys[1][0] >= 240 && move_xys[1][0] < 270); | |
1042 CU_ASSERT(move_xys[1][1] >= 170 && move_xys[1][1] < 185); | |
943 | 1043 |
944 _rdman_shape_stext_free((shape_t *)txt_o); | 1044 _rdman_shape_stext_free((shape_t *)txt_o); |
945 free_font_face(face); | 1045 free_font_face(face); |
946 } | 1046 } |
947 | 1047 |
954 CU_ADD_TEST(suite, test_make_scaled_font_face_matrix); | 1054 CU_ADD_TEST(suite, test_make_scaled_font_face_matrix); |
955 CU_ADD_TEST(suite, test_compute_text_extents); | 1055 CU_ADD_TEST(suite, test_compute_text_extents); |
956 CU_ADD_TEST(suite, test_extent_extents); | 1056 CU_ADD_TEST(suite, test_extent_extents); |
957 CU_ADD_TEST(suite, test_compute_utf8_chars_sz); | 1057 CU_ADD_TEST(suite, test_compute_utf8_chars_sz); |
958 CU_ADD_TEST(suite, test_compute_styled_extents_n_scaled_font); | 1058 CU_ADD_TEST(suite, test_compute_styled_extents_n_scaled_font); |
1059 CU_ADD_TEST(suite, test_compute_styled_extents_n_scaled_font_rotate); | |
959 CU_ADD_TEST(suite, test_sh_stext_transform); | 1060 CU_ADD_TEST(suite, test_sh_stext_transform); |
960 CU_ADD_TEST(suite, test_sh_stext_draw); | 1061 CU_ADD_TEST(suite, test_sh_stext_draw); |
1062 CU_ADD_TEST(suite, test_sh_stext_draw_rotate); | |
961 | 1063 |
962 return suite; | 1064 return suite; |
963 } | 1065 } |
964 | 1066 |
965 #endif /* UNITTEST */ | 1067 #endif /* UNITTEST */ |