tests.inc 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  1. Test:TextR_DoStraightFade0SCM()
  2. {
  3. state y_text_colour : y_text_colour_scm;
  4. new
  5. bool:pending = false,
  6. str[64] = "Hello There",
  7. curColour = 0xFEFEFE00;
  8. ASSERT(TextR_DoStraightFade(str, sizeof (str), curColour, 6, 0xAAAAAAAA, 5, 0xFFFFFFFF, pending) == 8 * 5);
  9. ASSERT(!strcmp(str, "Hello {AAAAAA}T{BABABA}h{CCCCCC}e{DCDCDC}r{EEEEEE}e"));
  10. ASSERT(curColour == 0xEEEEEE00);
  11. ASSERT(pending == false);
  12. }
  13. Test:TextR_DoStraightFade1SCM()
  14. {
  15. state y_text_colour : y_text_colour_scm;
  16. new
  17. bool:pending = false,
  18. str[64] = "Hello There",
  19. curColour = 0xFEFEFE00;
  20. ASSERT(TextR_DoStraightFade(str, sizeof (str), curColour, 6, 0xFFFFFFFF, 5, 0xAAAAAAAA, pending) == 8 * 4);
  21. ASSERT(!strcmp(str, "Hello T{EEEEEE}h{DCDCDC}e{CCCCCC}r{BABABA}e"));
  22. ASSERT(curColour == 0xBABABA00);
  23. ASSERT(pending == false);
  24. }
  25. Test:TextR_DoStraightFade2SCM()
  26. {
  27. state y_text_colour : y_text_colour_scm;
  28. new
  29. bool:pending = false,
  30. str[64] = "Hello There",
  31. curColour = 0;
  32. ASSERT(TextR_DoStraightFade(str, sizeof (str), curColour, 5, 0x00EE2200, 6, 0x0022EE00, pending) == 8 * 5);
  33. // TODO: account for pointless colourings of spaces, as below.
  34. ASSERT(!strcmp(str, "Hello {00CC44}T{00AA66}h{008888}e{0066AA}r{0044CC}e"));
  35. ASSERT(curColour == 0x0044CC00);
  36. ASSERT(pending == false);
  37. }
  38. Test:TextR_DoStraightFade3SCM()
  39. {
  40. state y_text_colour : y_text_colour_scm;
  41. new
  42. bool:pending = false,
  43. str[64] = "Hello There",
  44. curColour = 0xFEFEFE00;
  45. ASSERT(TextR_DoStraightFade(str, sizeof (str), curColour, 4, 0x00EE2200, 6, 0x0022EE00, pending) == 8 * 5);
  46. // TODO: account for pointless colourings of spaces, as below.
  47. ASSERT(!strcmp(str, "Hell{00EE22}o {00AA66}T{008888}h{0066AA}e{0044CC}re"));
  48. ASSERT(curColour == 0x0044CC00);
  49. ASSERT(pending == false);
  50. }
  51. Test:TextR_InsertColour0SCM()
  52. {
  53. state y_text_colour : y_text_colour_scm;
  54. new
  55. bool:pending = false,
  56. str[32] = "Hello There",
  57. curColour = 0xFEFEFE00;
  58. ASSERT(TextR_InsertColour(str, sizeof (str), 6, curColour, 0xAAAAAAAA, pending) == 8);
  59. ASSERT(!strcmp(str, "Hello {AAAAAA}There"));
  60. ASSERT(curColour == 0xAAAAAA00);
  61. ASSERT(pending == false);
  62. }
  63. Test:TextR_InsertColour1SCM()
  64. {
  65. state y_text_colour : y_text_colour_scm;
  66. new
  67. bool:pending = false,
  68. str[32] = "Hello There",
  69. curColour = 0xFEFEFE00;
  70. ASSERT(TextR_InsertColour(str, sizeof (str), 6, curColour, 0xFFFFFFAA, pending) == 0);
  71. ASSERT(!strcmp(str, "Hello There"));
  72. ASSERT(curColour == 0xFEFEFE00);
  73. ASSERT(pending == false);
  74. }
  75. Test:TextR_InsertColour2SCM()
  76. {
  77. state y_text_colour : y_text_colour_scm;
  78. new
  79. bool:pending = false,
  80. str[32] = "Hello There",
  81. curColour = 0xFEFEFE00;
  82. ASSERT(TextR_InsertColour(str, sizeof (str), 6, curColour, 0xABABABAB, pending) == 8);
  83. ASSERT(!strcmp(str, "Hello {AAAAAA}There"));
  84. ASSERT(curColour == 0xAAAAAA00);
  85. ASSERT(pending == false);
  86. }
  87. Test:TextR_InsertColour3SCM()
  88. {
  89. state y_text_colour : y_text_colour_scm;
  90. // Don't insert colours at the end of the string (no point).
  91. new
  92. bool:pending = false,
  93. str[32] = "Hello There",
  94. curColour = 0xFEFEFE00;
  95. ASSERT(TextR_InsertColour(str, sizeof (str), 11, curColour, 0xAAAAAAAA, pending) == 0);
  96. ASSERT(!strcmp(str, "Hello There"));
  97. ASSERT(curColour == 0xFEFEFE00);
  98. ASSERT(pending == true);
  99. }
  100. Test:TextR_InsertColour4SCM()
  101. {
  102. state y_text_colour : y_text_colour_scm;
  103. new
  104. bool:pending = false,
  105. str[32] = "Hello There",
  106. curColour = 0xFEFEFE00;
  107. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, 0x23456789, pending) == 8);
  108. ASSERT(!strcmp(str, "{224466}Hello There"));
  109. ASSERT(curColour == 0x22446600);
  110. ASSERT(pending == false);
  111. }
  112. Test:TextR_InsertColour5SCM()
  113. {
  114. state y_text_colour : y_text_colour_scm;
  115. new
  116. bool:pending = false,
  117. str[32] = "Hello There",
  118. curColour = 0xFEFEFE00;
  119. ASSERT(TextR_InsertColour(str, sizeof (str), 5, curColour, 0x23456789, pending) == 0);
  120. ASSERT(!strcmp(str, "Hello There"));
  121. ASSERT(curColour == 0xFEFEFE00);
  122. ASSERT(pending == true);
  123. }
  124. Test:TextR_InsertColour0GT()
  125. {
  126. state y_text_colour : y_text_colour_gt;
  127. new
  128. bool:pending = false,
  129. str[32] = "Hello There",
  130. curColour = 0x100 | 'r';
  131. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, SAMP_GAME_TEXT_RH, pending) == 0);
  132. ASSERT(!strcmp(str, "Hello There"));
  133. ASSERT(curColour == 0x100 | 'r');
  134. ASSERT(pending == false);
  135. }
  136. Test:TextR_InsertColour1GT()
  137. {
  138. state y_text_colour : y_text_colour_gt;
  139. new
  140. bool:pending = false,
  141. str[32] = "Hello There",
  142. curColour = 0x100 | 'r';
  143. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, SAMP_GAME_TEXT_RHH, pending) == 3);
  144. ASSERT(!strcmp(str, "~h~Hello There"));
  145. ASSERT(curColour == 0x200 | 'r');
  146. ASSERT(pending == false);
  147. }
  148. Test:TextR_InsertColour2GT()
  149. {
  150. state y_text_colour : y_text_colour_gt;
  151. new
  152. bool:pending = false,
  153. str[32] = "Hello There",
  154. curColour = 0x100 | 'r';
  155. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, SAMP_GAME_TEXT_R, pending) == 3);
  156. ASSERT(!strcmp(str, "~r~Hello There"));
  157. ASSERT(curColour == 0x000 | 'r');
  158. ASSERT(pending == false);
  159. }
  160. Test:TextR_InsertColour3GT()
  161. {
  162. state y_text_colour : y_text_colour_gt;
  163. new
  164. bool:pending = false,
  165. str[32] = "Hello There",
  166. curColour = 0x100 | 'r';
  167. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, SAMP_GAME_TEXT_RHHHH, pending) == 9);
  168. ASSERT(!strcmp(str, "~h~~h~~h~Hello There"));
  169. ASSERT(curColour == 0x400 | 'r');
  170. ASSERT(pending == false);
  171. }
  172. Test:TextR_InsertColour4GT()
  173. {
  174. state y_text_colour : y_text_colour_gt;
  175. new
  176. bool:pending = false,
  177. str[32] = "Hello There",
  178. curColour = 0x100 | 'g';
  179. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, SAMP_GAME_TEXT_YH, pending) == 6);
  180. ASSERT(!strcmp(str, "~y~~h~Hello There"));
  181. ASSERT(curColour == 0x100 | 'y');
  182. ASSERT(pending == false);
  183. }
  184. Test:TextR_InsertColour5GT()
  185. {
  186. state y_text_colour : y_text_colour_gt;
  187. new
  188. bool:pending = false,
  189. str[32] = "Hello There",
  190. curColour = 0x200 | 'p';
  191. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, SAMP_GAME_TEXT_BHHH, pending) == 12);
  192. ASSERT(!strcmp(str, "~b~~h~~h~~h~Hello There"));
  193. ASSERT(curColour == 0x300 | 'b');
  194. ASSERT(pending == false);
  195. }
  196. Test:TextR_InsertColour6GT()
  197. {
  198. state y_text_colour : y_text_colour_gt;
  199. new
  200. bool:pending = false,
  201. str[32] = "Hello There",
  202. curColour = 0;
  203. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, SAMP_GAME_TEXT_HH, pending) == 6);
  204. ASSERT(!strcmp(str, "~h~~h~Hello There"));
  205. ASSERT(curColour == 0x200 | 'x');
  206. ASSERT(pending == false);
  207. }
  208. Test:TextR_InsertColour7GT()
  209. {
  210. state y_text_colour : y_text_colour_gt;
  211. new
  212. bool:pending = false,
  213. str[32] = "Hello There",
  214. curColour = 0x100 | 'x';
  215. ASSERT(TextR_InsertColour(str, sizeof (str), 0, curColour, SAMP_GAME_TEXT_HH, pending) == 3);
  216. ASSERT(!strcmp(str, "~h~Hello There"));
  217. ASSERT(curColour == 0x200 | 'x');
  218. ASSERT(pending == false);
  219. }
  220. Test:TextR_Complete0()
  221. {
  222. // String 1.
  223. new
  224. idx = 0,
  225. //str[32] = "Hello There, are you?",
  226. rel[6] = {5, -2, 11, -3, 0},
  227. abs[6] = {0, 55, 55, 55, 55};
  228. // Insert "how ".
  229. TextR_CompleteRelToAbs(rel, abs,idx);
  230. ASSERT(abs[-1 + 1] == 4);
  231. ASSERT(abs[-1 + 2] == -2);
  232. ASSERT(abs[-1 + 3] == 5);
  233. ASSERT(abs[-1 + 4] == -3);
  234. ASSERT(abs[-1 + 5] == 16);
  235. ASSERT(idx == 4);
  236. }
  237. Test:TextR_RelToAbs0()
  238. {
  239. // String 1.
  240. new
  241. idx = 0,
  242. //str[32] = "Hello There, are you?",
  243. rel[6] = {5, -2, 11, -3, 0},
  244. abs[6] = {0, 55, 55, 55, 55};
  245. // Insert "how ".
  246. TextR_UpdateRelToAbs(rel, abs, idx, 4, 13);
  247. TextR_CompleteRelToAbs(rel, abs,idx);
  248. ASSERT(abs[-1 + 1] == 4);
  249. ASSERT(abs[-1 + 2] == -2);
  250. ASSERT(abs[-1 + 3] == 5);
  251. ASSERT(abs[-1 + 4] == -3);
  252. ASSERT(abs[-1 + 5] == 20);
  253. }
  254. Test:TextR_RelToAbs1()
  255. {
  256. // String 1.
  257. new
  258. idx = 0,
  259. //str[32] = "Hello There, are you?",
  260. rel[8] = {5, -2, 11, -3, 5, -3, 0},
  261. abs[8] = {0, 55, 55, 55, 55, 66, 66};
  262. // Insert "how ".
  263. TextR_UpdateRelToAbs(rel, abs, idx, 4, 13);
  264. TextR_CompleteRelToAbs(rel, abs,idx);
  265. ASSERT(abs[-1 + 1] == 6);
  266. ASSERT(abs[-1 + 2] == -2);
  267. ASSERT(abs[-1 + 3] == 5);
  268. ASSERT(abs[-1 + 4] == -3);
  269. ASSERT(abs[-1 + 5] == 20);
  270. ASSERT(abs[-1 + 6] == -3);
  271. ASSERT(abs[-1 + 7] == 25);
  272. }
  273. Test:TextR_RelToAbs2()
  274. {
  275. // String 1.
  276. new
  277. idx = 0,
  278. //str[32] = "Hello There, are you?",
  279. rel[6] = {5, -2, 11, -3, 0},
  280. abs[6] = {0, 55, 55, 55, 55};
  281. // Insert "how ".
  282. TextR_UpdateRelToAbs(rel, abs, idx, 4, 13);
  283. TextR_UpdateRelToAbs(rel, abs, idx, 5, 20);
  284. TextR_UpdateRelToAbs(rel, abs, idx, 6, 80);
  285. TextR_CompleteRelToAbs(rel, abs,idx);
  286. ASSERT(abs[-1 + 1] == 4);
  287. ASSERT(abs[-1 + 2] == -2);
  288. ASSERT(abs[-1 + 3] == 5);
  289. ASSERT(abs[-1 + 4] == -3);
  290. ASSERT(abs[-1 + 5] == 20);
  291. }
  292. Test:TextR_RelToAbs3()
  293. {
  294. // String 1.
  295. new
  296. idx = 0,
  297. //str[32] = "Hello There, are you?",
  298. rel[8] = {5, -2, 11, -3, 5, -4, 0},
  299. abs[8] = {0, 55, 55, 55, 55, 66, 66};
  300. // Insert "how ".
  301. TextR_UpdateRelToAbs(rel, abs, idx, 4, 13);
  302. TextR_UpdateRelToAbs(rel, abs, idx, 5, 20);
  303. TextR_UpdateRelToAbs(rel, abs, idx, 6, 80);
  304. TextR_CompleteRelToAbs(rel, abs,idx);
  305. ASSERT(abs[-1 + 1] == 6);
  306. ASSERT(abs[-1 + 2] == -2);
  307. ASSERT(abs[-1 + 3] == 5);
  308. ASSERT(abs[-1 + 4] == -3);
  309. ASSERT(abs[-1 + 5] == 20);
  310. ASSERT(abs[-1 + 6] == -4);
  311. ASSERT(abs[-1 + 7] == 30);
  312. }
  313. Test:TextR_RelToAbs4()
  314. {
  315. // String 1.
  316. new
  317. idx = 0,
  318. //str[32] = "Hello There, are you?",
  319. rel[8] = {5, -2, 11, -3, 5, -4, 0},
  320. abs[8] = {0, 55, 55, 55, 55, 66, 66};
  321. // Insert "how ".
  322. TextR_UpdateRelToAbs(rel, abs, idx, 4, 13);
  323. TextR_UpdateRelToAbs(rel, abs, idx, -2, 20);
  324. TextR_UpdateRelToAbs(rel, abs, idx, 6, 80);
  325. TextR_CompleteRelToAbs(rel, abs,idx);
  326. ASSERT(abs[-1 + 1] == 6);
  327. ASSERT(abs[-1 + 2] == -2);
  328. ASSERT(abs[-1 + 3] == 5);
  329. ASSERT(abs[-1 + 4] == -3);
  330. ASSERT(abs[-1 + 5] == 20);
  331. ASSERT(abs[-1 + 6] == -4);
  332. ASSERT(abs[-1 + 7] == 23);
  333. }
  334. Test:Colours_EncodeGameText0()
  335. {
  336. ASSERT(Colours_EncodeGameText("~r~") == 0x00 | 'r');
  337. ASSERT(Colours_EncodeGameText("~r~~h~") == 0x100 | 'r');
  338. ASSERT(Colours_EncodeGameText("~R~") == 0x00 | 'r');
  339. ASSERT(Colours_EncodeGameText("~r~~H~~h~") == 0x200 | 'r');
  340. ASSERT(Colours_EncodeGameText("~h~") == 0x100 | 'x');
  341. ASSERT(Colours_EncodeGameText("~h~~h~") == 0x200 | 'x');
  342. ASSERT(Colours_EncodeGameText("~r~") == 0x00 | 'r');
  343. ASSERT(Colours_EncodeGameText("~g~") == 0x00 | 'g');
  344. ASSERT(Colours_EncodeGameText("~b~") == 0x00 | 'b');
  345. ASSERT(Colours_EncodeGameText("~y~") == 0x00 | 'y');
  346. ASSERT(Colours_EncodeGameText("~p~") == 0x00 | 'p');
  347. ASSERT(Colours_EncodeGameText("~w~") == 0x00 | 'w');
  348. ASSERT(Colours_EncodeGameText("~l~") == 0x00 | 'l');
  349. ASSERT(Colours_EncodeGameText("~l~~h~") == 0x100 | 'l');
  350. ASSERT(Colours_EncodeGameText("~l~~h~~h~") == 0x200 | 'l');
  351. ASSERT(Colours_EncodeGameText("~l~~h~~h~~h~") == 0x300 | 'l');
  352. ASSERT(Colours_EncodeGameText("~l~~h~~h~~h~~h~") == 0x400 | 'l');
  353. ASSERT(Colours_EncodeGameText("~l~~h~~h~~h~~h~~h~") == 0x500 | 'l');
  354. ASSERT(Colours_EncodeGameText("~x~") == 0x00 | 'x');
  355. }
  356. Test:Colours_EncodeGameText1()
  357. {
  358. ASSERT(Colours_EncodeGameText("~z~") == 0);
  359. ASSERT(Colours_EncodeGameText("~~~") == 0);
  360. ASSERT(Colours_EncodeGameText("~r") == 0);
  361. ASSERT(Colours_EncodeGameText("~Y") == 0);
  362. ASSERT(Colours_EncodeGameText("~Y") == 0);
  363. }
  364. Test:TextR_GetFadeData0()
  365. {
  366. state y_text_colour : y_text_colour_scm;
  367. new
  368. colourLocations[] = {0,
  369. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE, 10,
  370. 0x22222222, 20},
  371. endColour,
  372. endPos,
  373. newlines;
  374. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  375. ASSERT(endColour == 0x22222222);
  376. ASSERT(endPos == 20);
  377. ASSERT(newlines == 0);
  378. }
  379. Test:TextR_GetFadeData1()
  380. {
  381. state y_text_colour : y_text_colour_scm;
  382. new
  383. colourLocations[] = {0,
  384. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  385. 0x22222222, 20},
  386. endColour,
  387. endPos,
  388. newlines;
  389. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  390. ASSERT(endColour == 0x22222222);
  391. ASSERT(endPos == 20);
  392. ASSERT(newlines == 1);
  393. }
  394. Test:TextR_GetFadeData2()
  395. {
  396. state y_text_colour : y_text_colour_scm;
  397. new
  398. colourLocations[] = {0,
  399. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE, 10,
  400. 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE, 20},
  401. endColour,
  402. endPos,
  403. newlines;
  404. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  405. ASSERT(endColour == 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE);
  406. ASSERT(endPos == 20);
  407. ASSERT(newlines == 0);
  408. }
  409. Test:TextR_GetFadeData3()
  410. {
  411. state y_text_colour : y_text_colour_scm;
  412. new
  413. colourLocations[] = {0,
  414. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  415. 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE, 20},
  416. endColour,
  417. endPos,
  418. newlines;
  419. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  420. ASSERT(endColour == 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE);
  421. ASSERT(endPos == 20);
  422. ASSERT(newlines == 1);
  423. }
  424. Test:TextR_GetFadeData4()
  425. {
  426. state y_text_colour : y_text_colour_scm;
  427. new
  428. colourLocations[] = {0,
  429. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE, 10,
  430. _:e_TEXT_RENDER_COLOUR_LINE, 15,
  431. 0x22222222, 20},
  432. endColour,
  433. endPos,
  434. newlines;
  435. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  436. ASSERT(endColour == 0x22222222);
  437. ASSERT(endPos == 20);
  438. ASSERT(newlines == 1);
  439. }
  440. Test:TextR_GetFadeData5()
  441. {
  442. state y_text_colour : y_text_colour_scm;
  443. new
  444. colourLocations[] = {0,
  445. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  446. 0x22222222, 20,
  447. 0x66666666, 30},
  448. endColour,
  449. endPos,
  450. newlines;
  451. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  452. ASSERT(endColour == 0x22222222);
  453. ASSERT(endPos == 20);
  454. ASSERT(newlines == 1);
  455. }
  456. Test:TextR_GetFadeData6()
  457. {
  458. state y_text_colour : y_text_colour_scm;
  459. new
  460. colourLocations[] = {0,
  461. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE, 10,
  462. 0x66666666, 15,
  463. 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE, 20},
  464. endColour,
  465. endPos,
  466. newlines;
  467. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  468. ASSERT(endColour == 0x66666666);
  469. ASSERT(endPos == 15);
  470. ASSERT(newlines == 0);
  471. }
  472. Test:TextR_GetFadeData7()
  473. {
  474. state y_text_colour : y_text_colour_scm;
  475. new
  476. colourLocations[] = {0,
  477. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  478. 0x88888800 | _:e_TEXT_RENDER_COLOUR_LINE, 14,
  479. 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE, 20},
  480. endColour,
  481. endPos,
  482. newlines;
  483. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  484. ASSERT(endColour == 0x88888800 | _:e_TEXT_RENDER_COLOUR_LINE);
  485. ASSERT(endPos == 14);
  486. ASSERT(newlines == 1);
  487. }
  488. Test:TextR_GetFadeData8()
  489. {
  490. state y_text_colour : y_text_colour_scm;
  491. new
  492. colourLocations[] = {0,
  493. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  494. _:e_TEXT_RENDER_COLOUR_LINE, 14,
  495. 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE, 20},
  496. endColour,
  497. endPos,
  498. newlines;
  499. TextR_GetFadeData(colourLocations, 2, endColour, endPos, newlines);
  500. ASSERT(endColour == 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE);
  501. ASSERT(endPos == 20);
  502. ASSERT(newlines == 2);
  503. }
  504. Test:TextR_DoNLFade0SCM()
  505. {
  506. state y_text_colour : y_text_colour_scm;
  507. new
  508. colourLocations[] = {0,
  509. 0x20408000 | _:e_TEXT_RENDER_COLOUR_LINE, 2,
  510. _:e_TEXT_RENDER_COLOUR_LINE, 4,
  511. _:e_TEXT_RENDER_COLOUR_LINE, 7,
  512. 0x00000002, 10, // Special encoding for pure white.
  513. 0, 65536},
  514. endPos,
  515. endColour,
  516. newLines,
  517. oc = 0xFEFEFEFE,
  518. bool:pending,
  519. idx = 2,
  520. str[64] = "A longer string.",
  521. sc = colourLocations[idx - 1];
  522. TextR_GetFadeData(colourLocations, idx, endColour, endPos, newLines);
  523. // printf("%d %d %d", endPos, endColour, newLines);
  524. ASSERT(endPos == 10);
  525. ASSERT(endColour == 0x00000002);
  526. ASSERT(newLines == 3);
  527. TextR_DoNLFade(str, sizeof (str), oc, colourLocations[idx], sc, endPos - colourLocations[idx], endColour, colourLocations, idx, pending, 0);
  528. //printf(str);
  529. // ASSERT(!strcmp(str, "A {204080}l{1C3870}o{183060}n{142850}g{102040}e{0C1830}r{081020} {040810}s{000000}tring."));
  530. ASSERT(!strcmp(str, "A l{1C3870}on{142850}g{102040}er {040810}string."));
  531. ASSERT(colourLocations[1] == 0x20408000 | _:e_TEXT_RENDER_COLOUR_LINE);
  532. ASSERT(colourLocations[3] == 0x18306000 | _:e_TEXT_RENDER_COLOUR_LINE);
  533. ASSERT(colourLocations[5] == 0x0C183000 | _:e_TEXT_RENDER_COLOUR_LINE);
  534. // printf("%x", colourLocations[1]);
  535. // printf("%x", colourLocations[3]);
  536. // printf("%x", colourLocations[5]);
  537. }
  538. Test:TextR_ResolvePending0()
  539. {
  540. state y_text_colour : y_text_colour_scm;
  541. new
  542. oldColour,
  543. str[64] = "{222222}Hello There",
  544. colourLocations[] = {0,
  545. -1, 65536};
  546. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 2, 0xAABBCC99, 0, oldColour) == 8);
  547. ASSERT(!strcmp(str, "{222222}Hello {AABACC}There"));
  548. }
  549. Test:TextR_ResolvePending1()
  550. {
  551. state y_text_colour : y_text_colour_scm;
  552. new
  553. oldColour,
  554. str[64] = "{222222}Hello There",
  555. colourLocations[] = {0,
  556. -1, 65536};
  557. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 2, 0xAABBCC99, 0, oldColour) == 8);
  558. ASSERT(!strcmp(str, "{222222}Hello {AABACC}There"));
  559. }
  560. Test:TextR_ResolvePending2()
  561. {
  562. state y_text_colour : y_text_colour_scm;
  563. new
  564. oldColour,
  565. str[64] = "{222222}Hello There",
  566. colourLocations[] = {0,
  567. -1, 65536};
  568. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 2, 0xAABBCC99, 0, oldColour) == 8);
  569. ASSERT(!strcmp(str, "{222222}Hello {AABACC}There"));
  570. }
  571. Test:TextR_ResolvePending3()
  572. {
  573. state y_text_colour : y_text_colour_scm;
  574. new
  575. oldColour,
  576. str[64] = "{222222}Hello There",
  577. colourLocations[] = {0,
  578. -1, 16};
  579. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 2, 0xAABBCC99, 0, oldColour) == 0);
  580. ASSERT(!strcmp(str, "{222222}Hello There"));
  581. }
  582. Test:TextR_ResolvePending4()
  583. {
  584. state y_text_colour : y_text_colour_scm;
  585. new
  586. oldColour,
  587. str[64] = "{222222}Hello ",
  588. colourLocations[] = {0,
  589. -1, 65536};
  590. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 2, 0xAABBCC99, 0, oldColour) == 0);
  591. ASSERT(!strcmp(str, "{222222}Hello "));
  592. }
  593. Test:TextR_ResolvePending5()
  594. {
  595. state y_text_colour : y_text_colour_scm;
  596. new
  597. str[64] = "{222222}Hello There",
  598. colourLocations[] = {0,
  599. 0xFEFEFE00, 16,
  600. -1, 65536},
  601. bool:pending,
  602. oldColour = 0x22222200;
  603. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 2, 0xAABBCC99, 0, oldColour) == 0);
  604. ASSERT(!strcmp(str, "{222222}Hello There"));
  605. ASSERT(TextR_InsertColour(str, sizeof (str), colourLocations[2], oldColour, colourLocations[1], pending) == 0);
  606. ASSERT(!strcmp(str, "{222222}Hello There"));
  607. ASSERT(pending == true);
  608. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 4, colourLocations[1], 0, oldColour) == 8);
  609. ASSERT(!strcmp(str, "{222222}Hello {FEFEFE}There"));
  610. }
  611. Test:TextR_ResolvePending6()
  612. {
  613. state y_text_colour : y_text_colour_scm;
  614. new
  615. str[64] = "{222222}Hello There",
  616. colourLocations[] = {0,
  617. 0x22222200, 16,
  618. -1, 65536},
  619. bool:pending,
  620. oldColour = 0x22222200;
  621. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 2, 0xAABBCC99, 0, oldColour) == 0);
  622. ASSERT(!strcmp(str, "{222222}Hello There"));
  623. ASSERT(TextR_InsertColour(str, sizeof (str), colourLocations[2], oldColour, colourLocations[1], pending) == 0);
  624. ASSERT(!strcmp(str, "{222222}Hello There"));
  625. ASSERT(pending == false);
  626. }
  627. Test:TextR_ResolvePending7()
  628. {
  629. state y_text_colour : y_text_colour_scm;
  630. new
  631. str[64] = "{222222}Hello There",
  632. colourLocations[] = {0,
  633. 0xFEFEFE00, 16,
  634. -1, 65536},
  635. bool:pending,
  636. oldColour = 0x22222200;
  637. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 2, 0xAABBCC99, 0, oldColour) == 0);
  638. ASSERT(!strcmp(str, "{222222}Hello There"));
  639. ASSERT(TextR_InsertColour(str, sizeof (str), colourLocations[2], oldColour, colourLocations[1], pending) == 0);
  640. ASSERT(!strcmp(str, "{222222}Hello There"));
  641. ASSERT(pending == true);
  642. ASSERT(TextR_ResolvePending(str, sizeof (str), 13, colourLocations, 4, colourLocations[1], 0, oldColour) == 8);
  643. ASSERT(!strcmp(str, "{222222}Hello {FEFEFE}There"));
  644. }
  645. Test:TextR_NoFadeSCM()
  646. {
  647. state y_text_colour : y_text_colour_scm;
  648. new
  649. str[64] = "Hello There",
  650. bool:pending,
  651. curColour = -1;
  652. ASSERT(TextR_DoStraightFade(str, sizeof (str), curColour, 0, 0xABCDEF00, 10, 0xABCDEF00, pending) == 8);
  653. ASSERT(!strcmp(str, "{AACCEE}Hello There"));
  654. ASSERT(curColour == 0xAACCEE00);
  655. ASSERT(TextR_InsertColour(str, sizeof (str), 10, curColour, 0xABCDEF00, pending) == 0);
  656. ASSERT(!strcmp(str, "{AACCEE}Hello There"));
  657. ASSERT(curColour == 0xAACCEE00);
  658. }
  659. Test:TextR_GetSlotColour()
  660. {
  661. state y_text_colour : y_text_colour_scm;
  662. // {/}
  663. ASSERT(TextR_GetSlotColour(_:e_TEXT_RENDER_COLOUR_END, 0xFF00BBAA, 0xCCDDEEBB) == 0xFF00BBAA);
  664. ASSERT(TextR_GetSlotColour(0x12345678 | _:e_TEXT_RENDER_COLOUR_END, 0xFF00BBAA, 0xCCDDEEBB) == 0xFF00BBAA);
  665. ASSERT(TextR_GetSlotColour(0x01 | _:e_TEXT_RENDER_COLOUR_END, 0xFF00BBAA, 0xCCDDEEBB) == 0xFF00BBAA);
  666. ASSERT(TextR_GetSlotColour(_:e_TEXT_RENDER_COLOUR_STAR | _:e_TEXT_RENDER_COLOUR_END, 0xFF00BBAA, 0xCCDDEEBB) == 0xFF00BBAA);
  667. // {*}
  668. ASSERT(TextR_GetSlotColour(_:e_TEXT_RENDER_COLOUR_STAR, 0xFF00BBAA, 0xCCDDEEBB) == 0xFEFEFE00);
  669. ASSERT(TextR_GetSlotColour((0x09876543 & _:e_TEXT_RENDER_COLOUR_MASK) | _:e_TEXT_RENDER_COLOUR_STAR, 0xFF00BBAA, 0xCCDDEEBB) == 0xFEFEFE00);
  670. ASSERT(TextR_GetSlotColour(0x01 | _:e_TEXT_RENDER_COLOUR_STAR, 0xFF00BBAA, 0xCCDDEEBB) == 0xFEFEFE00);
  671. // "\n"
  672. ASSERT(TextR_GetSlotColour(0, 0xFF00BBAA, 0xCCDDEEBB) == 0xCCDDEEBB);
  673. ASSERT(TextR_GetSlotColour(_:e_TEXT_RENDER_COLOUR_LINE, 0xFF00BBAA, 0xCCDDEEBB) == 0xCCDDEEBB);
  674. ASSERT(TextR_GetSlotColour(_:e_TEXT_RENDER_COLOUR_LINE | _:e_TEXT_RENDER_COLOUR_FADE, 0xFF00BBAA, 0xCCDDEEBB) == 0xCCDDEEBB);
  675. ASSERT(TextR_GetSlotColour(_:e_TEXT_RENDER_COLOUR_FADE, 0xFF00BBAA, 0xCCDDEEBB) == 0xCCDDEEBB);
  676. // {XXXXXX}
  677. ASSERT(TextR_GetSlotColour((0x771234AB & _:e_TEXT_RENDER_COLOUR_MASK), 0xFF00BBAA, 0xCCDDEEBB) == (0x771234AB & _:e_TEXT_RENDER_COLOUR_MASK));
  678. ASSERT(TextR_GetSlotColour((0x771234AB & _:e_TEXT_RENDER_COLOUR_MASK) | _:e_TEXT_RENDER_COLOUR_LINE, 0xFF00BBAA, 0xCCDDEEBB) == (0x771234AB & _:e_TEXT_RENDER_COLOUR_MASK));
  679. ASSERT(TextR_GetSlotColour((0x771234AB & _:e_TEXT_RENDER_COLOUR_MASK) | _:e_TEXT_RENDER_COLOUR_LINE | _:e_TEXT_RENDER_COLOUR_FADE, 0xFF00BBAA, 0xCCDDEEBB) == (0x771234AB & _:e_TEXT_RENDER_COLOUR_MASK));
  680. ASSERT(TextR_GetSlotColour((0x771234AB & _:e_TEXT_RENDER_COLOUR_MASK) | _:e_TEXT_RENDER_COLOUR_FADE, 0xFF00BBAA, 0xCCDDEEBB) == (0x771234AB & _:e_TEXT_RENDER_COLOUR_MASK));
  681. }
  682. Test:TextR_DoOneColour0SCM()
  683. {
  684. state y_text_colour : y_text_colour_scm;
  685. new
  686. str[64] = "This is a string to test :D.",
  687. len = sizeof (str),
  688. offset = 0,
  689. colourLocations[] = {0,
  690. 0xFEF00000, 5,
  691. 0xAA882200, 10,
  692. 0x12345678, 15,
  693. -1, 65536},
  694. idx = 2,
  695. curColour = 0,
  696. initialColour = 0xFE001000;
  697. while (colourLocations[idx] != 65536)
  698. {
  699. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  700. idx += 2;
  701. }
  702. ASSERT(!strcmp(str, "This {FEF000}is a {AA8822}strin{123456}g to test :D."));
  703. ASSERT(offset == 24);
  704. ASSERT(idx == 8);
  705. ASSERT(curColour == 0x12345600);
  706. }
  707. Test:TextR_DoOneColour1SCM()
  708. {
  709. state y_text_colour : y_text_colour_scm;
  710. new
  711. str[64] = "This is a string to test :D.",
  712. len = sizeof (str),
  713. offset = 0,
  714. colourLocations[] = {0,
  715. 0xFEF00000, 4,
  716. 0xAA882200, 9,
  717. 0x12345678, 16,
  718. -1, 65536},
  719. idx = 2,
  720. curColour = 0,
  721. initialColour = 0xFE001000;
  722. while (colourLocations[idx] != 65536)
  723. {
  724. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  725. idx += 2;
  726. }
  727. //printf(str);
  728. ASSERT(!strcmp(str, "This {FEF000}is a {AA8822}string {123456}to test :D."));
  729. ASSERT(offset == 24);
  730. ASSERT(idx == 8);
  731. ASSERT(curColour == 0x12345600);
  732. }
  733. Test:TextR_DoOneColour2SCM()
  734. {
  735. state y_text_colour : y_text_colour_scm;
  736. new
  737. str[64] = "This is a string to test :D.",
  738. len = sizeof (str),
  739. offset = 0,
  740. colourLocations[] = {0,
  741. 0xFEF00000, 9,
  742. 0xAA882200, 10,
  743. 0x12345678, 15,
  744. -1, 65536},
  745. idx = 2,
  746. curColour = 0,
  747. initialColour = 0xFE001000;
  748. while (colourLocations[idx] != 65536)
  749. {
  750. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  751. idx += 2;
  752. }
  753. ASSERT(!strcmp(str, "This is a {AA8822}strin{123456}g to test :D."));
  754. ASSERT(offset == 16);
  755. ASSERT(idx == 8);
  756. ASSERT(curColour == 0x12345600);
  757. }
  758. Test:TextR_DoOneColour3SCM()
  759. {
  760. state y_text_colour : y_text_colour_scm;
  761. new
  762. str[100] = "This is a string to test :D.",
  763. len = sizeof (str),
  764. offset = 0,
  765. colourLocations[] = {0,
  766. 0x00000002 | _:e_TEXT_RENDER_COLOUR_FADE, 5,
  767. 0x0A0A0A00, 10,
  768. 0x12345678, 15,
  769. -1, 65536},
  770. idx = 2,
  771. curColour = -1,
  772. initialColour = 0xFE001000;
  773. while (colourLocations[idx] != 65536)
  774. {
  775. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  776. idx += 2;
  777. }
  778. //printf(str);
  779. ASSERT(!strcmp(str, "This {000000}i{020202}s {060606}a {0A0A0A}strin{123456}g to test :D."));
  780. ASSERT(offset == 40);
  781. ASSERT(idx == 8);
  782. ASSERT(curColour == 0x12345600);
  783. }
  784. Test:TextR_DoOneColour4SCM()
  785. {
  786. state y_text_colour : y_text_colour_scm;
  787. new
  788. str[64] = "This is a string to test :D.",
  789. len = sizeof (str),
  790. offset = 0,
  791. colourLocations[] = {0,
  792. 0x00000002 | _:e_TEXT_RENDER_COLOUR_FADE, 5,
  793. 0x0A0A0A00 | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  794. 0x12345678, 15,
  795. -1, 65536},
  796. idx = 2,
  797. curColour = -1,
  798. initialColour = 0xFE001000;
  799. while (colourLocations[idx] != 65536)
  800. {
  801. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  802. idx += 2;
  803. }
  804. //printf(str);
  805. ASSERT(!strcmp(str, "This {000000}i{020202}s {060606}a strin{123456}g to test :D."));
  806. ASSERT(offset == 32);
  807. ASSERT(idx == 8);
  808. ASSERT(curColour == 0x12345600);
  809. }
  810. Test:TextR_DoOneColour3bSCM()
  811. {
  812. state y_text_colour : y_text_colour_scm;
  813. new
  814. str[64] = "This is a string to test :D.",
  815. len = sizeof (str),
  816. offset = 0,
  817. colourLocations[] = {0,
  818. 0x0000000 | _:e_TEXT_RENDER_COLOUR_FADE, 5,
  819. 0x0A0A0A00, 10,
  820. 0x12345678, 15,
  821. -1, 65536},
  822. idx = 2,
  823. curColour = 0,
  824. initialColour = 0xFE001000;
  825. while (colourLocations[idx] != 65536)
  826. {
  827. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  828. idx += 2;
  829. }
  830. //printf(str);
  831. ASSERT(!strcmp(str, "This i{020202}s {060606}a {0A0A0A}strin{123456}g to test :D."));
  832. ASSERT(offset == 32);
  833. ASSERT(idx == 8);
  834. ASSERT(curColour == 0x12345600);
  835. }
  836. Test:TextR_DoOneColour4bSCM()
  837. {
  838. state y_text_colour : y_text_colour_scm;
  839. new
  840. str[64] = "This is a string to test :D.",
  841. len = sizeof (str),
  842. offset = 0,
  843. colourLocations[] = {0,
  844. 0x00000002 | _:e_TEXT_RENDER_COLOUR_FADE, 5,
  845. 0x0A0A0A00 | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  846. 0x12345678, 15,
  847. -1, 65536},
  848. idx = 2,
  849. curColour = 0,
  850. initialColour = 0xFE001000;
  851. while (colourLocations[idx] != 65536)
  852. {
  853. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  854. idx += 2;
  855. }
  856. //printf(str);
  857. ASSERT(!strcmp(str, "This i{020202}s {060606}a strin{123456}g to test :D."));
  858. ASSERT(offset == 24);
  859. ASSERT(idx == 8);
  860. ASSERT(curColour == 0x12345600);
  861. }
  862. Test:TextR_DoOneColour5SCM()
  863. {
  864. state y_text_colour : y_text_colour_scm;
  865. new
  866. str[64] = "This is a string to test :D.",
  867. len = sizeof (str),
  868. offset = 0,
  869. colourLocations[] = {0,
  870. 0x00000002 | _:e_TEXT_RENDER_COLOUR_FADE, 5,
  871. _:e_TEXT_RENDER_COLOUR_LINE, 6,
  872. 0x0A0A0A00 | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  873. 0x12345678, 15,
  874. -1, 65536},
  875. idx = 2,
  876. curColour = -1,
  877. initialColour = 0xFE001000;
  878. while (colourLocations[idx] != 65536)
  879. {
  880. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  881. idx += 2;
  882. }
  883. ASSERT(!strcmp(str, "This {000000}is {060606}a strin{123456}g to test :D."));
  884. ASSERT(offset == 24);
  885. ASSERT(idx == 10);
  886. ASSERT(curColour == 0x12345600);
  887. ASSERT(colourLocations[3] == 0x02020200 | _:e_TEXT_RENDER_COLOUR_LINE);
  888. }
  889. Test:TextR_DoOneColour6SCM()
  890. {
  891. state y_text_colour : y_text_colour_scm;
  892. new
  893. str[64] = "This is a string to test :D.",
  894. len = sizeof (str),
  895. offset = 0,
  896. colourLocations[] = {0,
  897. 0x00000002, 5,
  898. _:e_TEXT_RENDER_COLOUR_LINE, 6,
  899. 0x0A0A0A00 | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  900. _:e_TEXT_RENDER_COLOUR_END, 15,
  901. -1, 65536},
  902. idx = 2,
  903. curColour = 0,
  904. initialColour = 0xFE001000;
  905. while (colourLocations[idx] != 65536)
  906. {
  907. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  908. idx += 2;
  909. }
  910. ASSERT(!strcmp(str, "This is a strin{FE0010}g to test :D."));
  911. ASSERT(offset == 8);
  912. ASSERT(idx == 10);
  913. ASSERT(curColour == 0xFE001000);
  914. ASSERT(colourLocations[3] == 0x00000000 | _:e_TEXT_RENDER_COLOUR_LINE);
  915. ASSERT(colourLocations[4] == 6);
  916. ASSERT(colourLocations[6] == 10);
  917. }
  918. Test:TextR_DoOneColour7SCM()
  919. {
  920. state y_text_colour : y_text_colour_scm;
  921. new
  922. str[64] = "This is a string to test :D.",
  923. len = sizeof (str),
  924. offset = 0,
  925. colourLocations[] = {0,
  926. _:e_TEXT_RENDER_COLOUR_STAR | _:e_TEXT_RENDER_COLOUR_FADE, 5,
  927. _:e_TEXT_RENDER_COLOUR_LINE, 6,
  928. _:e_TEXT_RENDER_COLOUR_END | _:e_TEXT_RENDER_COLOUR_LINE, 10,
  929. _:e_TEXT_RENDER_COLOUR_END, 15,
  930. -1, 65536},
  931. idx = 2,
  932. curColour = 0,
  933. initialColour = 0xF4F4F400;
  934. while (colourLocations[idx] != 65536)
  935. {
  936. //printf("cc: %04x%04x", curColour >>> 16, curColour & 0xFFFF);
  937. offset += TextR_DoOneColour(str, len, offset, colourLocations, idx, curColour, initialColour);
  938. idx += 2;
  939. }
  940. //printf(str);
  941. ASSERT(!strcmp(str, "This {FEFEFE}is {F8F8F8}a string to test :D."));
  942. ASSERT(offset == 16);
  943. ASSERT(idx == 10);
  944. ASSERT(curColour == 0xF4F4F400);
  945. ASSERT(colourLocations[4] == 6);
  946. ASSERT(colourLocations[6] == 10);
  947. ASSERT(colourLocations[3] == 0xFCFCFC00 | _:e_TEXT_RENDER_COLOUR_LINE);
  948. ASSERT(colourLocations[5] == 0xF4F4F400 | _:e_TEXT_RENDER_COLOUR_LINE);
  949. }
  950. /*Test:TextR_FindLast()
  951. {
  952. ASSERT(TextR_FindLast("Hello", 1, " ") == -1);
  953. ASSERT(TextR_FindLast("Hello", 5, " ") == -1);
  954. ASSERT(TextR_FindLast("Hello", 55, " ") == -1);
  955. ASSERT(TextR_FindLast("Hello There", 1, " ") == -1);
  956. ASSERT(TextR_FindLast("Hello There", 5, " ") == -1);
  957. ASSERT(TextR_FindLast("Hello There", 55, " ") == 5);
  958. ASSERT(TextR_FindLast(" Hello There", 1, " ") == 0);
  959. ASSERT(TextR_FindLast(" Hello There", 5, " ") == 0);
  960. ASSERT(TextR_FindLast(" Hello There", 55, " ") == 6);
  961. ASSERT(TextR_FindLast("::::", 4, ":") == 3);
  962. ASSERT(TextR_FindLast("iii:", 4, ":") == 3);
  963. ASSERT(TextR_FindLast("i:i:", 4, ":") == 3);
  964. ASSERT(TextR_FindLast("i:i:", 4, ":") == 3);
  965. ASSERT(TextR_FindLast(":::::", 4, ":") == 3);
  966. ASSERT(TextR_FindLast(":::::::", 4, ":") == 3);
  967. ASSERT(TextR_FindLast(":::::::", 5, ":") == 4);
  968. ASSERT(TextR_FindLast(":::::::", 6, ":") == 5);
  969. ASSERT(TextR_FindLast(":::::::", 7, ":") == 6);
  970. ASSERT(TextR_FindLast(":::::::", 7, ":") == 6);
  971. }
  972. Test:TextR_RTrim()
  973. {
  974. ASSERT(TextR_RTrim("Hello ", 0, 8) == 5);
  975. ASSERT(TextR_RTrim("Hello ", 0, 7) == 5);
  976. ASSERT(TextR_RTrim("Hello ", 1, 8) == 5);
  977. ASSERT(TextR_RTrim("Hello ", 1, 7) == 5);
  978. ASSERT(TextR_RTrim("Hello ", 1, 5) == 5);
  979. ASSERT(TextR_RTrim("Hello ", 1, 4) == 4);
  980. ASSERT(TextR_RTrim("Hello ", 0, 4) == 4);
  981. ASSERT(TextR_RTrim("Hello", 0, 5) == 5);
  982. ASSERT(TextR_RTrim(" ", 0, 5) == 0);
  983. ASSERT(TextR_RTrim(" ", 0, 6) == 0);
  984. ASSERT(TextR_RTrim(" ", 1, 5) == 1);
  985. ASSERT(TextR_RTrim(" ", 1, 6) == 1);
  986. ASSERT(TextR_RTrim("1 ", 1, 6) == 1);
  987. ASSERT(TextR_RTrim("11 ", 1, 6) == 2);
  988. }*/
  989. Test:TextR_SkipChars()
  990. {
  991. state y_text_colour : y_text_colour_scm;
  992. ASSERT(TextR_SkipChars("", 0, 0) == 0);
  993. ASSERT(TextR_SkipChars("Hello World", 0, 1) == 1);
  994. ASSERT(TextR_SkipChars("Hello World", 5, 1) == 6);
  995. ASSERT(TextR_SkipChars("{112233}Hello World", 0, 3) == 11);
  996. ASSERT(TextR_SkipChars("{112233}H{112233}e{112233}llo World", 0, 3) == 27);
  997. ASSERT(TextR_SkipChars("{112233}H{112233}e{112233}llo World", 8, 3) == 27);
  998. ASSERT(TextR_SkipChars("{112233}H{112233}e{112233}llo World", 9, 3) == 28);
  999. }
  1000. Test:TextR_CountCharsFore()
  1001. {
  1002. state y_text_colour : y_text_colour_scm;
  1003. ASSERT(TextR_CountCharsFore("", 0) == 0);
  1004. ASSERT(TextR_CountCharsFore("{112233}", 0) == 0);
  1005. ASSERT(TextR_CountCharsFore("Hello", 0) == 5);
  1006. ASSERT(TextR_CountCharsFore("Hello There", 0) == 5);
  1007. ASSERT(TextR_CountCharsFore("{112233}Hello There", 0) == 5);
  1008. ASSERT(TextR_CountCharsFore("{xxyyzz}Hello There", 0) == 6);
  1009. ASSERT(TextR_CountCharsFore("Hello_There", 0) == 6);
  1010. ASSERT(TextR_CountCharsFore("{112233}Hello_There", 0) == 6);
  1011. ASSERT(TextR_CountCharsFore("He{112233}llo_There", 0) == 6);
  1012. ASSERT(TextR_CountCharsFore("He{112233}ll{112233}o_There", 0) == 6);
  1013. ASSERT(TextR_CountCharsFore("He{112233}ll{112233}o_{112233}There", 0) == 6);
  1014. ASSERT(TextR_CountCharsFore("{112233}H{112233}e{112233}l{112233}l{112233}o There", 0) == 5);
  1015. }
  1016. Test:TextR_CountCharsBack()
  1017. {
  1018. state y_text_colour : y_text_colour_scm;
  1019. new str[100], pos;
  1020. str = " ", pos = strlen(str);
  1021. ASSERT(TextR_CountCharsBack(str, pos) == 0);
  1022. ASSERT(pos == 16);
  1023. str = " {112233}x", pos = strlen(str);
  1024. ASSERT(TextR_CountCharsBack(str, pos) == 1);
  1025. ASSERT(pos == 16);
  1026. str = " Hello", pos = strlen(str);
  1027. ASSERT(TextR_CountCharsBack(str, pos) == 5);
  1028. ASSERT(pos == 16);
  1029. str = " Hello There", pos = strlen(str);
  1030. ASSERT(TextR_CountCharsBack(str, pos) == 5);
  1031. ASSERT(pos == 22);
  1032. str = " {112233}Hello There", pos = strlen(str);
  1033. ASSERT(TextR_CountCharsBack(str, pos) == 5);
  1034. ASSERT(pos == 30);
  1035. str = " {xxyyzz}Hello There", pos = strlen(str);
  1036. ASSERT(TextR_CountCharsBack(str, pos) == 5);
  1037. ASSERT(pos == 30);
  1038. str = " Hello_There", pos = strlen(str);
  1039. ASSERT(TextR_CountCharsBack(str, pos) == 10);
  1040. ASSERT(pos == 17);
  1041. str = " {112233}Hello_There", pos = strlen(str);
  1042. ASSERT(TextR_CountCharsBack(str, pos) == 10);
  1043. ASSERT(pos == 25);
  1044. str = " He{112233}llo_There", pos = strlen(str);
  1045. ASSERT(TextR_CountCharsBack(str, pos) == 10);
  1046. ASSERT(pos == 17);
  1047. str = " He{112233}ll{112233}o_There", pos = strlen(str);
  1048. ASSERT(TextR_CountCharsBack(str, pos) == 10);
  1049. ASSERT(pos == 17);
  1050. str = " He{112233}ll{112233}o_{112233}There", pos = strlen(str);
  1051. ASSERT(TextR_CountCharsBack(str, pos) == 10);
  1052. ASSERT(pos == 17);
  1053. str = " {112233}H{112233}e{112233}l{112233}l{112233}o There", pos = strlen(str);
  1054. ASSERT(TextR_CountCharsBack(str, pos) == 5);
  1055. ASSERT(pos == 62);
  1056. str = " {112233}H{112233}e{112233}l{112233}l{112233}o_There", pos = strlen(str);
  1057. ASSERT(TextR_CountCharsBack(str, pos) == 10);
  1058. ASSERT(pos == 25);
  1059. str = " Hello {xxyyzz}There", pos = strlen(str);
  1060. ASSERT(TextR_CountCharsBack(str, pos) == 10);
  1061. ASSERT(pos == 25);
  1062. str = " Hello {112233}There", pos = strlen(str);
  1063. ASSERT(TextR_CountCharsBack(str, pos) == 5);
  1064. ASSERT(pos == 22);
  1065. str = " Hello {112233}The{112233}re", pos = strlen(str);
  1066. ASSERT(TextR_CountCharsBack(str, pos) == 5);
  1067. ASSERT(pos == 22);
  1068. str = " Hello Th{112233}er{112233}e", pos = strlen(str);
  1069. ASSERT(TextR_CountCharsBack(str, pos) == 5);
  1070. ASSERT(pos == 22);
  1071. }
  1072. Test:TextR_LTrim()
  1073. {
  1074. ASSERT(TextR_LTrim("", 0) == 0);
  1075. ASSERT(TextR_LTrim("Hello", 0) == 0);
  1076. ASSERT(TextR_LTrim(" Hello", 0) == 1);
  1077. ASSERT(TextR_LTrim(" Hello", 1) == 1);
  1078. ASSERT(TextR_LTrim(" Hello", 0) == 4);
  1079. ASSERT(TextR_LTrim(" Hello", 2) == 4);
  1080. ASSERT(TextR_LTrim(" Hello", 4) == 4);
  1081. ASSERT(TextR_LTrim(" ", 0) == 5);
  1082. ASSERT(TextR_LTrim(" ", 5) == 5);
  1083. }
  1084. Test:TextR_RTrim()
  1085. {
  1086. ASSERT(TextR_RTrim("", 0) == 0);
  1087. ASSERT(TextR_RTrim("hi ", 4) == 2);
  1088. ASSERT(TextR_RTrim(" ", 4) == 0);
  1089. ASSERT(TextR_RTrim(" ", 2) == 0);
  1090. ASSERT(TextR_RTrim(" ", 2) == 0);
  1091. ASSERT(TextR_RTrim(" hi", 2) == 0);
  1092. ASSERT(TextR_RTrim(" hi", 4) == 4);
  1093. }
  1094. Test:TextR_GetSplitPoint0()
  1095. {
  1096. state y_text_colour : y_text_colour_scm;
  1097. new
  1098. str[64],
  1099. start,
  1100. end;
  1101. // Split falls in a space.
  1102. str = "Hello There";
  1103. TextR_GetSplitPoint(str, 5, end, start);
  1104. ASSERT(!strcmp(str, "Hello There"));
  1105. ASSERT(end == 5);
  1106. ASSERT(start == 6);
  1107. //
  1108. str = "Hello There";
  1109. TextR_GetSplitPoint(str, 5, end, start);
  1110. ASSERT(!strcmp(str, "Hello There"));
  1111. ASSERT(end == 5);
  1112. ASSERT(start == 9);
  1113. //
  1114. str = "Hello There";
  1115. TextR_GetSplitPoint(str, 6, end, start);
  1116. ASSERT(!strcmp(str, "Hello There"));
  1117. ASSERT(end == 5);
  1118. ASSERT(start == 9);
  1119. //
  1120. str = "Hello There";
  1121. TextR_GetSplitPoint(str, 7, end, start);
  1122. ASSERT(!strcmp(str, "Hello There"));
  1123. ASSERT(end == 5);
  1124. ASSERT(start == 9);
  1125. //
  1126. str = "Hello There";
  1127. TextR_GetSplitPoint(str, 9, end, start);
  1128. ASSERT(!strcmp(str, "Hello There"));
  1129. ASSERT(end == 5);
  1130. ASSERT(start == 9);
  1131. //
  1132. }
  1133. Test:TextR_GetSplitPoint1()
  1134. {
  1135. state y_text_colour : y_text_colour_scm;
  1136. new
  1137. str[64],
  1138. start,
  1139. end;
  1140. // Split falls in a colour.
  1141. str = "Hello {098765}There";
  1142. TextR_GetSplitPoint(str, 10, end, start);
  1143. ASSERT(!strcmp(str, "Hello {098765}There"));
  1144. ASSERT(end == 5);
  1145. ASSERT(start == 14);
  1146. //
  1147. str = "Hello {098765}There";
  1148. TextR_GetSplitPoint(str, 10, end, start);
  1149. ASSERT(!strcmp(str, "Hello {098765}There"));
  1150. ASSERT(end == 5);
  1151. ASSERT(start == 16);
  1152. //
  1153. str = "Hello {098765}There";
  1154. TextR_GetSplitPoint(str, 8, end, start);
  1155. ASSERT(!strcmp(str, "Hello {098765}There"));
  1156. ASSERT(end == 5);
  1157. ASSERT(start == 16);
  1158. //
  1159. str = "Hello {098765}There";
  1160. TextR_GetSplitPoint(str, 16, end, start);
  1161. ASSERT(!strcmp(str, "Hello {098765}There"));
  1162. ASSERT(end == 5);
  1163. ASSERT(start == 16);
  1164. //
  1165. str = "Hello {098765}There";
  1166. TextR_GetSplitPoint(str, 9, end, start);
  1167. ASSERT(!strcmp(str, "Hello {098765}There"));
  1168. ASSERT(end == 5);
  1169. ASSERT(start == 16);
  1170. //
  1171. str = "Hello {098765}There";
  1172. TextR_GetSplitPoint(str, 15, end, start);
  1173. ASSERT(!strcmp(str, "Hello {098765}There"));
  1174. ASSERT(end == 5);
  1175. ASSERT(start == 16);
  1176. //
  1177. str = "Hello {098765}There";
  1178. TextR_GetSplitPoint(str, 6, end, start);
  1179. ASSERT(!strcmp(str, "Hello {098765}There"));
  1180. ASSERT(end == 5);
  1181. ASSERT(start == 16);
  1182. //
  1183. str = "Hello {098765}There";
  1184. TextR_GetSplitPoint(str, 7, end, start);
  1185. ASSERT(!strcmp(str, "Hello {098765}There"));
  1186. ASSERT(end == 5);
  1187. ASSERT(start == 16);
  1188. //
  1189. str = "Hello {098765}There";
  1190. TextR_GetSplitPoint(str, 8, end, start);
  1191. ASSERT(!strcmp(str, "Hello {098765}There"));
  1192. ASSERT(end == 5);
  1193. ASSERT(start == 16);
  1194. //
  1195. }
  1196. Test:TextR_GetSplitPoint2()
  1197. {
  1198. state y_text_colour : y_text_colour_scm;
  1199. new
  1200. str[64],
  1201. start,
  1202. end;
  1203. // Split falls near the start of a word.
  1204. str = "Other Hello_There";
  1205. TextR_GetSplitPoint(str, 8, end, start);
  1206. ASSERT(!strcmp(str, "Other Hello_There"));
  1207. ASSERT(end == 6);
  1208. ASSERT(start == 6);
  1209. //
  1210. str = "Other Hello_There";
  1211. TextR_GetSplitPoint(str, 9, end, start);
  1212. ASSERT(!strcmp(str, "Other Hello_There"));
  1213. ASSERT(end == 6);
  1214. ASSERT(start == 6);
  1215. //
  1216. str = "Other Hello_There";
  1217. TextR_GetSplitPoint(str, 9, end, start);
  1218. ASSERT(!strcmp(str, "Other Hello_There"));
  1219. ASSERT(end == 6);
  1220. ASSERT(start == 6);
  1221. //
  1222. str = "Other Hello";
  1223. TextR_GetSplitPoint(str, 10, end, start);
  1224. ASSERT(!strcmp(str, "Other Hello"));
  1225. ASSERT(end == 6);
  1226. ASSERT(start == 6);
  1227. //
  1228. str = "Other Hello There";
  1229. TextR_GetSplitPoint(str, 10, end, start);
  1230. ASSERT(!strcmp(str, "Other Hello There"));
  1231. ASSERT(end == 6);
  1232. ASSERT(start == 6);
  1233. //
  1234. }
  1235. Test:TextR_GetSplitPoint3()
  1236. {
  1237. state y_text_colour : y_text_colour_scm;
  1238. new
  1239. str[64],
  1240. start,
  1241. end;
  1242. // Split falls near the middle of a word.
  1243. str = "Other Hello_There";
  1244. ASSERT(TextR_GetSplitPoint(str, 10, end, start) == 'l');
  1245. ASSERT(!strcmp(str, "Other Hel-o_There"));
  1246. ASSERT(end == 10);
  1247. ASSERT(start == 9);
  1248. //
  1249. str = "Other Hello_There_Very_Long";
  1250. ASSERT(TextR_GetSplitPoint(str, 10, end, start) == 'l');
  1251. ASSERT(!strcmp(str, "Other Hel-o_There_Very_Long"));
  1252. ASSERT(end == 10);
  1253. ASSERT(start == 9);
  1254. //
  1255. str = "Other Hello_There_Very_Long";
  1256. ASSERT(TextR_GetSplitPoint(str, 12, end, start) == '_');
  1257. ASSERT(!strcmp(str, "Other Hello-There_Very_Long"));
  1258. ASSERT(end == 12);
  1259. ASSERT(start == 11);
  1260. //
  1261. str = "Other Hello_There_Very_Long";
  1262. ASSERT(TextR_GetSplitPoint(str, 13, end, start) == 'T');
  1263. ASSERT(!strcmp(str, "Other Hello_-here_Very_Long"));
  1264. ASSERT(end == 13);
  1265. ASSERT(start == 12);
  1266. //
  1267. str = "Other Hello_There_Very_Long";
  1268. ASSERT(TextR_GetSplitPoint(str, 24, end, start) == 'r');
  1269. ASSERT(!strcmp(str, "Other Hello_There_Ve-y_Long"));
  1270. ASSERT(end == 21);
  1271. ASSERT(start == 20);
  1272. //
  1273. }
  1274. Test:TextR_GetSplitPoint4()
  1275. {
  1276. state y_text_colour : y_text_colour_scm;
  1277. new
  1278. str[64],
  1279. start,
  1280. end;
  1281. // Split has colours.
  1282. str = "Other He{654321}llo";
  1283. TextR_GetSplitPoint(str, 8, end, start);
  1284. ASSERT(!strcmp(str, "Other He{654321}llo"));
  1285. ASSERT(end == 6);
  1286. ASSERT(start == 6);
  1287. //
  1288. str = "Other He{654321}llo";
  1289. TextR_GetSplitPoint(str, 16, end, start);
  1290. ASSERT(!strcmp(str, "Other He{654321}llo"));
  1291. ASSERT(end == 6);
  1292. ASSERT(start == 6);
  1293. //
  1294. str = "Other He{654321}llo";
  1295. TextR_GetSplitPoint(str, 17, end, start);
  1296. ASSERT(!strcmp(str, "Other He{654321}llo"));
  1297. ASSERT(end == 6);
  1298. ASSERT(start == 6);
  1299. //
  1300. str = "Other He{654321}lloo";
  1301. TextR_GetSplitPoint(str, 17, end, start);
  1302. ASSERT(!strcmp(str, "Other He{654321}lloo"));
  1303. ASSERT(end == 6);
  1304. ASSERT(start == 6);
  1305. //
  1306. str = "Other He{654321}lloo0";
  1307. TextR_GetSplitPoint(str, 17, end, start);
  1308. ASSERT(!strcmp(str, "Other He{654321}lloo0"));
  1309. ASSERT(end == 6);
  1310. ASSERT(start == 6);
  1311. //
  1312. str = "Other He{654321}lloo0";
  1313. //TextR_GetSplitPoint(str, 18, end, start);
  1314. ASSERT(TextR_GetSplitPoint(str, 18, end, start) == 'l');
  1315. ASSERT(!strcmp(str, "Other He{654321}l-oo0"));
  1316. ASSERT(end == 18);
  1317. ASSERT(start == 17);
  1318. //
  1319. str = "Other He{654321}lloo_L{567890}ong";
  1320. //TextR_GetSplitPoint(str, 21, end, start);
  1321. ASSERT(TextR_GetSplitPoint(str, 21, end, start) == 'o');
  1322. ASSERT(!strcmp(str, "Other He{654321}llo-_L{567890}ong"));
  1323. ASSERT(end == 20);
  1324. ASSERT(start == 19);
  1325. //
  1326. }
  1327. Test:TextR_GetSplitPoint5()
  1328. {
  1329. state y_text_colour : y_text_colour_scm;
  1330. new
  1331. str[64],
  1332. start,
  1333. end;
  1334. // Split has many colours.
  1335. str = "Other {654321}H{654321}e{654321}l{654321}l{654321}o";
  1336. TextR_GetSplitPoint(str, 38, end, start);
  1337. ASSERT(!strcmp(str, "Other {654321}H{654321}e{654321}l{654321}l{654321}o"));
  1338. ASSERT(end == 6);
  1339. ASSERT(start == 14);
  1340. //
  1341. str = "Other {654321}H{654321}e{654321}l{654321}l{654321}o{654321}2";
  1342. //TextR_GetSplitPoint(str, 42, end, start);
  1343. ASSERT(TextR_GetSplitPoint(str, 42, end, start) == '{');
  1344. ASSERT(!strcmp(str, "Other {654321}H{654321}e{654321}l-654321}l{654321}o{654321}2"));
  1345. ASSERT(end == 34);
  1346. ASSERT(start == 41);
  1347. //
  1348. }
  1349. Test:TextR_IsColour()
  1350. {
  1351. state y_text_colour : y_text_colour_scm;
  1352. new str[16];
  1353. ASSERT(TextR_IsColour("{123456}"));
  1354. ASSERT(TextR_IsColour("{AABBCC}"));
  1355. ASSERT(TextR_IsColour("{0A0B04}"));
  1356. ASSERT(!TextR_IsColour("{12345}"));
  1357. ASSERT(!TextR_IsColour("{00000G}"));
  1358. ASSERT(!TextR_IsColour("{00000#}"));
  1359. ASSERT(!TextR_IsColour("{@12345}"));
  1360. str = "{{12345}"; // Doesn't work in "ASSERT".
  1361. ASSERT(!TextR_IsColour(str));
  1362. ASSERT(!TextR_IsColour("{2212345}"));
  1363. ASSERT(!TextR_IsColour("{0KBEEF}"));
  1364. ASSERT(TextR_IsColour("{BDBEEF}"));
  1365. str = "BDBEEF}";
  1366. ASSERT(!TextR_IsColour(str));
  1367. str = "{BDBEEF";
  1368. ASSERT(!TextR_IsColour(str));
  1369. ASSERT(!TextR_IsColour("BDBEEF"));
  1370. ASSERT(!TextR_IsColour(""));
  1371. }
  1372. /*
  1373. Test:zzz_TextR_RunPhase2_0()
  1374. {
  1375. state y_text_colour : y_text_colour_scm;
  1376. new
  1377. colourLocations[] = {0xFEFEFE00,
  1378. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE, 10,
  1379. 0x22222222, 20,
  1380. 0, 65536},
  1381. str[128] = "Hello there, how are you? This is quite long";
  1382. TextR_RunPhase2(str, sizeof (str), colourLocations);
  1383. //print(str);
  1384. //printf("%d %d", colourLocations[2], colourLocations[4]);
  1385. ASSERT(colourLocations[2] == 10);
  1386. ASSERT(colourLocations[4] == 84);
  1387. ASSERT(!strcmp(str, "Hello ther{AAAAAA}e{9C9C9C}, {808080}h{727272}o{666666}w {4A4A4A}a{3C3C3C}r{2E2E2E}e {222222}you? This is quite long"));
  1388. }
  1389. */
  1390. static stock
  1391. YSI_g_sTextTest,
  1392. YSI_g_sTextColourTest[10],
  1393. YSI_g_sTextOutputTest[10][256];
  1394. _Y_TEXT_STATIC stock TextR_DoOutput(colour, str[], start, end) <y_text_output : y_text_output_test>
  1395. {
  1396. // printf("%d\n%06x", YSI_g_sTextTest, YSI_g_sTextColourTest[YSI_g_sTextTest]);
  1397. // printf("%06x:\n\"%.*s\"", colour >>> 8, end - start, str[start]);
  1398. // printf("\"%s\"", YSI_g_sTextOutputTest[YSI_g_sTextTest]);
  1399. ASSERT(!strcmp(YSI_g_sTextOutputTest[YSI_g_sTextTest], str[start], false, end - start));
  1400. ASSERT(colour >>> 8 == YSI_g_sTextColourTest[YSI_g_sTextTest]);
  1401. return ++YSI_g_sTextTest;
  1402. }
  1403. Test:zzz_TextR_RunPhase2_1()
  1404. {
  1405. state y_text_colour : y_text_colour_scm;
  1406. state y_text_output : y_text_output_test;
  1407. new
  1408. colourLocations[] = {0xFEFEFE00,
  1409. 0xAAAAAAAA | _:e_TEXT_RENDER_COLOUR_FADE, 10,
  1410. 0x22222222 | _:e_TEXT_RENDER_COLOUR_LINE, 20,
  1411. 0, 65536},
  1412. str[128] = "Hello there, how are you? This is quite long";
  1413. /*TextR_RunPhase2(str, sizeof (str), colourLocations);
  1414. //print(str);
  1415. //printf("%d %d", colourLocations[2], colourLocations[4]);
  1416. ASSERT(colourLocations[2] == 10);
  1417. ASSERT(colourLocations[4] == 84);
  1418. ASSERT(!strcmp(str, "Hello ther{AAAAAA}e{9C9C9C}, {808080}h{727272}o{666666}w {4A4A4A}a{3C3C3C}r{2E2E2E}e you? This is quite long"));*/
  1419. // Do phase 3.
  1420. YSI_g_sTextTest = 0;
  1421. YSI_g_sTextColourTest[0] = 0xFEFEFE;
  1422. YSI_g_sTextOutputTest[0] = "Hello ther{AAAAAA}e{9C9C9C}, {808080}h{727272}o{666666}w {4A4A4A}a{3C3C3C}r{2E2E2E}e";
  1423. YSI_g_sTextColourTest[1] = 0x222222;
  1424. YSI_g_sTextOutputTest[1] = " you? This is quite long";
  1425. TextR_RunPhase3(str, sizeof (str), colourLocations);
  1426. ASSERT(colourLocations[2] == 10);
  1427. ASSERT(colourLocations[4] == 84);
  1428. ASSERT(!strcmp(str, "Hello ther{AAAAAA}e{9C9C9C}, {808080}h{727272}o{666666}w {4A4A4A}a{3C3C3C}r{2E2E2E}e you? This is quite long"));
  1429. ASSERT(YSI_g_sTextTest == 2);
  1430. }
  1431. Test:zzz_TextR_RunPhase3_0()
  1432. {
  1433. state y_text_colour : y_text_colour_scm;
  1434. state y_text_output : y_text_output_test;
  1435. new
  1436. colourLocations[] = {0x02040608,
  1437. 0x000000FE | _:e_TEXT_RENDER_COLOUR_FADE, 40,
  1438. 0xFEFEFE00 | _:e_TEXT_RENDER_COLOUR_LINE, 200,
  1439. 0x14284256 | _:e_TEXT_RENDER_COLOUR_FADE, 210,
  1440. 0x9898ACEA | _:e_TEXT_RENDER_COLOUR_LINE, 220,
  1441. 0, 65536};
  1442. static
  1443. str[YSI_MAX_STRING * 80] = "Hello there, how are you? This is quite long, but this one is even longer, I don't really know what I'm saying - I'm just trying to make a very long string... Even to this point, it wasn't QUITE long enough, but now it is.";
  1444. //DebugLevel(3);
  1445. //printf("1");
  1446. /*TextR_RunPhase2(str, sizeof (str), colourLocations);
  1447. //printf("2");
  1448. //print(str);
  1449. //printf("%d %d", colourLocations[2], colourLocations[4]);
  1450. //printf("%d %d", colourLocations[6], colourLocations[8]);
  1451. ASSERT(colourLocations[2] == 40);
  1452. ASSERT(colourLocations[4] == 1064);
  1453. ASSERT(colourLocations[6] == 1074);
  1454. ASSERT(colourLocations[8] == 1148);*/
  1455. // Do phase 3.
  1456. YSI_g_sTextTest = 0;
  1457. //DebugLevel(0);
  1458. YSI_g_sTextOutputTest[0] = "Hello there, how are you? This is quite {000000}l{020202}o{040404}n{060606}g, {0A0A0A}b{0C0C0C}u{0E0E0E}t {101010}t{121212}h{141414}i{161616}s" ;
  1459. YSI_g_sTextOutputTest[1] = "o{1A1A1A}n{1C1C1C}e {1E1E1E}i{202020}s {242424}e{262626}ve{282828}n {2C2C2C}l{2E2E2E}on{303030}g{323232}e{343434}r, {383838}I " ;
  1460. YSI_g_sTextOutputTest[2] = "do{3E3E3E}n{404040}'{424242}t {444444}r{464646}e{484848}a{4A4A4A}l{4C4C4C}ly {505050}k{525252}n{545454}ow {585858}w{5A5A5A}h{5C5C5C}at " ;
  1461. YSI_g_sTextOutputTest[3] = "I{626262}'{646464}m {666666}s{686868}a{6A6A6A}yi{6C6C6C}n{6E6E6E}g {727272}- {747474}I{767676}'{787878}m {7A7A7A}j{7C7C7C}u{7E7E7E}s{808080}t" ;
  1462. YSI_g_sTextOutputTest[4] = "t{848484}r{868686}y{888888}i{8A8A8A}ng {8E8E8E}t{909090}o {929292}m{949494}a{969696}k{989898}e {9A9A9A}a {9E9E9E}v{A0A0A0}er{A2A2A2}y " ;
  1463. YSI_g_sTextOutputTest[5] = "l{A8A8A8}on{AAAAAA}g {AEAEAE}s{B0B0B0}tr{B2B2B2}i{B4B4B4}n{B6B6B6}g{B8B8B8}..{BABABA}. {C0C0C0}Ev{C2C2C2}e{C4C4C4}n {C8C8C8}to " ;
  1464. YSI_g_sTextOutputTest[6] = "t{CECECE}hi{D0D0D0}s {D4D4D4}p{D6D6D6}oi{D8D8D8}n{DADADA}t{DCDCDC}, {DEDEDE}i{E0E0E0}t {E4E4E4}w{E6E6E6}as{E8E8E8}n{EAEAEA}'{ECECEC}t " ;
  1465. YSI_g_sTextOutputTest[7] = "Q{F0F0F0}U{F2F2F2}I{F4F4F4}T{F6F6F6}E {F8F8F8}l{FAFAFA}o{FCFCFC}n" ;
  1466. YSI_g_sTextOutputTest[8] = "g enough, {142842}b{20324C}u{2E3E56}t {48546C}n{566076}o{626A80}w {7C8096}i{8A8CA0}t" ;
  1467. YSI_g_sTextOutputTest[9] = " is." ;
  1468. YSI_g_sTextColourTest[0] = 0x020406;
  1469. YSI_g_sTextColourTest[1] = 0x181818;
  1470. YSI_g_sTextColourTest[2] = 0x3C3C3C;
  1471. YSI_g_sTextColourTest[3] = 0x606060;
  1472. YSI_g_sTextColourTest[4] = 0x828282;
  1473. YSI_g_sTextColourTest[5] = 0xA6A6A6;
  1474. YSI_g_sTextColourTest[6] = 0xCCCCCC;
  1475. YSI_g_sTextColourTest[7] = 0xEEEEEE;
  1476. YSI_g_sTextColourTest[8] = 0xFEFEFE;
  1477. YSI_g_sTextColourTest[9] = 0x9898AC;
  1478. TextR_RunPhase3(str, sizeof (str), colourLocations);
  1479. //printf("3");
  1480. ASSERT(YSI_g_sTextTest == 10);
  1481. ASSERT(colourLocations[2] == 40);
  1482. ASSERT(colourLocations[4] == 1064);
  1483. ASSERT(colourLocations[6] == 1074);
  1484. ASSERT(colourLocations[8] == 1148);
  1485. //ASSERT(!strcmp(str, cmp));
  1486. }
  1487. Test:zzz_TextR_RunPhase3_1()
  1488. {
  1489. state y_text_colour : y_text_colour_scm;
  1490. state y_text_output : y_text_output_test;
  1491. new
  1492. colourLocations[] = {0x02040608,
  1493. 0x000000FE | _:e_TEXT_RENDER_COLOUR_FADE, 40,
  1494. 0xFEFEFE00 | _:e_TEXT_RENDER_COLOUR_LINE, 200,
  1495. 0x14284256 | _:e_TEXT_RENDER_COLOUR_FADE, 210,
  1496. 0x9898ACEA | _:e_TEXT_RENDER_COLOUR_LINE, 220,
  1497. 0, 65536};
  1498. static
  1499. str[YSI_MAX_STRING * 80] = "Hello there, how are you? This is quite long, but thisoneis even longer, I don't really know what I'm saying - I'm just trying to make a very long string... Even to this point, it wasn't QUITE long enough, but now it is.";
  1500. //DebugLevel(3);
  1501. //printf("1");
  1502. /*TextR_RunPhase2(str, sizeof (str), colourLocations);
  1503. //printf("2");
  1504. //print(str);
  1505. // printf("%d %d", colourLocations[2], colourLocations[4]);
  1506. // printf("%d %d", colourLocations[6], colourLocations[8]);
  1507. ASSERT(colourLocations[2] == 40);
  1508. ASSERT(colourLocations[4] == 1056);
  1509. ASSERT(colourLocations[6] == 1066);
  1510. ASSERT(colourLocations[8] == 1140);*/
  1511. // Do phase 3.
  1512. YSI_g_sTextTest = 0;
  1513. //DebugLevel(0);
  1514. YSI_g_sTextOutputTest[0] = "Hello there, how are you? This is quite {000000}l{020202}o{040404}n{060606}g, {0A0A0A}b{0C0C0C}u{0E0E0E}t {101010}t{121212}h{141414}i{161616}s-" ;
  1515. YSI_g_sTextOutputTest[1] = "o{181818}n{1A1A1A}e{1C1C1C}i{1E1E1E}s {242424}e{262626}ve{282828}n {2C2C2C}l{2E2E2E}on{303030}g{323232}e{343434}r, {383838}I " ;
  1516. YSI_g_sTextOutputTest[2] = "do{3E3E3E}n{404040}'{424242}t {444444}r{464646}e{484848}a{4A4A4A}l{4C4C4C}ly {505050}k{525252}n{545454}ow {585858}w{5A5A5A}h{5C5C5C}at " ;
  1517. YSI_g_sTextOutputTest[3] = "I{626262}'{646464}m {666666}s{686868}a{6A6A6A}yi{6C6C6C}n{6E6E6E}g {727272}- {747474}I{767676}'{787878}m {7A7A7A}j{7C7C7C}u{7E7E7E}s{808080}t" ;
  1518. YSI_g_sTextOutputTest[4] = "t{848484}r{868686}y{888888}i{8A8A8A}ng {8E8E8E}t{909090}o {929292}m{949494}a{969696}k{989898}e {9A9A9A}a {9E9E9E}v{A0A0A0}er{A2A2A2}y " ;
  1519. YSI_g_sTextOutputTest[5] = "l{A8A8A8}on{AAAAAA}g {AEAEAE}s{B0B0B0}tr{B2B2B2}i{B4B4B4}n{B6B6B6}g{B8B8B8}..{BABABA}. {C0C0C0}Ev{C2C2C2}e{C4C4C4}n {C8C8C8}to " ;
  1520. YSI_g_sTextOutputTest[6] = "t{CECECE}hi{D0D0D0}s {D4D4D4}p{D6D6D6}oi{D8D8D8}n{DADADA}t{DCDCDC}, {DEDEDE}i{E0E0E0}t {E4E4E4}w{E6E6E6}as{E8E8E8}n{EAEAEA}'{ECECEC}t " ;
  1521. YSI_g_sTextOutputTest[7] = "Q{F0F0F0}U{F2F2F2}I{F4F4F4}T{F6F6F6}E {F8F8F8}l{FAFAFA}o{FCFCFC}n" ;
  1522. YSI_g_sTextOutputTest[8] = "g enough, {142842}b{20324C}u{2E3E56}t {48546C}n{566076}o{626A80}w {7C8096}i{8A8CA0}t" ;
  1523. YSI_g_sTextOutputTest[9] = " is." ;
  1524. YSI_g_sTextColourTest[0] = 0x020406;
  1525. YSI_g_sTextColourTest[1] = 0x161616;
  1526. YSI_g_sTextColourTest[2] = 0x3C3C3C;
  1527. YSI_g_sTextColourTest[3] = 0x606060;
  1528. YSI_g_sTextColourTest[4] = 0x828282;
  1529. YSI_g_sTextColourTest[5] = 0xA6A6A6;
  1530. YSI_g_sTextColourTest[6] = 0xCCCCCC;
  1531. YSI_g_sTextColourTest[7] = 0xEEEEEE;
  1532. YSI_g_sTextColourTest[8] = 0xFEFEFE;
  1533. YSI_g_sTextColourTest[9] = 0x9898AC;
  1534. TextR_RunPhase3(str, sizeof (str), colourLocations);
  1535. //printf("3");
  1536. ASSERT(YSI_g_sTextTest == 10);
  1537. ASSERT(colourLocations[2] == 40);
  1538. ASSERT(colourLocations[4] == 1056);
  1539. ASSERT(colourLocations[6] == 1066);
  1540. ASSERT(colourLocations[8] == 1140);
  1541. //ASSERT(!strcmp(str, cmp));
  1542. }