api-special-cases.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  1. /*
  2. * Copyright © 2010 Red Hat Inc.
  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. * Red Hat, Inc. not be used in advertising or publicity pertaining to
  10. * distribution of the software without specific, written prior
  11. * permission. Red Hat, Inc. 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. * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL RED HAT, INC. 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: Benjamin Otte <otte@redhat.com>
  24. */
  25. /*
  26. * WHAT THIS TEST DOES
  27. *
  28. * This test tests that for all public APIs Cairo behaves correct, consistent
  29. * and most of all doesn't crash. It does this by calling all APIs that take
  30. * surfaces or contexts and calling them on specially prepared arguments that
  31. * should fail when called on this function.
  32. *
  33. * ADDING NEW FUNCTIONS
  34. *
  35. * You need (for adding the function cairo_surface_foo):
  36. * 1) A surface_test_func_t named test_cairo_surface_foo that gets passed the
  37. * prepared surface and has the job of calling the function and checking
  38. * the return value (if one exists) for correctness. The top of this file
  39. * contains all these shim functions.
  40. * 2) Knowledge if the function behaves like a setter or like a getter. A
  41. * setter should set an error status on the surface, a getter does not
  42. * modify the function.
  43. * 3) Knowledge if the function only works for a specific surface type and for
  44. * which one.
  45. * 4) An entry in the tests array using the TEST() macro. It takes as arguments:
  46. * - The function name
  47. * - TRUE if the function modifies the surface, FALSE otherwise
  48. * - the surface type for which the function is valid or -1 if it is valid
  49. * for all surface types.
  50. *
  51. * FIXING FAILURES
  52. *
  53. * The test will dump failures notices into the api-special-cases.log file (when
  54. * it doesn't crash). These should be pretty self-explanatory. Usually it is
  55. * enough to just add a new check to the function it complained about.
  56. */
  57. #ifdef HAVE_CONFIG_H
  58. #include "config.h"
  59. #endif
  60. #include <assert.h>
  61. #include <limits.h>
  62. #include "cairo-test.h"
  63. #if CAIRO_HAS_GL_SURFACE
  64. #include <cairo-gl.h>
  65. #endif
  66. #if CAIRO_HAS_OS2_SURFACE
  67. #include <cairo-os2.h>
  68. #endif
  69. #if CAIRO_HAS_PDF_SURFACE
  70. #include <cairo-pdf.h>
  71. #endif
  72. #if CAIRO_HAS_PS_SURFACE
  73. #include <cairo-ps.h>
  74. #endif
  75. #if CAIRO_HAS_QUARTZ_SURFACE
  76. #define Cursor QuartzCursor
  77. #include <cairo-quartz.h>
  78. #undef Cursor
  79. #endif
  80. #if CAIRO_HAS_SVG_SURFACE
  81. #include <cairo-svg.h>
  82. #endif
  83. #if CAIRO_HAS_TEE_SURFACE
  84. #include <cairo-tee.h>
  85. #endif
  86. #if CAIRO_HAS_XCB_SURFACE
  87. #include <cairo-xcb.h>
  88. #endif
  89. #if CAIRO_HAS_XLIB_SURFACE
  90. #define Cursor XCursor
  91. #include <cairo-xlib.h>
  92. #undef Cursor
  93. #endif
  94. #define surface_has_type(surface,type) (cairo_surface_get_type (surface) == (type))
  95. typedef cairo_test_status_t (* surface_test_func_t) (cairo_surface_t *surface);
  96. typedef cairo_test_status_t (* context_test_func_t) (cairo_t *cr);
  97. static cairo_test_status_t
  98. test_cairo_reference (cairo_t *cr)
  99. {
  100. cairo_destroy (cairo_reference (cr));
  101. return CAIRO_TEST_SUCCESS;
  102. }
  103. static cairo_test_status_t
  104. test_cairo_get_reference_count (cairo_t *cr)
  105. {
  106. unsigned int refcount = cairo_get_reference_count (cr);
  107. if (refcount > 0)
  108. return CAIRO_TEST_SUCCESS;
  109. /* inert error context have a refcount of 0 */
  110. return cairo_status (cr) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  111. }
  112. static cairo_test_status_t
  113. test_cairo_set_user_data (cairo_t *cr)
  114. {
  115. static cairo_user_data_key_t key;
  116. cairo_status_t status;
  117. status = cairo_set_user_data (cr, &key, &key, NULL);
  118. if (status == CAIRO_STATUS_NO_MEMORY)
  119. return CAIRO_TEST_NO_MEMORY;
  120. else if (status)
  121. return CAIRO_TEST_SUCCESS;
  122. if (cairo_get_user_data (cr, &key) != &key)
  123. return CAIRO_TEST_ERROR;
  124. return CAIRO_TEST_SUCCESS;
  125. }
  126. static cairo_test_status_t
  127. test_cairo_save (cairo_t *cr)
  128. {
  129. cairo_save (cr);
  130. cairo_restore (cr);
  131. return CAIRO_TEST_SUCCESS;
  132. }
  133. static cairo_test_status_t
  134. test_cairo_push_group (cairo_t *cr)
  135. {
  136. cairo_pattern_t *pattern;
  137. cairo_status_t status;
  138. cairo_push_group (cr);
  139. pattern = cairo_pop_group (cr);
  140. status = cairo_pattern_status (pattern);
  141. cairo_pattern_destroy (pattern);
  142. return status == CAIRO_STATUS_SUCCESS || status == cairo_status (cr) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  143. }
  144. static cairo_test_status_t
  145. test_cairo_push_group_with_content (cairo_t *cr)
  146. {
  147. cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA);
  148. cairo_pop_group_to_source (cr);
  149. return CAIRO_TEST_SUCCESS;
  150. }
  151. static cairo_test_status_t
  152. test_cairo_set_operator (cairo_t *cr)
  153. {
  154. cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  155. return CAIRO_TEST_SUCCESS;
  156. }
  157. static cairo_test_status_t
  158. test_cairo_set_source (cairo_t *cr)
  159. {
  160. cairo_pattern_t *source = cairo_pattern_create_rgb (0, 0, 0);
  161. cairo_set_source (cr, source);
  162. cairo_pattern_destroy (source);
  163. return CAIRO_TEST_SUCCESS;
  164. }
  165. static cairo_test_status_t
  166. test_cairo_set_source_rgb (cairo_t *cr)
  167. {
  168. cairo_set_source_rgb (cr, 0, 0, 0);
  169. return CAIRO_TEST_SUCCESS;
  170. }
  171. static cairo_test_status_t
  172. test_cairo_set_source_rgba (cairo_t *cr)
  173. {
  174. cairo_set_source_rgba (cr, 0, 0, 0, 1);
  175. return CAIRO_TEST_SUCCESS;
  176. }
  177. static cairo_test_status_t
  178. test_cairo_set_source_surface (cairo_t *cr)
  179. {
  180. cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
  181. cairo_set_source_surface (cr, surface, 0, 0);
  182. cairo_surface_destroy (surface);
  183. return CAIRO_TEST_SUCCESS;
  184. }
  185. static cairo_test_status_t
  186. test_cairo_set_tolerance (cairo_t *cr)
  187. {
  188. cairo_set_tolerance (cr, 42);
  189. return CAIRO_TEST_SUCCESS;
  190. }
  191. static cairo_test_status_t
  192. test_cairo_set_antialias (cairo_t *cr)
  193. {
  194. cairo_set_antialias (cr, CAIRO_ANTIALIAS_BEST);
  195. return CAIRO_TEST_SUCCESS;
  196. }
  197. static cairo_test_status_t
  198. test_cairo_set_fill_rule (cairo_t *cr)
  199. {
  200. cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
  201. return CAIRO_TEST_SUCCESS;
  202. }
  203. static cairo_test_status_t
  204. test_cairo_set_line_width (cairo_t *cr)
  205. {
  206. cairo_set_line_width (cr, 42);
  207. return CAIRO_TEST_SUCCESS;
  208. }
  209. static cairo_test_status_t
  210. test_cairo_set_line_cap (cairo_t *cr)
  211. {
  212. cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
  213. return CAIRO_TEST_SUCCESS;
  214. }
  215. static cairo_test_status_t
  216. test_cairo_set_line_join (cairo_t *cr)
  217. {
  218. cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
  219. return CAIRO_TEST_SUCCESS;
  220. }
  221. static cairo_test_status_t
  222. test_cairo_set_dash (cairo_t *cr)
  223. {
  224. cairo_set_dash (cr, NULL, 0, 0);
  225. return CAIRO_TEST_SUCCESS;
  226. }
  227. static cairo_test_status_t
  228. test_cairo_set_miter_limit (cairo_t *cr)
  229. {
  230. cairo_set_miter_limit (cr, 2);
  231. return CAIRO_TEST_SUCCESS;
  232. }
  233. static cairo_test_status_t
  234. test_cairo_translate (cairo_t *cr)
  235. {
  236. cairo_translate (cr, 2, 2);
  237. return CAIRO_TEST_SUCCESS;
  238. }
  239. static cairo_test_status_t
  240. test_cairo_scale (cairo_t *cr)
  241. {
  242. cairo_scale (cr, 2, 2);
  243. return CAIRO_TEST_SUCCESS;
  244. }
  245. static cairo_test_status_t
  246. test_cairo_rotate (cairo_t *cr)
  247. {
  248. cairo_rotate (cr, 2);
  249. return CAIRO_TEST_SUCCESS;
  250. }
  251. static cairo_test_status_t
  252. test_cairo_transform (cairo_t *cr)
  253. {
  254. cairo_matrix_t matrix;
  255. cairo_matrix_init_translate (&matrix, 1, 1);
  256. cairo_transform (cr, &matrix);
  257. return CAIRO_TEST_SUCCESS;
  258. }
  259. static cairo_test_status_t
  260. test_cairo_set_matrix (cairo_t *cr)
  261. {
  262. cairo_matrix_t matrix;
  263. cairo_matrix_init_translate (&matrix, 1, 1);
  264. cairo_set_matrix (cr, &matrix);
  265. return CAIRO_TEST_SUCCESS;
  266. }
  267. static cairo_test_status_t
  268. test_cairo_identity_matrix (cairo_t *cr)
  269. {
  270. cairo_identity_matrix (cr);
  271. return CAIRO_TEST_SUCCESS;
  272. }
  273. static cairo_test_status_t
  274. test_cairo_user_to_device (cairo_t *cr)
  275. {
  276. double x = 42, y = 42;
  277. cairo_user_to_device (cr, &x, &y);
  278. return CAIRO_TEST_SUCCESS;
  279. }
  280. static cairo_test_status_t
  281. test_cairo_user_to_device_distance (cairo_t *cr)
  282. {
  283. double x = 42, y = 42;
  284. cairo_user_to_device_distance (cr, &x, &y);
  285. return CAIRO_TEST_SUCCESS;
  286. }
  287. static cairo_test_status_t
  288. test_cairo_device_to_user (cairo_t *cr)
  289. {
  290. double x = 42, y = 42;
  291. cairo_device_to_user (cr, &x, &y);
  292. return CAIRO_TEST_SUCCESS;
  293. }
  294. static cairo_test_status_t
  295. test_cairo_device_to_user_distance (cairo_t *cr)
  296. {
  297. double x = 42, y = 42;
  298. cairo_device_to_user_distance (cr, &x, &y);
  299. return CAIRO_TEST_SUCCESS;
  300. }
  301. static cairo_test_status_t
  302. test_cairo_new_path (cairo_t *cr)
  303. {
  304. cairo_new_path (cr);
  305. return CAIRO_TEST_SUCCESS;
  306. }
  307. static cairo_test_status_t
  308. test_cairo_move_to (cairo_t *cr)
  309. {
  310. cairo_move_to (cr, 2, 2);
  311. return CAIRO_TEST_SUCCESS;
  312. }
  313. static cairo_test_status_t
  314. test_cairo_new_sub_path (cairo_t *cr)
  315. {
  316. cairo_new_sub_path (cr);
  317. return CAIRO_TEST_SUCCESS;
  318. }
  319. static cairo_test_status_t
  320. test_cairo_line_to (cairo_t *cr)
  321. {
  322. cairo_line_to (cr, 2, 2);
  323. return CAIRO_TEST_SUCCESS;
  324. }
  325. static cairo_test_status_t
  326. test_cairo_curve_to (cairo_t *cr)
  327. {
  328. cairo_curve_to (cr, 2, 2, 3, 3, 4, 4);
  329. return CAIRO_TEST_SUCCESS;
  330. }
  331. static cairo_test_status_t
  332. test_cairo_arc (cairo_t *cr)
  333. {
  334. cairo_arc (cr, 2, 2, 3, 0, 2 * M_PI);
  335. return CAIRO_TEST_SUCCESS;
  336. }
  337. static cairo_test_status_t
  338. test_cairo_arc_negative (cairo_t *cr)
  339. {
  340. cairo_arc_negative (cr, 2, 2, 3, 0, 2 * M_PI);
  341. return CAIRO_TEST_SUCCESS;
  342. }
  343. static cairo_test_status_t
  344. test_cairo_rel_move_to (cairo_t *cr)
  345. {
  346. cairo_rel_move_to (cr, 2, 2);
  347. return CAIRO_TEST_SUCCESS;
  348. }
  349. static cairo_test_status_t
  350. test_cairo_rel_line_to (cairo_t *cr)
  351. {
  352. cairo_rel_line_to (cr, 2, 2);
  353. return CAIRO_TEST_SUCCESS;
  354. }
  355. static cairo_test_status_t
  356. test_cairo_rel_curve_to (cairo_t *cr)
  357. {
  358. cairo_rel_curve_to (cr, 2, 2, 3, 3, 4, 4);
  359. return CAIRO_TEST_SUCCESS;
  360. }
  361. static cairo_test_status_t
  362. test_cairo_rectangle (cairo_t *cr)
  363. {
  364. cairo_rectangle (cr, 2, 2, 3, 3);
  365. return CAIRO_TEST_SUCCESS;
  366. }
  367. static cairo_test_status_t
  368. test_cairo_close_path (cairo_t *cr)
  369. {
  370. cairo_close_path (cr);
  371. return CAIRO_TEST_SUCCESS;
  372. }
  373. static cairo_test_status_t
  374. test_cairo_path_extents (cairo_t *cr)
  375. {
  376. double x1, y1, x2, y2;
  377. cairo_path_extents (cr, &x1, &y1, &x2, &y2);
  378. return CAIRO_TEST_SUCCESS;
  379. }
  380. static cairo_test_status_t
  381. test_cairo_paint (cairo_t *cr)
  382. {
  383. cairo_paint (cr);
  384. return CAIRO_TEST_SUCCESS;
  385. }
  386. static cairo_test_status_t
  387. test_cairo_paint_with_alpha (cairo_t *cr)
  388. {
  389. cairo_paint_with_alpha (cr, 0.5);
  390. return CAIRO_TEST_SUCCESS;
  391. }
  392. static cairo_test_status_t
  393. test_cairo_mask (cairo_t *cr)
  394. {
  395. cairo_pattern_t *pattern;
  396. pattern = cairo_pattern_create_rgb (0.5, 0.5, 0.5);
  397. cairo_mask (cr, pattern);
  398. cairo_pattern_destroy (pattern);
  399. return CAIRO_TEST_SUCCESS;
  400. }
  401. static cairo_test_status_t
  402. test_cairo_mask_surface (cairo_t *cr)
  403. {
  404. cairo_surface_t *surface;
  405. surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
  406. cairo_mask_surface (cr, surface, 0, 0);
  407. cairo_surface_destroy (surface);
  408. return CAIRO_TEST_SUCCESS;
  409. }
  410. static cairo_test_status_t
  411. test_cairo_stroke (cairo_t *cr)
  412. {
  413. cairo_stroke (cr);
  414. return CAIRO_TEST_SUCCESS;
  415. }
  416. static cairo_test_status_t
  417. test_cairo_stroke_preserve (cairo_t *cr)
  418. {
  419. cairo_stroke_preserve (cr);
  420. return CAIRO_TEST_SUCCESS;
  421. }
  422. static cairo_test_status_t
  423. test_cairo_fill (cairo_t *cr)
  424. {
  425. cairo_fill (cr);
  426. return CAIRO_TEST_SUCCESS;
  427. }
  428. static cairo_test_status_t
  429. test_cairo_fill_preserve (cairo_t *cr)
  430. {
  431. cairo_fill_preserve (cr);
  432. return CAIRO_TEST_SUCCESS;
  433. }
  434. static cairo_test_status_t
  435. test_cairo_copy_page (cairo_t *cr)
  436. {
  437. cairo_copy_page (cr);
  438. return CAIRO_TEST_SUCCESS;
  439. }
  440. static cairo_test_status_t
  441. test_cairo_show_page (cairo_t *cr)
  442. {
  443. cairo_show_page (cr);
  444. return CAIRO_TEST_SUCCESS;
  445. }
  446. static cairo_test_status_t
  447. test_cairo_in_stroke (cairo_t *cr)
  448. {
  449. cairo_in_stroke (cr, 1, 1);
  450. return CAIRO_TEST_SUCCESS;
  451. }
  452. static cairo_test_status_t
  453. test_cairo_in_fill (cairo_t *cr)
  454. {
  455. cairo_in_fill (cr, 1, 1);
  456. return CAIRO_TEST_SUCCESS;
  457. }
  458. static cairo_test_status_t
  459. test_cairo_in_clip (cairo_t *cr)
  460. {
  461. cairo_in_clip (cr, 1, 1);
  462. return CAIRO_TEST_SUCCESS;
  463. }
  464. static cairo_test_status_t
  465. test_cairo_stroke_extents (cairo_t *cr)
  466. {
  467. double x1, y1, x2, y2;
  468. cairo_stroke_extents (cr, &x1, &y1, &x2, &y2);
  469. return CAIRO_TEST_SUCCESS;
  470. }
  471. static cairo_test_status_t
  472. test_cairo_fill_extents (cairo_t *cr)
  473. {
  474. double x1, y1, x2, y2;
  475. cairo_fill_extents (cr, &x1, &y1, &x2, &y2);
  476. return CAIRO_TEST_SUCCESS;
  477. }
  478. static cairo_test_status_t
  479. test_cairo_reset_clip (cairo_t *cr)
  480. {
  481. cairo_reset_clip (cr);
  482. return CAIRO_TEST_SUCCESS;
  483. }
  484. static cairo_test_status_t
  485. test_cairo_clip (cairo_t *cr)
  486. {
  487. cairo_clip (cr);
  488. return CAIRO_TEST_SUCCESS;
  489. }
  490. static cairo_test_status_t
  491. test_cairo_clip_preserve (cairo_t *cr)
  492. {
  493. cairo_clip_preserve (cr);
  494. return CAIRO_TEST_SUCCESS;
  495. }
  496. static cairo_test_status_t
  497. test_cairo_clip_extents (cairo_t *cr)
  498. {
  499. double x1, y1, x2, y2;
  500. cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
  501. return CAIRO_TEST_SUCCESS;
  502. }
  503. static cairo_test_status_t
  504. test_cairo_copy_clip_rectangle_list (cairo_t *cr)
  505. {
  506. cairo_rectangle_list_destroy (cairo_copy_clip_rectangle_list (cr));
  507. return CAIRO_TEST_SUCCESS;
  508. }
  509. static cairo_test_status_t
  510. test_cairo_select_font_face (cairo_t *cr)
  511. {
  512. cairo_select_font_face (cr, "Arial", CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_WEIGHT_BOLD);
  513. return CAIRO_TEST_SUCCESS;
  514. }
  515. static cairo_test_status_t
  516. test_cairo_set_font_size (cairo_t *cr)
  517. {
  518. cairo_set_font_size (cr, 42);
  519. return CAIRO_TEST_SUCCESS;
  520. }
  521. static cairo_test_status_t
  522. test_cairo_set_font_matrix (cairo_t *cr)
  523. {
  524. cairo_matrix_t matrix;
  525. cairo_matrix_init_translate (&matrix, 1, 1);
  526. cairo_set_font_matrix (cr, &matrix);
  527. return CAIRO_TEST_SUCCESS;
  528. }
  529. static cairo_test_status_t
  530. test_cairo_get_font_matrix (cairo_t *cr)
  531. {
  532. cairo_matrix_t matrix;
  533. cairo_get_font_matrix (cr, &matrix);
  534. return CAIRO_TEST_SUCCESS;
  535. }
  536. static cairo_test_status_t
  537. test_cairo_set_font_options (cairo_t *cr)
  538. {
  539. cairo_font_options_t *opt = cairo_font_options_create ();
  540. cairo_set_font_options (cr, opt);
  541. cairo_font_options_destroy (opt);
  542. return CAIRO_TEST_SUCCESS;
  543. }
  544. static cairo_test_status_t
  545. test_cairo_get_font_options (cairo_t *cr)
  546. {
  547. cairo_font_options_t *opt = cairo_font_options_create ();
  548. cairo_get_font_options (cr, opt);
  549. cairo_font_options_destroy (opt);
  550. return CAIRO_TEST_SUCCESS;
  551. }
  552. static cairo_test_status_t
  553. test_cairo_set_font_face (cairo_t *cr)
  554. {
  555. cairo_set_font_face (cr, cairo_get_font_face (cr));
  556. return CAIRO_TEST_SUCCESS;
  557. }
  558. static cairo_test_status_t
  559. test_cairo_set_scaled_font (cairo_t *cr)
  560. {
  561. cairo_set_scaled_font (cr, cairo_get_scaled_font (cr));
  562. return CAIRO_TEST_SUCCESS;
  563. }
  564. static cairo_test_status_t
  565. test_cairo_show_text (cairo_t *cr)
  566. {
  567. cairo_show_text (cr, "Cairo");
  568. return CAIRO_TEST_SUCCESS;
  569. }
  570. static cairo_test_status_t
  571. test_cairo_show_glyphs (cairo_t *cr)
  572. {
  573. cairo_glyph_t glyph;
  574. glyph.index = 65;
  575. glyph.x = 0;
  576. glyph.y = 0;
  577. cairo_show_glyphs (cr, &glyph, 1);
  578. return CAIRO_TEST_SUCCESS;
  579. }
  580. static cairo_test_status_t
  581. test_cairo_show_text_glyphs (cairo_t *cr)
  582. {
  583. cairo_glyph_t glyph;
  584. cairo_text_cluster_t cluster;
  585. glyph.index = 65;
  586. glyph.x = 0;
  587. glyph.y = 0;
  588. cluster.num_bytes = 1;
  589. cluster.num_glyphs = 1;
  590. cairo_show_text_glyphs (cr, "a", -1, &glyph, 1, &cluster, 1, 0);
  591. return CAIRO_TEST_SUCCESS;
  592. }
  593. static cairo_test_status_t
  594. test_cairo_text_path (cairo_t *cr)
  595. {
  596. cairo_text_path (cr, "Cairo");
  597. return CAIRO_TEST_SUCCESS;
  598. }
  599. static cairo_test_status_t
  600. test_cairo_glyph_path (cairo_t *cr)
  601. {
  602. cairo_glyph_t glyph;
  603. glyph.index = 65;
  604. glyph.x = 0;
  605. glyph.y = 0;
  606. cairo_glyph_path (cr, &glyph, 1);
  607. return CAIRO_TEST_SUCCESS;
  608. }
  609. static cairo_test_status_t
  610. test_cairo_text_extents (cairo_t *cr)
  611. {
  612. cairo_text_extents_t extents;
  613. cairo_text_extents (cr, "Cairo", &extents);
  614. return CAIRO_TEST_SUCCESS;
  615. }
  616. static cairo_test_status_t
  617. test_cairo_glyph_extents (cairo_t *cr)
  618. {
  619. cairo_glyph_t glyph;
  620. cairo_text_extents_t extents;
  621. glyph.index = 65;
  622. glyph.x = 0;
  623. glyph.y = 0;
  624. cairo_glyph_extents (cr, &glyph, 1, &extents);
  625. return CAIRO_TEST_SUCCESS;
  626. }
  627. static cairo_test_status_t
  628. test_cairo_font_extents (cairo_t *cr)
  629. {
  630. cairo_font_extents_t extents;
  631. cairo_font_extents (cr, &extents);
  632. return CAIRO_TEST_SUCCESS;
  633. }
  634. static cairo_test_status_t
  635. test_cairo_get_operator (cairo_t *cr)
  636. {
  637. cairo_get_operator (cr);
  638. return CAIRO_TEST_SUCCESS;
  639. }
  640. static cairo_test_status_t
  641. test_cairo_get_source (cairo_t *cr)
  642. {
  643. cairo_get_source (cr);
  644. return CAIRO_TEST_SUCCESS;
  645. }
  646. static cairo_test_status_t
  647. test_cairo_get_tolerance (cairo_t *cr)
  648. {
  649. cairo_get_tolerance (cr);
  650. return CAIRO_TEST_SUCCESS;
  651. }
  652. static cairo_test_status_t
  653. test_cairo_get_antialias (cairo_t *cr)
  654. {
  655. cairo_get_antialias (cr);
  656. return CAIRO_TEST_SUCCESS;
  657. }
  658. static cairo_test_status_t
  659. test_cairo_has_current_point (cairo_t *cr)
  660. {
  661. cairo_has_current_point (cr);
  662. return CAIRO_TEST_SUCCESS;
  663. }
  664. static cairo_test_status_t
  665. test_cairo_get_current_point (cairo_t *cr)
  666. {
  667. double x, y;
  668. cairo_get_current_point (cr, &x, &y);
  669. return CAIRO_TEST_SUCCESS;
  670. }
  671. static cairo_test_status_t
  672. test_cairo_get_fill_rule (cairo_t *cr)
  673. {
  674. cairo_get_fill_rule (cr);
  675. return CAIRO_TEST_SUCCESS;
  676. }
  677. static cairo_test_status_t
  678. test_cairo_get_line_width (cairo_t *cr)
  679. {
  680. cairo_get_line_width (cr);
  681. return CAIRO_TEST_SUCCESS;
  682. }
  683. static cairo_test_status_t
  684. test_cairo_get_line_cap (cairo_t *cr)
  685. {
  686. cairo_get_line_cap (cr);
  687. return CAIRO_TEST_SUCCESS;
  688. }
  689. static cairo_test_status_t
  690. test_cairo_get_line_join (cairo_t *cr)
  691. {
  692. cairo_get_line_join (cr);
  693. return CAIRO_TEST_SUCCESS;
  694. }
  695. static cairo_test_status_t
  696. test_cairo_get_miter_limit (cairo_t *cr)
  697. {
  698. cairo_get_miter_limit (cr);
  699. return CAIRO_TEST_SUCCESS;
  700. }
  701. static cairo_test_status_t
  702. test_cairo_get_dash_count (cairo_t *cr)
  703. {
  704. cairo_get_dash_count (cr);
  705. return CAIRO_TEST_SUCCESS;
  706. }
  707. static cairo_test_status_t
  708. test_cairo_get_dash (cairo_t *cr)
  709. {
  710. double dashes[42];
  711. double offset;
  712. cairo_get_dash (cr, &dashes[0], &offset);
  713. return CAIRO_TEST_SUCCESS;
  714. }
  715. static cairo_test_status_t
  716. test_cairo_get_matrix (cairo_t *cr)
  717. {
  718. cairo_matrix_t matrix;
  719. cairo_get_matrix (cr, &matrix);
  720. return CAIRO_TEST_SUCCESS;
  721. }
  722. static cairo_test_status_t
  723. test_cairo_get_target (cairo_t *cr)
  724. {
  725. cairo_get_target (cr);
  726. return CAIRO_TEST_SUCCESS;
  727. }
  728. static cairo_test_status_t
  729. test_cairo_get_group_target (cairo_t *cr)
  730. {
  731. cairo_get_group_target (cr);
  732. return CAIRO_TEST_SUCCESS;
  733. }
  734. static cairo_test_status_t
  735. test_cairo_copy_path (cairo_t *cr)
  736. {
  737. cairo_path_destroy (cairo_copy_path (cr));
  738. return CAIRO_TEST_SUCCESS;
  739. }
  740. static cairo_test_status_t
  741. test_cairo_copy_path_flat (cairo_t *cr)
  742. {
  743. cairo_path_destroy (cairo_copy_path_flat (cr));
  744. return CAIRO_TEST_SUCCESS;
  745. }
  746. static cairo_test_status_t
  747. test_cairo_append_path (cairo_t *cr)
  748. {
  749. cairo_path_data_t data[3];
  750. cairo_path_t path;
  751. path.status = CAIRO_STATUS_SUCCESS;
  752. path.data = &data[0];
  753. path.num_data = ARRAY_LENGTH(data);
  754. data[0].header.type = CAIRO_PATH_MOVE_TO;
  755. data[0].header.length = 2;
  756. data[1].point.x = 1;
  757. data[1].point.y = 2;
  758. data[2].header.type = CAIRO_PATH_CLOSE_PATH;
  759. data[2].header.length = 1;
  760. cairo_append_path (cr, &path);
  761. return CAIRO_TEST_SUCCESS;
  762. }
  763. static cairo_test_status_t
  764. test_cairo_surface_create_similar (cairo_surface_t *surface)
  765. {
  766. cairo_surface_t *similar;
  767. similar = cairo_surface_create_similar (surface, CAIRO_CONTENT_ALPHA, 100, 100);
  768. cairo_surface_destroy (similar);
  769. return CAIRO_TEST_SUCCESS;
  770. }
  771. static cairo_test_status_t
  772. test_cairo_surface_create_for_rectangle (cairo_surface_t *surface)
  773. {
  774. cairo_surface_t *similar;
  775. similar = cairo_surface_create_for_rectangle (surface, 1, 1, 8, 8);
  776. cairo_surface_destroy (similar);
  777. return CAIRO_TEST_SUCCESS;
  778. }
  779. static cairo_test_status_t
  780. test_cairo_surface_reference (cairo_surface_t *surface)
  781. {
  782. cairo_surface_destroy (cairo_surface_reference (surface));
  783. return CAIRO_TEST_SUCCESS;
  784. }
  785. static cairo_test_status_t
  786. test_cairo_surface_finish (cairo_surface_t *surface)
  787. {
  788. cairo_surface_finish (surface);
  789. return CAIRO_TEST_SUCCESS;
  790. }
  791. static cairo_test_status_t
  792. test_cairo_surface_get_device (cairo_surface_t *surface)
  793. {
  794. /* cairo_device_t *device = */cairo_surface_get_device (surface);
  795. return CAIRO_TEST_SUCCESS;
  796. }
  797. static cairo_test_status_t
  798. test_cairo_surface_get_reference_count (cairo_surface_t *surface)
  799. {
  800. unsigned int refcount = cairo_surface_get_reference_count (surface);
  801. if (refcount > 0)
  802. return CAIRO_TEST_SUCCESS;
  803. /* inert error surfaces have a refcount of 0 */
  804. return cairo_surface_status (surface) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  805. }
  806. static cairo_test_status_t
  807. test_cairo_surface_status (cairo_surface_t *surface)
  808. {
  809. cairo_status_t status = cairo_surface_status (surface);
  810. return status < CAIRO_STATUS_LAST_STATUS ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  811. }
  812. static cairo_test_status_t
  813. test_cairo_surface_get_type (cairo_surface_t *surface)
  814. {
  815. /* cairo_surface_type_t type = */cairo_surface_get_type (surface);
  816. return CAIRO_TEST_SUCCESS;
  817. }
  818. static cairo_test_status_t
  819. test_cairo_surface_get_content (cairo_surface_t *surface)
  820. {
  821. cairo_content_t content = cairo_surface_get_content (surface);
  822. switch (content) {
  823. case CAIRO_CONTENT_COLOR:
  824. case CAIRO_CONTENT_ALPHA:
  825. case CAIRO_CONTENT_COLOR_ALPHA:
  826. return CAIRO_TEST_SUCCESS;
  827. default:
  828. return CAIRO_TEST_ERROR;
  829. }
  830. }
  831. static cairo_test_status_t
  832. test_cairo_surface_set_user_data (cairo_surface_t *surface)
  833. {
  834. static cairo_user_data_key_t key;
  835. cairo_status_t status;
  836. status = cairo_surface_set_user_data (surface, &key, &key, NULL);
  837. if (status == CAIRO_STATUS_NO_MEMORY)
  838. return CAIRO_TEST_NO_MEMORY;
  839. else if (status)
  840. return CAIRO_TEST_SUCCESS;
  841. if (cairo_surface_get_user_data (surface, &key) != &key)
  842. return CAIRO_TEST_ERROR;
  843. return CAIRO_TEST_SUCCESS;
  844. }
  845. static cairo_test_status_t
  846. test_cairo_surface_set_mime_data (cairo_surface_t *surface)
  847. {
  848. const char *mimetype = "text/x-uri";
  849. const char *data = "http://www.cairographics.org";
  850. cairo_status_t status;
  851. status = cairo_surface_set_mime_data (surface,
  852. mimetype,
  853. (const unsigned char *) data,
  854. strlen (data),
  855. NULL, NULL);
  856. return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  857. }
  858. static cairo_test_status_t
  859. test_cairo_surface_get_mime_data (cairo_surface_t *surface)
  860. {
  861. const char *mimetype = "text/x-uri";
  862. const unsigned char *data;
  863. unsigned long length;
  864. cairo_surface_get_mime_data (surface, mimetype, &data, &length);
  865. return data == NULL && length == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  866. }
  867. static cairo_test_status_t
  868. test_cairo_surface_get_font_options (cairo_surface_t *surface)
  869. {
  870. cairo_font_options_t *options;
  871. cairo_status_t status;
  872. options = cairo_font_options_create ();
  873. if (likely (!cairo_font_options_status (options)))
  874. cairo_surface_get_font_options (surface, options);
  875. status = cairo_font_options_status (options);
  876. cairo_font_options_destroy (options);
  877. return status ? CAIRO_TEST_ERROR : CAIRO_TEST_SUCCESS;
  878. }
  879. static cairo_test_status_t
  880. test_cairo_surface_flush (cairo_surface_t *surface)
  881. {
  882. cairo_surface_flush (surface);
  883. return CAIRO_TEST_SUCCESS;
  884. }
  885. static cairo_test_status_t
  886. test_cairo_surface_mark_dirty (cairo_surface_t *surface)
  887. {
  888. cairo_surface_mark_dirty (surface);
  889. return CAIRO_TEST_SUCCESS;
  890. }
  891. static cairo_test_status_t
  892. test_cairo_surface_mark_dirty_rectangle (cairo_surface_t *surface)
  893. {
  894. cairo_surface_mark_dirty_rectangle (surface, 1, 1, 8, 8);
  895. return CAIRO_TEST_SUCCESS;
  896. }
  897. static cairo_test_status_t
  898. test_cairo_surface_set_device_offset (cairo_surface_t *surface)
  899. {
  900. cairo_surface_set_device_offset (surface, 5, 5);
  901. return CAIRO_TEST_SUCCESS;
  902. }
  903. static cairo_test_status_t
  904. test_cairo_surface_get_device_offset (cairo_surface_t *surface)
  905. {
  906. double x, y;
  907. cairo_surface_get_device_offset (surface, &x, &y);
  908. return CAIRO_TEST_SUCCESS;
  909. }
  910. static cairo_test_status_t
  911. test_cairo_surface_set_fallback_resolution (cairo_surface_t *surface)
  912. {
  913. cairo_surface_set_fallback_resolution (surface, 42, 42);
  914. return CAIRO_TEST_SUCCESS;
  915. }
  916. static cairo_test_status_t
  917. test_cairo_surface_get_fallback_resolution (cairo_surface_t *surface)
  918. {
  919. double x, y;
  920. cairo_surface_get_fallback_resolution (surface, &x, &y);
  921. return CAIRO_TEST_SUCCESS;
  922. }
  923. static cairo_test_status_t
  924. test_cairo_surface_copy_page (cairo_surface_t *surface)
  925. {
  926. cairo_surface_copy_page (surface);
  927. return CAIRO_TEST_SUCCESS;
  928. }
  929. static cairo_test_status_t
  930. test_cairo_surface_show_page (cairo_surface_t *surface)
  931. {
  932. cairo_surface_show_page (surface);
  933. return CAIRO_TEST_SUCCESS;
  934. }
  935. static cairo_test_status_t
  936. test_cairo_surface_has_show_text_glyphs (cairo_surface_t *surface)
  937. {
  938. cairo_surface_has_show_text_glyphs (surface);
  939. return CAIRO_TEST_SUCCESS;
  940. }
  941. static cairo_test_status_t
  942. test_cairo_image_surface_get_data (cairo_surface_t *surface)
  943. {
  944. unsigned char *data = cairo_image_surface_get_data (surface);
  945. return data == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  946. }
  947. static cairo_test_status_t
  948. test_cairo_image_surface_get_format (cairo_surface_t *surface)
  949. {
  950. cairo_format_t format = cairo_image_surface_get_format (surface);
  951. return format == CAIRO_FORMAT_INVALID || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  952. }
  953. static cairo_test_status_t
  954. test_cairo_image_surface_get_width (cairo_surface_t *surface)
  955. {
  956. unsigned int width = cairo_image_surface_get_width (surface);
  957. return width == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  958. }
  959. static cairo_test_status_t
  960. test_cairo_image_surface_get_height (cairo_surface_t *surface)
  961. {
  962. unsigned int height = cairo_image_surface_get_height (surface);
  963. return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  964. }
  965. static cairo_test_status_t
  966. test_cairo_image_surface_get_stride (cairo_surface_t *surface)
  967. {
  968. unsigned int stride = cairo_image_surface_get_stride (surface);
  969. return stride == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_IMAGE) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  970. }
  971. #if CAIRO_HAS_PNG_FUNCTIONS
  972. static cairo_test_status_t
  973. test_cairo_surface_write_to_png (cairo_surface_t *surface)
  974. {
  975. cairo_status_t status;
  976. status = cairo_surface_write_to_png (surface, "/this/file/will/definitely/not/exist.png");
  977. return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  978. }
  979. static cairo_status_t
  980. write_func_that_always_fails (void *closure, const unsigned char *data, unsigned int length)
  981. {
  982. return CAIRO_STATUS_WRITE_ERROR;
  983. }
  984. static cairo_test_status_t
  985. test_cairo_surface_write_to_png_stream (cairo_surface_t *surface)
  986. {
  987. cairo_status_t status;
  988. status = cairo_surface_write_to_png_stream (surface,
  989. write_func_that_always_fails,
  990. NULL);
  991. return status && status != CAIRO_STATUS_WRITE_ERROR ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  992. }
  993. #endif /* CAIRO_HAS_PNG_FUNCTIONS */
  994. static cairo_test_status_t
  995. test_cairo_recording_surface_ink_extents (cairo_surface_t *surface)
  996. {
  997. double x, y, w, h;
  998. cairo_recording_surface_ink_extents (surface, &x, &y, &w, &h);
  999. return x == 0 && y == 0 && w == 0 && h == 0 ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1000. }
  1001. #if CAIRO_HAS_TEE_SURFACE
  1002. static cairo_test_status_t
  1003. test_cairo_tee_surface_add (cairo_surface_t *surface)
  1004. {
  1005. cairo_surface_t *image = cairo_image_surface_create (CAIRO_FORMAT_A8, 10, 10);
  1006. cairo_tee_surface_add (surface, image);
  1007. cairo_surface_destroy (image);
  1008. return CAIRO_TEST_SUCCESS;
  1009. }
  1010. static cairo_test_status_t
  1011. test_cairo_tee_surface_remove (cairo_surface_t *surface)
  1012. {
  1013. cairo_surface_t *image = cairo_image_surface_create (CAIRO_FORMAT_A8, 10, 10);
  1014. cairo_tee_surface_remove (surface, image);
  1015. cairo_surface_destroy (image);
  1016. return CAIRO_TEST_SUCCESS;
  1017. }
  1018. static cairo_test_status_t
  1019. test_cairo_tee_surface_index (cairo_surface_t *surface)
  1020. {
  1021. cairo_surface_t *master;
  1022. cairo_status_t status;
  1023. master = cairo_tee_surface_index (surface, 0);
  1024. status = cairo_surface_status (master);
  1025. cairo_surface_destroy (master);
  1026. return status ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1027. }
  1028. #endif /* CAIRO_HAS_TEE_SURFACE */
  1029. #if CAIRO_HAS_GL_SURFACE
  1030. static cairo_test_status_t
  1031. test_cairo_gl_surface_set_size (cairo_surface_t *surface)
  1032. {
  1033. cairo_gl_surface_set_size (surface, 5, 5);
  1034. return CAIRO_TEST_SUCCESS;
  1035. }
  1036. static cairo_test_status_t
  1037. test_cairo_gl_surface_get_width (cairo_surface_t *surface)
  1038. {
  1039. unsigned int width = cairo_gl_surface_get_width (surface);
  1040. return width == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_GL) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1041. }
  1042. static cairo_test_status_t
  1043. test_cairo_gl_surface_get_height (cairo_surface_t *surface)
  1044. {
  1045. unsigned int height = cairo_gl_surface_get_height (surface);
  1046. return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_GL) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1047. }
  1048. static cairo_test_status_t
  1049. test_cairo_gl_surface_swapbuffers (cairo_surface_t *surface)
  1050. {
  1051. cairo_gl_surface_swapbuffers (surface);
  1052. return CAIRO_TEST_SUCCESS;
  1053. }
  1054. #endif /* CAIRO_HAS_GL_SURFACE */
  1055. #if CAIRO_HAS_PDF_SURFACE
  1056. static cairo_test_status_t
  1057. test_cairo_pdf_surface_restrict_to_version (cairo_surface_t *surface)
  1058. {
  1059. cairo_pdf_surface_restrict_to_version (surface, CAIRO_PDF_VERSION_1_4);
  1060. return CAIRO_TEST_SUCCESS;
  1061. }
  1062. static cairo_test_status_t
  1063. test_cairo_pdf_surface_set_size (cairo_surface_t *surface)
  1064. {
  1065. cairo_pdf_surface_set_size (surface, 5, 5);
  1066. return CAIRO_TEST_SUCCESS;
  1067. }
  1068. #endif /* CAIRO_HAS_PDF_SURFACE */
  1069. #if CAIRO_HAS_PS_SURFACE
  1070. static cairo_test_status_t
  1071. test_cairo_ps_surface_restrict_to_level (cairo_surface_t *surface)
  1072. {
  1073. cairo_ps_surface_restrict_to_level (surface, CAIRO_PS_LEVEL_2);
  1074. return CAIRO_TEST_SUCCESS;
  1075. }
  1076. static cairo_test_status_t
  1077. test_cairo_ps_surface_set_eps (cairo_surface_t *surface)
  1078. {
  1079. cairo_ps_surface_set_eps (surface, TRUE);
  1080. return CAIRO_TEST_SUCCESS;
  1081. }
  1082. static cairo_test_status_t
  1083. test_cairo_ps_surface_get_eps (cairo_surface_t *surface)
  1084. {
  1085. cairo_bool_t eps = cairo_ps_surface_get_eps (surface);
  1086. return eps ? CAIRO_TEST_ERROR : CAIRO_TEST_SUCCESS;
  1087. }
  1088. static cairo_test_status_t
  1089. test_cairo_ps_surface_set_size (cairo_surface_t *surface)
  1090. {
  1091. cairo_ps_surface_set_size (surface, 5, 5);
  1092. return CAIRO_TEST_SUCCESS;
  1093. }
  1094. static cairo_test_status_t
  1095. test_cairo_ps_surface_dsc_comment (cairo_surface_t *surface)
  1096. {
  1097. cairo_ps_surface_dsc_comment (surface, "54, 74, 90, 2010");
  1098. return CAIRO_TEST_SUCCESS;
  1099. }
  1100. static cairo_test_status_t
  1101. test_cairo_ps_surface_dsc_begin_setup (cairo_surface_t *surface)
  1102. {
  1103. cairo_ps_surface_dsc_begin_setup (surface);
  1104. return CAIRO_TEST_SUCCESS;
  1105. }
  1106. static cairo_test_status_t
  1107. test_cairo_ps_surface_dsc_begin_page_setup (cairo_surface_t *surface)
  1108. {
  1109. cairo_ps_surface_dsc_begin_page_setup (surface);
  1110. return CAIRO_TEST_SUCCESS;
  1111. }
  1112. #endif /* CAIRO_HAS_PS_SURFACE */
  1113. #if CAIRO_HAS_QUARTZ_SURFACE
  1114. static cairo_test_status_t
  1115. test_cairo_quartz_surface_get_cg_context (cairo_surface_t *surface)
  1116. {
  1117. CGContextRef context = cairo_quartz_surface_get_cg_context (surface);
  1118. return context == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_QUARTZ) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1119. }
  1120. #endif /* CAIRO_HAS_QUARTZ_SURFACE */
  1121. #if CAIRO_HAS_SVG_SURFACE
  1122. static cairo_test_status_t
  1123. test_cairo_svg_surface_restrict_to_version (cairo_surface_t *surface)
  1124. {
  1125. cairo_svg_surface_restrict_to_version (surface, CAIRO_SVG_VERSION_1_1);
  1126. return CAIRO_TEST_SUCCESS;
  1127. }
  1128. #endif /* CAIRO_HAS_SVG_SURFACE */
  1129. #if CAIRO_HAS_XCB_SURFACE
  1130. static cairo_test_status_t
  1131. test_cairo_xcb_surface_set_size (cairo_surface_t *surface)
  1132. {
  1133. cairo_xcb_surface_set_size (surface, 5, 5);
  1134. return CAIRO_TEST_SUCCESS;
  1135. }
  1136. static cairo_test_status_t
  1137. test_cairo_xcb_surface_set_drawable (cairo_surface_t *surface)
  1138. {
  1139. cairo_xcb_surface_set_drawable (surface, 0, 5, 5);
  1140. return CAIRO_TEST_SUCCESS;
  1141. }
  1142. #endif
  1143. #if CAIRO_HAS_XLIB_SURFACE
  1144. static cairo_test_status_t
  1145. test_cairo_xlib_surface_set_size (cairo_surface_t *surface)
  1146. {
  1147. cairo_xlib_surface_set_size (surface, 5, 5);
  1148. return CAIRO_TEST_SUCCESS;
  1149. }
  1150. static cairo_test_status_t
  1151. test_cairo_xlib_surface_set_drawable (cairo_surface_t *surface)
  1152. {
  1153. cairo_xlib_surface_set_drawable (surface, 0, 5, 5);
  1154. return CAIRO_TEST_SUCCESS;
  1155. }
  1156. static cairo_test_status_t
  1157. test_cairo_xlib_surface_get_display (cairo_surface_t *surface)
  1158. {
  1159. Display *display = cairo_xlib_surface_get_display (surface);
  1160. return display == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1161. }
  1162. static cairo_test_status_t
  1163. test_cairo_xlib_surface_get_screen (cairo_surface_t *surface)
  1164. {
  1165. Screen *screen = cairo_xlib_surface_get_screen (surface);
  1166. return screen == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1167. }
  1168. static cairo_test_status_t
  1169. test_cairo_xlib_surface_get_visual (cairo_surface_t *surface)
  1170. {
  1171. Visual *visual = cairo_xlib_surface_get_visual (surface);
  1172. return visual == NULL || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1173. }
  1174. static cairo_test_status_t
  1175. test_cairo_xlib_surface_get_drawable (cairo_surface_t *surface)
  1176. {
  1177. Drawable drawable = cairo_xlib_surface_get_drawable (surface);
  1178. return drawable == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1179. }
  1180. static cairo_test_status_t
  1181. test_cairo_xlib_surface_get_depth (cairo_surface_t *surface)
  1182. {
  1183. int depth = cairo_xlib_surface_get_depth (surface);
  1184. return depth == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1185. }
  1186. static cairo_test_status_t
  1187. test_cairo_xlib_surface_get_width (cairo_surface_t *surface)
  1188. {
  1189. int width = cairo_xlib_surface_get_width (surface);
  1190. return width == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1191. }
  1192. static cairo_test_status_t
  1193. test_cairo_xlib_surface_get_height (cairo_surface_t *surface)
  1194. {
  1195. int height = cairo_xlib_surface_get_height (surface);
  1196. return height == 0 || surface_has_type (surface, CAIRO_SURFACE_TYPE_XLIB) ? CAIRO_TEST_SUCCESS : CAIRO_TEST_ERROR;
  1197. }
  1198. #endif
  1199. #define TEST(name) { #name, test_ ## name }
  1200. struct {
  1201. const char *name;
  1202. context_test_func_t func;
  1203. } context_tests[] = {
  1204. TEST (cairo_reference),
  1205. TEST (cairo_get_reference_count),
  1206. TEST (cairo_set_user_data),
  1207. TEST (cairo_save),
  1208. TEST (cairo_push_group),
  1209. TEST (cairo_push_group_with_content),
  1210. TEST (cairo_set_operator),
  1211. TEST (cairo_set_source),
  1212. TEST (cairo_set_source_rgb),
  1213. TEST (cairo_set_source_rgba),
  1214. TEST (cairo_set_source_surface),
  1215. TEST (cairo_set_tolerance),
  1216. TEST (cairo_set_antialias),
  1217. TEST (cairo_set_fill_rule),
  1218. TEST (cairo_set_line_width),
  1219. TEST (cairo_set_line_cap),
  1220. TEST (cairo_set_line_join),
  1221. TEST (cairo_set_dash),
  1222. TEST (cairo_set_miter_limit),
  1223. TEST (cairo_translate),
  1224. TEST (cairo_scale),
  1225. TEST (cairo_rotate),
  1226. TEST (cairo_transform),
  1227. TEST (cairo_set_matrix),
  1228. TEST (cairo_identity_matrix),
  1229. TEST (cairo_user_to_device),
  1230. TEST (cairo_user_to_device_distance),
  1231. TEST (cairo_device_to_user),
  1232. TEST (cairo_device_to_user_distance),
  1233. TEST (cairo_new_path),
  1234. TEST (cairo_move_to),
  1235. TEST (cairo_new_sub_path),
  1236. TEST (cairo_line_to),
  1237. TEST (cairo_curve_to),
  1238. TEST (cairo_arc),
  1239. TEST (cairo_arc_negative),
  1240. TEST (cairo_rel_move_to),
  1241. TEST (cairo_rel_line_to),
  1242. TEST (cairo_rel_curve_to),
  1243. TEST (cairo_rectangle),
  1244. TEST (cairo_close_path),
  1245. TEST (cairo_path_extents),
  1246. TEST (cairo_paint),
  1247. TEST (cairo_paint_with_alpha),
  1248. TEST (cairo_mask),
  1249. TEST (cairo_mask_surface),
  1250. TEST (cairo_stroke),
  1251. TEST (cairo_stroke_preserve),
  1252. TEST (cairo_fill),
  1253. TEST (cairo_fill_preserve),
  1254. TEST (cairo_copy_page),
  1255. TEST (cairo_show_page),
  1256. TEST (cairo_in_stroke),
  1257. TEST (cairo_in_fill),
  1258. TEST (cairo_in_clip),
  1259. TEST (cairo_stroke_extents),
  1260. TEST (cairo_fill_extents),
  1261. TEST (cairo_reset_clip),
  1262. TEST (cairo_clip),
  1263. TEST (cairo_clip_preserve),
  1264. TEST (cairo_clip_extents),
  1265. TEST (cairo_copy_clip_rectangle_list),
  1266. TEST (cairo_select_font_face),
  1267. TEST (cairo_set_font_size),
  1268. TEST (cairo_set_font_matrix),
  1269. TEST (cairo_get_font_matrix),
  1270. TEST (cairo_set_font_options),
  1271. TEST (cairo_get_font_options),
  1272. TEST (cairo_set_font_face),
  1273. TEST (cairo_set_scaled_font),
  1274. TEST (cairo_show_text),
  1275. TEST (cairo_show_glyphs),
  1276. TEST (cairo_show_text_glyphs),
  1277. TEST (cairo_text_path),
  1278. TEST (cairo_glyph_path),
  1279. TEST (cairo_text_extents),
  1280. TEST (cairo_glyph_extents),
  1281. TEST (cairo_font_extents),
  1282. TEST (cairo_get_operator),
  1283. TEST (cairo_get_source),
  1284. TEST (cairo_get_tolerance),
  1285. TEST (cairo_get_antialias),
  1286. TEST (cairo_has_current_point),
  1287. TEST (cairo_get_current_point),
  1288. TEST (cairo_get_fill_rule),
  1289. TEST (cairo_get_line_width),
  1290. TEST (cairo_get_line_cap),
  1291. TEST (cairo_get_line_join),
  1292. TEST (cairo_get_miter_limit),
  1293. TEST (cairo_get_dash_count),
  1294. TEST (cairo_get_dash),
  1295. TEST (cairo_get_matrix),
  1296. TEST (cairo_get_target),
  1297. TEST (cairo_get_group_target),
  1298. TEST (cairo_copy_path),
  1299. TEST (cairo_copy_path_flat),
  1300. TEST (cairo_append_path),
  1301. };
  1302. #undef TEST
  1303. #define TEST(name, surface_type, sets_status) { #name, test_ ## name, surface_type, sets_status }
  1304. struct {
  1305. const char *name;
  1306. surface_test_func_t func;
  1307. int surface_type; /* cairo_surface_type_t or -1 */
  1308. cairo_bool_t modifies_surface;
  1309. } surface_tests[] = {
  1310. TEST (cairo_surface_create_similar, -1, FALSE),
  1311. TEST (cairo_surface_create_for_rectangle, -1, FALSE),
  1312. TEST (cairo_surface_reference, -1, FALSE),
  1313. TEST (cairo_surface_finish, -1, TRUE),
  1314. TEST (cairo_surface_get_device, -1, FALSE),
  1315. TEST (cairo_surface_get_reference_count, -1, FALSE),
  1316. TEST (cairo_surface_status, -1, FALSE),
  1317. TEST (cairo_surface_get_type, -1, FALSE),
  1318. TEST (cairo_surface_get_content, -1, FALSE),
  1319. TEST (cairo_surface_set_user_data, -1, FALSE),
  1320. TEST (cairo_surface_set_mime_data, -1, TRUE),
  1321. TEST (cairo_surface_get_mime_data, -1, FALSE),
  1322. TEST (cairo_surface_get_font_options, -1, FALSE),
  1323. TEST (cairo_surface_flush, -1, TRUE),
  1324. TEST (cairo_surface_mark_dirty, -1, TRUE),
  1325. TEST (cairo_surface_mark_dirty_rectangle, -1, TRUE),
  1326. TEST (cairo_surface_set_device_offset, -1, TRUE),
  1327. TEST (cairo_surface_get_device_offset, -1, FALSE),
  1328. TEST (cairo_surface_set_fallback_resolution, -1, TRUE),
  1329. TEST (cairo_surface_get_fallback_resolution, -1, FALSE),
  1330. TEST (cairo_surface_copy_page, -1, TRUE),
  1331. TEST (cairo_surface_show_page, -1, TRUE),
  1332. TEST (cairo_surface_has_show_text_glyphs, -1, FALSE),
  1333. TEST (cairo_image_surface_get_data, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
  1334. TEST (cairo_image_surface_get_format, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
  1335. TEST (cairo_image_surface_get_width, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
  1336. TEST (cairo_image_surface_get_height, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
  1337. TEST (cairo_image_surface_get_stride, CAIRO_SURFACE_TYPE_IMAGE, FALSE),
  1338. #if CAIRO_HAS_PNG_FUNCTIONS
  1339. TEST (cairo_surface_write_to_png, -1, FALSE),
  1340. TEST (cairo_surface_write_to_png_stream, -1, FALSE),
  1341. #endif
  1342. TEST (cairo_recording_surface_ink_extents, CAIRO_SURFACE_TYPE_RECORDING, FALSE),
  1343. #if CAIRO_HAS_TEE_SURFACE
  1344. TEST (cairo_tee_surface_add, CAIRO_SURFACE_TYPE_TEE, TRUE),
  1345. TEST (cairo_tee_surface_remove, CAIRO_SURFACE_TYPE_TEE, TRUE),
  1346. TEST (cairo_tee_surface_index, CAIRO_SURFACE_TYPE_TEE, FALSE),
  1347. #endif
  1348. #if CAIRO_HAS_GL_SURFACE
  1349. TEST (cairo_gl_surface_set_size, CAIRO_SURFACE_TYPE_GL, TRUE),
  1350. TEST (cairo_gl_surface_get_width, CAIRO_SURFACE_TYPE_GL, FALSE),
  1351. TEST (cairo_gl_surface_get_height, CAIRO_SURFACE_TYPE_GL, FALSE),
  1352. TEST (cairo_gl_surface_swapbuffers, CAIRO_SURFACE_TYPE_GL, TRUE),
  1353. #endif
  1354. #if CAIRO_HAS_PDF_SURFACE
  1355. TEST (cairo_pdf_surface_restrict_to_version, CAIRO_SURFACE_TYPE_PDF, TRUE),
  1356. TEST (cairo_pdf_surface_set_size, CAIRO_SURFACE_TYPE_PDF, TRUE),
  1357. #endif
  1358. #if CAIRO_HAS_PS_SURFACE
  1359. TEST (cairo_ps_surface_restrict_to_level, CAIRO_SURFACE_TYPE_PS, TRUE),
  1360. TEST (cairo_ps_surface_set_eps, CAIRO_SURFACE_TYPE_PS, TRUE),
  1361. TEST (cairo_ps_surface_get_eps, CAIRO_SURFACE_TYPE_PS, FALSE),
  1362. TEST (cairo_ps_surface_set_size, CAIRO_SURFACE_TYPE_PS, TRUE),
  1363. TEST (cairo_ps_surface_dsc_comment, CAIRO_SURFACE_TYPE_PS, TRUE),
  1364. TEST (cairo_ps_surface_dsc_begin_setup, CAIRO_SURFACE_TYPE_PS, TRUE),
  1365. TEST (cairo_ps_surface_dsc_begin_page_setup, CAIRO_SURFACE_TYPE_PS, TRUE),
  1366. #endif
  1367. #if CAIRO_HAS_QUARTZ_SURFACE
  1368. TEST (cairo_quartz_surface_get_cg_context, CAIRO_SURFACE_TYPE_QUARTZ, FALSE),
  1369. #endif
  1370. #if CAIRO_HAS_SVG_SURFACE
  1371. TEST (cairo_svg_surface_restrict_to_version, CAIRO_SURFACE_TYPE_SVG, TRUE),
  1372. #endif
  1373. #if CAIRO_HAS_XCB_SURFACE
  1374. TEST (cairo_xcb_surface_set_size, CAIRO_SURFACE_TYPE_XCB, TRUE),
  1375. TEST (cairo_xcb_surface_set_drawable, CAIRO_SURFACE_TYPE_XCB, TRUE),
  1376. #endif
  1377. #if CAIRO_HAS_XLIB_SURFACE
  1378. TEST (cairo_xlib_surface_set_size, CAIRO_SURFACE_TYPE_XLIB, TRUE),
  1379. TEST (cairo_xlib_surface_set_drawable, CAIRO_SURFACE_TYPE_XLIB, TRUE),
  1380. TEST (cairo_xlib_surface_get_display, CAIRO_SURFACE_TYPE_XLIB, FALSE),
  1381. TEST (cairo_xlib_surface_get_drawable, CAIRO_SURFACE_TYPE_XLIB, FALSE),
  1382. TEST (cairo_xlib_surface_get_screen, CAIRO_SURFACE_TYPE_XLIB, FALSE),
  1383. TEST (cairo_xlib_surface_get_visual, CAIRO_SURFACE_TYPE_XLIB, FALSE),
  1384. TEST (cairo_xlib_surface_get_depth, CAIRO_SURFACE_TYPE_XLIB, FALSE),
  1385. TEST (cairo_xlib_surface_get_width, CAIRO_SURFACE_TYPE_XLIB, FALSE),
  1386. TEST (cairo_xlib_surface_get_height, CAIRO_SURFACE_TYPE_XLIB, FALSE),
  1387. #endif
  1388. };
  1389. static cairo_test_status_t
  1390. preamble (cairo_test_context_t *ctx)
  1391. {
  1392. cairo_surface_t *surface;
  1393. cairo_t *cr;
  1394. cairo_test_status_t test_status;
  1395. cairo_status_t status_before, status_after;
  1396. unsigned int i;
  1397. /* Test an error surface */
  1398. for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
  1399. surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);
  1400. status_before = cairo_surface_status (surface);
  1401. assert (status_before);
  1402. test_status = surface_tests[i].func (surface);
  1403. status_after = cairo_surface_status (surface);
  1404. cairo_surface_destroy (surface);
  1405. if (test_status != CAIRO_TEST_SUCCESS) {
  1406. cairo_test_log (ctx,
  1407. "Failed test %s with %d\n",
  1408. surface_tests[i].name, (int) test_status);
  1409. return test_status;
  1410. }
  1411. if (status_before != status_after) {
  1412. cairo_test_log (ctx,
  1413. "Failed test %s: Modified surface status from %u (%s) to %u (%s)\n",
  1414. surface_tests[i].name,
  1415. status_before, cairo_status_to_string (status_before),
  1416. status_after, cairo_status_to_string (status_after));
  1417. return CAIRO_TEST_ERROR;
  1418. }
  1419. }
  1420. /* Test an error context */
  1421. for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
  1422. cr = cairo_create (NULL);
  1423. status_before = cairo_status (cr);
  1424. assert (status_before);
  1425. test_status = context_tests[i].func (cr);
  1426. status_after = cairo_status (cr);
  1427. cairo_destroy (cr);
  1428. if (test_status != CAIRO_TEST_SUCCESS) {
  1429. cairo_test_log (ctx,
  1430. "Failed test %s with %d\n",
  1431. context_tests[i].name, (int) test_status);
  1432. return test_status;
  1433. }
  1434. if (status_before != status_after) {
  1435. cairo_test_log (ctx,
  1436. "Failed test %s: Modified context status from %u (%s) to %u (%s)\n",
  1437. context_tests[i].name,
  1438. status_before, cairo_status_to_string (status_before),
  1439. status_after, cairo_status_to_string (status_after));
  1440. return CAIRO_TEST_ERROR;
  1441. }
  1442. }
  1443. /* Test a context for an error surface */
  1444. for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
  1445. surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, INT_MAX, INT_MAX);
  1446. cr = cairo_create (surface);
  1447. cairo_surface_destroy (surface);
  1448. status_before = cairo_status (cr);
  1449. assert (status_before);
  1450. test_status = context_tests[i].func (cr);
  1451. status_after = cairo_status (cr);
  1452. cairo_destroy (cr);
  1453. if (test_status != CAIRO_TEST_SUCCESS) {
  1454. cairo_test_log (ctx,
  1455. "Failed test %s with %d\n",
  1456. context_tests[i].name, (int) test_status);
  1457. return test_status;
  1458. }
  1459. if (status_before != status_after) {
  1460. cairo_test_log (ctx,
  1461. "Failed test %s: Modified context status from %u (%s) to %u (%s)\n",
  1462. context_tests[i].name,
  1463. status_before, cairo_status_to_string (status_before),
  1464. status_after, cairo_status_to_string (status_after));
  1465. return CAIRO_TEST_ERROR;
  1466. }
  1467. }
  1468. return CAIRO_TEST_SUCCESS;
  1469. }
  1470. static cairo_test_status_t
  1471. test_context (const cairo_test_context_t *ctx, cairo_t *cr, const char *name, unsigned int i)
  1472. {
  1473. cairo_test_status_t test_status;
  1474. cairo_status_t status_before, status_after;
  1475. /* Make sure that there is a current point */
  1476. cairo_move_to (cr, 0, 0);
  1477. status_before = cairo_status (cr);
  1478. test_status = context_tests[i].func (cr);
  1479. status_after = cairo_status (cr);
  1480. if (test_status != CAIRO_TEST_SUCCESS) {
  1481. cairo_test_log (ctx,
  1482. "Failed test %s on %s with %d\n",
  1483. context_tests[i].name, name, (int) test_status);
  1484. return test_status;
  1485. }
  1486. if (status_after != CAIRO_STATUS_SURFACE_FINISHED && status_before != status_after) {
  1487. cairo_test_log (ctx,
  1488. "Failed test %s on %s: Modified context status from %u (%s) to %u (%s)\n",
  1489. context_tests[i].name, name,
  1490. status_before, cairo_status_to_string (status_before),
  1491. status_after, cairo_status_to_string (status_after));
  1492. return CAIRO_TEST_ERROR;
  1493. }
  1494. return CAIRO_TEST_SUCCESS;
  1495. }
  1496. static cairo_test_status_t
  1497. draw (cairo_t *cr, int width, int height)
  1498. {
  1499. const cairo_test_context_t *ctx = cairo_test_get_context (cr);
  1500. cairo_surface_t *similar, *target;
  1501. cairo_test_status_t test_status;
  1502. cairo_status_t status;
  1503. cairo_t *cr2;
  1504. unsigned int i;
  1505. target = cairo_get_target (cr);
  1506. /* Test a finished similar surface */
  1507. for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
  1508. similar = cairo_surface_create_similar (target,
  1509. cairo_surface_get_content (target),
  1510. 10, 10);
  1511. cairo_surface_finish (similar);
  1512. test_status = surface_tests[i].func (similar);
  1513. status = cairo_surface_status (similar);
  1514. cairo_surface_destroy (similar);
  1515. if (test_status != CAIRO_TEST_SUCCESS) {
  1516. cairo_test_log (ctx,
  1517. "Failed test %s with %d\n",
  1518. surface_tests[i].name, (int) test_status);
  1519. return test_status;
  1520. }
  1521. if (surface_tests[i].modifies_surface &&
  1522. strcmp (surface_tests[i].name, "cairo_surface_finish") &&
  1523. strcmp (surface_tests[i].name, "cairo_surface_flush") &&
  1524. status != CAIRO_STATUS_SURFACE_FINISHED) {
  1525. cairo_test_log (ctx,
  1526. "Failed test %s: Finished surface not set into error state\n",
  1527. surface_tests[i].name);
  1528. return CAIRO_TEST_ERROR;
  1529. }
  1530. }
  1531. /* Test a context for a finished similar surface */
  1532. for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
  1533. similar = cairo_surface_create_similar (target,
  1534. cairo_surface_get_content (target),
  1535. 10, 10);
  1536. cairo_surface_finish (similar);
  1537. cr2 = cairo_create (similar);
  1538. test_status = test_context (ctx, cr2, "finished surface", i);
  1539. cairo_surface_destroy (similar);
  1540. cairo_destroy (cr2);
  1541. if (test_status != CAIRO_TEST_SUCCESS)
  1542. return test_status;
  1543. }
  1544. /* Test a context for a similar surface finished later */
  1545. for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
  1546. similar = cairo_surface_create_similar (target,
  1547. cairo_surface_get_content (target),
  1548. 10, 10);
  1549. cr2 = cairo_create (similar);
  1550. cairo_surface_finish (similar);
  1551. test_status = test_context (ctx, cr2, "finished surface after create", i);
  1552. cairo_surface_destroy (similar);
  1553. cairo_destroy (cr2);
  1554. if (test_status != CAIRO_TEST_SUCCESS)
  1555. return test_status;
  1556. }
  1557. /* Test a context for a similar surface finished later with a path */
  1558. for (i = 0; i < ARRAY_LENGTH (context_tests); i++) {
  1559. similar = cairo_surface_create_similar (target,
  1560. cairo_surface_get_content (target),
  1561. 10, 10);
  1562. cr2 = cairo_create (similar);
  1563. cairo_rectangle (cr2, 2, 2, 4, 4);
  1564. cairo_surface_finish (similar);
  1565. test_status = test_context (ctx, cr2, "finished surface with path", i);
  1566. cairo_surface_destroy (similar);
  1567. cairo_destroy (cr2);
  1568. if (test_status != CAIRO_TEST_SUCCESS)
  1569. return test_status;
  1570. }
  1571. /* Test a normal surface for functions that have the wrong type */
  1572. for (i = 0; i < ARRAY_LENGTH (surface_tests); i++) {
  1573. cairo_status_t desired_status;
  1574. if (surface_tests[i].surface_type == -1)
  1575. continue;
  1576. similar = cairo_surface_create_similar (target,
  1577. cairo_surface_get_content (target),
  1578. 10, 10);
  1579. if (cairo_surface_get_type (similar) == (cairo_surface_type_t) surface_tests[i].surface_type) {
  1580. cairo_surface_destroy (similar);
  1581. continue;
  1582. }
  1583. test_status = surface_tests[i].func (similar);
  1584. status = cairo_surface_status (similar);
  1585. cairo_surface_destroy (similar);
  1586. if (test_status != CAIRO_TEST_SUCCESS) {
  1587. cairo_test_log (ctx,
  1588. "Failed test %s with %d\n",
  1589. surface_tests[i].name, (int) test_status);
  1590. return test_status;
  1591. }
  1592. desired_status = surface_tests[i].modifies_surface ? CAIRO_STATUS_SURFACE_TYPE_MISMATCH : CAIRO_STATUS_SUCCESS;
  1593. if (status != desired_status) {
  1594. cairo_test_log (ctx,
  1595. "Failed test %s: Surface status should be %u (%s), but is %u (%s)\n",
  1596. surface_tests[i].name,
  1597. desired_status, cairo_status_to_string (desired_status),
  1598. status, cairo_status_to_string (status));
  1599. return CAIRO_TEST_ERROR;
  1600. }
  1601. }
  1602. /* 565-compatible gray background */
  1603. cairo_set_source_rgb (cr, 0.51613, 0.55555, 0.51613);
  1604. cairo_paint (cr);
  1605. return CAIRO_TEST_SUCCESS;
  1606. }
  1607. CAIRO_TEST (api_special_cases,
  1608. "Check surface functions properly handle wrong surface arguments",
  1609. "api", /* keywords */
  1610. NULL, /* requirements */
  1611. 10, 10,
  1612. preamble, draw)