tcnvint4.pp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondtypeconvert() -> second_int_to_real }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondcalln() }
  9. { secondinline() }
  10. { secondadd() }
  11. {****************************************************************}
  12. { DEFINES: }
  13. {****************************************************************}
  14. { REMARKS: Tests integer to real conversion }
  15. { This routine assumes that there is a type conversion }
  16. { from all types to s32bit, u32bit or s64bit before conversion }
  17. { to a real. }
  18. {****************************************************************}
  19. program tcnvint4;
  20. {$ifdef VER70}
  21. {$define tp}
  22. {$endif}
  23. {$R-}
  24. {$ifdef tp}
  25. type
  26. smallint = integer;
  27. {$endif}
  28. procedure fail;
  29. begin
  30. WriteLn('Failure.');
  31. halt(1);
  32. end;
  33. const
  34. RESULT_S64BIT = 101234;
  35. RESULT_S32BIT = -1000000;
  36. RESULT_U32BIT = 2000000;
  37. RESULT_S16BIT = -12123;
  38. RESULT_U16BIT = 12123;
  39. RESULT_U8BIT = 247;
  40. RESULT_S8BIT = -123;
  41. {$ifndef tp}
  42. function gets64bit : int64;
  43. begin
  44. gets64bit := RESULT_S64BIT;
  45. end;
  46. {$endif}
  47. function gets32bit : longint;
  48. begin
  49. gets32bit := RESULT_S32BIT;
  50. end;
  51. function gets16bit : smallint;
  52. begin
  53. gets16bit := RESULT_S16BIT;
  54. end;
  55. function gets8bit : shortint;
  56. begin
  57. gets8bit := RESULT_S8BIT;
  58. end;
  59. function getu8bit : byte;
  60. begin
  61. getu8bit := RESULT_U8BIT;
  62. end;
  63. function getu16bit : word;
  64. begin
  65. getu16bit := RESULT_U16BIT;
  66. end;
  67. function getu32bit : longint;
  68. begin
  69. getu32bit := RESULT_U32BIT;
  70. end;
  71. var
  72. s32bit : longint;
  73. failed : boolean;
  74. s16bit : smallint;
  75. s8bit : shortint;
  76. u8bit : byte;
  77. u16bit : word;
  78. {$ifndef tp}
  79. s64bit : int64;
  80. u32bit : cardinal;
  81. {$endif}
  82. result_val : real;
  83. begin
  84. { left : LOC_REFERENCE }
  85. Write('second_int_to_real (left : LOC_REFERENCE)...');
  86. s64bit := RESULT_S64BIT;
  87. failed := false;
  88. result_val := s64bit;
  89. if trunc(result_val) <> RESULT_S64BIT then
  90. failed:=true;
  91. s32bit := RESULT_S32BIT;
  92. result_val := s32bit;
  93. if trunc(result_val) <> RESULT_S32BIT then
  94. failed:=true;
  95. u32bit := high(u32bit);
  96. result_val := u32bit;
  97. if trunc(result_val) <> high(u32bit) then
  98. failed:=true;
  99. u32bit := RESULT_U32BIT;
  100. result_val := u32bit;
  101. if trunc(result_val) <> RESULT_U32BIT then
  102. failed:=true;
  103. s16bit := RESULT_S16BIT;
  104. result_val := s16bit;
  105. if trunc(result_val) <> RESULT_S16BIT then
  106. failed:=true;
  107. u16bit := RESULT_U16BIT;
  108. result_val := u16bit;
  109. if trunc(result_val) <> RESULT_U16BIT then
  110. failed:=true;
  111. s8bit := RESULT_S8BIT;
  112. result_val := s8bit;
  113. if trunc(result_val) <> RESULT_S8BIT then
  114. failed:=true;
  115. u8bit := RESULT_U8BIT;
  116. result_val := u8bit;
  117. if trunc(result_val) <> RESULT_U8BIT then
  118. failed:=true;
  119. if failed then
  120. fail
  121. else
  122. WriteLn('Passed!');
  123. Write('second_int_to_real (left : LOC_REGISTER)...');
  124. failed := false;
  125. result_val := gets64bit;
  126. if trunc(result_val) <> RESULT_S64BIT then
  127. failed:=true;
  128. result_val := gets32bit;
  129. if trunc(result_val) <> RESULT_S32BIT then
  130. failed:=true;
  131. result_val := getu32bit;
  132. if trunc(result_val) <> RESULT_U32BIT then
  133. failed:=true;
  134. result_val := getu8bit;
  135. if trunc(result_val) <> RESULT_u8BIT then
  136. failed:=true;
  137. result_val := gets8bit;
  138. if trunc(result_val) <> RESULT_s8BIT then
  139. failed:=true;
  140. result_val := gets16bit;
  141. if trunc(result_val) <> RESULT_S16BIT then
  142. failed:=true;
  143. result_val := getu16bit;
  144. if trunc(result_val) <> RESULT_U16BIT then
  145. failed:=true;
  146. if failed then
  147. fail
  148. else
  149. WriteLn('Passed!');
  150. end.