rel-path.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright © 2005 Keith Packard
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that
  7. * copyright notice and this permission notice appear in supporting
  8. * documentation, and that the name of Keith Packard not be used in
  9. * advertising or publicity pertaining to distribution of the software without
  10. * specific, written prior permission. Keith Packard makes no
  11. * representations about the suitability of this software for any purpose. It
  12. * is provided "as is" without express or implied warranty.
  13. *
  14. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  20. * PERFORMANCE OF THIS SOFTWARE.
  21. */
  22. #include "cairo-test.h"
  23. #define SIZE 10
  24. static cairo_status_t
  25. invalid_rel_move_to (cairo_surface_t *target)
  26. {
  27. cairo_t *cr;
  28. cairo_status_t status;
  29. cr = cairo_create (target);
  30. cairo_rel_move_to (cr, SIZE, SIZE/2);
  31. status = cairo_status (cr);
  32. cairo_destroy (cr);
  33. return status;
  34. }
  35. static cairo_status_t
  36. invalid_rel_line_to (cairo_surface_t *target)
  37. {
  38. cairo_t *cr;
  39. cairo_status_t status;
  40. cr = cairo_create (target);
  41. cairo_rel_line_to (cr, -SIZE, SIZE/2);
  42. status = cairo_status (cr);
  43. cairo_destroy (cr);
  44. return status;
  45. }
  46. static cairo_status_t
  47. invalid_rel_curve_to (cairo_surface_t *target)
  48. {
  49. cairo_t *cr;
  50. cairo_status_t status;
  51. cr = cairo_create (target);
  52. cairo_rel_curve_to (cr,
  53. SIZE/2, -SIZE/2,
  54. SIZE*2/3, -SIZE/3,
  55. SIZE/2, -SIZE);
  56. status = cairo_status (cr);
  57. cairo_destroy (cr);
  58. return status;
  59. }
  60. static cairo_test_status_t
  61. draw (cairo_t *cr, int width, int height)
  62. {
  63. const cairo_test_context_t *ctx = cairo_test_get_context (cr);
  64. cairo_status_t status;
  65. cairo_test_status_t result;
  66. /* first test that a relative move without a current point fails... */
  67. status = invalid_rel_move_to (cairo_get_target (cr));
  68. if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
  69. result = cairo_test_status_from_status (ctx, status);
  70. if (result == CAIRO_TEST_NO_MEMORY)
  71. return result;
  72. cairo_test_log (ctx, "Error: invalid cairo_rel_move_to() did not raise NO_CURRENT_POINT\n");
  73. return result;
  74. }
  75. status = invalid_rel_line_to (cairo_get_target (cr));
  76. if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
  77. result = cairo_test_status_from_status (ctx, status);
  78. if (result == CAIRO_TEST_NO_MEMORY)
  79. return result;
  80. cairo_test_log (ctx, "Error: invalid cairo_rel_line_to() did not raise NO_CURRENT_POINT\n");
  81. return result;
  82. }
  83. status = invalid_rel_curve_to (cairo_get_target (cr));
  84. if (status != CAIRO_STATUS_NO_CURRENT_POINT) {
  85. result = cairo_test_status_from_status (ctx, status);
  86. if (result == CAIRO_TEST_NO_MEMORY)
  87. return result;
  88. cairo_test_log (ctx, "Error: invalid cairo_rel_curve_to() did not raise NO_CURRENT_POINT\n");
  89. return result;
  90. }
  91. cairo_set_source_rgb (cr, 1, 1, 1);
  92. cairo_move_to (cr, 0, 0);
  93. cairo_rel_move_to (cr, SIZE, SIZE/2);
  94. cairo_rel_line_to (cr, -SIZE, SIZE/2);
  95. cairo_rel_curve_to (cr,
  96. SIZE/2, -SIZE/2,
  97. SIZE*2/3, -SIZE/3,
  98. SIZE/2, -SIZE);
  99. cairo_stroke (cr);
  100. return CAIRO_TEST_SUCCESS;
  101. }
  102. CAIRO_TEST (rel_path,
  103. "Tests calls to various relative path functions",
  104. "path", /* keywords */
  105. NULL, /* requirements */
  106. SIZE, SIZE,
  107. NULL, draw)