tcalext.pp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondcalln() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondcalln() }
  9. { secondadd() }
  10. { secondtypeconv() }
  11. {****************************************************************}
  12. { DEFINES: }
  13. {****************************************************************}
  14. { REMARKS: This tests a subset of the secondcalln() , it }
  15. { verifies the usage of external cdecl }
  16. { modules compiled with C compilers. }
  17. {****************************************************************}
  18. program tcalext;
  19. {$MODE OBJFPC}
  20. {$STATIC ON}
  21. {$R+}
  22. uses strings;
  23. {$L ctest.o}
  24. { Use C alignment of records }
  25. {$PACKRECORDS C}
  26. const
  27. RESULT_U8BIT = $55;
  28. RESULT_U16BIT = $500F;
  29. RESULT_U32BIT = $500F0000;
  30. RESULT_S64BIT = -12000;
  31. RESULT_FLOAT = 14.54;
  32. RESULT_DOUBLE = RESULT_FLOAT;
  33. RESULT_LONGDOUBLE = RESULT_FLOAT;
  34. RESULT_PCHAR = 'Hello world';
  35. type
  36. _3byte_ = record
  37. u8 : byte;
  38. u16 : word;
  39. end;
  40. _7byte_ = record
  41. u8: byte;
  42. s64: int64;
  43. u16: word;
  44. end;
  45. { simple parameter passing }
  46. procedure test_param_u8(x: byte); cdecl; external;
  47. procedure test_param_u16(x : word); cdecl; external;
  48. procedure test_param_u32(x: cardinal); cdecl; external;
  49. procedure test_param_s64(x: int64); cdecl; external;
  50. procedure test_param_float(x : single); cdecl; external;
  51. procedure test_param_double(x: double); cdecl; external;
  52. procedure test_param_longdouble(x: extended); cdecl; external;
  53. procedure test_param_var_u8(var x: byte); cdecl; external;
  54. { mixed parameter passing }
  55. procedure test_param_mixed_u16(z: byte; x : word; y :byte); cdecl; external;
  56. procedure test_param_mixed_u32(z: byte; x: cardinal; y: byte); cdecl; external;
  57. procedure test_param_mixed_s64(z: byte; x: int64; y: byte); cdecl; external;
  58. { structure parameter testing }
  59. procedure test_param_struct_small(buffer : _3BYTE_); cdecl; external;
  60. procedure test_param_struct_large(buffer : _7BYTE_); cdecl; external;
  61. { function result value testing }
  62. function test_function_u8: byte; cdecl; external;
  63. function test_function_u16: word; cdecl; external;
  64. function test_function_u32: cardinal; cdecl; external;
  65. function test_function_s64: int64; cdecl; external;
  66. function test_function_pchar: pchar; cdecl; external;
  67. function test_function_float : single; cdecl; external;
  68. function test_function_double : double; cdecl; external;
  69. function test_function_longdouble: extended; cdecl; external;
  70. function test_function_struct : _7byte_; cdecl; external;
  71. var
  72. global_u8bit : byte; cvar; external;
  73. global_u16bit : word; cvar; external;
  74. global_u32bit : longint; cvar;external;
  75. global_s64bit : int64; cvar; external;
  76. global_float : single; cvar;external;
  77. global_double : double; cvar;external;
  78. global_long_double : extended; cvar; external;
  79. value_u8bit : byte;
  80. value_u16bit : word;
  81. value_u32bit : cardinal;
  82. value_s64bit : int64;
  83. value_float : single;
  84. value_double : double;
  85. value_longdouble : extended;
  86. procedure clear_globals;
  87. begin
  88. global_u8bit := 0;
  89. global_u16bit := 0;
  90. global_u32bit := 0;
  91. global_s64bit := 0;
  92. global_float := 0.0;
  93. global_double := 0.0;
  94. global_long_double := 0.0;
  95. end;
  96. procedure clear_values;
  97. begin
  98. value_u8bit := 0;
  99. value_u16bit := 0;
  100. value_u32bit := 0;
  101. value_s64bit := 0;
  102. value_float := 0.0;
  103. value_double := 0.0;
  104. value_longdouble := 0.0;
  105. end;
  106. procedure fail;
  107. begin
  108. WriteLn('Failed!');
  109. halt(1);
  110. end;
  111. var failed : boolean;
  112. smallstruct : _3BYTE_;
  113. bigstruct : _7BYTE_;
  114. pc: pchar;
  115. begin
  116. Write('External simple parameter testing...');
  117. failed := false;
  118. clear_values;
  119. clear_globals;
  120. value_u8bit := RESULT_U8BIT;
  121. test_param_u8(value_u8bit);
  122. if global_u8bit <> RESULT_U8BIT then
  123. failed := true;
  124. clear_values;
  125. clear_globals;
  126. value_u16bit := RESULT_U16BIT;
  127. test_param_u16(value_u16bit);
  128. if global_u16bit <> RESULT_U16BIT then
  129. failed := true;
  130. clear_values;
  131. clear_globals;
  132. value_u32bit := RESULT_U32BIT;
  133. test_param_u32(value_u32bit);
  134. if global_u32bit <> RESULT_U32BIT then
  135. failed := true;
  136. clear_values;
  137. clear_globals;
  138. value_s64bit := RESULT_S64BIT;
  139. test_param_s64(value_s64bit);
  140. if global_s64bit <> RESULT_S64BIT then
  141. failed := true;
  142. clear_values;
  143. clear_globals;
  144. value_float := RESULT_FLOAT;
  145. test_param_float(value_float);
  146. if trunc(global_float) <> trunc(RESULT_FLOAT) then
  147. failed := true;
  148. clear_values;
  149. clear_globals;
  150. value_double := RESULT_DOUBLE;
  151. test_param_double(value_double);
  152. if trunc(global_double) <> trunc(RESULT_DOUBLE) then
  153. failed := true;
  154. clear_values;
  155. clear_globals;
  156. value_longdouble := RESULT_LONGDOUBLE;
  157. test_param_longdouble(value_longdouble);
  158. if trunc(global_long_double) <> trunc(RESULT_LONGDOUBLE) then
  159. failed := true;
  160. { var parameter testing }
  161. clear_values;
  162. clear_globals;
  163. test_param_var_u8(value_u8bit);
  164. if value_u8bit <> RESULT_U8BIT then
  165. failed := true;
  166. If failed then
  167. fail
  168. else
  169. WriteLn('Passed!');
  170. Write('External mixed parameter testing...');
  171. failed := false;
  172. clear_values;
  173. clear_globals;
  174. value_u8bit := RESULT_U8BIT;
  175. value_u16bit := RESULT_U16BIT;
  176. test_param_mixed_u16(value_u8bit, value_u16bit, value_u8bit);
  177. if global_u16bit <> RESULT_U16BIT then
  178. failed := true;
  179. if global_u8bit <> RESULT_U8BIT then
  180. failed := true;
  181. clear_values;
  182. clear_globals;
  183. value_u8bit := RESULT_U8BIT;
  184. value_u32bit := RESULT_U32BIT;
  185. test_param_mixed_u32(value_u8bit, value_u32bit, value_u8bit);
  186. if global_u32bit <> RESULT_U32BIT then
  187. failed := true;
  188. if global_u8bit <> RESULT_U8BIT then
  189. failed := true;
  190. clear_values;
  191. clear_globals;
  192. value_u8bit := RESULT_U8BIT;
  193. value_s64bit := RESULT_S64BIT;
  194. test_param_mixed_s64(value_u8bit, value_s64bit, value_u8bit);
  195. if global_s64bit <> RESULT_S64BIT then
  196. failed := true;
  197. if global_u8bit <> RESULT_U8BIT then
  198. failed := true;
  199. If failed then
  200. fail
  201. else
  202. WriteLn('Passed!');
  203. Write('External struct parameter testing...');
  204. failed := false;
  205. clear_values;
  206. clear_globals;
  207. smallstruct.u8 := RESULT_U8BIT;
  208. smallstruct.u16 := RESULT_u16BIT;
  209. test_param_struct_small(smallstruct);
  210. if global_u16bit <> RESULT_U16BIT then
  211. failed := true;
  212. if global_u8bit <> RESULT_U8BIT then
  213. failed := true;
  214. clear_values;
  215. clear_globals;
  216. bigstruct.u8 := RESULT_U8BIT;
  217. bigstruct.u16 := RESULT_U16BIT;
  218. bigstruct.s64 := RESULT_S64BIT;
  219. test_param_struct_large(bigstruct);
  220. if global_s64bit <> RESULT_S64BIT then
  221. failed := true;
  222. if global_u16bit <> RESULT_U16BIT then
  223. failed := true;
  224. if global_u8bit <> RESULT_U8BIT then
  225. failed := true;
  226. If failed then
  227. fail
  228. else
  229. WriteLn('Passed!');
  230. Write('Function result testing...');
  231. failed := false;
  232. clear_values;
  233. clear_globals;
  234. value_u8bit := test_function_u8;
  235. if value_u8bit <> RESULT_U8BIT then
  236. failed := true;
  237. clear_values;
  238. clear_globals;
  239. value_u16bit := test_function_u16;
  240. if value_u16bit <> RESULT_U16BIT then
  241. failed := true;
  242. clear_values;
  243. clear_globals;
  244. value_u32bit := test_function_u32;
  245. if value_u32bit <> RESULT_U32BIT then
  246. failed := true;
  247. clear_values;
  248. clear_globals;
  249. value_s64bit := test_function_s64;
  250. if value_s64bit <> RESULT_S64BIT then
  251. failed := true;
  252. clear_values;
  253. clear_globals;
  254. { verify if the contents both strings are equal }
  255. pc := test_function_pchar;
  256. if strcomp(pc, RESULT_PCHAR) <> 0 then
  257. failed := true;
  258. clear_values;
  259. clear_globals;
  260. value_float := test_function_float;
  261. if trunc(value_float) <> trunc(RESULT_FLOAT) then
  262. failed := true;
  263. clear_values;
  264. clear_globals;
  265. value_double := test_function_double;
  266. if trunc(value_double) <> trunc(RESULT_DOUBLE) then
  267. failed := true;
  268. clear_values;
  269. clear_globals;
  270. value_longdouble := test_function_longdouble;
  271. if trunc(value_longdouble) <> trunc(RESULT_LONGDOUBLE) then
  272. failed := true;
  273. clear_values;
  274. clear_globals;
  275. bigstruct := test_function_struct;
  276. if bigstruct.u8 <> RESULT_U8BIT then
  277. failed := true;
  278. if bigstruct.s64 <> RESULT_S64BIT then
  279. failed := true;
  280. if bigstruct.u16 <> RESULT_U16BIT then
  281. failed := true;
  282. If failed then
  283. fail
  284. else
  285. WriteLn('Passed!');
  286. end.
  287. {
  288. $Log$
  289. Revision 1.5 2002-09-07 15:40:51 peter
  290. * old logs removed and tabs fixed
  291. Revision 1.4 2002/08/25 19:28:07 peter
  292. * fixed long double typo that was using double instead of extended
  293. Revision 1.3 2002/05/04 16:56:54 carl
  294. + var parameter testing
  295. + function result testing
  296. + floating point testing
  297. Revision 1.2 2002/04/22 19:09:28 carl
  298. + added structure testing
  299. Revision 1.1 2002/04/13 21:03:43 carl
  300. + C module testing (unfinished)
  301. }