path-precision.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright © 2008 Chris Wilson
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software
  5. * and its documentation for any purpose is hereby granted without
  6. * fee, provided that the above copyright notice appear in all copies
  7. * and that both that copyright notice and this permission notice
  8. * appear in supporting documentation, and that the name of
  9. * Chris Wilson not be used in advertising or publicity pertaining to
  10. * distribution of the software without specific, written prior
  11. * permission. Chris Wilson makes no representations about the
  12. * suitability of this software for any purpose. It is provided "as
  13. * is" without express or implied warranty.
  14. *
  15. * CHRIS WILSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL CHRIS WILSON BE LIABLE FOR ANY SPECIAL,
  18. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19. * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  21. * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. *
  23. * Author: Chris Wilson <chris@chris-wilson.co.uk>
  24. *
  25. * Based on an example by Dirk "krit" Schulze found during WebKit integration.
  26. */
  27. #include "cairo-test.h"
  28. /* we know that this is an inherent limitation in cairo */
  29. #define FAIL CAIRO_TEST_XFAILURE
  30. /* Test the idempotency of path construction and copying */
  31. static cairo_test_status_t
  32. draw (cairo_t *cr, int width, int height)
  33. {
  34. cairo_path_data_t path_data[] = {
  35. { { CAIRO_PATH_MOVE_TO, 2 }, },
  36. { { 95.000000, 40.000000 }, },
  37. { { CAIRO_PATH_LINE_TO, 2 }, },
  38. { { 94.960533, 41.255810 }, },
  39. { { CAIRO_PATH_LINE_TO, 2 }, },
  40. { { 94.842293, 42.50666 }, },
  41. { { CAIRO_PATH_LINE_TO, 2 }, },
  42. { { 94.645744, 43.747627 }, },
  43. { { CAIRO_PATH_LINE_TO, 2 }, },
  44. { { 94.371666, 44.973797 }, },
  45. };
  46. const cairo_test_context_t *ctx = cairo_test_get_context (cr);
  47. cairo_path_t path, *path_copy;
  48. int i, j, n;
  49. cairo_test_status_t result = CAIRO_TEST_SUCCESS;
  50. path.status = CAIRO_STATUS_SUCCESS;
  51. path.num_data = ARRAY_LENGTH (path_data);
  52. path.data = path_data;
  53. cairo_new_path (cr);
  54. cairo_append_path (cr, &path);
  55. path_copy = cairo_copy_path (cr);
  56. if (path_copy->status)
  57. return cairo_test_status_from_status (ctx, path_copy->status);
  58. for (i = j = n = 0;
  59. i < path.num_data && j < path_copy->num_data;
  60. i += path.data[i].header.length,
  61. j += path_copy->data[j].header.length,
  62. n++)
  63. {
  64. const cairo_path_data_t *src, *dst;
  65. src = &path.data[i];
  66. dst = &path_copy->data[j];
  67. if (src->header.type != dst->header.type) {
  68. cairo_test_log (ctx,
  69. "Paths differ in header type after %d operations.\n"
  70. "Expected path operation %d, found %d.\n",
  71. n, src->header.type, dst->header.type);
  72. result = FAIL;
  73. break;
  74. }
  75. if (memcmp (&src[1].point, &dst[1].point, sizeof (src->point))) {
  76. cairo_test_log (ctx,
  77. "Paths differ in coordinates after %d operations.\n"
  78. "Expected point (%f, %f), found (%f, %f).\n",
  79. n,
  80. src[1].point.x, src[1].point.y,
  81. dst[1].point.x, dst[1].point.y);
  82. result = FAIL;
  83. break;
  84. }
  85. }
  86. cairo_path_destroy (path_copy);
  87. return result;
  88. }
  89. CAIRO_TEST (path_precision,
  90. "Check that the path append/copy is idempotent.",
  91. "api", /* keywords */
  92. NULL, /* requirements */
  93. 0, 0,
  94. NULL, draw)