Mercurial > hg > dmlib
view tests/fptest.c @ 2208:90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
lib64util for handling external palette file options and add support for
specifying one of the "internal" palettes or external (.act) palette file to
gfxconv and 64vw.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 05:01:12 +0300 |
parents | 186cf6a7d634 |
children | 88be5cf55caf |
line wrap: on
line source
#include "dmtool.h" #include "dmlib.h" #include <stdio.h> #define FP_DW_SIZE 8 #define FP_W0_SIZE 4 static int test_number = 0; void check(const char *str, DMFixedPoint v, Sint64 dw) { DMFixedPoint *q = (DMFixedPoint *) &dw; printf("%-15s = ", str); FP_PRINTF64(v); printf("\n"); printf("should be = "); FP_PRINTF64((*q)); printf("\n"); if (v.dw != dw) { printf("ERROR! A test value differs from expected!\n"); } } void header(const char *msg) { test_number++; printf("\nTEST #%d: %s\n", test_number, msg); } int main(int argc, char *argv[]) { int i; DMFixedPoint a, b, delta; char *s; (void) argc; (void) argv; // Check host characteristics switch (SDL_BYTEORDER) { case SDL_BIG_ENDIAN: s = "big endian"; break; case SDL_LIL_ENDIAN: s = "little endian"; break; default: s = "unknown?"; break; } printf( "SDL byte order = %s (%d)\n\n", s, SDL_BYTEORDER); printf( "sizeof(DMFixedPoint) = %" DM_PRId64 " bytes\n" "sizeof(DMFixedPoint.dw) = %" DM_PRId64 " bytes (should be %d)\n" "sizeof(DMFixedPoint.w[0]) = %" DM_PRId64 " bytes (should be %d)\n", sizeof(a), sizeof(a.dw), FP_DW_SIZE, sizeof(a.w[0]), FP_W0_SIZE); if (sizeof(a.dw) != FP_DW_SIZE || sizeof(a.w[0]) != FP_W0_SIZE) { printf("ERROR! Some type sizes DO NOT MATCH!\n"); return -1; } //----------------------------------------------- header("set initial values"); FP_SETHL(a, 55, 0); check("a", a, 0x0000003700000000ULL); FP_CONV(b, 178); check("b", b, 0x00000000000000b2ULL); FP_DIV_R(delta, a, b); check("delta", delta, 0x000000004f19e33cULL); //----------------------------------------------- header("50 x (a + delta)"); for (i = 0; i < 50; i++) { FP_ADD(a, delta); } check("a end", a, 0x00000046730e61b8ULL); //----------------------------------------------- header("50 x (a - delta)"); for (i = 0; i < 50; i++) { FP_SUB(a, delta); } check("a end", a, 0x0000003700000000ULL); //----------------------------------------------- header("5 x (a * delta)"); for (i = 0; i < 5; i++) { FP_MUL(a, delta); } check("a end", a, 0xd644e40000000000ULL); //----------------------------------------------- header("a / 2"); FP_CONV(delta, 2); FP_DIV(a, delta); check("a end", a, 0xeb22720000000000ULL); //----------------------------------------------- header("a / 2"); FP_DIV(a, delta); check("a end", a, 0xf591390000000000ULL); //----------------------------------------------- header(""); FP_SETHL(a, -200, 50); FP_CONV(b, 15); FP_DIV(a, b); check("a end", a, 0xfffffff2aaaaaaaeULL); return 0; }