#include #include #include #include #include #include #include START_TEST(test_ximage_to_png) { FILE *f = fopen("level3.dump", "rb"); fail_if(f == NULL, "level3.dump doesn't exist"); XImage *xi = x_imagedump_load(f); fail_if(xi == NULL, "XImage null pointer"); fclose(f); x_image_to_png(xi, "level3.png"); XDestroyImage(xi); } END_TEST START_TEST(test_capture) { Display *dpy = XOpenDisplay(NULL); fail_if(dpy == NULL, "Unable to open X display"); int screen_num = XDefaultScreen(dpy); fail_if(screen_num < 0, "Unable to acquire screen number"); Window win = RootWindow(dpy, screen_num); XWindowAttributes win_info; fail_unless(XGetWindowAttributes(dpy, win, &win_info), "Unable to get window properties"); XImage *xi = x_window_dump(dpy, win); fail_unless(xi->width == win_info.width && xi->height == win_info.height, "Unable to get image from window"); XCloseDisplay(dpy); } END_TEST /* * x_pixel_from_rgb * x_pixel_to_rgb */ START_TEST(test_pixel_convert) { pixel_t pix=0; short r, g, b; /* Create a pixel */ r = 10; g = 40; b = 20; pix = x_pixel_from_rgb(r, g, b); fail_unless(pix == 665620, "Pixel was not created from RGB values"); /* Get value back */ r = g = b = 0; x_pixel_to_rgb(pix, &r, &g, &b); fail_unless(r = 10, "Wrong Red value"); fail_unless(r = 40, "Wrong Green value"); fail_unless(r = 20, "Wrong Blue value"); } END_TEST /** * x_imagedump_save * x_imagedump_load */ START_TEST(test_ximage_save_load) { Display *dpy = XOpenDisplay(NULL); fail_if(dpy == NULL, "Unable to open X display"); int screen_num = XDefaultScreen(dpy); fail_if(screen_num < 0, "Unable to acquire screen number"); Window win = RootWindow(dpy, screen_num); XWindowAttributes win_info; fail_unless(XGetWindowAttributes(dpy, win, &win_info), "Unable to get window properties"); XImage *xi = x_window_dump(dpy, win); FILE *f; f = fopen("test.dump", "wb"); fail_unless(x_imagedump_save(xi, f), "Unable to dump file"); fclose(f); f = fopen("test.dump", "rb"); fail_if(f == NULL, "Unable to reopen file"); XImage *r = x_imagedump_load(f); fail_if(memcmp(xi->data, r->data, xi->bytes_per_line*xi->height), "Dump data doesn't match original"); fail_if(xi->height != r->height, "Dump height doesn't match original"); fail_if(xi->width != r->width, "Dump width doesn't match original"); fclose(f); XCloseDisplay(dpy); } END_TEST /* Test suite for "Check" */ Suite *xtools_suite() { Suite *s = suite_create("xtools"); TCase *tc_core = tcase_create("Core"); /* Add tests here */ tcase_add_test(tc_core, test_capture); tcase_add_test(tc_core, test_pixel_convert); tcase_add_test(tc_core, test_ximage_save_load); tcase_add_test(tc_core, test_ximage_to_png); suite_add_tcase(s, tc_core); } int main() { int number_failed; Suite *s = xtools_suite (); SRunner *sr = srunner_create (s); srunner_run_all (sr, CK_NORMAL); number_failed = srunner_ntests_failed (sr); srunner_free (sr); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; }