Changeset c78a03d in mainline for uspace/lib/gfxfont/test/font.c
- Timestamp:
- 2020-07-21T22:48:59Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5592c56
- Parents:
- 703c743
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/gfxfont/test/font.c
r703c743 rc78a03d 27 27 */ 28 28 29 #include <gfx/context.h> 29 30 #include <gfx/font.h> 30 31 #include <pcut/pcut.h> … … 34 35 PCUT_TEST_SUITE(font); 35 36 36 PCUT_TEST(dummy) 37 { 37 static errno_t testgc_set_color(void *, gfx_color_t *); 38 static errno_t testgc_fill_rect(void *, gfx_rect_t *); 39 40 static gfx_context_ops_t test_ops = { 41 .set_color = testgc_set_color, 42 .fill_rect = testgc_fill_rect 43 }; 44 45 /** Test creating and destroying font */ 46 PCUT_TEST(create_destroy) 47 { 48 gfx_font_metrics_t metrics; 49 gfx_font_t *font; 50 gfx_context_t *gc; 51 errno_t rc; 52 53 rc = gfx_context_new(&test_ops, NULL, &gc); 54 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 55 56 gfx_font_metrics_init(&metrics); 57 rc = gfx_font_create(gc, &metrics, &font); 58 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 59 60 gfx_font_destroy(font); 61 rc = gfx_context_delete(gc); 62 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 63 } 64 65 /** Test gfx_font_get_metrics() */ 66 PCUT_TEST(get_metrics) 67 { 68 gfx_font_metrics_t metrics; 69 gfx_font_metrics_t gmetrics; 70 gfx_font_t *font; 71 gfx_context_t *gc; 72 errno_t rc; 73 74 rc = gfx_context_new(&test_ops, NULL, &gc); 75 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 76 77 gfx_font_metrics_init(&metrics); 78 metrics.ascent = 1; 79 metrics.descent = 2; 80 metrics.leading = 3; 81 82 rc = gfx_font_create(gc, &metrics, &font); 83 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 84 85 gfx_font_get_metrics(font, &gmetrics); 86 PCUT_ASSERT_INT_EQUALS(metrics.ascent, gmetrics.ascent); 87 PCUT_ASSERT_INT_EQUALS(metrics.descent, gmetrics.descent); 88 PCUT_ASSERT_INT_EQUALS(metrics.leading, gmetrics.leading); 89 90 gfx_font_destroy(font); 91 rc = gfx_context_delete(gc); 92 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 93 } 94 95 /** Test gfx_font_set_metrics() */ 96 PCUT_TEST(set_metrics) 97 { 98 gfx_font_metrics_t metrics1; 99 gfx_font_metrics_t metrics2; 100 gfx_font_metrics_t gmetrics; 101 gfx_font_t *font; 102 gfx_context_t *gc; 103 errno_t rc; 104 105 rc = gfx_context_new(&test_ops, NULL, &gc); 106 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 107 108 gfx_font_metrics_init(&metrics1); 109 metrics1.ascent = 1; 110 metrics1.descent = 2; 111 metrics1.leading = 3; 112 113 rc = gfx_font_create(gc, &metrics1, &font); 114 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 115 116 gfx_font_metrics_init(&metrics2); 117 metrics1.ascent = 4; 118 metrics1.descent = 5; 119 metrics1.leading = 6; 120 121 rc = gfx_font_set_metrics(font, &metrics2); 122 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 123 124 gfx_font_get_metrics(font, &gmetrics); 125 PCUT_ASSERT_INT_EQUALS(metrics2.ascent, gmetrics.ascent); 126 PCUT_ASSERT_INT_EQUALS(metrics2.descent, gmetrics.descent); 127 PCUT_ASSERT_INT_EQUALS(metrics2.leading, gmetrics.leading); 128 129 gfx_font_destroy(font); 130 rc = gfx_context_delete(gc); 131 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 132 } 133 134 /** Test gfx_font_first_glyph() */ 135 PCUT_TEST(first_glyph) 136 { 137 gfx_font_metrics_t metrics; 138 gfx_font_t *font; 139 gfx_context_t *gc; 140 gfx_glyph_t *glyph; 141 errno_t rc; 142 143 rc = gfx_context_new(&test_ops, NULL, &gc); 144 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 145 146 gfx_font_metrics_init(&metrics); 147 148 rc = gfx_font_create(gc, &metrics, &font); 149 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 150 151 glyph = gfx_font_first_glyph(font); 152 PCUT_ASSERT_NULL(glyph); 153 154 gfx_font_destroy(font); 155 rc = gfx_context_delete(gc); 156 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 157 } 158 159 /** Test gfx_font_next_glyph() */ 160 PCUT_TEST(next_glyph) 161 { 162 /* TODO */ 163 } 164 165 /** Test gfx_font_search_glyph() */ 166 PCUT_TEST(search_glyph) 167 { 168 gfx_font_metrics_t metrics; 169 gfx_font_t *font; 170 gfx_context_t *gc; 171 gfx_glyph_t *glyph; 172 size_t bytes; 173 errno_t rc; 174 175 rc = gfx_context_new(&test_ops, NULL, &gc); 176 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 177 178 gfx_font_metrics_init(&metrics); 179 180 rc = gfx_font_create(gc, &metrics, &font); 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 183 rc = gfx_font_search_glyph(font, "Hello", &glyph, &bytes); 184 PCUT_ASSERT_ERRNO_VAL(ENOENT, rc); 185 186 gfx_font_destroy(font); 187 rc = gfx_context_delete(gc); 188 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 189 } 190 191 static errno_t testgc_set_color(void *arg, gfx_color_t *color) 192 { 193 return EOK; 194 } 195 196 static errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect) 197 { 198 return EOK; 38 199 } 39 200
Note:
See TracChangeset
for help on using the changeset viewer.