check_mode.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stdbool.h>
  2. #include "greatest.h"
  3. #include "libmegapixels.h"
  4. static enum greatest_test_res
  5. check_bytesused(
  6. uint32_t pixfmt,
  7. uint32_t width,
  8. uint32_t height,
  9. uint32_t expected_width_to_bytes,
  10. uint32_t expected_width_to_padding,
  11. uint32_t expected_bytes_used
  12. )
  13. {
  14. int format = libmegapixels_v4l_pixfmt_to_index(pixfmt);
  15. uint32_t width_to_bytes = libmegapixels_mode_width_to_bytes(format, width);
  16. uint32_t width_to_padding = libmegapixels_mode_width_to_padding(format, width);
  17. uint32_t bytes_used = (width_to_bytes + width_to_padding) * height;
  18. // printf(
  19. // "\nFormat name: %s, width: %u, height: %u, width to bytes: %u, width to padding: %u, bytes used: %u\n",
  20. // libmegapixels_format_name(format),
  21. // width,
  22. // height,
  23. // width_to_bytes,
  24. // width_to_padding,
  25. // bytes_used
  26. // );
  27. ASSERT_EQ(width_to_bytes, expected_width_to_bytes);
  28. ASSERT_EQ(width_to_padding, expected_width_to_padding);
  29. ASSERT_EQ(bytes_used, expected_bytes_used);
  30. PASS();
  31. }
  32. TEST bytesused_for_rggb8(void)
  33. {
  34. CHECK_CALL(check_bytesused(V4L2_PIX_FMT_SRGGB8, 4208, 3120, 4208, 0, 13128960));
  35. PASS();
  36. }
  37. TEST bytesused_for_rggb10(void)
  38. {
  39. CHECK_CALL(check_bytesused(V4L2_PIX_FMT_SRGGB10, 4208, 3120, 8416, 0, 26257920));
  40. PASS();
  41. }
  42. TEST bytesused_for_rggb10p(void)
  43. {
  44. CHECK_CALL(check_bytesused(V4L2_PIX_FMT_SRGGB10P, 4208, 3120, 5260, 4, 16423680));
  45. PASS();
  46. }
  47. SUITE (test_suite)
  48. {
  49. RUN_TEST(bytesused_for_rggb8);
  50. RUN_TEST(bytesused_for_rggb10);
  51. RUN_TEST(bytesused_for_rggb10p);
  52. }
  53. GREATEST_MAIN_DEFS();
  54. int
  55. main(int argc, char **argv)
  56. {
  57. GREATEST_MAIN_BEGIN();
  58. RUN_SUITE(test_suite);
  59. GREATEST_MAIN_END();
  60. }