PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/xts5/Xlib7/XcmsAllocNamedColor.m

#
Objective C | 462 lines | 325 code | 68 blank | 69 comment | 44 complexity | ded802927422cf0fe5b530154ff4f49b MD5 | raw file
  1. Copyright (c) 2005 X.Org Foundation LLC
  2. Permission is hereby granted, free of charge, to any person obtaining a copy of
  3. this software and associated documentation files (the "Software"), to deal in
  4. the Software without restriction, including without limitation the rights to
  5. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  6. of the Software, and to permit persons to whom the Software is furnished to do
  7. so, subject to the following conditions:
  8. The above copyright notice and this permission notice shall be included in all
  9. copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. SOFTWARE.
  17. Copyright (c) Applied Testing and Technology, Inc. 1993, 1994, 1995
  18. Copyright (c) 88open Consortium, Ltd. 1990, 1991, 1992, 1993
  19. All Rights Reserved.
  20. >>#
  21. >># Project: VSW5
  22. >>#
  23. >># File: xts/Xlib7/XcmsAllocNamedColor.m
  24. >>#
  25. >># Description:
  26. >># Tests for XcmsAllocNamedColor()
  27. >>#
  28. >># Modifications:
  29. >># $Log: cmsanc.m,v $
  30. >># Revision 1.1 2005-02-12 14:37:35 anderson
  31. >># Initial revision
  32. >>#
  33. >># Revision 8.0 1998/12/23 23:27:03 mar
  34. >># Branch point for Release 5.0.2
  35. >>#
  36. >># Revision 7.0 1998/10/30 22:45:22 mar
  37. >># Branch point for Release 5.0.2b1
  38. >>#
  39. >># Revision 6.0 1998/03/02 05:19:16 tbr
  40. >># Branch point for Release 5.0.1
  41. >>#
  42. >># Revision 5.0 1998/01/26 03:15:47 tbr
  43. >># Branch point for Release 5.0.1b1
  44. >>#
  45. >># Revision 4.0 1995/12/15 08:49:38 tbr
  46. >># Branch point for Release 5.0.0
  47. >>#
  48. >># Revision 3.1 1995/12/15 00:49:11 andy
  49. >># Prepare for GA Release
  50. >>#
  51. >>AVSCODE
  52. >>TITLE XcmsAllocNamedColor Xlib7
  53. XcmsAllocNamedColor()
  54. >>EXTERN
  55. /******
  56. * User defined globals for test
  57. ******/
  58. Bool writeable_colormaps = 1;
  59. /******
  60. * User defined globals for test case sets
  61. ******/
  62. Display *display_good;
  63. Visual *visual_good ;
  64. XcmsCCC ccc_good ;
  65. Colormap colormap_good, colormap_return ;
  66. Colormap rw_colormap ;
  67. XcmsColor color_good ;
  68. XcmsColor color_array[2] ;
  69. XcmsColor write_many_color[2] ;
  70. XcmsColor query_many_color[2] ;
  71. XcmsColor scrnColor, exactColor ;
  72. XcmsColor color_in_out ;
  73. XcmsColorFormat format_good ;
  74. double minv, maxv, deltav ;
  75. double hue, chroma ;
  76. int screen_good ;
  77. int depth_good ;
  78. /******
  79. * generated globals
  80. ******/
  81. char *exec_file_name;
  82. int x_init,
  83. y_init,
  84. h_init,
  85. w_init;
  86. /******
  87. * routines
  88. ******/
  89. /*****
  90. * svccmsAllocNamedColor routine
  91. *****/
  92. svccmsAllocNamedColor(display, colormap, color_string, scrn, exact, format)
  93. Display *display ;
  94. Colormap colormap ;
  95. char *color_string ;
  96. XcmsColor scrn ;
  97. XcmsColor exact ;
  98. XcmsColorFormat format ;
  99. {
  100. /*****
  101. * external defs
  102. *****/
  103. extern int errcnt;
  104. extern int errflg;
  105. extern int chkflg;
  106. extern int signal_status();
  107. extern int unexp_err();
  108. /******
  109. * local storage
  110. ******/
  111. char fmtstr[256], *call_string;
  112. union msglst fmt_lst[1];
  113. int
  114. ss_status, /* save stat return status */
  115. stat_status, /* check stat return status */
  116. cleanup_status;
  117. Status svc_ret_value;
  118. #ifdef DEBUG
  119. step("Inside the service routine");
  120. #endif
  121. /******
  122. * Turn on buffering and buffer parameter information
  123. * in case an error occurs
  124. ******/
  125. regr_args.l_flags.bufrout = 1;
  126. (void)strcpy(fmtstr, "*********************\n");
  127. message(fmtstr, fmt_lst, 0);
  128. (void)strcpy(fmtstr, "An error occurred during a call to %s\n\n");
  129. fmt_lst[0].typ_str = TestName;
  130. message(fmtstr, fmt_lst, 1);
  131. call_string = "svc_ret_value = XcmsAllocNamedColor(";
  132. (void)strcpy(fmtstr, "The routine call looked like this - \n %s\n");
  133. fmt_lst[0].typ_str = call_string;
  134. message(fmtstr, fmt_lst, 1);
  135. call_string = " display, colormap, color_string, scrn. exact, format);\n\n";
  136. message(call_string, fmt_lst, 0);
  137. (void)strcpy(fmtstr, "The parameter values were as follows... \n");
  138. message(fmtstr, fmt_lst, 0);
  139. bufrdisp(display); /* buffer display struct info for error checking */
  140. /******
  141. * Setup code for this service - this should always be executed.
  142. ******/
  143. XSync(display_arg, 0);
  144. /******
  145. * save environment
  146. ******/
  147. if (regr_args.l_flags.chksta == 1)
  148. ss_status = save_stat(dpy_msk | win_msk ,
  149. gc_id,
  150. display_arg,
  151. drawable_id);
  152. first_error = 0; /* no errors encountered yet */
  153. /******
  154. * service call
  155. ******/
  156. svc_ret_value = 0 ;
  157. errflg = 0;
  158. XSetErrorHandler(signal_status);
  159. svc_ret_value = XcmsAllocNamedColor(
  160. display,
  161. colormap,
  162. color_string,
  163. &scrn,
  164. &exact,
  165. format
  166. );
  167. XSync(display_arg, 0);
  168. XSetErrorHandler(unexp_err);
  169. r_wait(display_arg, window_arg, time_delay, None); /* no colormap by default */
  170. /******
  171. * check saved environment with current environment.
  172. ******/
  173. if (regr_args.l_flags.chksta == 1)
  174. stat_status = chek_stat (dpy_msk | win_msk ,
  175. gc_id,
  176. display_arg,
  177. drawable_id,
  178. ss_status);
  179. else
  180. stat_status = REGR_NORMAL;
  181. /******
  182. * check Success returns with expected returns
  183. ******/
  184. if ((!errflg) && (!chkflg))
  185. if ((badstat(display_arg, estatus, Success)) != REGR_NORMAL)
  186. errflg = 1;
  187. /******
  188. * verify the results of the service if successful completion.
  189. ******/
  190. if ((regr_args.l_flags.check) &&
  191. (errflg == 0) &&
  192. (stat_status == REGR_NORMAL))
  193. {
  194. /* All the display may not return the exact value */
  195. /* look for within delta value */
  196. double closer_to_one = 0.900000 ;
  197. check_dec(XcmsSuccess, svc_ret_value, "return value") ;
  198. if ( scrn.spec.RGBi.red < closer_to_one ) {
  199. errflg = 1 ;
  200. message("Expected screen red color closer to 1.00\n", NULL, 0) ;
  201. }
  202. if ( exact.spec.RGBi.red <= closer_to_one ) {
  203. errflg = 1 ;
  204. message("Expected exact red color closer to 1.00\n", NULL, 0) ;
  205. }
  206. }
  207. XSync(display_arg, 0);
  208. /******
  209. * cleanup code for this service.
  210. ******/
  211. if (regr_args.l_flags.cleanup)
  212. {
  213. cleanup_status = REGR_NORMAL;
  214. }
  215. XSync(display_arg, 0);
  216. if (errflg) { /* if there was an error ... */
  217. errcnt++; /* ...increment the error count */
  218. (void)strcpy(fmtstr, "\nEnd of error report\n");
  219. message(fmtstr, fmt_lst, 0);
  220. (void)strcpy(fmtstr, "*********************\n");
  221. message(fmtstr, fmt_lst, 0);
  222. }
  223. /*****
  224. * clear all flags
  225. *****/
  226. chkflg = 0;
  227. regr_args.l_flags.bufrout = 0;
  228. dumpbuf();
  229. } /* end of svccmsAllocNamedColor service routine */
  230. >>ASSERTION Good C
  231. If the implementation is X11R5 or later:
  232. A call to xname
  233. shall allocate a named device-independent color. A color string
  234. shall be in the client-side color database or device independent color
  235. specification in one of the following formats
  236. .P
  237. RGB:red/green/blue
  238. .br
  239. RGBi:R/G/B
  240. .br
  241. CIEXYZ:X/Y/Z
  242. .br
  243. CIEuvY:u/v/Y
  244. .br
  245. CIExyY:x/y/Y
  246. .br
  247. CIELab:L/a/b
  248. .br
  249. CIELuv:L/u/v
  250. .br
  251. TekHVC:H/V/C
  252. .P
  253. The RGB color space,
  254. .I red,
  255. .I green
  256. and
  257. .I blue
  258. parameters shall be hexadecimal strings of one to four digits, and other
  259. color spaces, each parameter shall be a floating-point number in standard
  260. string format.
  261. >>CODE
  262. #if XT_X_RELEASE > 4
  263. display_arg = Dsp;
  264. /*
  265. * Create a GC to save environmental data in
  266. */
  267. gc_save = XCreateGC(display_arg, XRootWindow(display_arg,XDefaultScreen(display_arg)),(unsigned long)0,(XGCValues *)0);
  268. regr_args.l_flags.check = 0;
  269. regr_args.l_flags.nostat = 0;
  270. regr_args.l_flags.perf = 0;
  271. regr_args.l_flags.setup = 0;
  272. regr_args.l_flags.cleanup = 0;
  273. regr_args.l_flags.chksta = 0;
  274. regr_args.l_flags.chkdpy = 0;
  275. regr_args.l_flags.verbose = 0;
  276. regr_args.iter = 1; /* execute service once */
  277. estatus[0] = 1;
  278. /******
  279. * User defined initialization code for test case sets
  280. ******/
  281. display_good = display_arg;
  282. /*****
  283. * Test wide set up
  284. *****/
  285. screen_good = XDefaultScreen(display_good);
  286. depth_good = DisplayPlanes( display_good, screen_good );
  287. visual_good = XDefaultVisual(display_good, screen_good );
  288. colormap_good = XDefaultColormap(display_good, screen_good );
  289. if ((visual_good->class == StaticGray) ||
  290. (visual_good->class == StaticColor) ||
  291. (visual_good->class == TrueColor))
  292. writeable_colormaps = 0 ;
  293. if ( writeable_colormaps ) {
  294. colormap_good = XDefaultColormap(display_good, screen_good );
  295. ccc_good = XcmsCCCOfColormap(display_good, colormap_good) ;
  296. }
  297. if (writeable_colormaps)
  298. {
  299. step("service specific testcase set.\n");
  300. estatus[0] = 1;
  301. estatus[1] = Success;
  302. if ((regr_args.l_flags.good == 0) || (estatus[1] == Success))
  303. {
  304. tet_infoline("TEST: Testing XcmsAllocNamedColor for Success\n");
  305. regr_args.l_flags.check = 1;
  306. regr_args.l_flags.setup = 1;
  307. regr_args.l_flags.cleanup = 1;
  308. regr_args.l_flags.chksta = 0;
  309. regr_args.l_flags.chkdpy = 0;
  310. {
  311. svccmsAllocNamedColor( display_good, colormap_good, "red",
  312. scrnColor, exactColor, XcmsRGBiFormat);
  313. }
  314. }
  315. }
  316. else
  317. message("Warning: not a writeable colormap\n", NULL, 0) ;
  318. tet_result(TET_PASS);
  319. #else
  320. tet_infoline("INFO: Implementation not X11R5 or greater");
  321. tet_result(TET_UNSUPPORTED);
  322. #endif
  323. >>ASSERTION Good C
  324. If the implementation is X11R5 or later:
  325. If the value for the colormap argument does not name a defined colormap a
  326. call to xname shall return the BadColor error code.
  327. >>CODE
  328. #if XT_X_RELEASE > 4
  329. display_arg = Dsp;
  330. /*
  331. * Create a GC to save environmental data in
  332. */
  333. gc_save = XCreateGC(display_arg,XRootWindow(display_arg,XDefaultScreen(display_arg)),(unsigned long)0,(XGCValues *)0);
  334. regr_args.l_flags.check = 0;
  335. regr_args.l_flags.nostat = 0;
  336. regr_args.l_flags.perf = 0;
  337. regr_args.l_flags.setup = 0;
  338. regr_args.l_flags.cleanup = 0;
  339. regr_args.l_flags.chksta = 0;
  340. regr_args.l_flags.chkdpy = 0;
  341. regr_args.l_flags.verbose = 0;
  342. regr_args.iter = 1; /* execute service once */
  343. estatus[0] = 1;
  344. /******
  345. * User defined initialization code for test case sets
  346. ******/
  347. display_good = display_arg;
  348. /*****
  349. * Test wide set up
  350. *****/
  351. screen_good = XDefaultScreen(display_good);
  352. depth_good = DisplayPlanes( display_good, screen_good );
  353. visual_good = XDefaultVisual(display_good, screen_good );
  354. colormap_good = XDefaultColormap(display_good, screen_good );
  355. if ((visual_good->class == StaticGray) ||
  356. (visual_good->class == StaticColor) ||
  357. (visual_good->class == TrueColor))
  358. writeable_colormaps = 0 ;
  359. if ( writeable_colormaps ) {
  360. colormap_good = XDefaultColormap(display_good, screen_good );
  361. ccc_good = XcmsCCCOfColormap(display_good, colormap_good) ;
  362. }
  363. if (writeable_colormaps)
  364. {
  365. chkflg = 1;
  366. estatus[0] = 1;
  367. estatus[1] = BadColor;
  368. if ((regr_args.l_flags.good == 0) || (estatus[1] == Success))
  369. {
  370. tet_infoline("TEST: Testing XcmsAllocNamedColor for BadColor\n");
  371. regr_args.l_flags.check = 0;
  372. regr_args.l_flags.setup = 1;
  373. regr_args.l_flags.cleanup = 1;
  374. regr_args.l_flags.chksta = 0;
  375. regr_args.l_flags.chkdpy = 0;
  376. {
  377. svccmsAllocNamedColor(
  378. display_good,
  379. -999,
  380. "red",
  381. scrnColor,
  382. exactColor,
  383. XcmsRGBiFormat
  384. );
  385. }
  386. } /* end if */
  387. }
  388. else
  389. message("Warning: not a writeable colormap\n", NULL, 0) ;
  390. tet_result(TET_PASS);
  391. #else
  392. tet_infoline("INFO: Implementation not X11R5 or greater");
  393. tet_result(TET_UNSUPPORTED);
  394. #endif