#include // for strcmp #include // for abs #include #include #include // for allocator, basic_string, operator+, string #include "color.h" #include "types.h" #include "utils/string.h" #include "unit_common.h" #include "video.h" #include "video_frame.h" extern "C" { int misc_test_color_coeff_range(); int misc_test_replace_all(); int misc_test_video_desc_io_op_symmetry(); } using namespace std; /** * check that scaled coefficient for minimal values match approximately minimal * value of nominal range (== there is not significant shift) */ int misc_test_color_coeff_range() { const int depths[] = { 8, 10, 12, 16 }; for (unsigned i = 0; i < sizeof depths / sizeof depths[0]; ++i) { const int d = depths[i]; const int d_max = (1 << d) - 1; const int max_diff = 1 << (d - 8); const struct color_coeffs *cfs = get_color_coeffs(d); // Y ASSERT_LE_MESSAGE( "min Y diverges from nominal range min", max_diff, abs((RGB_TO_Y(*cfs, 0, 0, 0) >> COMP_BASE) + LIMIT_LO(d)) - LIMIT_LO(d)); ASSERT_LE_MESSAGE( "max Y diverges from nominal range max", max_diff, abs((RGB_TO_Y(*cfs, d_max, d_max, d_max) >> COMP_BASE) + LIMIT_LO(d) - LIMIT_HI_Y(d))); // Cb ASSERT_LE_MESSAGE( "min Cb diverges from nominal range min", max_diff, abs((RGB_TO_CB(*cfs, d_max, d_max, 0) >> COMP_BASE) + (1 << (d - 1)) - LIMIT_LO(d))); ASSERT_LE_MESSAGE( "max Cb diverges from nominal range max", max_diff, abs((RGB_TO_CB(*cfs, 0, 0, d_max) >> COMP_BASE) + (1 << (d - 1)) - LIMIT_HI_CBCR(d))); // Cr ASSERT_LE_MESSAGE( "min Cr diverges from nominal range min", max_diff, abs((RGB_TO_CR(*cfs, 0, d_max, d_max) >> COMP_BASE) + (1 << (d - 1)) - LIMIT_LO(d))); ASSERT_LE_MESSAGE( "max Cr diverges from nominal range max", max_diff, abs((RGB_TO_CR(*cfs, d_max, 0, 0) >> COMP_BASE) + (1 << (d - 1)) - LIMIT_HI_CBCR(d))); } return 0; } #ifdef __clang__ #pragma clang diagnostic ignored "-Wstring-concatenation" #endif int misc_test_replace_all() { char test[][20] = { DELDEL DELDEL DELDEL, DELDEL DELDEL, "XYZX" DELDEL, "XXXyX" }; const char *repl_from[] = { DELDEL , DELDEL, "X", "X" }; const char *repl_to[] = { ":" , ESCAPED_COLON, "x", "" }; const char *res[] = { ":::" , ESCAPED_COLON ESCAPED_COLON, "xYZx" DELDEL, "y" }; for (unsigned i = 0; i < sizeof test / sizeof test[0]; ++i) { replace_all(test[i], repl_from[i], repl_to[i]); ASSERT(strcmp(test[i], res[i]) == 0); } return 0; } int misc_test_video_desc_io_op_symmetry() { const std::list test_desc = { {1920, 1080, DXT5, 60, PROGRESSIVE, 4}, {640, 480, H264, 15, PROGRESSIVE, 1}}; for (const auto & i : test_desc) { video_desc tmp; ostringstream oss; oss << i; istringstream iss(oss.str()); iss >> tmp; // Check ostringstream oss2; oss2 << tmp; string err_elem = oss.str() + " vs " + oss2.str(); ASSERT_MESSAGE(err_elem, video_desc_eq(tmp, i)); ASSERT_EQUAL_MESSAGE(err_elem, tmp, i); } return 0; }