tcalext.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  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. { in sub procedure to detect stack corruption when exiting }
  196. procedure dotest;
  197. const
  198. has_errors : boolean = false;
  199. procedure fail;
  200. begin
  201. WriteLn('Failed!');
  202. has_errors:=true;
  203. end;
  204. var failed : boolean;
  205. tinystruct : _1BYTE_;
  206. smallstruct : _3BYTE_;
  207. smallstruct_s : _3BYTE_S;
  208. mediumstruct : _5BYTE_;
  209. bigstruct : _7BYTE_;
  210. pc: pchar;
  211. begin
  212. Write('External simple parameter testing...');
  213. failed := false;
  214. clear_values;
  215. clear_globals;
  216. value_u8bit := RESULT_U8BIT;
  217. test_param_u8(value_u8bit);
  218. if global_u8bit <> RESULT_U8BIT then
  219. failed := true;
  220. clear_values;
  221. clear_globals;
  222. value_u16bit := RESULT_U16BIT;
  223. test_param_u16(value_u16bit);
  224. if global_u16bit <> RESULT_U16BIT then
  225. failed := true;
  226. clear_values;
  227. clear_globals;
  228. value_u32bit := RESULT_U32BIT;
  229. test_param_u32(value_u32bit);
  230. if global_u32bit <> RESULT_U32BIT then
  231. failed := true;
  232. clear_values;
  233. clear_globals;
  234. value_u64bit := RESULT_U64BIT;
  235. test_param_u64(value_u64bit);
  236. if global_u64bit <> RESULT_U64BIT then
  237. failed := true;
  238. clear_values;
  239. clear_globals;
  240. value_s16bit := RESULT_S16BIT;
  241. test_param_s16(value_s16bit);
  242. if global_s16bit <> RESULT_S16BIT then
  243. failed := true;
  244. clear_values;
  245. clear_globals;
  246. value_s32bit := RESULT_S32BIT;
  247. test_param_s32(value_s32bit);
  248. if global_s32bit <> RESULT_S32BIT then
  249. failed := true;
  250. clear_values;
  251. clear_globals;
  252. value_s64bit := RESULT_S64BIT;
  253. test_param_s64(value_s64bit);
  254. if global_s64bit <> RESULT_S64BIT then
  255. failed := true;
  256. clear_values;
  257. clear_globals;
  258. value_float := RESULT_FLOAT;
  259. test_param_float(value_float);
  260. if trunc(global_float) <> trunc(RESULT_FLOAT) then
  261. failed := true;
  262. clear_values;
  263. clear_globals;
  264. value_double := RESULT_DOUBLE;
  265. test_param_double(value_double);
  266. if trunc(global_double) <> trunc(RESULT_DOUBLE) then
  267. failed := true;
  268. clear_values;
  269. clear_globals;
  270. {$ifdef FPC_HAS_TYPE_EXTENDED}
  271. value_long_double := RESULT_LONGDOUBLE;
  272. test_param_longdouble(value_long_double);
  273. if trunc(global_long_double) <> trunc(RESULT_LONGDOUBLE) then
  274. failed := true;
  275. {$endif FPC_HAS_TYPE_EXTENDED}
  276. { var parameter testing }
  277. clear_values;
  278. clear_globals;
  279. test_param_var_u8(value_u8bit);
  280. if value_u8bit <> RESULT_U8BIT then
  281. failed := true;
  282. If failed then
  283. fail
  284. else
  285. WriteLn('Passed!');
  286. Write('External array parameter testing...');
  287. failed := false;
  288. clear_values;
  289. clear_globals;
  290. array_u8bit[1] := RESULT_U8BIT;
  291. test_array_param_u8(array_u8bit);
  292. if global_u8bit <> RESULT_U8BIT then
  293. failed := true;
  294. clear_values;
  295. clear_globals;
  296. array_u16bit[1] := RESULT_U16BIT;
  297. test_array_param_u16(array_u16bit);
  298. if global_u16bit <> RESULT_U16BIT then
  299. failed := true;
  300. clear_values;
  301. clear_globals;
  302. array_u32bit[1] := RESULT_U32BIT;
  303. test_array_param_u32(array_u32bit);
  304. if global_u32bit <> RESULT_U32BIT then
  305. failed := true;
  306. clear_values;
  307. clear_globals;
  308. array_u64bit[1] := RESULT_U64BIT;
  309. test_array_param_u64(array_u64bit);
  310. if global_u64bit <> RESULT_U64BIT then
  311. failed := true;
  312. clear_values;
  313. clear_globals;
  314. array_s16bit[1] := RESULT_S16BIT;
  315. test_array_param_s16(array_s16bit);
  316. if global_s16bit <> RESULT_S16BIT then
  317. failed := true;
  318. clear_values;
  319. clear_globals;
  320. array_s32bit[1] := RESULT_S32BIT;
  321. test_array_param_s32(array_s32bit);
  322. if global_s32bit <> RESULT_S32BIT then
  323. failed := true;
  324. clear_values;
  325. clear_globals;
  326. array_s64bit[1] := RESULT_S64BIT;
  327. test_array_param_s64(array_s64bit);
  328. if global_s64bit <> RESULT_S64BIT then
  329. failed := true;
  330. clear_values;
  331. clear_globals;
  332. array_float[1] := RESULT_FLOAT;
  333. test_array_param_float(array_float);
  334. if trunc(global_float) <> trunc(RESULT_FLOAT) then
  335. failed := true;
  336. clear_values;
  337. clear_globals;
  338. array_double[1] := RESULT_DOUBLE;
  339. test_array_param_double(array_double);
  340. if trunc(global_double) <> trunc(RESULT_DOUBLE) then
  341. failed := true;
  342. clear_values;
  343. clear_globals;
  344. {$ifdef FPC_HAS_TYPE_EXTENDED}
  345. array_long_double[1] := RESULT_LONGDOUBLE;
  346. test_array_param_longdouble(array_long_double);
  347. if trunc(global_long_double) <> trunc(RESULT_LONGDOUBLE) then
  348. begin
  349. {$ifdef cpui386}
  350. if sizeof(global_long_double)=10 then
  351. begin
  352. { Known issue, ignore tcalext2 contains that test }
  353. end
  354. else
  355. {$endif cpui386}
  356. failed := true;
  357. end;
  358. {$endif FPC_HAS_TYPE_EXTENDED}
  359. If failed then
  360. fail
  361. else
  362. WriteLn('Passed!');
  363. Write('External mixed parameter testing...');
  364. failed := false;
  365. clear_values;
  366. clear_globals;
  367. test_param_mixed_var_u8(value_u8bit,RESULT_U8BIT);
  368. if value_u8bit <> RESULT_U8BIT then
  369. failed := true;
  370. if global_u8bit <> RESULT_U8BIT then
  371. failed := true;
  372. clear_values;
  373. clear_globals;
  374. value_u8bit := RESULT_U8BIT;
  375. value_u16bit := RESULT_U16BIT;
  376. test_param_mixed_u16(value_u8bit, value_u16bit, value_u8bit);
  377. if global_u16bit <> RESULT_U16BIT then
  378. failed := true;
  379. if global_u8bit <> RESULT_U8BIT then
  380. failed := true;
  381. clear_values;
  382. clear_globals;
  383. value_u8bit := RESULT_U8BIT;
  384. value_u32bit := RESULT_U32BIT;
  385. test_param_mixed_u32(value_u8bit, value_u32bit, value_u8bit);
  386. if global_u32bit <> RESULT_U32BIT then
  387. failed := true;
  388. if global_u8bit <> RESULT_U8BIT then
  389. failed := true;
  390. clear_values;
  391. clear_globals;
  392. value_u8bit := RESULT_U8BIT;
  393. value_s64bit := RESULT_S64BIT;
  394. test_param_mixed_s64(value_u8bit, value_s64bit, value_u8bit);
  395. if global_s64bit <> RESULT_S64BIT then
  396. failed := true;
  397. if global_u8bit <> RESULT_U8BIT then
  398. failed := true;
  399. clear_values;
  400. clear_globals;
  401. value_u8bit := RESULT_U8BIT;
  402. value_float := RESULT_FLOAT;
  403. test_param_mixed_float(value_float, value_u8bit);
  404. if global_float <> value_float then
  405. failed := true;
  406. if global_u8bit <> RESULT_U8BIT then
  407. failed := true;
  408. If failed then
  409. fail
  410. else
  411. WriteLn('Passed!');
  412. Write('External mixed parameter testing with floating values...');
  413. failed := false;
  414. clear_values;
  415. clear_globals;
  416. value_u8bit := RESULT_U8BIT;
  417. value_double := RESULT_DOUBLE;
  418. test_param_mixed_double(value_double, value_u8bit);
  419. if global_double <> value_double then
  420. failed := true;
  421. if global_u8bit <> RESULT_U8BIT then
  422. failed := true;
  423. clear_values;
  424. clear_globals;
  425. {$ifdef FPC_HAS_TYPE_EXTENDED}
  426. value_u8bit := RESULT_U8BIT;
  427. value_long_double := RESULT_LONGDOUBLE;
  428. test_param_mixed_long_double(value_long_double, value_u8bit);
  429. if global_long_double <> value_long_double then
  430. failed := true;
  431. if global_u8bit <> RESULT_U8BIT then
  432. failed := true;
  433. {$endif FPC_HAS_TYPE_EXTENDED}
  434. If failed then
  435. fail
  436. else
  437. WriteLn('Passed!');
  438. Write('External struct parameter testing...');
  439. failed := false;
  440. clear_values;
  441. clear_globals;
  442. tinystruct.u8 := RESULT_U8BIT;
  443. test_param_struct_tiny(tinystruct);
  444. if global_u8bit <> RESULT_U8BIT then
  445. failed := true;
  446. clear_values;
  447. clear_globals;
  448. smallstruct.u8 := RESULT_U8BIT;
  449. smallstruct.u16 := RESULT_u16BIT;
  450. test_param_struct_small(smallstruct);
  451. if global_u16bit <> RESULT_U16BIT then
  452. failed := true;
  453. if global_u8bit <> RESULT_U8BIT then
  454. failed := true;
  455. clear_values;
  456. clear_globals;
  457. smallstruct_s.u16 := RESULT_U16BIT;
  458. smallstruct_s.w8 := RESULT_U8BIT;
  459. test_param_struct_small_s(smallstruct_s);
  460. if global_u16bit <> RESULT_U16BIT then
  461. failed := true;
  462. if global_u8bit <> RESULT_U8BIT then
  463. failed := true;
  464. clear_values;
  465. clear_globals;
  466. mediumstruct.u8 := RESULT_U8BIT;
  467. mediumstruct.u32 := RESULT_U32BIT;
  468. test_param_struct_medium(mediumstruct);
  469. if global_u32bit <> RESULT_U32BIT then
  470. failed := true;
  471. if global_u8bit <> RESULT_U8BIT then
  472. failed := true;
  473. clear_values;
  474. clear_globals;
  475. bigstruct.u8 := RESULT_U8BIT;
  476. bigstruct.u16 := RESULT_U16BIT;
  477. bigstruct.s64 := RESULT_S64BIT;
  478. test_param_struct_large(bigstruct);
  479. if global_s64bit <> RESULT_S64BIT then
  480. failed := true;
  481. if global_u16bit <> RESULT_U16BIT then
  482. failed := true;
  483. if global_u8bit <> RESULT_U8BIT then
  484. failed := true;
  485. If failed then
  486. fail
  487. else
  488. WriteLn('Passed!');
  489. Write('External mixed struct/byte parameter testing...');
  490. failed := false;
  491. clear_values;
  492. clear_globals;
  493. test_param_mixed_struct_tiny(tinystruct,RESULT_U8BIT);
  494. if global_u8bit <> RESULT_U8BIT then
  495. failed := true;
  496. clear_values;
  497. clear_globals;
  498. smallstruct.u16 := RESULT_u16BIT;
  499. test_param_mixed_struct_small(smallstruct,RESULT_U8BIT);
  500. if global_u16bit <> RESULT_U16BIT then
  501. failed := true;
  502. if global_u8bit <> RESULT_U8BIT then
  503. failed := true;
  504. clear_values;
  505. clear_globals;
  506. smallstruct_s.u16 := RESULT_U16BIT;
  507. test_param_mixed_struct_small_s(smallstruct_s,RESULT_U8BIT);
  508. if global_u16bit <> RESULT_U16BIT then
  509. failed := true;
  510. if global_u8bit <> RESULT_U8BIT then
  511. failed := true;
  512. clear_values;
  513. clear_globals;
  514. mediumstruct.u32 := RESULT_U32BIT;
  515. test_param_mixed_struct_medium(mediumstruct,RESULT_U8BIT);
  516. if global_u32bit <> RESULT_U32BIT then
  517. failed := true;
  518. if global_u8bit <> RESULT_U8BIT then
  519. failed := true;
  520. clear_values;
  521. clear_globals;
  522. bigstruct.u16 := RESULT_U16BIT;
  523. bigstruct.s64 := RESULT_S64BIT;
  524. test_param_mixed_struct_large(bigstruct,RESULT_U8BIT);
  525. if global_s64bit <> RESULT_S64BIT then
  526. failed := true;
  527. if global_u16bit <> RESULT_U16BIT then
  528. failed := true;
  529. if global_u8bit <> RESULT_U8BIT then
  530. failed := true;
  531. If failed then
  532. fail
  533. else
  534. WriteLn('Passed!');
  535. Write('Integer function result testing...');
  536. failed := false;
  537. clear_values;
  538. clear_globals;
  539. value_u8bit := test_function_u8;
  540. if value_u8bit <> RESULT_U8BIT then
  541. failed := true;
  542. clear_values;
  543. clear_globals;
  544. value_u16bit := test_function_u16;
  545. if value_u16bit <> RESULT_U16BIT then
  546. failed := true;
  547. clear_values;
  548. clear_globals;
  549. value_u32bit := test_function_u32;
  550. if value_u32bit <> RESULT_U32BIT then
  551. failed := true;
  552. clear_values;
  553. clear_globals;
  554. value_u64bit := test_function_u64;
  555. if value_u64bit <> RESULT_U64BIT then
  556. failed := true;
  557. clear_values;
  558. clear_globals;
  559. value_s16bit := test_function_s16;
  560. if value_s16bit <> RESULT_S16BIT then
  561. failed := true;
  562. clear_values;
  563. clear_globals;
  564. value_s32bit := test_function_s32;
  565. if value_s32bit <> RESULT_S32BIT then
  566. failed := true;
  567. clear_values;
  568. clear_globals;
  569. value_s64bit := test_function_s64;
  570. if value_s64bit <> RESULT_S64BIT then
  571. failed := true;
  572. clear_values;
  573. clear_globals;
  574. If failed then
  575. fail
  576. else
  577. WriteLn('Passed!');
  578. Write('pchar function result testing...');
  579. failed := false;
  580. { verify if the contents both strings are equal }
  581. pc := test_function_pchar;
  582. if strcomp(pc, RESULT_PCHAR) <> 0 then
  583. failed := true;
  584. clear_values;
  585. clear_globals;
  586. If failed then
  587. fail
  588. else
  589. WriteLn('Passed!');
  590. Write('Real function result testing...');
  591. failed := false;
  592. value_float := test_function_float;
  593. if trunc(value_float) <> trunc(RESULT_FLOAT) then
  594. failed := true;
  595. clear_values;
  596. clear_globals;
  597. value_double := test_function_double;
  598. if trunc(value_double) <> trunc(RESULT_DOUBLE) then
  599. failed := true;
  600. clear_values;
  601. clear_globals;
  602. {$ifdef FPC_HAS_TYPE_EXTENDED}
  603. value_long_double := test_function_longdouble;
  604. if trunc(value_long_double) <> trunc(RESULT_LONGDOUBLE) then
  605. failed := true;
  606. {$endif FPC_HAS_TYPE_EXTENDED}
  607. clear_values;
  608. clear_globals;
  609. If failed then
  610. fail
  611. else
  612. WriteLn('Passed!');
  613. Write('Function result testing for struct...');
  614. failed := false;
  615. tinystruct := test_function_tiny_struct;
  616. if tinystruct.u8 <> RESULT_U8BIT then
  617. failed := true;
  618. smallstruct := test_function_small_struct;
  619. if smallstruct.u8 <> RESULT_U8BIT then
  620. failed := true;
  621. if smallstruct.u16 <> RESULT_U16BIT then
  622. failed := true;
  623. smallstruct_s := test_function_small_struct_s;
  624. if smallstruct_s.u16 <> RESULT_U16BIT then
  625. failed := true;
  626. if smallstruct_s.w8 <> RESULT_U8BIT then
  627. failed := true;
  628. mediumstruct := test_function_medium_struct;
  629. if mediumstruct.u8 <> RESULT_U8BIT then
  630. failed := true;
  631. if mediumstruct.u32 <> RESULT_U32BIT then
  632. failed := true;
  633. bigstruct := test_function_struct;
  634. if bigstruct.u8 <> RESULT_U8BIT then
  635. failed := true;
  636. if bigstruct.s64 <> RESULT_S64BIT then
  637. failed := true;
  638. if bigstruct.u16 <> RESULT_U16BIT then
  639. failed := true;
  640. If failed then
  641. fail
  642. else
  643. WriteLn('Passed!');
  644. if has_errors then
  645. Halt(1);
  646. end;
  647. begin
  648. dotest;
  649. end.