tcase.pp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondcase() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondcalln() }
  9. {****************************************************************}
  10. { DEFINES: }
  11. {****************************************************************}
  12. { REMARKS: Tests the case statement (except jump table gen.) }
  13. {****************************************************************}
  14. program tcase;
  15. {$ifdef FPC}
  16. {$IFNDEF ver1_0}
  17. {$define int64_Test}
  18. {$endif}
  19. {$else}
  20. {$define int64_Test}
  21. {$endif}
  22. {
  23. The value is in LOC_REGISTER (operand to test)
  24. }
  25. procedure fail;
  26. begin
  27. WriteLn('Failed!');
  28. halt(1);
  29. end;
  30. {************************************************************************}
  31. { LINEAR LIST }
  32. {************************************************************************}
  33. { low = high }
  34. procedure TestCmpListOneShort;
  35. var
  36. s: smallint;
  37. failed :boolean;
  38. begin
  39. Write('Linear Comparison list without ranges (smallint)...');
  40. s := -12;
  41. failed := true;
  42. case s of
  43. -12 : failed := false;
  44. -10 : ;
  45. 3 : ;
  46. else
  47. end;
  48. if failed then
  49. fail
  50. else
  51. WriteLn('Passed!');
  52. end;
  53. { low = high }
  54. procedure TestCmpListTwoShort;
  55. var
  56. s: smallint;
  57. failed :boolean;
  58. begin
  59. Write('Linear Comparison list without ranges (smallint)...');
  60. s := 30000;
  61. failed := true;
  62. case s of
  63. -12 : ;
  64. -10 : ;
  65. 3 : ;
  66. else
  67. failed := false;
  68. end;
  69. if failed then
  70. fail
  71. else
  72. WriteLn('Passed!');
  73. end;
  74. { low = high }
  75. procedure TestCmpListOneWord;
  76. var
  77. s: word;
  78. failed :boolean;
  79. begin
  80. Write('Linear Comparison list without ranges (word)...');
  81. s := 12;
  82. failed := true;
  83. case s of
  84. 12 : failed := false;
  85. 10 : ;
  86. 3 : ;
  87. end;
  88. if failed then
  89. fail
  90. else
  91. WriteLn('Passed!');
  92. end;
  93. { low = high }
  94. procedure TestCmpListTwoWord;
  95. var
  96. s: word;
  97. failed :boolean;
  98. begin
  99. Write('Linear Comparison list without ranges (word)...');
  100. s := 30000;
  101. failed := true;
  102. case s of
  103. 0 : ;
  104. 512 : ;
  105. 3 : ;
  106. else
  107. failed := false;
  108. end;
  109. if failed then
  110. fail
  111. else
  112. WriteLn('Passed!');
  113. end;
  114. {$IFDEF INT64_TEST}
  115. { low = high }
  116. procedure TestCmpListOneInt64;
  117. var
  118. s: int64;
  119. failed :boolean;
  120. begin
  121. Write('Linear Comparison list without ranges (int64)...');
  122. s := 3000000;
  123. failed := true;
  124. case s of
  125. 3000000 : failed := false;
  126. 10 : ;
  127. 3 : ;
  128. end;
  129. if failed then
  130. fail
  131. else
  132. WriteLn('Passed!');
  133. end;
  134. { low = high }
  135. procedure TestCmpListTwoInt64;
  136. var
  137. s: int64;
  138. failed :boolean;
  139. begin
  140. Write('Linear Comparison list without ranges (int64)...');
  141. s := 30000;
  142. failed := true;
  143. case s of
  144. 0 : ;
  145. 512 : ;
  146. 3 : ;
  147. else
  148. failed := false;
  149. end;
  150. if failed then
  151. fail
  152. else
  153. WriteLn('Passed!');
  154. end;
  155. { low = high }
  156. procedure TestCmpListThreeInt64;
  157. var
  158. s: int64;
  159. l : longint;
  160. failed :boolean;
  161. begin
  162. Write('Linear Comparison list without ranges (int64)...');
  163. l:=3000000;
  164. s := (int64(l) shl 32);
  165. failed := true;
  166. case s of
  167. (int64(3000000) shl 32) : failed := false;
  168. 10 : ;
  169. 3 : ;
  170. end;
  171. if failed then
  172. fail
  173. else
  174. WriteLn('Passed!');
  175. end;
  176. {$ENDIF}
  177. procedure TestCmpListRangesOneShort;
  178. var
  179. s: smallint;
  180. failed :boolean;
  181. begin
  182. Write('Linear Comparison list with ranges (smallint)...');
  183. s := -12;
  184. failed := true;
  185. case s of
  186. -12..-8 : failed := false;
  187. -7 : ;
  188. 3 : ;
  189. else
  190. end;
  191. if failed then
  192. fail
  193. else
  194. WriteLn('Passed!');
  195. end;
  196. procedure TestCmpListRangesTwoShort;
  197. var
  198. s: smallint;
  199. failed :boolean;
  200. begin
  201. Write('Linear Comparison list with ranges (smallint)...');
  202. s := 30000;
  203. failed := true;
  204. case s of
  205. -12..-8 : ;
  206. -7 : ;
  207. 3 : ;
  208. else
  209. failed := false;
  210. end;
  211. if failed then
  212. fail
  213. else
  214. WriteLn('Passed!');
  215. end;
  216. { low = high }
  217. procedure TestCmpListRangesOneWord;
  218. var
  219. s: word;
  220. failed :boolean;
  221. begin
  222. Write('Linear Comparison list with ranges (word)...');
  223. s := 12;
  224. failed := true;
  225. case s of
  226. 12..13 : failed := false;
  227. 10 : ;
  228. 3..7 : ;
  229. end;
  230. if failed then
  231. fail
  232. else
  233. WriteLn('Passed!');
  234. end;
  235. { low = high }
  236. procedure TestCmpListRangesTwoWord;
  237. var
  238. s: word;
  239. failed :boolean;
  240. begin
  241. Write('Linear Comparison list with ranges (word)...');
  242. s := 30000;
  243. failed := true;
  244. case s of
  245. 0..2 : ;
  246. 3..29999 : ;
  247. else
  248. failed := false;
  249. end;
  250. if failed then
  251. fail
  252. else
  253. WriteLn('Passed!');
  254. end;
  255. procedure TestCmpListRangesThreeWord;
  256. var
  257. s: word;
  258. failed :boolean;
  259. begin
  260. Write('Linear Comparison list with ranges (word)...');
  261. s := 3;
  262. failed := true;
  263. case s of
  264. 12..13 : ;
  265. 10 : ;
  266. 3..7 : failed := false;
  267. end;
  268. if failed then
  269. fail
  270. else
  271. WriteLn('Passed!');
  272. end;
  273. {$IFDEF INT64_TEST}
  274. { low = high }
  275. procedure TestCmpListRangesOneInt64;
  276. var
  277. s: int64;
  278. failed :boolean;
  279. begin
  280. Write('Linear Comparison list with ranges (int64)...');
  281. s := 3000000;
  282. failed := true;
  283. case s of
  284. 11..3000000 : failed := false;
  285. 10 : ;
  286. 0..2 : ;
  287. end;
  288. if failed then
  289. fail
  290. else
  291. WriteLn('Passed!');
  292. end;
  293. { low = high }
  294. procedure TestCmpListRangesTwoInt64;
  295. var
  296. s: int64;
  297. failed :boolean;
  298. begin
  299. Write('Linear Comparison list with ranges (int64)...');
  300. s := 30000;
  301. failed := true;
  302. case s of
  303. 513..10000 : ;
  304. 512 : ;
  305. 0..3 : ;
  306. else
  307. failed := false;
  308. end;
  309. if failed then
  310. fail
  311. else
  312. WriteLn('Passed!');
  313. end;
  314. {$ENDIF}
  315. Begin
  316. TestCmpListOneShort;
  317. TestCmpListTwoShort;
  318. TestCmpListOneWord;
  319. TestCmpListTwoWord;
  320. TestCmpListRangesOneShort;
  321. TestCmpListRangesTwoShort;
  322. TestCmpListRangesOneWord;
  323. TestCmpListRangesTwoWord;
  324. TestCmpListRangesThreeWord;
  325. {$ifdef int64_test}
  326. TestCmpListOneInt64;
  327. TestCmpListTwoInt64;
  328. TestCmpListThreeInt64;
  329. TestCmpListRangesOneInt64;
  330. TestCmpListRangesTwoInt64;
  331. {$endif}
  332. end.