tcalext.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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. {$ifndef USE_PASCAL_OBJECT}
  19. {$MODE OBJFPC}
  20. {$R+}
  21. uses strings,ctypes;
  22. {$L ctest.o}
  23. {$endif USE_PASCAL_OBJECT}
  24. {$ifdef FPC_HAS_TYPE_EXTENDED}
  25. {$define test_longdouble}
  26. {$endif}
  27. { Use C alignment of records }
  28. {$PACKRECORDS C}
  29. const
  30. RESULT_U8BIT = $55;
  31. RESULT_U16BIT = $500F;
  32. RESULT_U32BIT = $500F0000;
  33. RESULT_U64BIT = $1BCDABCD;
  34. RESULT_S16BIT = -12;
  35. RESULT_S32BIT = -120;
  36. RESULT_S64BIT = -12000;
  37. RESULT_FLOAT = 14.54;
  38. RESULT_DOUBLE = 15.54;
  39. RESULT_LONGDOUBLE = 16.54;
  40. RESULT_PCHAR = 'Hello world';
  41. type
  42. _1byte_ = record
  43. u8 : byte;
  44. end;
  45. _3byte_ = record
  46. u8 : byte;
  47. u16 : word;
  48. end;
  49. _3byte_s = record
  50. u16 : word;
  51. w8 : byte;
  52. end;
  53. _5byte_ = record
  54. u8 : byte;
  55. u32 : cardinal;
  56. end;
  57. _7byte_ = record
  58. u8: byte;
  59. s64: int64;
  60. u16: word;
  61. end;
  62. byte_array = array [0..1] of byte;
  63. word_array = array [0..1] of word;
  64. cardinal_array = array [0..1] of cardinal;
  65. qword_array = array [0..1] of qword;
  66. smallint_array = array [0..1] of smallint;
  67. longint_array = array [0..1] of longint;
  68. int64_array = array [0..1] of int64;
  69. single_array = array [0..1] of single;
  70. double_array = array [0..1] of double;
  71. clongdouble_array = array [0..1] of clongdouble;
  72. { simple parameter passing }
  73. procedure test_param_u8(x: byte); cdecl; external;
  74. procedure test_param_u16(x : word); cdecl; external;
  75. procedure test_param_u32(x: cardinal); cdecl; external;
  76. procedure test_param_u64(x: qword); cdecl; external;
  77. procedure test_param_s16(x : smallint); cdecl; external;
  78. procedure test_param_s32(x: longint); cdecl; external;
  79. procedure test_param_s64(x: int64); cdecl; external;
  80. procedure test_param_float(x : single); cdecl; external;
  81. procedure test_param_double(x: double); cdecl; external;
  82. procedure test_param_longdouble(x: clongdouble); cdecl; external;
  83. procedure test_param_var_u8(var x: byte); cdecl; external;
  84. { array parameter passing }
  85. procedure test_array_param_u8(x: byte_array); cdecl; external;
  86. procedure test_array_param_u16(x : word_array); cdecl; external;
  87. procedure test_array_param_u32(x: cardinal_array); cdecl; external;
  88. procedure test_array_param_u64(x: qword_array); cdecl; external;
  89. procedure test_array_param_s16(x :smallint_array); cdecl; external;
  90. procedure test_array_param_s32(x: longint_array); cdecl; external;
  91. procedure test_array_param_s64(x: int64_array); cdecl; external;
  92. procedure test_array_param_float(x : single_array); cdecl; external;
  93. procedure test_array_param_double(x: double_array); cdecl; external;
  94. procedure test_array_param_longdouble(x: clongdouble_array); cdecl; external;
  95. { mixed parameter passing }
  96. procedure test_param_mixed_u16(z: byte; x : word; y :byte); cdecl; external;
  97. procedure test_param_mixed_u32(z: byte; x: cardinal; y: byte); cdecl; external;
  98. procedure test_param_mixed_s64(z: byte; x: int64; y: byte); cdecl; external;
  99. procedure test_param_mixed_float(x: single; y: byte); cdecl; external;
  100. procedure test_param_mixed_double(x: double; y: byte); cdecl; external;
  101. procedure test_param_mixed_long_double(x: clongdouble; y: byte); cdecl; external;
  102. procedure test_param_mixed_var_u8(var x: byte;y:byte); cdecl; external;
  103. { structure parameter testing }
  104. procedure test_param_struct_tiny(buffer : _1BYTE_); cdecl; external;
  105. procedure test_param_struct_small(buffer : _3BYTE_); cdecl; external;
  106. procedure test_param_struct_small_s(buffer : _3BYTE_S); cdecl; external;
  107. procedure test_param_struct_medium(buffer : _5BYTE_); cdecl; external;
  108. procedure test_param_struct_large(buffer : _7BYTE_); cdecl; external;
  109. { mixed with structure parameter testing }
  110. procedure test_param_mixed_struct_tiny(buffer : _1BYTE_; y :byte); cdecl; external;
  111. procedure test_param_mixed_struct_small(buffer : _3BYTE_; y :byte); cdecl; external;
  112. procedure test_param_mixed_struct_small_s(buffer : _3BYTE_S; y :byte); cdecl; external;
  113. procedure test_param_mixed_struct_medium(buffer : _5BYTE_; y :byte); cdecl; external;
  114. procedure test_param_mixed_struct_large(buffer : _7BYTE_; y :byte); cdecl; external;
  115. { function result value testing }
  116. function test_function_u8: byte; cdecl; external;
  117. function test_function_u16: word; cdecl; external;
  118. function test_function_u32: cardinal; cdecl; external;
  119. function test_function_u64: qword; cdecl; external;
  120. function test_function_s16: smallint; cdecl; external;
  121. function test_function_s32: longint; cdecl; external;
  122. function test_function_s64: int64; cdecl; external;
  123. function test_function_pchar: pchar; cdecl; external;
  124. function test_function_float : single; cdecl; external;
  125. function test_function_double : double; cdecl; external;
  126. function test_function_longdouble: clongdouble; cdecl; external;
  127. function test_function_tiny_struct : _1byte_; cdecl; external;
  128. function test_function_small_struct : _3byte_; cdecl; external;
  129. function test_function_small_struct_s : _3byte_s; cdecl; external;
  130. function test_function_medium_struct : _5byte_; cdecl; external;
  131. function test_function_struct : _7byte_; cdecl; external;
  132. var
  133. global_u8bit : byte; cvar; external;
  134. global_u16bit : word; cvar; external;
  135. global_u32bit : cardinal; cvar;external;
  136. global_u64bit : qword; cvar; external;
  137. global_s16bit : smallint; cvar; external;
  138. global_s32bit : longint; cvar;external;
  139. global_s64bit : int64; cvar; external;
  140. global_float : single; cvar;external;
  141. global_double : double; cvar;external;
  142. global_long_double : clongdouble; cvar; external;
  143. value_u8bit : byte;
  144. value_s16bit : smallint;
  145. value_s32bit : longint;
  146. value_s64bit : int64;
  147. value_u16bit : word;
  148. value_u32bit : cardinal;
  149. value_u64bit : qword;
  150. value_float : single;
  151. value_double : double;
  152. value_long_double : extended;
  153. array_u8bit : array [0..1] of byte;
  154. array_s16bit : array [0..1] of smallint;
  155. array_s32bit : array [0..1] of longint;
  156. array_s64bit : array [0..1] of int64;
  157. array_u16bit : array [0..1] of word;
  158. array_u32bit : array [0..1] of cardinal;
  159. array_u64bit : array [0..1] of qword;
  160. array_float : array [0..1] of single;
  161. array_double : array [0..1] of double;
  162. array_long_double : array [0..1] of clongdouble;
  163. procedure clear_globals;
  164. begin
  165. global_u8bit := 0;
  166. global_u16bit := 0;
  167. global_u32bit := 0;
  168. global_u64bit := 0;
  169. global_s16bit := 0;
  170. global_s32bit := 0;
  171. global_s64bit := 0;
  172. global_float := 0.0;
  173. global_double := 0.0;
  174. global_long_double := 0.0;
  175. end;
  176. procedure clear_values;
  177. begin
  178. value_u8bit := 0;
  179. value_u16bit := 0;
  180. value_u32bit := 0;
  181. value_u64bit := 0;
  182. value_s16bit := 0;
  183. value_s32bit := 0;
  184. value_s64bit := 0;
  185. value_float := 0.0;
  186. value_double := 0.0;
  187. value_long_double := 0.0;
  188. end;
  189. { in sub procedure to detect stack corruption when exiting }
  190. procedure dotest;
  191. const
  192. has_errors : boolean = false;
  193. procedure fail;
  194. begin
  195. WriteLn('Failed!');
  196. has_errors:=true;
  197. end;
  198. var failed : boolean;
  199. tinystruct : _1BYTE_;
  200. smallstruct : _3BYTE_;
  201. smallstruct_s : _3BYTE_S;
  202. mediumstruct : _5BYTE_;
  203. bigstruct : _7BYTE_;
  204. pc: pchar;
  205. begin
  206. Write('External simple parameter testing...');
  207. failed := false;
  208. clear_values;
  209. clear_globals;
  210. value_u8bit := RESULT_U8BIT;
  211. test_param_u8(value_u8bit);
  212. if global_u8bit <> RESULT_U8BIT then
  213. failed := true;
  214. clear_values;
  215. clear_globals;
  216. value_u16bit := RESULT_U16BIT;
  217. test_param_u16(value_u16bit);
  218. if global_u16bit <> RESULT_U16BIT then
  219. failed := true;
  220. clear_values;
  221. clear_globals;
  222. value_u32bit := RESULT_U32BIT;
  223. test_param_u32(value_u32bit);
  224. if global_u32bit <> RESULT_U32BIT then
  225. failed := true;
  226. clear_values;
  227. clear_globals;
  228. value_u64bit := RESULT_U64BIT;
  229. test_param_u64(value_u64bit);
  230. if global_u64bit <> RESULT_U64BIT then
  231. failed := true;
  232. clear_values;
  233. clear_globals;
  234. value_s16bit := RESULT_S16BIT;
  235. test_param_s16(value_s16bit);
  236. if global_s16bit <> RESULT_S16BIT then
  237. failed := true;
  238. clear_values;
  239. clear_globals;
  240. value_s32bit := RESULT_S32BIT;
  241. test_param_s32(value_s32bit);
  242. if global_s32bit <> RESULT_S32BIT then
  243. failed := true;
  244. clear_values;
  245. clear_globals;
  246. value_s64bit := RESULT_S64BIT;
  247. test_param_s64(value_s64bit);
  248. if global_s64bit <> RESULT_S64BIT then
  249. failed := true;
  250. clear_values;
  251. clear_globals;
  252. value_float := RESULT_FLOAT;
  253. test_param_float(value_float);
  254. if trunc(global_float) <> trunc(RESULT_FLOAT) then
  255. failed := true;
  256. clear_values;
  257. clear_globals;
  258. value_double := RESULT_DOUBLE;
  259. test_param_double(value_double);
  260. if trunc(global_double) <> trunc(RESULT_DOUBLE) then
  261. failed := true;
  262. {$ifdef test_longdouble}
  263. clear_values;
  264. clear_globals;
  265. value_long_double := RESULT_LONGDOUBLE;
  266. test_param_longdouble(value_long_double);
  267. if trunc(global_long_double) <> trunc(RESULT_LONGDOUBLE) then
  268. failed := true;
  269. {$endif}
  270. { var parameter testing }
  271. clear_values;
  272. clear_globals;
  273. test_param_var_u8(value_u8bit);
  274. if value_u8bit <> RESULT_U8BIT then
  275. failed := true;
  276. If failed then
  277. fail
  278. else
  279. WriteLn('Passed!');
  280. Write('External array parameter testing...');
  281. failed := false;
  282. clear_values;
  283. clear_globals;
  284. array_u8bit[1] := RESULT_U8BIT;
  285. test_array_param_u8(array_u8bit);
  286. if global_u8bit <> RESULT_U8BIT then
  287. failed := true;
  288. clear_values;
  289. clear_globals;
  290. array_u16bit[1] := RESULT_U16BIT;
  291. test_array_param_u16(array_u16bit);
  292. if global_u16bit <> RESULT_U16BIT then
  293. failed := true;
  294. clear_values;
  295. clear_globals;
  296. array_u32bit[1] := RESULT_U32BIT;
  297. test_array_param_u32(array_u32bit);
  298. if global_u32bit <> RESULT_U32BIT then
  299. failed := true;
  300. clear_values;
  301. clear_globals;
  302. array_u64bit[1] := RESULT_U64BIT;
  303. test_array_param_u64(array_u64bit);
  304. if global_u64bit <> RESULT_U64BIT then
  305. failed := true;
  306. clear_values;
  307. clear_globals;
  308. array_s16bit[1] := RESULT_S16BIT;
  309. test_array_param_s16(array_s16bit);
  310. if global_s16bit <> RESULT_S16BIT then
  311. failed := true;
  312. clear_values;
  313. clear_globals;
  314. array_s32bit[1] := RESULT_S32BIT;
  315. test_array_param_s32(array_s32bit);
  316. if global_s32bit <> RESULT_S32BIT then
  317. failed := true;
  318. clear_values;
  319. clear_globals;
  320. array_s64bit[1] := RESULT_S64BIT;
  321. test_array_param_s64(array_s64bit);
  322. if global_s64bit <> RESULT_S64BIT then
  323. failed := true;
  324. clear_values;
  325. clear_globals;
  326. array_float[1] := RESULT_FLOAT;
  327. test_array_param_float(array_float);
  328. if trunc(global_float) <> trunc(RESULT_FLOAT) then
  329. failed := true;
  330. clear_values;
  331. clear_globals;
  332. array_double[1] := RESULT_DOUBLE;
  333. test_array_param_double(array_double);
  334. if trunc(global_double) <> trunc(RESULT_DOUBLE) then
  335. failed := true;
  336. clear_values;
  337. clear_globals;
  338. {$ifdef test_longdouble}
  339. array_long_double[1] := RESULT_LONGDOUBLE;
  340. test_array_param_longdouble(array_long_double);
  341. if trunc(global_long_double) <> trunc(RESULT_LONGDOUBLE) then
  342. failed := true;
  343. {$endif test_longdouble}
  344. If failed then
  345. fail
  346. else
  347. WriteLn('Passed!');
  348. Write('External mixed parameter testing...');
  349. failed := false;
  350. clear_values;
  351. clear_globals;
  352. test_param_mixed_var_u8(value_u8bit,RESULT_U8BIT);
  353. if value_u8bit <> RESULT_U8BIT then
  354. failed := true;
  355. if global_u8bit <> RESULT_U8BIT then
  356. failed := true;
  357. clear_values;
  358. clear_globals;
  359. value_u8bit := RESULT_U8BIT;
  360. value_u16bit := RESULT_U16BIT;
  361. test_param_mixed_u16(value_u8bit, value_u16bit, value_u8bit);
  362. if global_u16bit <> RESULT_U16BIT then
  363. failed := true;
  364. if global_u8bit <> RESULT_U8BIT then
  365. failed := true;
  366. clear_values;
  367. clear_globals;
  368. value_u8bit := RESULT_U8BIT;
  369. value_u32bit := RESULT_U32BIT;
  370. test_param_mixed_u32(value_u8bit, value_u32bit, value_u8bit);
  371. if global_u32bit <> RESULT_U32BIT then
  372. failed := true;
  373. if global_u8bit <> RESULT_U8BIT then
  374. failed := true;
  375. clear_values;
  376. clear_globals;
  377. value_u8bit := RESULT_U8BIT;
  378. value_s64bit := RESULT_S64BIT;
  379. test_param_mixed_s64(value_u8bit, value_s64bit, value_u8bit);
  380. if global_s64bit <> RESULT_S64BIT then
  381. failed := true;
  382. if global_u8bit <> RESULT_U8BIT then
  383. failed := true;
  384. clear_values;
  385. clear_globals;
  386. value_u8bit := RESULT_U8BIT;
  387. value_float := RESULT_FLOAT;
  388. test_param_mixed_float(value_float, value_u8bit);
  389. if global_float <> value_float then
  390. failed := true;
  391. if global_u8bit <> RESULT_U8BIT then
  392. failed := true;
  393. If failed then
  394. fail
  395. else
  396. WriteLn('Passed!');
  397. Write('External mixed parameter testing with floating values...');
  398. failed := false;
  399. clear_values;
  400. clear_globals;
  401. value_u8bit := RESULT_U8BIT;
  402. value_double := RESULT_DOUBLE;
  403. test_param_mixed_double(value_double, value_u8bit);
  404. if global_double <> value_double then
  405. failed := true;
  406. if global_u8bit <> RESULT_U8BIT then
  407. failed := true;
  408. clear_values;
  409. clear_globals;
  410. {$ifdef test_longdouble}
  411. value_u8bit := RESULT_U8BIT;
  412. value_long_double := RESULT_LONGDOUBLE;
  413. test_param_mixed_long_double(value_long_double, value_u8bit);
  414. if global_long_double <> value_long_double then
  415. failed := true;
  416. if global_u8bit <> RESULT_U8BIT then
  417. failed := true;
  418. {$endif}
  419. If failed then
  420. fail
  421. else
  422. WriteLn('Passed!');
  423. Write('External struct parameter testing...');
  424. failed := false;
  425. clear_values;
  426. clear_globals;
  427. tinystruct.u8 := RESULT_U8BIT;
  428. test_param_struct_tiny(tinystruct);
  429. if global_u8bit <> RESULT_U8BIT then
  430. failed := true;
  431. clear_values;
  432. clear_globals;
  433. smallstruct.u8 := RESULT_U8BIT;
  434. smallstruct.u16 := RESULT_u16BIT;
  435. test_param_struct_small(smallstruct);
  436. if global_u16bit <> RESULT_U16BIT then
  437. failed := true;
  438. if global_u8bit <> RESULT_U8BIT then
  439. failed := true;
  440. clear_values;
  441. clear_globals;
  442. smallstruct_s.u16 := RESULT_U16BIT;
  443. smallstruct_s.w8 := RESULT_U8BIT;
  444. test_param_struct_small_s(smallstruct_s);
  445. if global_u16bit <> RESULT_U16BIT then
  446. failed := true;
  447. if global_u8bit <> RESULT_U8BIT then
  448. failed := true;
  449. clear_values;
  450. clear_globals;
  451. mediumstruct.u8 := RESULT_U8BIT;
  452. mediumstruct.u32 := RESULT_U32BIT;
  453. test_param_struct_medium(mediumstruct);
  454. if global_u32bit <> RESULT_U32BIT then
  455. failed := true;
  456. if global_u8bit <> RESULT_U8BIT then
  457. failed := true;
  458. clear_values;
  459. clear_globals;
  460. bigstruct.u8 := RESULT_U8BIT;
  461. bigstruct.u16 := RESULT_U16BIT;
  462. bigstruct.s64 := RESULT_S64BIT;
  463. test_param_struct_large(bigstruct);
  464. if global_s64bit <> RESULT_S64BIT then
  465. failed := true;
  466. if global_u16bit <> RESULT_U16BIT then
  467. failed := true;
  468. if global_u8bit <> RESULT_U8BIT then
  469. failed := true;
  470. If failed then
  471. fail
  472. else
  473. WriteLn('Passed!');
  474. Write('External mixed struct/byte parameter testing...');
  475. failed := false;
  476. clear_values;
  477. clear_globals;
  478. test_param_mixed_struct_tiny(tinystruct,RESULT_U8BIT);
  479. if global_u8bit <> RESULT_U8BIT then
  480. failed := true;
  481. clear_values;
  482. clear_globals;
  483. smallstruct.u16 := RESULT_u16BIT;
  484. test_param_mixed_struct_small(smallstruct,RESULT_U8BIT);
  485. if global_u16bit <> RESULT_U16BIT then
  486. failed := true;
  487. if global_u8bit <> RESULT_U8BIT then
  488. failed := true;
  489. clear_values;
  490. clear_globals;
  491. smallstruct_s.u16 := RESULT_U16BIT;
  492. test_param_mixed_struct_small_s(smallstruct_s,RESULT_U8BIT);
  493. if global_u16bit <> RESULT_U16BIT then
  494. failed := true;
  495. if global_u8bit <> RESULT_U8BIT then
  496. failed := true;
  497. clear_values;
  498. clear_globals;
  499. mediumstruct.u32 := RESULT_U32BIT;
  500. test_param_mixed_struct_medium(mediumstruct,RESULT_U8BIT);
  501. if global_u32bit <> RESULT_U32BIT then
  502. failed := true;
  503. if global_u8bit <> RESULT_U8BIT then
  504. failed := true;
  505. clear_values;
  506. clear_globals;
  507. bigstruct.u16 := RESULT_U16BIT;
  508. bigstruct.s64 := RESULT_S64BIT;
  509. test_param_mixed_struct_large(bigstruct,RESULT_U8BIT);
  510. if global_s64bit <> RESULT_S64BIT then
  511. failed := true;
  512. if global_u16bit <> RESULT_U16BIT then
  513. failed := true;
  514. if global_u8bit <> RESULT_U8BIT then
  515. failed := true;
  516. If failed then
  517. fail
  518. else
  519. WriteLn('Passed!');
  520. Write('Integer function result testing...');
  521. failed := false;
  522. clear_values;
  523. clear_globals;
  524. value_u8bit := test_function_u8;
  525. if value_u8bit <> RESULT_U8BIT then
  526. failed := true;
  527. clear_values;
  528. clear_globals;
  529. value_u16bit := test_function_u16;
  530. if value_u16bit <> RESULT_U16BIT then
  531. failed := true;
  532. clear_values;
  533. clear_globals;
  534. value_u32bit := test_function_u32;
  535. if value_u32bit <> RESULT_U32BIT then
  536. failed := true;
  537. clear_values;
  538. clear_globals;
  539. value_u64bit := test_function_u64;
  540. if value_u64bit <> RESULT_U64BIT then
  541. failed := true;
  542. clear_values;
  543. clear_globals;
  544. value_s16bit := test_function_s16;
  545. if value_s16bit <> RESULT_S16BIT then
  546. failed := true;
  547. clear_values;
  548. clear_globals;
  549. value_s32bit := test_function_s32;
  550. if value_s32bit <> RESULT_S32BIT then
  551. failed := true;
  552. clear_values;
  553. clear_globals;
  554. value_s64bit := test_function_s64;
  555. if value_s64bit <> RESULT_S64BIT then
  556. failed := true;
  557. clear_values;
  558. clear_globals;
  559. If failed then
  560. fail
  561. else
  562. WriteLn('Passed!');
  563. Write('pchar function result testing...');
  564. failed := false;
  565. { verify if the contents both strings are equal }
  566. pc := test_function_pchar;
  567. if strcomp(pc, RESULT_PCHAR) <> 0 then
  568. failed := true;
  569. clear_values;
  570. clear_globals;
  571. If failed then
  572. fail
  573. else
  574. WriteLn('Passed!');
  575. Write('Real function result testing...');
  576. failed := false;
  577. value_float := test_function_float;
  578. if trunc(value_float) <> trunc(RESULT_FLOAT) then
  579. failed := true;
  580. clear_values;
  581. clear_globals;
  582. value_double := test_function_double;
  583. if trunc(value_double) <> trunc(RESULT_DOUBLE) then
  584. failed := true;
  585. {$ifdef test_longdouble}
  586. clear_values;
  587. clear_globals;
  588. value_long_double := test_function_longdouble;
  589. if trunc(value_long_double) <> trunc(RESULT_LONGDOUBLE) then
  590. failed := true;
  591. {$endif}
  592. clear_values;
  593. clear_globals;
  594. If failed then
  595. fail
  596. else
  597. WriteLn('Passed!');
  598. Write('Function result testing for struct...');
  599. failed := false;
  600. tinystruct := test_function_tiny_struct;
  601. if tinystruct.u8 <> RESULT_U8BIT then
  602. failed := true;
  603. smallstruct := test_function_small_struct;
  604. if smallstruct.u8 <> RESULT_U8BIT then
  605. failed := true;
  606. if smallstruct.u16 <> RESULT_U16BIT then
  607. failed := true;
  608. smallstruct_s := test_function_small_struct_s;
  609. if smallstruct_s.u16 <> RESULT_U16BIT then
  610. failed := true;
  611. if smallstruct_s.w8 <> RESULT_U8BIT then
  612. failed := true;
  613. mediumstruct := test_function_medium_struct;
  614. if mediumstruct.u8 <> RESULT_U8BIT then
  615. failed := true;
  616. if mediumstruct.u32 <> RESULT_U32BIT then
  617. failed := true;
  618. bigstruct := test_function_struct;
  619. if bigstruct.u8 <> RESULT_U8BIT then
  620. failed := true;
  621. if bigstruct.s64 <> RESULT_S64BIT then
  622. failed := true;
  623. if bigstruct.u16 <> RESULT_U16BIT then
  624. failed := true;
  625. If failed then
  626. fail
  627. else
  628. WriteLn('Passed!');
  629. if has_errors then
  630. Halt(1);
  631. end;
  632. begin
  633. dotest;
  634. end.