1
0

tests.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. static
  2. YSI_g_sVariable;
  3. static stock y_va_CallRemoteFunction(va_args<>)
  4. {
  5. va_CallRemoteFunction("y_va_PublicTestFunction", "ii", va_start<0>);
  6. }
  7. static stock y_va_CallLocalFunction(va_args<>)
  8. {
  9. new
  10. local1 = 123,
  11. local2 = 1,
  12. local3 = 7,
  13. local4 = 7;
  14. va_CallLocalFunction("y_va_PublicTestFunction", "ii", va_start<0>);
  15. return local1 * local2 + local3 - local4;
  16. }
  17. static stock y_va_CallLocalFunction_X(func[], va_args<>)
  18. {
  19. new
  20. local1 = 61,
  21. local2 = 2,
  22. local3 = 8,
  23. local4 = 7;
  24. va_CallLocalFunction(func, "si", va_start<1>);
  25. return local1 * local2 + local3 - local4;
  26. }
  27. static stock y_va_CallRemoteFunction_X(func[], va_args<>)
  28. {
  29. va_CallRemoteFunction(func, "si", va_start<1>);
  30. }
  31. forward y_va_PublicTestFunction(vara, varb);
  32. public y_va_PublicTestFunction(vara, varb)
  33. {
  34. new
  35. varc = 55,
  36. vard = 101;
  37. if (vara)
  38. {
  39. YSI_g_sVariable = varb;
  40. }
  41. else
  42. {
  43. ++YSI_g_sVariable;
  44. }
  45. // Just use them so they can't be optimised out.
  46. vara = clamp(varb, varc, vard);
  47. }
  48. forward y_va_PublicRecurseFunction(func[], vara);
  49. public y_va_PublicRecurseFunction(func[], vara)
  50. {
  51. // "" Passed to "CallLocalFunction" crashes it.
  52. ASSERT(123 == y_va_CallLocalFunction_X(func, "\1", vara));
  53. }
  54. forward y_va_PublicCallFunction(func[], vara);
  55. public y_va_PublicCallFunction(func[], vara)
  56. {
  57. y_va_PublicTestFunction(vara, 123456);
  58. }
  59. Test:y_va_CallRemoteFunction()
  60. {
  61. YSI_g_sVariable = 5;
  62. y_va_CallRemoteFunction(0, 11);
  63. ASSERT(YSI_g_sVariable == 6);
  64. y_va_CallRemoteFunction(1, 11);
  65. ASSERT(YSI_g_sVariable == 11);
  66. }
  67. static stock y_va_printf_0(va_args<>)
  68. {
  69. va_printf("", va_start<0>);
  70. }
  71. static stock y_va_printf_1(num, va_args<>)
  72. {
  73. #pragma unused num
  74. va_printf("", va_start<1>);
  75. }
  76. static stock y_va_printf_2(num, other, va_args<>)
  77. {
  78. #pragma unused num, other
  79. va_printf("", va_start<2>);
  80. }
  81. static stock y_va_printf_3(num, other, str[], va_args<>)
  82. {
  83. #pragma unused num, other, str
  84. va_printf("", va_start<3>);
  85. }
  86. Test:y_va_printf()
  87. {
  88. y_va_printf_0(42, 1, "hi", I@);
  89. y_va_printf_1(42, 1, "hi", I@);
  90. y_va_printf_2(42, 1, "hi", I@);
  91. y_va_printf_3(42, 1, "hi", I@);
  92. }
  93. Test:y_va_recurse_local()
  94. {
  95. YSI_g_sVariable = 0;
  96. y_va_CallLocalFunction_X("y_va_PublicRecurseFunction", "y_va_PublicCallFunction", true);
  97. ASSERT(YSI_g_sVariable == 123456);
  98. y_va_CallLocalFunction_X("y_va_PublicRecurseFunction", "y_va_PublicCallFunction", false);
  99. ASSERT(YSI_g_sVariable == 123457);
  100. }
  101. Test:y_va_recurse_remote()
  102. {
  103. YSI_g_sVariable = 0;
  104. y_va_CallRemoteFunction_X("y_va_PublicRecurseFunction", "y_va_PublicCallFunction", true);
  105. ASSERT(YSI_g_sVariable == 123456);
  106. y_va_CallRemoteFunction_X("y_va_PublicRecurseFunction", "y_va_PublicCallFunction", false);
  107. ASSERT(YSI_g_sVariable == 123457);
  108. }
  109. Test:y_va_CallLocalFunction()
  110. {
  111. YSI_g_sVariable = 8;
  112. y_va_CallLocalFunction(0, 45);
  113. ASSERT(YSI_g_sVariable == 9);
  114. ASSERT(123 == y_va_CallLocalFunction(1, 45));
  115. ASSERT(YSI_g_sVariable == 45);
  116. }
  117. static stock y_va_SetTimerEx(va_args<>)
  118. {
  119. return va_SetTimerEx("y_va_SetTimerExPublic", 1000, false, "iii", va_start<0>);
  120. }
  121. Test:y_va_SetTimerEx()
  122. {
  123. ASSERT(y_va_SetTimerEx(5, 6, 7) != 0);
  124. }
  125. static stock y_va_format(dest[], size, fmat[], va_args<>)
  126. {
  127. va_format(dest, size, fmat, va_start<3>);
  128. }
  129. Test:y_va_format()
  130. {
  131. new
  132. str[64];
  133. y_va_format(str, sizeof (str), "Hello %d %04x %s", 99, 0x1F, "woop");
  134. ASSERT(!strcmp(str, "Hello 99 001F woop"));
  135. }
  136. static stock y_va_return(dest[], size, fmat[], va_args<>)
  137. {
  138. strcpy(dest, va_return(fmat, va_start<3>), size);
  139. }
  140. Test:y_va_return()
  141. {
  142. new
  143. str[YSI_MAX_STRING];
  144. y_va_return(str, sizeof (str), "Hi %.3f %8.8s %8.8s", 5.5, "this is a very long string", "short");
  145. ASSERT(!strcmp(str, "Hi 5.500 this is short "));
  146. }
  147. static stock y_va_DoubleIndirection(dest[YSI_MAX_STRING], fmat[], var0, var1, var2, va_args<>) //var3, var4, size = sizeof (dest))
  148. {
  149. #pragma unused var0, var1, var2
  150. // va_format(dest, 32, fmat, va_start<5>);
  151. //dest = "hello 03/06/17";
  152. dest = va_return(fmat, va_start<5>);
  153. //print(dest);
  154. }
  155. Test:y_va_DoubleIndirection()
  156. {
  157. new
  158. dest[YSI_MAX_STRING],
  159. var0 = 44,
  160. var1 = 55,
  161. var2 = 66,
  162. var3 = 77,
  163. var4 = 88;
  164. y_va_DoubleIndirection(dest, "%d %d", var0, var1, var2, var3, var4);
  165. ASSERT(var0 == 44);
  166. ASSERT(var1 == 55);
  167. ASSERT(var2 == 66);
  168. ASSERT(var3 == 77);
  169. ASSERT(var4 == 88);
  170. ASSERT(!strcmp(dest, "77 88"));
  171. }
  172. static stock bool:y_va_Locals(real[], fmat[], va_args<>)
  173. {
  174. new
  175. dest[128];
  176. va_format(dest, sizeof (dest), fmat, va_start<2>);
  177. return !strcmp(dest, real);
  178. }
  179. Test:y_va_Locals()
  180. {
  181. ASSERT(y_va_Locals("42", "%d", 42));
  182. ASSERT(y_va_Locals("42 43 44", "%d %d %d", 42, 43, 44));
  183. ASSERT(y_va_Locals("hi", "%s", "hi"));
  184. ASSERT(y_va_Locals("he -1", "%.2s %d", "hello", -1));
  185. }
  186. static stock y_va2_printf_0(GLOBAL_TAG_TYPES:...)
  187. {
  188. printf("", ___);
  189. }
  190. static stock y_va2_printf_1(num, GLOBAL_TAG_TYPES:...)
  191. {
  192. #pragma unused num
  193. printf("", ___(1));
  194. }
  195. static stock y_va2_printf_2(num, other, GLOBAL_TAG_TYPES:...)
  196. {
  197. #pragma unused num, other
  198. printf("", ___2);
  199. }
  200. static stock y_va2_printf_3(num, other, str[], GLOBAL_TAG_TYPES:...)
  201. {
  202. #pragma unused num, other, str
  203. printf("", ___(3));
  204. }
  205. Test:y_va2_printf()
  206. {
  207. y_va2_printf_0(42, 1, "hi", I@);
  208. y_va2_printf_1(42, 1, "hi", I@);
  209. y_va2_printf_2(42, 1, "hi", I@);
  210. y_va2_printf_3(42, 1, "hi", I@);
  211. }
  212. static stock y_va2_Extract(num, ...)
  213. {
  214. new
  215. ret[YSI_MAX_STRING];
  216. va_getstring(ret, num + 1);
  217. __COMPILER_STRING_RETURN(ret);
  218. }
  219. static stock y_va2_Three(...)
  220. {
  221. return 3;
  222. }
  223. static stock y_va2_Nest2(fmat[YSI_MAX_STRING], ...)
  224. {
  225. new
  226. dest[YSI_MAX_STRING];
  227. format(dest, sizeof (dest), fmat, ___1);
  228. ASSERT(!strcmp(dest, "second param second param final param"));
  229. }
  230. static stock y_va2_Nest1(...)
  231. {
  232. y_va2_Nest2(y_va2_Extract(1, ___), y_va2_Extract(y_va2_Three(___), ___), y_va2_Extract(2, ___(1)), ___);
  233. }
  234. Test:y_va2_Nesting()
  235. {
  236. y_va2_Nest1("final param", "%s %s %s", "third param", "second param");
  237. }
  238. static stock y_va2_format(dest[], size, fmat[], GLOBAL_TAG_TYPES:...)
  239. {
  240. format(dest, size, fmat, ___(3));
  241. }
  242. Test:y_va2_format()
  243. {
  244. new
  245. str[64];
  246. y_va2_format(str, sizeof (str), "Hello %d %04x %s", 99, 0x1F, "woop");
  247. ASSERT(!strcmp(str, "Hello 99 001F woop"));
  248. }
  249. static stock y_va2_return(dest[], size, fmat[], GLOBAL_TAG_TYPES:...)
  250. {
  251. format(dest, size, fmat, ___(3));
  252. }
  253. Test:y_va2_return()
  254. {
  255. new
  256. str[YSI_MAX_STRING];
  257. y_va2_return(str, sizeof (str), "Hi %.3f %8.8s %8.8s", 5.5, "this is a very long string", "short");
  258. ASSERT(!strcmp(str, "Hi 5.500 this is short "));
  259. }
  260. static stock y_va2_DoubleIndirection(dest[1040], fmat[], var0, var1, var2, GLOBAL_TAG_TYPES:...) //var3, var4, size = sizeof (dest))
  261. {
  262. #pragma unused var0, var1, var2
  263. // va_format(dest, 32, fmat, ___(5));
  264. format(dest, sizeof (dest), fmat, ___(5));
  265. }
  266. Test:y_va2_DoubleIndirection()
  267. {
  268. new
  269. dest[1040],
  270. var0 = 44,
  271. var1 = 55,
  272. var2 = 66,
  273. var3 = 77,
  274. var4 = 88;
  275. y_va2_DoubleIndirection(dest, "%d %d", var0, var1, var2, var3, var4);
  276. ASSERT(var0 == 44);
  277. ASSERT(var1 == 55);
  278. ASSERT(var2 == 66);
  279. ASSERT(var3 == 77);
  280. ASSERT(var4 == 88);
  281. ASSERT(!strcmp(dest, "77 88"));
  282. }
  283. static stock y_va2_TripleIndirectionC(dest[1040], fmat[], var0, var1, var2, GLOBAL_TAG_TYPES:...)
  284. {
  285. #pragma unused var0, var1, var2
  286. format(dest, sizeof (dest), fmat, ___(5));
  287. setarg(5, 0, 101);
  288. }
  289. static stock y_va2_TripleIndirectionB(dest[1040], fmat[], var0, var1, var2, GLOBAL_TAG_TYPES:...)
  290. {
  291. y_va2_TripleIndirectionC(dest, fmat, var0, var1, var2, ___(5));
  292. }
  293. static stock y_va2_TripleIndirectionA(dest[1040], fmat[], var0, var1, var2, GLOBAL_TAG_TYPES:...)
  294. {
  295. y_va2_TripleIndirectionB(dest, fmat, var0, var1, var2, ___(5));
  296. }
  297. Test:y_va2_TripleIndirection()
  298. {
  299. new
  300. dest[1040],
  301. var0 = 44,
  302. var1 = 55,
  303. var2 = 66,
  304. var3 = 77,
  305. var4 = 88;
  306. y_va2_TripleIndirectionA(dest, "%d %d", var0, var1, var2, var3, var4);
  307. ASSERT(var0 == 44);
  308. ASSERT(var1 == 55);
  309. ASSERT(var2 == 66);
  310. ASSERT(var3 == 101);
  311. ASSERT(var4 == 88);
  312. ASSERT(!strcmp(dest, "77 88"));
  313. }
  314. static stock bool:y_va2_Locals(real[], fmat[], GLOBAL_TAG_TYPES:...)
  315. {
  316. new
  317. dest[128];
  318. format(dest, sizeof (dest), fmat, ___2);
  319. return !strcmp(dest, real);
  320. }
  321. Test:y_va2_Locals()
  322. {
  323. ASSERT(y_va2_Locals("42", "%d", 42));
  324. ASSERT(y_va2_Locals("42 43 44", "%d %d %d", 42, 43, 44));
  325. ASSERT(y_va2_Locals("hi", "%s", "hi"));
  326. ASSERT(y_va2_Locals("he -1", "%.2s %d", "hello", -1));
  327. }
  328. Test:y_va2_Types()
  329. {
  330. ASSERT(y_va2_Locals("4.67", "%.2f", 4.672));
  331. ASSERT(y_va2_Locals("Hello World", "%s", "Hello World"));
  332. }
  333. Test:y_va2_NoParameters()
  334. {
  335. ASSERT(y_va2_Locals("hello", "hello"));
  336. ASSERT(y_va2_Locals("Hello World", "Hello World"));
  337. ASSERT(y_va2_Locals("42 43 44 45 46 47", "42 43 44 45 46 47"));
  338. }
  339. static stock
  340. YSI_g_sDestString[YSI_MAX_STRING];
  341. Test:y_va2_PassThree()
  342. {
  343. y_va2_MyFunc1("Hello", "there", "world");
  344. ASSERT(!strcmp(YSI_g_sDestString, "woo there world"));
  345. y_va2_MyFunc1("In", "the", "world");
  346. ASSERT(!strcmp(YSI_g_sDestString, "woo the world"));
  347. y_va2_MyFunc1("Hello", "one", "world");
  348. ASSERT(!strcmp(YSI_g_sDestString, "woo one world"));
  349. y_va2_MyFunc1("Hello", "there", "yeah");
  350. ASSERT(!strcmp(YSI_g_sDestString, "woo there yeah"));
  351. y_va2_MyFunc1("Hello", "there", "5");
  352. ASSERT(!strcmp(YSI_g_sDestString, "woo there 5"));
  353. y_va2_MyFunc1("Hello", "there", "C");
  354. ASSERT(!strcmp(YSI_g_sDestString, "woo there C"));
  355. }
  356. static stock y_va2_MyFunc3(...)
  357. {
  358. new woo[32] = "woo";
  359. __COMPILER_STRING_RETURN(woo);
  360. //__COMPILER_STRING_RETURN("woo", 32);
  361. }
  362. static stock y_va2_MyFunc1(...)
  363. {
  364. y_va2_MyFunc2(y_va2_MyFunc3(___), ___(1));
  365. }
  366. static stock y_va2_MyFunc2(...)
  367. {
  368. format(YSI_g_sDestString, sizeof (YSI_g_sDestString), "%s %s %s", ___);
  369. }
  370. static stock y_va_BlankFormat1(...)
  371. {
  372. new string[144];
  373. va_format(string, sizeof (string), "%s", ___);
  374. // print(string);
  375. }
  376. Test:y_va_BlankFormat1()
  377. {
  378. new abc[32] = "WAT";
  379. y_va_BlankFormat1(abc);
  380. y_va_BlankFormat1(abc);
  381. y_va_BlankFormat1(abc);
  382. y_va_BlankFormat1(abc);
  383. }
  384. static stock
  385. YSI_g_sString[144];
  386. static stock y_va_BlankFormat2(...)
  387. {
  388. new string[144];
  389. va_format(YSI_g_sString, sizeof (YSI_g_sString), "%s", ___);
  390. #pragma unused string
  391. // print(string);
  392. }
  393. Test:y_va_BlankFormat2()
  394. {
  395. new abc[32] = "WAT";
  396. YSI_g_sString[0] = '\0';
  397. y_va_BlankFormat2(abc);
  398. ASSERT(!strcmp(YSI_g_sString, "WAT"));
  399. YSI_g_sString[0] = '\0';
  400. y_va_BlankFormat2(abc);
  401. ASSERT(!strcmp(YSI_g_sString, "WAT"));
  402. YSI_g_sString[0] = '\0';
  403. y_va_BlankFormat2(abc);
  404. ASSERT(!strcmp(YSI_g_sString, "WAT"));
  405. YSI_g_sString[0] = '\0';
  406. y_va_BlankFormat2(abc);
  407. ASSERT(!strcmp(YSI_g_sString, "WAT"));
  408. }