ctest.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 long global_u32bit;
  13. unsigned long long global_s64bit;
  14. float global_float;
  15. double global_double;
  16. long double global_long_double;
  17. #define RESULT_U8BIT 0x55
  18. #define RESULT_U16BIT 0x500F
  19. #define RESULT_U32BIT 0x500F0000
  20. #define RESULT_S64BIT -12000
  21. #define RESULT_FLOAT 14.54
  22. #define RESULT_PCHAR "Hello world"
  23. #define RESULT_LONGDOUBLE RESULT_FLOAT
  24. #define RESULT_DOUBLE RESULT_FLOAT
  25. struct _3BYTE_
  26. {
  27. unsigned char u8;
  28. unsigned short u16;
  29. };
  30. struct _7BYTE_
  31. {
  32. unsigned char u8;
  33. long long s64;
  34. unsigned short u16;
  35. };
  36. struct _7BYTE_ test_struct;
  37. /* simple parameter testing */
  38. void test_param_u8(unsigned char v)
  39. {
  40. global_u8bit = v;
  41. }
  42. void test_param_u16(unsigned short v)
  43. {
  44. global_u16bit = v;
  45. }
  46. void test_param_u32(unsigned long v)
  47. {
  48. global_u32bit = v;
  49. }
  50. void test_param_s64(long long v)
  51. {
  52. global_s64bit = v;
  53. }
  54. void test_param_float(float v)
  55. {
  56. global_float = v;
  57. }
  58. void test_param_double(double v)
  59. {
  60. global_double = v;
  61. }
  62. void test_param_longdouble(long double v)
  63. {
  64. global_long_double = v;
  65. }
  66. /* if this one works, others should also automatically */
  67. void test_param_var_u8(unsigned char *x)
  68. {
  69. *x = RESULT_U8BIT;
  70. }
  71. /* mixed parameter testing */
  72. void test_param_mixed_u16(unsigned char z, unsigned short x, unsigned char y)
  73. {
  74. global_u16bit = x;
  75. global_u8bit = y;
  76. }
  77. void test_param_mixed_u32(unsigned char z, unsigned long x, unsigned char y)
  78. {
  79. global_u32bit = x;
  80. global_u8bit = y;
  81. }
  82. void test_param_mixed_s64(unsigned char z, long long x, unsigned char y)
  83. {
  84. global_s64bit = x;
  85. global_u8bit = y;
  86. }
  87. /* simple record testing */
  88. void test_param_struct_small(struct _3BYTE_ buffer)
  89. {
  90. global_u8bit = buffer.u8;
  91. global_u16bit = buffer.u16;
  92. }
  93. void test_param_struct_large(struct _7BYTE_ buffer)
  94. {
  95. global_u8bit = buffer.u8;
  96. global_u16bit = buffer.u16;
  97. global_s64bit = buffer.s64;
  98. }
  99. /* function result testing */
  100. unsigned char test_function_u8()
  101. {
  102. return RESULT_U8BIT;
  103. }
  104. unsigned short test_function_u16()
  105. {
  106. return RESULT_U16BIT;
  107. }
  108. unsigned long test_function_u32()
  109. {
  110. return RESULT_U32BIT;
  111. }
  112. unsigned long long test_function_s64()
  113. {
  114. return RESULT_S64BIT;
  115. }
  116. char* test_function_pchar()
  117. {
  118. return RESULT_PCHAR;
  119. }
  120. float test_function_float()
  121. {
  122. return RESULT_FLOAT;
  123. }
  124. double test_function_double()
  125. {
  126. return RESULT_DOUBLE;
  127. }
  128. long double test_function_longdouble()
  129. {
  130. return RESULT_LONGDOUBLE;
  131. }
  132. struct _7BYTE_ test_function_struct()
  133. {
  134. test_struct.u8 = RESULT_U8BIT;
  135. test_struct.s64 = RESULT_S64BIT;
  136. test_struct.u16 = RESULT_U16BIT;
  137. return test_struct;
  138. }
  139. /*
  140. $Log$
  141. Revision 1.4 2002-09-07 15:40:56 peter
  142. * old logs removed and tabs fixed
  143. Revision 1.3 2002/05/04 16:57:23 carl
  144. + var parameter testing
  145. + function result testing
  146. + floating point testing
  147. Revision 1.2 2002/04/22 19:09:12 carl
  148. + added structure testing
  149. Revision 1.1 2002/04/13 21:06:39 carl
  150. + c module testing
  151. */