bng_test.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. #include <assert.h>
  5. #include <string.h>
  6. #include "bng.h"
  7. void test_convert_pixel()
  8. {
  9. #define TEST_CASE(input, source, desired, expected) \
  10. do { \
  11. uint32_t actual = convert_pixel(input, source, desired); \
  12. if (actual != expected) { \
  13. printf("%s:%d: Oopsie-doopsie!\n", __FILE__, __LINE__); \
  14. printf("Actual: %08X\n", actual); \
  15. printf("Expected: %08X\n", expected); \
  16. exit(1); \
  17. } \
  18. printf("%08X == %08X, OK\n", actual, expected); \
  19. } while (0)
  20. TEST_CASE(0xAABBCCDD, RGBA, ABGR, 0xDDCCBBAA);
  21. TEST_CASE(0xAABBCCDD, ABGR, GRAB, 0xCCDDAABB);
  22. TEST_CASE(0xAABBCCDD, RGBA, GRAB, 0xBBAADDCC);
  23. #undef TEST_CASE
  24. }
  25. void test_pixel_format_by_name()
  26. {
  27. #define TEST_CASE(input, expected)\
  28. do {\
  29. const struct Bng_Pixel_Format actual = pixel_format_by_name(input);\
  30. if (!bng_pixel_format_equals(expected, actual)) {\
  31. fprintf(stderr, "%s:%d: Oopsie-doopsie!\n", __FILE__, __LINE__);\
  32. fprintf(stderr, "Actual: %s\n", name_of_pixel_format(actual));\
  33. fprintf(stderr, "Expected: %s\n", name_of_pixel_format(expected));\
  34. exit(1);\
  35. }\
  36. printf("%s == %s, OK\n", name_of_pixel_format(actual).cstr, name_of_pixel_format(expected).cstr);\
  37. } while(0);
  38. TEST_CASE("RGBA", RGBA);
  39. TEST_CASE("ABGR", ABGR);
  40. TEST_CASE("GRAB", GRAB);
  41. #undef TEST_CASE
  42. }
  43. int main(int argc, char *argv[])
  44. {
  45. test_convert_pixel();
  46. test_pixel_format_by_name();
  47. return 0;
  48. }