tcalext.pp 20 KB

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