tcalext4.pp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. { Tests passing of byte arrays by value of different sizes to C methods }
  2. program passvaluestest;
  3. {$MODE DELPHI}
  4. type
  5. int8_t = shortint;
  6. pint8_t = ^int8_t;
  7. var
  8. success : boolean;
  9. {$packrecords c}
  10. type
  11. arr1 = array[1..1] of int8_t;
  12. arr2 = array[1..2] of int8_t;
  13. arr3 = array[1..3] of int8_t;
  14. arr4 = array[1..4] of int8_t;
  15. arr5 = array[1..5] of int8_t;
  16. arr7 = array[1..7] of int8_t;
  17. arr8 = array[1..8] of int8_t;
  18. arr9 = array[1..9] of int8_t;
  19. arr15 = array[1..15] of int8_t;
  20. arr16 = array[1..16] of int8_t;
  21. arr17 = array[1..17] of int8_t;
  22. arr24 = array[1..24] of int8_t;
  23. arr31 = array[1..31] of int8_t;
  24. arr32 = array[1..32] of int8_t;
  25. arr33 = array[1..33] of int8_t;
  26. procedure fill(var mem; size : integer);
  27. var
  28. i : Integer;
  29. p : pint8_t;
  30. begin
  31. p := @mem;
  32. for i := 0 to size-1 do begin
  33. p^ := random(255)+1;
  34. inc(p);
  35. end;
  36. end;
  37. procedure verify(val1, val2 : int64; nr : Integer);
  38. begin
  39. success := success and (val1 = val2);
  40. Write('Testing test ', nr , ', was ', val1, ', should be ', val2, '...');
  41. if (val1 = val2) then
  42. WriteLn('Success.')
  43. else
  44. WriteLn('Failed');
  45. end;
  46. function check(const s : array of int8_t) : int64;
  47. var
  48. i : Integer;
  49. begin
  50. result := 0;
  51. for i := low(s) to high(s) do
  52. inc(result, s[i]);
  53. end;
  54. {$L tcext4.o}
  55. function pass1(s : arr1) : int64; cdecl; external;
  56. function pass2(s : arr2) : int64; cdecl; external;
  57. function pass3(s : arr3) : int64; cdecl; external;
  58. function pass4(s : arr4) : int64; cdecl; external;
  59. function pass5(s : arr5) : int64; cdecl; external;
  60. function pass7(s : arr7) : int64; cdecl; external;
  61. function pass8(s : arr8) : int64; cdecl; external;
  62. function pass9(s : arr9) : int64; cdecl; external;
  63. function pass15(s : arr15) : int64; cdecl; external;
  64. function pass16(s : arr16) : int64; cdecl; external;
  65. function pass17(s : arr17) : int64; cdecl; external;
  66. function pass24(s : arr24) : int64; cdecl; external;
  67. function pass31(s : arr31) : int64; cdecl; external;
  68. function pass32(s : arr32) : int64; cdecl; external;
  69. function pass33(s : arr33) : int64; cdecl; external;
  70. var
  71. s1 : arr1;
  72. s2 : arr2;
  73. s3 : arr3;
  74. s4 : arr4;
  75. s5 : arr5;
  76. s7 : arr7;
  77. s8 : arr8;
  78. s9 : arr9;
  79. s15 : arr15;
  80. s16 : arr16;
  81. s17 : arr17;
  82. s24 : arr24;
  83. s31 : arr31;
  84. s32 : arr32;
  85. s33 : arr33;
  86. begin
  87. randseed := 20;
  88. success := true;
  89. fill(s1, sizeof(s1));
  90. fill(s2, sizeof(s2));
  91. fill(s3, sizeof(s3));
  92. fill(s4, sizeof(s4));
  93. fill(s5, sizeof(s5));
  94. fill(s7, sizeof(s7));
  95. fill(s8, sizeof(s8));
  96. fill(s9, sizeof(s9));
  97. fill(s15, sizeof(s15));
  98. fill(s16, sizeof(s16));
  99. fill(s17, sizeof(s17));
  100. fill(s24, sizeof(s24));
  101. fill(s31, sizeof(s31));
  102. fill(s32, sizeof(s32));
  103. fill(s33, sizeof(s33));
  104. verify(pass1(s1), check(s1), 1);
  105. verify(pass2(s2), check(s2), 2);
  106. verify(pass3(s3), check(s3), 3);
  107. verify(pass4(s4), check(s4), 4);
  108. verify(pass5(s5), check(s5), 5);
  109. verify(pass7(s7), check(s7), 7);
  110. verify(pass8(s8), check(s8), 8);
  111. verify(pass9(s9), check(s9), 9);
  112. verify(pass15(s15), check(s15), 15);
  113. verify(pass16(s16), check(s16), 16);
  114. verify(pass17(s17), check(s17), 17);
  115. verify(pass24(s24), check(s24), 24);
  116. verify(pass31(s31), check(s31), 31);
  117. verify(pass32(s32), check(s32), 32);
  118. verify(pass33(s33), check(s33), 33);
  119. if (not success) then
  120. halt(1);
  121. end.