add coordinate and surface x/y increment/offset tests

This commit is contained in:
Gered 2015-01-18 22:54:38 -05:00
parent 2982915da3
commit 5d6519a8be

View file

@ -72,7 +72,56 @@ void test_alpha(SURFACE_FLAGS flags) {
surface_destroy(surface);
}
void test_coords_and_offsets(SURFACE_FLAGS flags) {
SURFACE *surface = surface_create(100, 100, SURFACE_FORMAT_RGBA, flags);
assert(surface != NULL);
COLOR color = color_create_rgba(0, 255, 0, 255);
int x = 3;
int y = 42;
uint32_t index = (surface->x_inc * 3) + (surface->y_inc * 42);
// testing first sets a pixel using x,y coordinates, then reads
// it back using an offset set to be equivalent to the x,y coords
// using the surface's x_inc and y_inc properties.
assert(color != surface_get_pixel_idx_rgba_fast(surface, index));
surface_set_pixel(surface, x, y, color);
assert(color == surface_get_pixel_idx_rgba_fast(surface, index));
x += 10;
index += (surface->x_inc * 10);
assert(color != surface_get_pixel_idx_rgba_fast(surface, index));
surface_set_pixel(surface, x, y, color);
assert(color == surface_get_pixel_idx_rgb_fast(surface, index));
y += 15;
index += (surface->y_inc * 15);
assert(color != surface_get_pixel_idx_rgba_fast(surface, index));
surface_set_pixel(surface, x, y, color);
assert(color == surface_get_pixel_idx_rgb_fast(surface, index));
x -= 7;
index -= (surface->x_inc * 7);
assert(color != surface_get_pixel_idx_rgba_fast(surface, index));
surface_set_pixel(surface, x, y, color);
assert(color == surface_get_pixel_idx_rgb_fast(surface, index));
y -= 9;
index -= (surface->y_inc * 9);
assert(color != surface_get_pixel_idx_rgba_fast(surface, index));
surface_set_pixel(surface, x, y, color);
assert(color == surface_get_pixel_idx_rgb_fast(surface, index));
surface_destroy(surface);
}
int main(int argc, char **argv) {
test_coords_and_offsets(SURFACE_FLAGS_NONE);
test_rgba(SURFACE_FLAGS_NONE);
test_rgb(SURFACE_FLAGS_NONE);
test_alpha(SURFACE_FLAGS_NONE);