tcnvint2.pp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondtypeconvert() -> second_int_to_bool }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondcalln() }
  9. { secondinline() }
  10. {****************************************************************}
  11. { DEFINES: }
  12. {****************************************************************}
  13. { REMARKS: This code is specific to FPC, this testsuite FAILS }
  14. { under Turbo Pascal / Borland Pascal. }
  15. {****************************************************************}
  16. program tcnvint2;
  17. {$ifdef VER70}
  18. {$define tp}
  19. {$endif}
  20. var
  21. failed : boolean;
  22. function getbyte: byte;
  23. begin
  24. getbyte := $10;
  25. end;
  26. function getword: word;
  27. begin
  28. getword := $0F00;
  29. end;
  30. function getlongint: longint;
  31. begin
  32. getlongint := $10000000;
  33. end;
  34. {$ifndef tp}
  35. function getint64: int64;
  36. begin
  37. getint64 := $10000000;
  38. end;
  39. function getint64_2 : int64;
  40. var
  41. i: longint;
  42. begin
  43. i:=1;
  44. getint64_2 := int64(i) shl 36;
  45. end;
  46. {$endif}
  47. procedure Test(const s:string;b:boolean);
  48. begin
  49. Writeln(s,b);
  50. if not b then
  51. failed:=true;
  52. end;
  53. var
  54. frombyte : byte;
  55. fromword : word;
  56. fromlong : longint;
  57. {$ifndef tp}
  58. fromint64 : int64;
  59. {$endif}
  60. b : boolean;
  61. bb1 : bytebool;
  62. wb1 : wordbool;
  63. lb1 : longbool;
  64. bb2 : bytebool;
  65. wb2 : wordbool;
  66. lb2 : longbool;
  67. value : longint;
  68. begin
  69. failed:=false;
  70. { left : LOC_REGISTER }
  71. { from : LOC_REFERENCE }
  72. Writeln('Testing LOC_REFERENCE...');
  73. frombyte := $10;
  74. bb1 := bytebool(frombyte);
  75. Test('byte-> bytebool : Value should be TRUE...',bb1);
  76. frombyte := $10;
  77. wb1 := wordbool(frombyte);
  78. Test('byte -> wordbool : Value should be TRUE...',wb1);
  79. { ------------------------------------------------------------ }
  80. { WARNING : This test fails under Borland Pascal v7, but }
  81. { works under Delphi 3.0 (normally it should give TRUE). }
  82. { ------------------------------------------------------------ }
  83. fromword := $1000;
  84. wb1 := wordbool(fromword);
  85. Test('word -> wordbool : Value should be TRUE...',wb1);
  86. frombyte := $10;
  87. lb1 := longbool(frombyte);
  88. Test('byte -> longbool : Value should be TRUE...',lb1);
  89. { ------------------------------------------------------------ }
  90. { WARNING : This test fails under Borland Pascal v7, but }
  91. { works under Delphi 3.0 (normally it should give TRUE). }
  92. { ------------------------------------------------------------ }
  93. fromword := $1000;
  94. lb1 := longbool(fromword);
  95. Test('word -> longbool : Value should be TRUE...',lb1);
  96. if not lb1 then
  97. failed:=true;
  98. { ------------------------------------------------------------ }
  99. { WARNING : This test fails under Borland Pascal v7, but }
  100. { works under Delphi 3.0 (normally it should give TRUE). }
  101. { ------------------------------------------------------------ }
  102. fromlong := $00000100;
  103. lb1 := longbool(fromlong);
  104. Test('longint -> longbool : Value should be TRUE...',lb1);
  105. {$ifndef tp}
  106. fromint64 := $10000000;
  107. lb1 := longbool(fromint64);
  108. Test('int64 -> longbool : Value should be TRUE...',lb1);
  109. { does it indirectly, since it might not work in direct mode }
  110. value:=1;
  111. fromint64 := int64(value) shl int64(36) ;
  112. lb1 := longbool(fromint64);
  113. Test('int64 -> longbool : Value should be TRUE...',lb1);
  114. {$endif}
  115. { left : LOC_REGISTER }
  116. Writeln('Testing LOC_REGISTER...');
  117. frombyte := $10;
  118. bb1 := bytebool(getbyte);
  119. Test('byte-> bytebool : Value should be TRUE...',bb1);
  120. frombyte := $10;
  121. wb1 := wordbool(getbyte);
  122. Test('byte -> wordbool : Value should be TRUE...',wb1);
  123. { ------------------------------------------------------------ }
  124. { WARNING : This test fails under Borland Pascal v7, but }
  125. { works under Delphi 3.0 (normally it should give TRUE). }
  126. { ------------------------------------------------------------ }
  127. fromword := $1000;
  128. wb1 := wordbool(getword);
  129. Test('word -> wordbool : Value should be TRUE...',wb1);
  130. frombyte := $10;
  131. lb1 := longbool(getbyte);
  132. Test('byte -> longbool : Value should be TRUE...',lb1);
  133. { ------------------------------------------------------------ }
  134. { WARNING : This test fails under Borland Pascal v7, but }
  135. { works under Delphi 3.0 (normally it should give TRUE). }
  136. { ------------------------------------------------------------ }
  137. fromword := $1000;
  138. lb1 := longbool(getword);
  139. Test('word -> longbool : Value should be TRUE...',lb1);
  140. { ------------------------------------------------------------ }
  141. { WARNING : This test fails under Borland Pascal v7, but }
  142. { works under Delphi 3.0 (normally it should give TRUE). }
  143. { ------------------------------------------------------------ }
  144. fromlong := $00000100;
  145. lb1 := longbool(getlongint);
  146. Test('longint -> longbool : Value should be TRUE...',lb1);
  147. {$ifndef tp}
  148. fromint64 := $10000000;
  149. lb1 := longbool(getint64);
  150. Test('int64 -> longbool : Value should be TRUE...',lb1);
  151. lb1 := longbool(getint64_2);
  152. Test('int64 -> longbool : Value should be TRUE...',lb1);
  153. {$endif}
  154. (* CURRENTLY NEVER GOES INTO THE LOC_FLAGS LOCATION!
  155. { left : LOC_FLAGS }
  156. Test('Testing LOC_FLAGS...');
  157. frombyte := 10;
  158. fromword := 2;
  159. bb1 := bytebool(frombyte > fromword);
  160. Test('Value should be TRUE...',bb1);
  161. frombyte := $10;
  162. fromword := 2;
  163. wb1 := wordbool(frombyte > fromword);
  164. Test('Value should be TRUE...',wb1);
  165. fromword := $1000;
  166. fromlong := $4000;
  167. wb1 := wordbool(fromlong > fromword);
  168. Test('Value should be TRUE...',wb1);
  169. frombyte := $10;
  170. fromword := $20;
  171. lb1 := longbool(fromword > frombyte);
  172. Test('Value should be TRUE...',lb1);
  173. fromword := $1000;
  174. fromlong := $0100;
  175. lb1 := longbool(fromlong > fromword);
  176. Test('Value should be FALSE...',lb1);
  177. {$ifndef tp}
  178. fromint64 := $10000000;
  179. fromlong := $02;
  180. lb1 := longbool(fromint64 > fromlong);
  181. Test('Value should be TRUE...',lb1);
  182. {$endif}
  183. *)
  184. if failed then
  185. begin
  186. Writeln('Some tests failed!');
  187. halt(1);
  188. end;
  189. end.