tcnvint4.pp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 := RESULT_U32BIT;
  96. result_val := u32bit;
  97. if trunc(result_val) <> RESULT_U32BIT then
  98. failed:=true;
  99. s16bit := RESULT_S16BIT;
  100. result_val := s16bit;
  101. if trunc(result_val) <> RESULT_S16BIT then
  102. failed:=true;
  103. u16bit := RESULT_U16BIT;
  104. result_val := u16bit;
  105. if trunc(result_val) <> RESULT_U16BIT then
  106. failed:=true;
  107. s8bit := RESULT_S8BIT;
  108. result_val := s8bit;
  109. if trunc(result_val) <> RESULT_S8BIT then
  110. failed:=true;
  111. u8bit := RESULT_U8BIT;
  112. result_val := u8bit;
  113. if trunc(result_val) <> RESULT_U8BIT then
  114. failed:=true;
  115. if failed then
  116. fail
  117. else
  118. WriteLn('Passed!');
  119. Write('second_int_to_real (left : LOC_REGISTER)...');
  120. failed := false;
  121. result_val := gets64bit;
  122. if trunc(result_val) <> RESULT_S64BIT then
  123. failed:=true;
  124. result_val := gets32bit;
  125. if trunc(result_val) <> RESULT_S32BIT then
  126. failed:=true;
  127. result_val := getu32bit;
  128. if trunc(result_val) <> RESULT_U32BIT then
  129. failed:=true;
  130. result_val := getu8bit;
  131. if trunc(result_val) <> RESULT_u8BIT then
  132. failed:=true;
  133. result_val := gets8bit;
  134. if trunc(result_val) <> RESULT_s8BIT then
  135. failed:=true;
  136. result_val := gets16bit;
  137. if trunc(result_val) <> RESULT_S16BIT then
  138. failed:=true;
  139. result_val := getu16bit;
  140. if trunc(result_val) <> RESULT_U16BIT then
  141. failed:=true;
  142. if failed then
  143. fail
  144. else
  145. WriteLn('Passed!');
  146. end.