ctest.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. /*
  2. Program to test linking between C and pascal units.
  3. Copyright (c) 2002, Carl Eric Codere
  4. */
  5. /*
  6. Note : Arrays seem to always be passed by reference
  7. in the C language. Therefore, no testing is required
  8. to use them.
  9. */
  10. unsigned char global_u8bit;
  11. unsigned short global_u16bit;
  12. unsigned int global_u32bit;
  13. short global_s16bit;
  14. int global_s32bit;
  15. long long global_s64bit;
  16. unsigned long long global_u64bit;
  17. float global_float;
  18. double global_double;
  19. long double global_long_double;
  20. #define RESULT_U8BIT 0x55
  21. #define RESULT_U16BIT 0x500F
  22. #define RESULT_U32BIT 0x500F0000
  23. #define RESULT_S16BIT -12
  24. #define RESULT_S32BIT -120
  25. #define RESULT_S64BIT -12000
  26. #define RESULT_U64BIT 0x1BCDABCD
  27. #define RESULT_PCHAR "Hello world"
  28. #define RESULT_FLOAT 14.54
  29. #define RESULT_DOUBLE 15.54
  30. #define RESULT_LONGDOUBLE 16.54
  31. struct _1BYTE_
  32. {
  33. unsigned char u8;
  34. };
  35. struct _3BYTE_
  36. {
  37. unsigned char u8;
  38. unsigned short u16;
  39. };
  40. struct _3BYTE_S
  41. {
  42. unsigned short u16;
  43. unsigned char w8;
  44. };
  45. struct _5BYTE_
  46. {
  47. unsigned char u8;
  48. unsigned int u32;
  49. };
  50. struct _7BYTE_
  51. {
  52. unsigned char u8;
  53. long long s64;
  54. unsigned short u16;
  55. };
  56. struct _7BYTE_ test_struct;
  57. /* simple parameter testing */
  58. void test_param_u8(unsigned char v)
  59. {
  60. global_u8bit = v;
  61. }
  62. void test_param_u16(unsigned short v)
  63. {
  64. global_u16bit = v;
  65. }
  66. void test_param_u32(unsigned int v)
  67. {
  68. global_u32bit = v;
  69. }
  70. void test_param_s16(short v)
  71. {
  72. global_s16bit = v;
  73. }
  74. void test_param_s32(int v)
  75. {
  76. global_s32bit = v;
  77. }
  78. void test_param_s64(long long v)
  79. {
  80. global_s64bit = v;
  81. }
  82. void test_param_u64(unsigned long long v)
  83. {
  84. global_u64bit = v;
  85. }
  86. void test_param_float(float v)
  87. {
  88. global_float = v;
  89. }
  90. void test_param_double(double v)
  91. {
  92. global_double = v;
  93. }
  94. void test_param_longdouble(long double v)
  95. {
  96. global_long_double = v;
  97. }
  98. /* simple array parameter testing */
  99. void test_array_param_u8(unsigned char v[2])
  100. {
  101. global_u8bit = v[1];
  102. }
  103. void test_array_param_u16(unsigned short v[2])
  104. {
  105. global_u16bit = v[1];
  106. }
  107. void test_array_param_u32(unsigned int v[2])
  108. {
  109. global_u32bit = v[1];
  110. }
  111. void test_array_param_s16(short v[2])
  112. {
  113. global_s16bit = v[1];
  114. }
  115. void test_array_param_s32(int v[2])
  116. {
  117. global_s32bit = v[1];
  118. }
  119. void test_array_param_s64(long long v[2])
  120. {
  121. global_s64bit = v[1];
  122. }
  123. void test_array_param_u64(unsigned long long v[2])
  124. {
  125. global_u64bit = v[1];
  126. }
  127. void test_array_param_float(float v[2])
  128. {
  129. global_float = v[1];
  130. }
  131. void test_array_param_double(double v[2])
  132. {
  133. global_double = v[1];
  134. }
  135. void test_array_param_longdouble(long double v[2])
  136. {
  137. global_long_double = v[1];
  138. }
  139. /* if this one works, others should also automatically */
  140. void test_param_var_u8(unsigned char *x)
  141. {
  142. *x = RESULT_U8BIT;
  143. }
  144. /* mixed parameter testing */
  145. void test_param_mixed_u16(unsigned char z, unsigned short x, unsigned char y)
  146. {
  147. global_u16bit = x;
  148. global_u8bit = y;
  149. }
  150. void test_param_mixed_u32(unsigned char z, unsigned int x, unsigned char y)
  151. {
  152. global_u32bit = x;
  153. global_u8bit = y;
  154. }
  155. void test_param_mixed_s64(unsigned char z, long long x, unsigned char y)
  156. {
  157. global_s64bit = x;
  158. global_u8bit = y;
  159. }
  160. void test_param_mixed_var_u8(unsigned char *x, unsigned char y)
  161. {
  162. global_u8bit = y;
  163. *x = RESULT_U8BIT;
  164. }
  165. /* mixed parameter testing with floating point args */
  166. void test_param_mixed_float(float x, unsigned char y)
  167. {
  168. global_float = x;
  169. global_u8bit = y;
  170. }
  171. void test_param_mixed_double(double x, unsigned char y)
  172. {
  173. global_double = x;
  174. global_u8bit = y;
  175. }
  176. void test_param_mixed_long_double(long double x, unsigned char y)
  177. {
  178. global_long_double = x;
  179. global_u8bit = y;
  180. }
  181. /* simple record testing */
  182. void test_param_struct_tiny(struct _1BYTE_ buffer)
  183. {
  184. global_u8bit = buffer.u8;
  185. }
  186. void test_param_struct_small(struct _3BYTE_ buffer)
  187. {
  188. global_u8bit = buffer.u8;
  189. global_u16bit = buffer.u16;
  190. }
  191. void test_param_struct_small_s(struct _3BYTE_S buffer)
  192. {
  193. global_u8bit = buffer.w8;
  194. global_u16bit = buffer.u16;
  195. }
  196. void test_param_struct_medium(struct _5BYTE_ buffer)
  197. {
  198. global_u8bit = buffer.u8;
  199. global_u32bit = buffer.u32;
  200. }
  201. void test_param_struct_large(struct _7BYTE_ buffer)
  202. {
  203. global_u8bit = buffer.u8;
  204. global_u16bit = buffer.u16;
  205. global_s64bit = buffer.s64;
  206. }
  207. /* record+char testing */
  208. void test_param_mixed_struct_tiny(struct _1BYTE_ buffer, unsigned char y)
  209. {
  210. global_u8bit = y;
  211. }
  212. void test_param_mixed_struct_small(struct _3BYTE_ buffer, unsigned char y)
  213. {
  214. global_u8bit = y;
  215. global_u16bit = buffer.u16;
  216. }
  217. void test_param_mixed_struct_small_s(struct _3BYTE_S buffer, unsigned char y)
  218. {
  219. global_u8bit = y;
  220. global_u16bit = buffer.u16;
  221. }
  222. void test_param_mixed_struct_medium(struct _5BYTE_ buffer, unsigned char y)
  223. {
  224. global_u8bit = y;
  225. global_u32bit = buffer.u32;
  226. }
  227. void test_param_mixed_struct_large(struct _7BYTE_ buffer, unsigned char y)
  228. {
  229. global_u8bit = y;
  230. global_u16bit = buffer.u16;
  231. global_s64bit = buffer.s64;
  232. }
  233. /* function result testing */
  234. unsigned char test_function_u8()
  235. {
  236. return RESULT_U8BIT;
  237. }
  238. unsigned short test_function_u16()
  239. {
  240. return RESULT_U16BIT;
  241. }
  242. unsigned int test_function_u32()
  243. {
  244. return RESULT_U32BIT;
  245. }
  246. unsigned long long test_function_u64()
  247. {
  248. return RESULT_U64BIT;
  249. }
  250. unsigned short test_function_s16()
  251. {
  252. return RESULT_S16BIT;
  253. }
  254. unsigned int test_function_s32()
  255. {
  256. return RESULT_S32BIT;
  257. }
  258. unsigned long long test_function_s64()
  259. {
  260. return RESULT_S64BIT;
  261. }
  262. char* test_function_pchar()
  263. {
  264. return RESULT_PCHAR;
  265. }
  266. float test_function_float()
  267. {
  268. return RESULT_FLOAT;
  269. }
  270. double test_function_double()
  271. {
  272. return RESULT_DOUBLE;
  273. }
  274. long double test_function_longdouble()
  275. {
  276. return RESULT_LONGDOUBLE;
  277. }
  278. struct _1BYTE_ test_function_tiny_struct()
  279. {
  280. struct _1BYTE_ test_struct;
  281. test_struct.u8 = RESULT_U8BIT;
  282. return test_struct;
  283. }
  284. struct _3BYTE_ test_function_small_struct()
  285. {
  286. struct _3BYTE_ test_struct;
  287. test_struct.u8 = RESULT_U8BIT;
  288. test_struct.u16 = RESULT_U16BIT;
  289. return test_struct;
  290. }
  291. struct _3BYTE_S test_function_small_struct_s()
  292. {
  293. struct _3BYTE_S test_struct;
  294. test_struct.u16 = RESULT_U16BIT;
  295. test_struct.w8 = RESULT_U8BIT;
  296. return test_struct;
  297. }
  298. struct _5BYTE_ test_function_medium_struct()
  299. {
  300. struct _5BYTE_ test_struct;
  301. test_struct.u8 = RESULT_U8BIT;
  302. test_struct.u32 = RESULT_U32BIT;
  303. return test_struct;
  304. }
  305. struct _7BYTE_ test_function_struct()
  306. {
  307. test_struct.u8 = RESULT_U8BIT;
  308. test_struct.s64 = RESULT_S64BIT;
  309. test_struct.u16 = RESULT_U16BIT;
  310. return test_struct;
  311. }
  312. /*
  313. Revision 1.7 2005/02/06 20:00:41 peter
  314. * use int for 32bit types
  315. Revision 1.6 2002/11/18 00:42:16 pierre
  316. + records with really 3 byte size tests added
  317. Revision 1.5 2002/11/04 15:17:45 pierre
  318. * compatibility with C checks improved
  319. Revision 1.4 2002/09/07 15:40:56 peter
  320. * old logs removed and tabs fixed
  321. Revision 1.3 2002/05/04 16:57:23 carl
  322. + var parameter testing
  323. + function result testing
  324. + floating point testing
  325. Revision 1.2 2002/04/22 19:09:12 carl
  326. + added structure testing
  327. Revision 1.1 2002/04/13 21:06:39 carl
  328. + c module testing
  329. */