Mercurial > MadButterfly
diff src/geo.c @ 17:41f0907b27ac
Unittest for rdman_redraw_changed().
geo_init() is seperated into geo_init() and geo_from_positions().
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 01 Aug 2008 23:32:22 +0800 |
parents | c2ce186a5c37 |
children | 0f3baa488a62 |
line wrap: on
line diff
--- a/src/geo.c Fri Aug 01 18:20:28 2008 +0800 +++ b/src/geo.c Fri Aug 01 23:32:22 2008 +0800 @@ -53,14 +53,18 @@ } area->x = min_x; - area->w = max_x - min_x; + area->w = max_x - min_x + 1; area->y = min_y; - area->h = max_y - min_y; + area->h = max_y - min_y + 1; } -void geo_init(geo_t *g, int n_pos, co_aix pos[][2]) { +void geo_init(geo_t *g) { + memset(g, 0, sizeof(geo_t)); g->cur_area = g->areas; g->last_area = g->areas + 1; +} + +void geo_from_positions(geo_t *g, int n_pos, co_aix pos[][2]) { area_init(g->cur_area, n_pos, pos); } @@ -81,17 +85,18 @@ #include <CUnit/Basic.h> -void test_geo_init(void) { +void test_geo_from_positions(void) { co_aix data[][2] = { {33, 25}, {49, 12}, {14, 28}, {39, 56}}; geo_t g; - geo_init(&g, 4, data); + geo_init(&g); + geo_from_positions(&g, 4, data); CU_ASSERT(g.cur_area->x == 14); - CU_ASSERT(g.cur_area->w == 35); + CU_ASSERT(g.cur_area->w == 36); CU_ASSERT(g.cur_area->y == 12); - CU_ASSERT(g.cur_area->h == 44); + CU_ASSERT(g.cur_area->h == 45); } void test_geo_mark_overlay(void) { @@ -105,14 +110,16 @@ pos[0][1] = i * 50; pos[1][0] = i * 50 + 55; pos[1][1] = i * 50 + 66; - geo_init(_geos + i, 2, pos); + geo_init(_geos + i); + geo_from_positions(_geos + i, 2, pos); geos[i] = _geos + i; } pos[0][0] = 88; pos[0][1] = 79; pos[1][0] = 88 + 70; pos[1][1] = 79 + 70; - geo_init(&g, 2, pos); + geo_init(&g); + geo_from_positions(&g, 2, pos); /* overlay with geos[1] and geos[2] */ geo_mark_overlay(&g, 3, geos, &n_ov, overlays); @@ -121,11 +128,11 @@ CU_ASSERT(overlays[1] == geos[2]); /* right side of geos[1], and up side of geos[2] */ - pos[0][0] = 105; - pos[0][1] = 50; - pos[1][0] = 105 + 50; - pos[1][1] = 50 + 51; - geo_init(&g, 2, pos); + pos[0][0] = 106; + pos[0][1] = 51; + pos[1][0] = 106 + 49; + pos[1][1] = 51 + 49; + geo_from_positions(&g, 2, pos); geo_mark_overlay(&g, 3, geos, &n_ov, overlays); CU_ASSERT(n_ov == 1); CU_ASSERT(overlays[0] == geos[2]); @@ -135,7 +142,7 @@ CU_pSuite suite; suite = CU_add_suite("Suite_geo", NULL, NULL); - CU_ADD_TEST(suite, test_geo_init); + CU_ADD_TEST(suite, test_geo_from_positions); CU_ADD_TEST(suite, test_geo_mark_overlay); return suite;