test.pp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  1. {$mode delphi}
  2. {$codepage utf-8}
  3. {$namespace org.freepascal.test}
  4. {$j-}
  5. Unit test;
  6. interface
  7. const
  8. unitintconst = 3;
  9. unitfloatconst = 2.0;
  10. unitdoubleconst = 0.1;
  11. const
  12. tcl: longint = 4;
  13. type
  14. trec = record
  15. a,b,c,d,e: longint;
  16. end;
  17. const
  18. tcrec: trec = (a:1;b:2;c:3;d:4;e:5);
  19. type
  20. TMyClass = class
  21. const
  22. classintconst = 4;
  23. classfloatconst = 3.0;
  24. classdoubleconst = 0.3;
  25. classtcstringconst: unicodestring = 'abcdef';
  26. class var
  27. rec: trec;
  28. var
  29. intfield: jint;
  30. staticbytefield: jbyte; static;
  31. constructor create; overload;
  32. constructor create(l: longint);overload;
  33. constructor create(l1, l2: longint);overload;
  34. function sub(a1, a2: longint): longint;
  35. function test(l1, l2: longint): longint;
  36. class function staticmul3(l: longint): longint; static;
  37. procedure longboolobj(l: jlong; b: boolean; obj: tobject);
  38. procedure setintfield(l: jint);
  39. function getintfield: jint;
  40. property propintfield: jint read getintfield write setintfield;
  41. procedure setstaticbytefield(b: byte);
  42. function getstaticbytefield: byte;
  43. class procedure setstaticbytefieldstatic(b: byte); static;
  44. class function getstaticbytefieldstatic: byte; static;
  45. class procedure settestglobal(l: longint); static;
  46. class function gettestglobal: longint; static;
  47. end;
  48. tisinterface = interface
  49. end;
  50. tisclassbase = class
  51. procedure abstr; virtual; abstract;
  52. end;
  53. tisclassbase2 = class(tisclassbase)
  54. end;
  55. tisclass1 = class(tisclassbase2)
  56. type
  57. tisclass1nested = class(tisinterface)
  58. var
  59. anonrec: record c: char; end;
  60. type
  61. tisclass1nestedl2 = class
  62. anonrec: record l: longint; end;
  63. constructor create;
  64. function testl2: jint;
  65. end;
  66. constructor create;
  67. function testl1: jint;
  68. end;
  69. constructor create;
  70. procedure abstr; override;
  71. end;
  72. tisclass1ref = class of tisclass1;
  73. type
  74. tnestrec = record
  75. r: trec;
  76. arr: array[3..4] of byte;
  77. end;
  78. const
  79. tcnestrec: tnestrec = (r:(a:1;b:2;c:3;d:4;e:5);arr:(7,6));
  80. var
  81. anonrec: record s: string; end;
  82. function testset: jint;
  83. function testloop: longint;
  84. function testfloat: jint;
  85. function testcnvint1: longint;
  86. function testint2real: longint;
  87. function TestCmpListOneShort: longint;
  88. function TestCmpListTwoShort: longint;
  89. function TestCmpListOneWord: longint;
  90. function TestCmpListTwoWord: longint;
  91. function TestCmpListOneInt64: longint;
  92. function TestCmpListTwoInt64: longint;
  93. function TestCmpListThreeInt64: longint;
  94. function TestCmpListRangesOneShort: longint;
  95. function TestCmpListRangesTwoShort: longint;
  96. function TestCmpListRangesOneWord: longint;
  97. function TestCmpListRangesTwoWord: longint;
  98. function TestCmpListRangesThreeWord: longint;
  99. function TestCmpListRangesOneInt64: longint;
  100. function TestCmpListRangesTwoInt64: longint;
  101. function testsqr: longint;
  102. function testtrunc: longint;
  103. function testdynarr: longint;
  104. function testdynarr2: longint;
  105. function testbitcastintfloat: jint;
  106. function testis: longint;
  107. function testneg: longint;
  108. function testtry1: longint;
  109. function testtry2: longint;
  110. function testtryfinally1: longint;
  111. function testtryfinally2: longint;
  112. function testtryfinally3: longint;
  113. function testsmallarr1: longint;
  114. function testopenarr1: longint;
  115. function testopenarr2: longint;
  116. function testopenarr3: longint;
  117. function testopendynarr: longint;
  118. function testsmallarr2: longint;
  119. function testsmallarr3: longint;
  120. function testsmallarr4: longint;
  121. function testrec1: longint;
  122. function testopenarr1rec: longint;
  123. function testrec2: longint;
  124. function testunicodestring: JLString;
  125. function testunicodestring2: JLString;
  126. function testunicodestring3(a: unicodestring): unicodestring;
  127. function testunicodestring4(a: unicodestring): unicodestring;
  128. function testunicodestring5: unicodestring;
  129. function testunicodestring6: unicodestring;
  130. function testunicodestring7: unicodestring;
  131. procedure main(const args: array of string);
  132. var
  133. myrec: trec;
  134. implementation
  135. uses
  136. {$ifdef java}jdk15{$else}androidr14{$endif};
  137. { package visibility }
  138. var
  139. testglobal: jint;
  140. var
  141. funkyl: longint;
  142. function funky: longint;
  143. begin
  144. result:=funkyl;
  145. inc(funkyl);
  146. end;
  147. function testset: jint;
  148. var
  149. s,s2: set of 0..31;
  150. c1, c2: cardinal;
  151. const
  152. exit1: jint = 1;
  153. begin
  154. result:=0;
  155. s:=[3..6];
  156. s:=s+[10..20];
  157. if not([3..4]<=s) then
  158. exit(exit1);
  159. s:=s-[15..20];
  160. s2:=[15..20];
  161. if s2<=s then
  162. exit(2);
  163. s:=s+s2;
  164. if not(s2<=s) then
  165. exit(3);
  166. if s<=s2 then
  167. exit(4);
  168. c1:=1234;
  169. c2:=c1 mod 5;
  170. if c2<>4 then
  171. exit(5);
  172. end;
  173. function testloop: longint;
  174. var
  175. i,j: longint;
  176. const
  177. exit1: jint = 1;
  178. begin
  179. result:=0;
  180. i:=0;
  181. while i<10 do
  182. i:=i+1;
  183. if i<>10 then
  184. exit(exit1);
  185. i:=0;
  186. repeat
  187. i:=i+5;
  188. until i=20;
  189. if (i<20) or
  190. (i>20) then
  191. exit(2);
  192. j:=0;
  193. for i:=1 to 10 do
  194. j:=j+i;
  195. i:=10;
  196. if (j<(i*(i+1) div 2)) or
  197. (j>(i*(i+1) div 2)) then
  198. exit(3);
  199. end;
  200. function testfloat: jint;
  201. var
  202. s1, s2: single;
  203. d1, d2: double;
  204. begin
  205. result:=0;
  206. s1:=0.5;
  207. s1:=s1+1.5;
  208. s2:=2.0;
  209. if (s1 < s2) or
  210. (s1 > s2) or
  211. (s1 <> s2) then
  212. exit(1);
  213. s1:=s1+s2;
  214. if s1<>4.0 then
  215. exit(2);
  216. s1:=s1-s2;
  217. if s1<>s2 then
  218. exit(3);
  219. s1:=s1*s2;
  220. if s1<>4.0 then
  221. exit(4);
  222. s1:=s1/s2;
  223. if s1<>s2 then
  224. exit(5);
  225. d1:=0.5;
  226. d1:=d1+1.5;
  227. d2:=2.0;
  228. if (d1 < d2) or
  229. (d1 > d2) or
  230. (d1 <> d2) then
  231. exit(6);
  232. d1:=d1+d2;
  233. if d1<>4.0 then
  234. exit(7);
  235. d1:=d1-d2;
  236. if d1<>d2 then
  237. exit(8);
  238. d1:=d1*d2;
  239. if d1<>4.0 then
  240. exit(9);
  241. d1:=d1/d2;
  242. if d1<>d2 then
  243. exit(10);
  244. end;
  245. function testcnvint1: longint;
  246. var
  247. tobyte : byte;
  248. toword : word;
  249. tolong : longint;
  250. {$ifndef tp}
  251. toint64 : int64;
  252. {$endif}
  253. b1 : boolean;
  254. bb1 : bytebool;
  255. wb1 : wordbool;
  256. lb1 : longbool;
  257. b2 : boolean;
  258. bb2 : bytebool;
  259. wb2 : wordbool;
  260. lb2 : longbool;
  261. begin
  262. result:=0;
  263. { left : LOC_REGISTER }
  264. { from : LOC_REFERENCE/LOC_REGISTER }
  265. b1 := TRUE;
  266. tobyte := byte(b1);
  267. if tobyte <> 1 then
  268. exit(1);
  269. b1 := FALSE;
  270. tobyte := byte(b1);
  271. if tobyte <> 0 then
  272. exit(2);
  273. b1 := TRUE;
  274. toword := word(b1);
  275. if toword <> 1 then
  276. exit(3);
  277. b1 := FALSE;
  278. toword := word(b1);
  279. if toword <> 0 then
  280. exit(4);
  281. b1 := TRUE;
  282. tolong := longint(b1);
  283. if tolong <> 1 then
  284. exit(5);
  285. b1 := FALSE;
  286. tolong := longint(b1);
  287. if tolong <> 0 then
  288. exit(6);
  289. bb1 := TRUE;
  290. tobyte := byte(bb1);
  291. if tobyte <> 255 then
  292. exit(7);
  293. bb1 := FALSE;
  294. tobyte := byte(bb1);
  295. if tobyte <> 0 then
  296. exit(8);
  297. bb1 := TRUE;
  298. toword := word(bb1);
  299. if toword <> 65535 then
  300. exit(9);
  301. bb1 := FALSE;
  302. toword := word(bb1);
  303. if toword <> 0 then
  304. exit(10);
  305. bb1 := TRUE;
  306. tolong := longint(bb1);
  307. if tolong <> -1 then
  308. exit(11);
  309. bb1 := FALSE;
  310. tolong := longint(bb1);
  311. if tolong <> 0 then
  312. exit(12);
  313. wb1 := TRUE;
  314. tobyte := byte(wb1);
  315. if tobyte <> 255 then
  316. exit(13);
  317. wb1 := FALSE;
  318. tobyte := byte(wb1);
  319. if tobyte <> 0 then
  320. exit(14);
  321. wb1 := TRUE;
  322. toword := word(wb1);
  323. if toword <> 65535 then
  324. exit(15);
  325. wb1 := FALSE;
  326. toword := word(wb1);
  327. if toword <> 0 then
  328. exit(16);
  329. wb1 := TRUE;
  330. tolong := longint(wb1);
  331. if tolong <> -1 then
  332. exit(17);
  333. wb1 := FALSE;
  334. tolong := longint(wb1);
  335. if tolong <> 0 then
  336. exit(18);
  337. {$ifndef tp}
  338. b1 := TRUE;
  339. toint64 :=int64(b1);
  340. if toint64 <> 1 then
  341. exit(19);
  342. b1 := FALSE;
  343. toint64 :=int64(b1);
  344. if toint64 <> 0 then
  345. exit(20);
  346. bb1 := TRUE;
  347. toint64 :=int64(bb1);
  348. if toint64 <> -1 then
  349. exit(21);
  350. bb1 := FALSE;
  351. toint64 :=int64(bb1);
  352. if toint64 <> 0 then
  353. exit(22);
  354. wb1 := TRUE;
  355. toint64 :=int64(wb1);
  356. if toint64 <> -1 then
  357. exit(23);
  358. wb1 := FALSE;
  359. toint64 :=int64(wb1);
  360. if toint64 <> 0 then
  361. exit(24);
  362. {$endif}
  363. lb1 := TRUE;
  364. tobyte := byte(lb1);
  365. if tobyte <> 255 then
  366. exit(25);
  367. lb1 := FALSE;
  368. tobyte := byte(lb1);
  369. if tobyte <> 0 then
  370. exit(26);
  371. lb1 := TRUE;
  372. toword := word(lb1);
  373. if toword <> 65535 then
  374. exit(27);
  375. lb1 := FALSE;
  376. toword := word(lb1);
  377. if toword <> 0 then
  378. exit(28);
  379. lb1 := TRUE;
  380. tolong := longint(lb1);
  381. if tolong <> -1 then
  382. exit(29);
  383. lb1 := FALSE;
  384. tolong := longint(lb1);
  385. if tolong <> 0 then
  386. exit(30);
  387. { left : LOC_REGISTER }
  388. { from : LOC_REFERENCE }
  389. wb1 := TRUE;
  390. b2 := wb1;
  391. if not b2 then
  392. exit(31);
  393. wb1 := FALSE;
  394. b2 := wb1;
  395. if b2 then
  396. exit(32);
  397. lb1 := TRUE;
  398. b2 := lb1;
  399. if not b2 then
  400. exit(33);
  401. lb1 := FALSE;
  402. b2 := lb1;
  403. if b2 then
  404. exit(34);
  405. wb1 := TRUE;
  406. bb2 := wb1;
  407. if not bb2 then
  408. exit(35);
  409. wb1 := FALSE;
  410. bb2 := wb1;
  411. if bb2 then
  412. exit(36);
  413. lb1 := TRUE;
  414. bb2 := lb1;
  415. if not bb2 then
  416. exit(37);
  417. lb1 := FALSE;
  418. bb2 := lb1;
  419. if bb2 then
  420. exit(38);
  421. b1 := TRUE;
  422. lb2 := b1;
  423. if not lb2 then
  424. exit(39);
  425. b1 := FALSE;
  426. lb2 := b1;
  427. if lb2 then
  428. exit(40);
  429. bb1 := TRUE;
  430. lb2 := bb1;
  431. if not lb2 then
  432. exit(41);
  433. bb1 := FALSE;
  434. lb2 := bb1;
  435. if lb2 then
  436. exit(42);
  437. { left : LOC_REGISTER }
  438. { from : LOC_JUMP }
  439. toword := 0;
  440. tobyte := 1;
  441. tobyte:=byte(toword > tobyte);
  442. if tobyte <> 0 then
  443. exit(43);
  444. toword := 2;
  445. tobyte := 1;
  446. tobyte:=byte(toword > tobyte);
  447. if tobyte <> 1 then
  448. exit(44);
  449. toword := 0;
  450. tobyte := 1;
  451. toword:=word(toword > tobyte);
  452. if toword <> 0 then
  453. exit(45);
  454. toword := 2;
  455. tobyte := 1;
  456. toword:=word(toword > tobyte);
  457. if toword <> 1 then
  458. exit(46);
  459. toword := 0;
  460. tobyte := 1;
  461. tolong:=longint(toword > tobyte);
  462. if tolong <> 0 then
  463. exit(47);
  464. toword := 2;
  465. tobyte := 1;
  466. tolong:=longint(toword > tobyte);
  467. if tolong <> 1 then
  468. exit(48);
  469. {$ifndef tp}
  470. toword := 0;
  471. tobyte := 1;
  472. toint64:=int64(toword > tobyte);
  473. if toint64 <> 0 then
  474. exit(49);
  475. toword := 2;
  476. tobyte := 1;
  477. toint64:=int64(toword > tobyte);
  478. if toint64 <> 1 then
  479. exit(50);
  480. {$endif}
  481. { left : LOC_REGISTER }
  482. { from : LOC_FLAGS }
  483. wb1 := TRUE;
  484. bb1 := FALSE;
  485. bb1 := (wb1 <> bb1);
  486. if not bb1 then
  487. exit(51);
  488. wb1 := FALSE;
  489. bb1 := FALSE;
  490. bb1 := (wb1 <> bb1);
  491. if bb1 then
  492. exit(52);
  493. lb1 := TRUE;
  494. bb1 := FALSE;
  495. bb1 := (bb1 = lb1);
  496. if bb1 then
  497. exit(53);
  498. lb1 := FALSE;
  499. bb1 := TRUE;
  500. bb1 := (bb1 <> lb1);
  501. if not bb1 then
  502. exit(54);
  503. lb1 := TRUE;
  504. bb1 := FALSE;
  505. wb1 := (bb1 = lb1);
  506. if wb1 then
  507. exit(55);
  508. lb1 := TRUE;
  509. bb1 := TRUE;
  510. wb1 := (bb1 = lb1);
  511. if not wb1 then
  512. exit(56);
  513. lb1 := TRUE;
  514. bb1 := FALSE;
  515. lb1 := (bb1 = lb1);
  516. if lb1 then
  517. exit(57);
  518. lb1 := FALSE;
  519. bb1 := FALSE;
  520. lb1 := (bb1 = lb1);
  521. if not lb1 then
  522. exit(58);
  523. bb1 := TRUE;
  524. bb2 := FALSE;
  525. lb1 := (bb1 <> bb2);
  526. if not lb1 then
  527. exit(59);
  528. bb1 := FALSE;
  529. bb2 := TRUE;
  530. lb1 := (bb1 = bb2);
  531. if lb1 then
  532. exit(60);
  533. end;
  534. function testint2real: longint;
  535. var
  536. l: longint;
  537. c: cardinal;
  538. i: int64;
  539. q: qword;
  540. s: single;
  541. d: double;
  542. begin
  543. result:=0;
  544. l:=-12345;
  545. c:=high(longint)+33;
  546. i:=-56789;
  547. q:=qword(high(int64))+48;
  548. s:=l;
  549. if s<>-12345 then
  550. exit(1);
  551. s:=c;
  552. if s<>high(longint)+33 then
  553. exit(2);
  554. s:=i;
  555. if s<>-56789 then
  556. exit(3);
  557. s:=q;
  558. if s<>qword(high(int64))+48 then
  559. exit(4);
  560. l:=-12345;
  561. c:=high(longint)+33;
  562. i:=-56789;
  563. q:=qword(high(int64))+48;
  564. d:=l;
  565. if d<>-12345 then
  566. exit(5);
  567. d:=c;
  568. if d<>high(longint)+33 then
  569. exit(6);
  570. d:=i;
  571. if d<>-56789 then
  572. exit(7);
  573. d:=q;
  574. if d<>qword(high(int64))+48 then
  575. exit(8);
  576. l:=123456789;
  577. c:=987654321;
  578. i:=high(cardinal)+12345;
  579. q:=12345;
  580. s:=l;
  581. if s<>123456789 then
  582. exit(11);
  583. s:=c;
  584. if s<>987654321 then
  585. exit(12);
  586. s:=i;
  587. if s<>high(cardinal)+12345 then
  588. exit(13);
  589. s:=q;
  590. if s<>12345 then
  591. exit(14);
  592. l:=123456789;
  593. c:=987654321;
  594. i:=high(cardinal)+12345;
  595. q:=12345;
  596. d:=l;
  597. if d<>123456789 then
  598. exit(16);
  599. d:=c;
  600. if d<>987654321 then
  601. exit(17);
  602. d:=i;
  603. if d<>high(cardinal)+12345 then
  604. exit(18);
  605. d:=q;
  606. if d<>12345 then
  607. exit(19);
  608. end;
  609. { low = high }
  610. function TestCmpListOneShort: longint;
  611. var
  612. s: smallint;
  613. failed :boolean;
  614. begin
  615. s := -12;
  616. failed := true;
  617. case s of
  618. -12 : failed := false;
  619. -10 : ;
  620. 3 : ;
  621. else
  622. end;
  623. if failed then
  624. result:=1
  625. else
  626. result:=0;
  627. end;
  628. { low = high }
  629. function TestCmpListTwoShort: longint;
  630. var
  631. s: smallint;
  632. failed :boolean;
  633. begin
  634. s := 30000;
  635. failed := true;
  636. case s of
  637. -12 : ;
  638. -10 : ;
  639. 3 : ;
  640. else
  641. failed := false;
  642. end;
  643. if failed then
  644. result:=1
  645. else
  646. result:=0;
  647. end;
  648. { low = high }
  649. function TestCmpListOneWord: longint;
  650. var
  651. s: word;
  652. failed :boolean;
  653. begin
  654. s := 12;
  655. failed := true;
  656. case s of
  657. 12 : failed := false;
  658. 10 : ;
  659. 3 : ;
  660. end;
  661. if failed then
  662. result:=1
  663. else
  664. result:=0;
  665. end;
  666. { low = high }
  667. function TestCmpListTwoWord: longint;
  668. var
  669. s: word;
  670. failed :boolean;
  671. begin
  672. s := 30000;
  673. failed := true;
  674. case s of
  675. 0 : ;
  676. 512 : ;
  677. 3 : ;
  678. else
  679. failed := false;
  680. end;
  681. if failed then
  682. result:=1
  683. else
  684. result:=0;
  685. end;
  686. { low = high }
  687. function TestCmpListOneInt64: longint;
  688. var
  689. s: int64;
  690. failed :boolean;
  691. begin
  692. s := 3000000;
  693. failed := true;
  694. case s of
  695. 3000000 : failed := false;
  696. 10 : ;
  697. 3 : ;
  698. end;
  699. if failed then
  700. result:=1
  701. else
  702. result:=0;
  703. end;
  704. { low = high }
  705. function TestCmpListTwoInt64: longint;
  706. var
  707. s: int64;
  708. failed :boolean;
  709. begin
  710. s := 30000;
  711. failed := true;
  712. case s of
  713. 0 : ;
  714. 512 : ;
  715. 3 : ;
  716. else
  717. failed := false;
  718. end;
  719. if failed then
  720. result:=1
  721. else
  722. result:=0;
  723. end;
  724. { low = high }
  725. function TestCmpListThreeInt64: longint;
  726. var
  727. s: int64;
  728. l : longint;
  729. failed :boolean;
  730. begin
  731. l:=3000000;
  732. s := (int64(l) shl 32);
  733. failed := true;
  734. case s of
  735. (int64(3000000) shl 32) : failed := false;
  736. 10 : ;
  737. 3 : ;
  738. end;
  739. if failed then
  740. result:=1
  741. else
  742. result:=0;
  743. end;
  744. function TestCmpListRangesOneShort: longint;
  745. var
  746. s: smallint;
  747. failed :boolean;
  748. begin
  749. s := -12;
  750. failed := true;
  751. case s of
  752. -12..-8 : failed := false;
  753. -7 : ;
  754. 3 : ;
  755. else
  756. end;
  757. if failed then
  758. result:=1
  759. else
  760. result:=0;
  761. end;
  762. function TestCmpListRangesTwoShort: longint;
  763. var
  764. s: smallint;
  765. failed :boolean;
  766. begin
  767. s := 30000;
  768. failed := true;
  769. case s of
  770. -12..-8 : ;
  771. -7 : ;
  772. 3 : ;
  773. else
  774. failed := false;
  775. end;
  776. if failed then
  777. result:=1
  778. else
  779. result:=0;
  780. end;
  781. { low = high }
  782. function TestCmpListRangesOneWord: longint;
  783. var
  784. s: word;
  785. failed :boolean;
  786. begin
  787. s := 12;
  788. failed := true;
  789. case s of
  790. 12..13 : failed := false;
  791. 10 : ;
  792. 3..7 : ;
  793. end;
  794. if failed then
  795. result:=1
  796. else
  797. result:=0;
  798. end;
  799. { low = high }
  800. function TestCmpListRangesTwoWord: longint;
  801. var
  802. s: word;
  803. failed :boolean;
  804. begin
  805. s := 30000;
  806. failed := true;
  807. case s of
  808. 0..2 : ;
  809. 3..29999 : ;
  810. else
  811. failed := false;
  812. end;
  813. if failed then
  814. result:=1
  815. else
  816. result:=0;
  817. end;
  818. function TestCmpListRangesThreeWord: longint;
  819. var
  820. s: word;
  821. failed :boolean;
  822. begin
  823. s := 3;
  824. failed := true;
  825. case s of
  826. 12..13 : ;
  827. 10 : ;
  828. 3..7 : failed := false;
  829. end;
  830. if failed then
  831. result:=1
  832. else
  833. result:=0;
  834. end;
  835. { low = high }
  836. function TestCmpListRangesOneInt64: longint;
  837. var
  838. s: int64;
  839. failed :boolean;
  840. begin
  841. s := 3000000;
  842. failed := true;
  843. case s of
  844. 11..3000000 : failed := false;
  845. 10 : ;
  846. 0..2 : ;
  847. end;
  848. if failed then
  849. result:=1
  850. else
  851. result:=0;
  852. end;
  853. { low = high }
  854. function TestCmpListRangesTwoInt64: longint;
  855. var
  856. s: int64;
  857. failed :boolean;
  858. begin
  859. s := 30000;
  860. failed := true;
  861. case s of
  862. 513..10000 : ;
  863. 512 : ;
  864. 0..3 : ;
  865. else
  866. failed := false;
  867. end;
  868. if failed then
  869. result:=1
  870. else
  871. result:=0;
  872. end;
  873. function testsqr: longint;
  874. var
  875. s1, s2: single;
  876. d1, d2: double;
  877. begin
  878. result:=0;
  879. s1:=25.0;
  880. s2:=sqr(s1);
  881. if s2<>625.0 then
  882. exit(1);
  883. d2:=sqr(s1);
  884. if d2<>625.0 then
  885. exit(2);
  886. d1:=7.0;
  887. d2:=sqr(d1);
  888. if d2<>49.0 then
  889. exit(3);
  890. d2:=sqr(d1);
  891. if d2<>49.0 then
  892. exit(4);
  893. end;
  894. function testtrunc: longint;
  895. var
  896. s1: single;
  897. d1: double;
  898. l: longint;
  899. i: int64;
  900. begin
  901. result:=0;
  902. s1:=123.99;
  903. l:=trunc(s1);
  904. if l<>123 then
  905. exit(1);
  906. i:=trunc(s1);
  907. if i<>123 then
  908. exit(2);
  909. d1:=67533.345923;
  910. l:=trunc(d1);
  911. if l<>67533 then
  912. exit(3);
  913. i:=trunc(d1);
  914. if i<>67533 then
  915. exit(4);
  916. end;
  917. function testdynarr: longint;
  918. type
  919. TReal1DArray = array of Double;
  920. TReal2DArray = array of array of Double;
  921. var
  922. MaxMN : Integer;
  923. PassCount : Integer;
  924. Threshold : Double;
  925. AEffective : TReal2DArray;
  926. AParam : TReal2DArray;
  927. XE : TReal1DArray;
  928. B : TReal1DArray;
  929. N : Integer;
  930. Pass : Integer;
  931. I : Integer;
  932. J : Integer;
  933. CntS : Integer;
  934. CntU : Integer;
  935. CntT : Integer;
  936. CntM : Integer;
  937. WasErrors : Boolean;
  938. IsUpper : Boolean;
  939. IsTrans : Boolean;
  940. IsUnit : Boolean;
  941. V : Double;
  942. S : Double;
  943. begin
  944. SetLength(AEffective, 2, 2); // crash occurs at this line
  945. WasErrors := False;
  946. MaxMN := 10;
  947. PassCount := 5;
  948. N:=2;
  949. isupper:=false;
  950. isunit:=true;
  951. istrans:=false;
  952. while N<=MaxMN do
  953. begin
  954. for i:=low(aeffective) to pred(length(aeffective)) do
  955. for j:=low(aeffective[i]) to pred(length(aeffective[i])) do
  956. aeffective[i,j]:=i*10+j;
  957. SetLength(AEffective, N+1, N+1);
  958. for i:=low(aeffective) to pred(length(aeffective))-1 do
  959. for j:=low(aeffective[i]) to pred(length(aeffective[i]))-1 do
  960. if aeffective[i,j]<>i*10+j then
  961. begin
  962. result:=-1;
  963. exit;
  964. end;
  965. for i:=low(aeffective) to pred(length(aeffective))-1 do
  966. if aeffective[i,pred(length(aeffective[i]))]<>0 then
  967. begin
  968. result:=-2;
  969. exit;
  970. end;
  971. Inc(N);
  972. end;
  973. { check shallow copy }
  974. AParam:=aeffective;
  975. aeffective[1,1]:=123;
  976. if AParam[1,1]<>123 then
  977. exit(-3);
  978. result:=0;
  979. end;
  980. function testdynarr2: longint;
  981. type
  982. tstaticarr = array[0..1] of longint;
  983. tstaticarr2 = array[0..1] of array of array of longint;
  984. var
  985. a,b: array of array of tstaticarr;
  986. c,d: tstaticarr2;
  987. w: word;
  988. arrb: array of byte;
  989. arrc: array of char;
  990. arrw: array of word;
  991. arrwc: array of unicodechar;
  992. arrd: array of dword;
  993. arrq: array of qword;
  994. arra: array of ansistring;
  995. arrs: array of shortstring;
  996. begin
  997. setlength(a,2,2);
  998. a[0,0,0]:=1;
  999. b:=a;
  1000. a[0,0,1]:=1;
  1001. funkyl:=1;
  1002. setlength(a[funky],35);
  1003. if b[0,0,0]<>1 then
  1004. exit(1);
  1005. if b[0,0,1]<>1 then
  1006. exit(2);
  1007. if length(b[1])<>35 then
  1008. exit(3);
  1009. setlength(c[0],2,2);
  1010. d:=c;
  1011. c[0,0,0]:=1;
  1012. setlength(c[1],42);
  1013. if d[0,0,0]<>1 then
  1014. exit(4);
  1015. if length(d[1])<>0 then
  1016. exit(5);
  1017. b[1,0,0]:=555;
  1018. a:=copy(b,1,1);
  1019. if length(a)<>1 then
  1020. exit(6);
  1021. if a[0,0,0]<>555 then
  1022. exit(7);
  1023. setlength(arrb,4);
  1024. if length(arrb)<>4 then
  1025. exit(8);
  1026. for w:=low(arrb) to high(arrb) do
  1027. if arrb[w]<>0 then
  1028. exit(9);
  1029. setlength(arrc,32);
  1030. if length(arrc)<>32 then
  1031. exit(10);
  1032. for w:=low(arrc) to high(arrc) do
  1033. if arrc[w]<>#0 then
  1034. exit(11);
  1035. setlength(arrw,666);
  1036. if length(arrw)<>666 then
  1037. exit(11);
  1038. for w:=low(arrw) to high(arrw) do
  1039. if arrw[w]<>0 then
  1040. exit(12);
  1041. setlength(arrwc,12346);
  1042. if length(arrwc)<>12346 then
  1043. exit(13);
  1044. for w:=low(arrwc) to high(arrwc) do
  1045. if arrwc[w]<>#0 then
  1046. exit(14);
  1047. setlength(arrd,20000);
  1048. if length(arrd)<>20000 then
  1049. exit(15);
  1050. for w:=low(arrd) to high(arrd) do
  1051. if arrd[w]<>0 then
  1052. exit(16);
  1053. setlength(arrq,21532);
  1054. if length(arrq)<>21532 then
  1055. exit(17);
  1056. for w:=low(arrq) to high(arrq) do
  1057. if arrq[w]<>0 then
  1058. exit(18);
  1059. setlength(arra,21533);
  1060. if length(arra)<>21533 then
  1061. exit(19);
  1062. for w:=low(arra) to high(arra) do
  1063. if arra[w]<>'' then
  1064. exit(20);
  1065. setlength(arrs,21534);
  1066. if length(arrs)<>21534 then
  1067. exit(21);
  1068. for w:=low(arrs) to high(arrs) do
  1069. if arrs[w]<>'' then
  1070. exit(12);
  1071. result:=0;
  1072. end;
  1073. function testbitcastintfloat: jint;
  1074. var
  1075. f: jfloat;
  1076. d: jdouble;
  1077. i: jint;
  1078. l: jlong;
  1079. begin
  1080. result:=-1;
  1081. f:=123.125;
  1082. i:=jint(f);
  1083. f:=1.0;
  1084. f:=jfloat(i);
  1085. if f<>1123434496.0 then
  1086. exit;
  1087. result:=-2;
  1088. d:=9876.0625;
  1089. l:=jlong(d);
  1090. d:=1.0;
  1091. d:=jdouble(l);
  1092. if d<>4666655037106159616 then
  1093. exit;
  1094. result:=0;
  1095. end;
  1096. { ********************** Is test ******************** }
  1097. type
  1098. tisclass2 = class(tisclass1)
  1099. constructor create;
  1100. end;
  1101. constructor tisclass1.create;
  1102. begin
  1103. end;
  1104. constructor tisclass1.tisclass1nested.create;
  1105. begin
  1106. anonrec.c:='x';
  1107. end;
  1108. function tisclass1.tisclass1nested.testl1: jint;
  1109. begin
  1110. if anonrec.c='x' then
  1111. result:=12345
  1112. else
  1113. result:=-1;
  1114. end;
  1115. constructor tisclass1.tisclass1nested.tisclass1nestedl2.create;
  1116. begin
  1117. anonrec.l:=961;
  1118. end;
  1119. function tisclass1.tisclass1nested.tisclass1nestedl2.testl2: jint;
  1120. begin
  1121. if anonrec.l=961 then
  1122. result:=42
  1123. else
  1124. result:=-1;
  1125. end;
  1126. procedure tisclass1.abstr;
  1127. begin
  1128. end;
  1129. constructor tisclass2.create;
  1130. begin
  1131. end;
  1132. function testispara(cref: tisclass1ref): longint;
  1133. begin
  1134. if cref<>tisclass2 then
  1135. result:=14;
  1136. result:=0;
  1137. end;
  1138. function testis: longint;
  1139. var
  1140. myclass1 : tisclass1;
  1141. myclass2 : tisclass2;
  1142. nested1 : tisclass1.tisclass1nested;
  1143. nested2 : tisclass1.tisclass1nested.tisclass1nestedl2;
  1144. myclassref : tisclass1ref;
  1145. begin
  1146. { create class instance }
  1147. myclass1:=tisclass1.create;
  1148. myclass2:=tisclass2.create;
  1149. {if myclass1 is tisclass1 }
  1150. if not(myclass1 is tisclass1) then
  1151. exit(1);
  1152. if (myclass1 is tisclass2) then
  1153. exit(2);
  1154. if not (myclass2 is tisclass2) then
  1155. exit(3);
  1156. if (myclass1 is tisclass2) then
  1157. exit(4);
  1158. nested1:=tisclass1.tisclass1nested.create;
  1159. nested2:=tisclass1.tisclass1nested.tisclass1nestedl2.create;
  1160. if not(nested1 is tisclass1.tisclass1nested) then
  1161. exit(5);
  1162. if nested1.testl1<>12345 then
  1163. exit(6);
  1164. if not(nested2 is tisclass2.tisclass1nested.tisclass1nestedl2) then
  1165. exit(7);
  1166. if nested2.testl2<>42 then
  1167. exit(8);
  1168. {$ifndef oldcomp}
  1169. myclassref:=tisclass1;
  1170. if not(myclass1 is myclassref) then
  1171. exit(10);
  1172. if not(myclass2 is myclassref) then
  1173. exit(11);
  1174. myclassref:=tisclass2;
  1175. if (myclass1 is myclassref) then
  1176. exit(12);
  1177. if not(myclass2 is myclassref) then
  1178. exit(13);
  1179. myclass1:=myclass2;
  1180. myclass1.abstr;
  1181. myclass2:=tisclass2(myclass1 as myclassref);
  1182. result:=testispara(tisclass2);
  1183. if result<>0 then
  1184. exit(14);
  1185. if not(nested1 is tisinterface) then
  1186. exit(15);
  1187. if nested2 is tisinterface then
  1188. exit(16);
  1189. {$endif}
  1190. result:=0;
  1191. end;
  1192. function testneg: longint;
  1193. var
  1194. b: shortint;
  1195. l: longint;
  1196. i: int64;
  1197. s: single;
  1198. d: double;
  1199. begin
  1200. b:=1;
  1201. b:=-b;
  1202. if b<>-1 then
  1203. exit(1);
  1204. l:=-1234567;
  1205. l:=-l;
  1206. if l<>1234567 then
  1207. exit(2);
  1208. i:=-123456789012345;
  1209. i:=-i;
  1210. if i<>123456789012345 then
  1211. exit(3);
  1212. s:=123.5;
  1213. s:=-s;
  1214. if s<>-123.5 then
  1215. exit(4);
  1216. d:=-4567.78;
  1217. d:=-d;
  1218. if d<>4567.78 then
  1219. exit(5);
  1220. result:=0;
  1221. end;
  1222. { ******************** End Is test ****************** }
  1223. { ****************** Exception test ***************** }
  1224. function testtry1: longint;
  1225. begin
  1226. result:=-1;
  1227. try
  1228. raise JLException.create;
  1229. except
  1230. result:=0;
  1231. end;
  1232. end;
  1233. function testtry2: longint;
  1234. begin
  1235. result:=-1;
  1236. try
  1237. raise JLException.create;
  1238. except
  1239. on JLException do
  1240. result:=0;
  1241. else
  1242. result:=-2
  1243. end;
  1244. if result<>0 then
  1245. exit;
  1246. result:=-3;
  1247. try
  1248. try
  1249. raise JLException.create;
  1250. except
  1251. result:=-4;
  1252. raise
  1253. end;
  1254. except
  1255. on JLException do
  1256. if result=-4 then
  1257. result:=0;
  1258. end;
  1259. end;
  1260. function testtryfinally1: longint;
  1261. begin
  1262. result:=-1;
  1263. try
  1264. try
  1265. try
  1266. raise JLException.create;
  1267. except
  1268. on JLException do
  1269. begin
  1270. result:=1;
  1271. raise;
  1272. end
  1273. else
  1274. result:=-2
  1275. end;
  1276. finally
  1277. if result=1 then
  1278. result:=0;
  1279. end;
  1280. except
  1281. on JLException do
  1282. if result<>0 then
  1283. raise
  1284. end;
  1285. end;
  1286. function testtryfinally2: longint;
  1287. var
  1288. i,j: longint;
  1289. check1, check2: byte;
  1290. begin
  1291. j:=0;
  1292. check1:=0;
  1293. check2:=0;
  1294. result:=-1;
  1295. try
  1296. for i:=1 to 10 do
  1297. try
  1298. inc(j);
  1299. if j=1 then
  1300. begin
  1301. inc(check1);
  1302. continue;
  1303. end;
  1304. if j=2 then
  1305. begin
  1306. inc(check2);
  1307. break;
  1308. end;
  1309. finally
  1310. if j=1 then
  1311. inc(check1);
  1312. if j=2 then
  1313. inc(check2);
  1314. end;
  1315. finally
  1316. if check1<>2 then
  1317. result:=-1
  1318. else if check2<>2 then
  1319. result:=-2
  1320. else if j<>2 then
  1321. result:=-3
  1322. else
  1323. result:=0;
  1324. end;
  1325. end;
  1326. function testtryfinally3: longint;
  1327. var
  1328. i,j: longint;
  1329. check1, check2: byte;
  1330. begin
  1331. j:=0;
  1332. check1:=0;
  1333. check2:=0;
  1334. result:=-1;
  1335. try
  1336. for i:=1 to 10 do
  1337. try
  1338. inc(j);
  1339. if j=1 then
  1340. begin
  1341. inc(check1);
  1342. continue;
  1343. end;
  1344. if j=2 then
  1345. begin
  1346. inc(check2);
  1347. exit;
  1348. end;
  1349. finally
  1350. if j=1 then
  1351. inc(check1);
  1352. if j=2 then
  1353. inc(check2);
  1354. end;
  1355. finally
  1356. if check1<>2 then
  1357. result:=-10
  1358. else if check2<>2 then
  1359. result:=-20
  1360. else if j<>2 then
  1361. result:=-30
  1362. else
  1363. result:=0;
  1364. end;
  1365. end;
  1366. { **************** End Exception test *************** }
  1367. { **************** Begin array test *************** }
  1368. function testsmallarr1: longint;
  1369. type
  1370. tarr = array[4..6] of longint;
  1371. var
  1372. a1,a2: tarr;
  1373. a3,a4: array[1..2,3..5] of tarr;
  1374. i,j,k: longint;
  1375. begin
  1376. a1[4]:=1;
  1377. a1[5]:=2;
  1378. a1[6]:=3;
  1379. { plain copy }
  1380. a2:=a1;
  1381. if (a2[4]<>1) or
  1382. (a2[5]<>2) or
  1383. (a2[6]<>3) then
  1384. exit(1);
  1385. { has to be deep copy }
  1386. a1[5]:=255;
  1387. if a2[5]<>2 then
  1388. exit(2);
  1389. { copy to multi-dim array }
  1390. a3[1,4]:=a1;
  1391. if (a3[1,4,4]<>1) or
  1392. (a3[1,4,5]<>255) or
  1393. (a3[1,4,6]<>3) then
  1394. exit(3);
  1395. i:=2;
  1396. j:=3;
  1397. a1[4]:=38;
  1398. a1[5]:=39;
  1399. a1[6]:=40;
  1400. { copy to multi-dim array }
  1401. a3[i,j]:=a1;
  1402. if (a3[i,j,4]<>38) or
  1403. (a3[i,j,5]<>39) or
  1404. (a3[i,j,6]<>40) then
  1405. exit(4);
  1406. { copy multi-dim array to multi-dim array }
  1407. a4:=a3;
  1408. { check for deep copy }
  1409. for i:=low(a3) to high(a3) do
  1410. for j:=low(a3[i]) to high(a3[i]) do
  1411. for k:=low(a3[i,j]) to high(a3[i,j]) do
  1412. a3[i,j,k]:=-1;
  1413. if (a4[1,4,4]<>1) or
  1414. (a4[1,4,5]<>255) or
  1415. (a4[1,4,6]<>3) then
  1416. exit(5);
  1417. i:=2;
  1418. j:=3;
  1419. if (a4[i,j,4]<>38) or
  1420. (a4[i,j,5]<>39) or
  1421. (a4[i,j,6]<>40) then
  1422. exit(6);
  1423. result:=0;
  1424. end;
  1425. function testopenarrval(a1: longint; arr: array of jfloat; a2: longint): longint;
  1426. var
  1427. i: longint;
  1428. begin
  1429. result:=a1+length(arr)+trunc(arr[high(arr)])+a2;
  1430. for i:=low(arr) to high(arr) do
  1431. arr[i]:=1.0;
  1432. end;
  1433. function testopenarrconst(a1: longint; const arr: array of jfloat; a2: longint): longint;
  1434. begin
  1435. result:=a1+length(arr)+trunc(arr[high(arr)])+a2;
  1436. end;
  1437. function testopenarrvar(a1: longint; var arr: array of jfloat; a2: longint): longint;
  1438. begin
  1439. result:=a1+length(arr)+trunc(arr[high(arr)])+a2;
  1440. arr[0]:=3.0;
  1441. end;
  1442. function testopenarr1: longint;
  1443. var
  1444. arr: array[4..10] of jfloat;
  1445. i: longint;
  1446. begin
  1447. result:=0;
  1448. arr[10]:=2.0;
  1449. if testopenarrval(1,arr,3)<>13 then
  1450. exit(1);
  1451. for i:=4 to 9 do
  1452. if arr[i]<>0.0 then
  1453. exit(2);
  1454. if arr[10]<>2.0 then
  1455. exit(3);
  1456. if testopenarrconst(2,arr,4)<>15 then
  1457. exit(4);
  1458. if testopenarrvar(3,arr,5)<>17 then
  1459. exit(5);
  1460. if arr[4]<>3.0 then
  1461. exit(6);
  1462. end;
  1463. type
  1464. tarrdynarr = array[1..10,1..4] of array of array of byte;
  1465. function testoutopenarrdyn(out arr: array of tarrdynarr): longint;
  1466. var
  1467. i, j, k: longint;
  1468. begin
  1469. for i:=low(arr) to high(arr) do
  1470. for j:=low(arr[i]) to high(arr[i]) do
  1471. for k:=low(arr[i][j]) to high(arr[i][j]) do
  1472. begin
  1473. if length(arr[i][j,k])<>0 then
  1474. exit(-1);
  1475. setlength(arr[i][j,k],j,k);
  1476. end;
  1477. result:=0;
  1478. end;
  1479. function testopenarr2: longint;
  1480. var
  1481. arr: array[20..30] of tarrdynarr;
  1482. dynarr: array of tarrdynarr;
  1483. i,j,k: longint;
  1484. barr, barr2: array of byte;
  1485. rarr: array of trec;
  1486. rarr2: array of array of trec;
  1487. begin
  1488. setlength(barr,4);
  1489. barr[1]:=4;
  1490. if barr[1]<>4 then
  1491. exit(-40);
  1492. barr2:=copy(barr);
  1493. if barr2[1]<>4 then
  1494. exit(-50);
  1495. barr2[2]:=48;
  1496. if barr[2]=48 then
  1497. exit(-60);
  1498. setlength(rarr,5);
  1499. rarr[4].a:=135;
  1500. if rarr[4].a<>135 then
  1501. exit(-70);
  1502. setlength(rarr2,4,5);
  1503. rarr2[3,4].b:=124;
  1504. if rarr2[3,4].b<>124 then
  1505. exit(-80);
  1506. for i:=low(arr) to high(arr) do
  1507. for j:=low(arr[i]) to high(arr[i]) do
  1508. for k:=low(arr[i][j]) to high(arr[i][j]) do
  1509. begin
  1510. setlength(arr[i][j,k],20,20);
  1511. end;
  1512. result:=testoutopenarrdyn(arr);
  1513. if result<>0 then
  1514. exit;
  1515. for i:=low(arr) to high(arr) do
  1516. for j:=low(arr[i]) to high(arr[i]) do
  1517. for k:=low(arr[i][j]) to high(arr[i][j]) do
  1518. begin
  1519. if (length(arr[i][j,k])<>j) then
  1520. exit(-2);
  1521. if (length(arr[i][j,k][0])<>k) then
  1522. exit(-3);
  1523. if (length(arr[i][j,k][j-1])<>k) then
  1524. exit(-4);
  1525. end;
  1526. setlength(dynarr,31);
  1527. result:=testoutopenarrdyn(dynarr);
  1528. for i:=low(arr) to high(arr) do
  1529. for j:=low(arr[i]) to high(arr[i]) do
  1530. for k:=low(arr[i][j]) to high(arr[i][j]) do
  1531. begin
  1532. if (length(arr[i][j,k])<>j) then
  1533. exit(-5);
  1534. if (length(arr[i][j,k][0])<>k) then
  1535. exit(-6);
  1536. if (length(arr[i][j,k][j-1])<>k) then
  1537. exit(-7);
  1538. end;
  1539. end;
  1540. function testopenarr3: longint;
  1541. var
  1542. arr: array[4..10] of jfloat;
  1543. i: longint;
  1544. begin
  1545. result:=0;
  1546. arr[10]:=2.0;
  1547. if testopenarrval(1,[1.0,2.0,3.0,4.0,5.0,6.0,2.0],3)<>13 then
  1548. exit(1);
  1549. if testopenarrconst(2,[1.0,2.0,3.0,4.0,5.0,6.0,7.0],4)<>20 then
  1550. exit(2);
  1551. end;
  1552. type
  1553. ByteArray = array of byte;
  1554. procedure FillChar(var X: Array of Byte; Count: integer; Value: byte; FirstIndex: integer);
  1555. var
  1556. i: integer;
  1557. y: bytearray;
  1558. begin
  1559. for i := FirstIndex to (FirstIndex + Count) - 1 do
  1560. X[i] := Value;
  1561. end;
  1562. function Err : ByteArray;
  1563. begin
  1564. SetLength(Result, 10);
  1565. FillChar(Result, Length(Result)-2, 1, 2); // !!!!
  1566. end;
  1567. function testopendynarr: longint;
  1568. var
  1569. x: bytearray;
  1570. i: longint;
  1571. begin
  1572. x:=err;
  1573. for i:=0 to 1 do
  1574. if x[i]<>0 then
  1575. exit(1);
  1576. for i:=2 to high(x) do
  1577. if x[i]<>1 then
  1578. exit(2);
  1579. result:=0;
  1580. end;
  1581. type
  1582. tdoublearray10 = array[1..10] of jdouble;
  1583. function testarrval(arr: tdoublearray10): double;
  1584. var
  1585. i: longint;
  1586. begin
  1587. result:=0.0;
  1588. for i:=low(arr) to high(arr) do
  1589. begin
  1590. result:=result+arr[i];
  1591. arr[i]:=-1.0;
  1592. end;
  1593. end;
  1594. function testsmallarr2: longint;
  1595. var
  1596. arr: tdoublearray10;
  1597. i: longint;
  1598. barr1,barr2: array[1..2] of byte;
  1599. begin
  1600. result:=0;
  1601. for i:=low(arr) to high(arr) do
  1602. arr[i]:=i;
  1603. if testarrval(arr)<>(10*11 div 2) then
  1604. exit(1);
  1605. for i:=low(arr) to high(arr) do
  1606. if arr[i]<>i then
  1607. exit(2);
  1608. barr1[1]:=1;
  1609. barr1[2]:=2;
  1610. barr2:=barr1;
  1611. if barr2[1]<>1 then
  1612. exit(3);
  1613. if barr2[2]<>2 then
  1614. exit(4);
  1615. end;
  1616. type
  1617. tsmall2darr = array[1..10,5..9] of longint;
  1618. function smallarr2dfunc: tsmall2darr;
  1619. var
  1620. i, j: longint;
  1621. begin
  1622. for i:=low(result) to high(result) do
  1623. for j:=low(result[i]) to high(result[i]) do
  1624. result[i,j]:=i*(high(result[i])-low(result[i])+1)+(j-low(result[i]));
  1625. end;
  1626. function testsmallarr3: longint;
  1627. var
  1628. a: tsmall2darr;
  1629. begin
  1630. a:=smallarr2dfunc;
  1631. if a[1,5]<>5 then
  1632. exit(1);
  1633. if a[2,9]<>14 then
  1634. exit(2);
  1635. result:=0;
  1636. end;
  1637. function testoutarrdyn(out arr: tarrdynarr): longint;
  1638. var
  1639. i, j: longint;
  1640. begin
  1641. for i:=low(arr) to high(arr) do
  1642. for j:=low(arr[i]) to high(arr[i]) do
  1643. begin
  1644. if length(arr[i,j])<>0 then
  1645. exit(-1);
  1646. setlength(arr[i,j],i,j);
  1647. end;
  1648. result:=0;
  1649. end;
  1650. function testsmallarr4: longint;
  1651. var
  1652. arr: tarrdynarr;
  1653. i,j: longint;
  1654. begin
  1655. for i:=low(arr) to high(arr) do
  1656. for j:=low(arr[i]) to high(arr[i]) do
  1657. begin
  1658. setlength(arr[i,j],20,20);
  1659. end;
  1660. result:=testoutarrdyn(arr);
  1661. if result<>0 then
  1662. exit;
  1663. for i:=low(arr) to high(arr) do
  1664. for j:=low(arr[i]) to high(arr[i]) do
  1665. begin
  1666. if (length(arr[i,j])<>i) then
  1667. exit(-2);
  1668. if (length(arr[i,j][0])<>j) then
  1669. exit(-3);
  1670. if (length(arr[i,j][i-1])<>j) then
  1671. exit(-4);
  1672. end;
  1673. end;
  1674. function testrec1: longint;
  1675. var
  1676. r1, r2: trec;
  1677. begin
  1678. r1.a:=1;
  1679. r1.b:=2;
  1680. r1.c:=3;
  1681. r1.d:=4;
  1682. r1.e:=5;
  1683. if r1.a<>1 then
  1684. exit(1);
  1685. if r1.b<>2 then
  1686. exit(2);
  1687. if r1.c<>3 then
  1688. exit(3);
  1689. if r1.d<>4 then
  1690. exit(4);
  1691. if r1.e<>5 then
  1692. exit(5);
  1693. r2:=r1;
  1694. if r2.a<>1 then
  1695. exit(6);
  1696. if r2.b<>2 then
  1697. exit(7);
  1698. if r2.c<>3 then
  1699. exit(8);
  1700. if r2.d<>4 then
  1701. exit(9);
  1702. if r2.e<>5 then
  1703. exit(10);
  1704. r2.a:=10;
  1705. if r1.a<>1 then
  1706. exit(11);
  1707. result:=0;
  1708. end;
  1709. function testrec2: longint;
  1710. var
  1711. r1, r2: tnestrec;
  1712. begin
  1713. r1:=tcnestrec;
  1714. r1.r.a:=1;
  1715. r1.r.b:=2;
  1716. r1.r.c:=3;
  1717. r1.r.d:=4;
  1718. r1.r.e:=5;
  1719. r1.arr[4]:=6;
  1720. if r1.r.a<>1 then
  1721. exit(1);
  1722. if r1.r.b<>2 then
  1723. exit(2);
  1724. if r1.r.c<>3 then
  1725. exit(3);
  1726. if r1.r.d<>4 then
  1727. exit(4);
  1728. if r1.r.e<>5 then
  1729. exit(5);
  1730. if r1.arr[4]<>6 then
  1731. exit(12);
  1732. r2:=r1;
  1733. if r2.r.a<>1 then
  1734. exit(6);
  1735. if r2.r.b<>2 then
  1736. exit(7);
  1737. if r2.r.c<>3 then
  1738. exit(8);
  1739. if r2.r.d<>4 then
  1740. exit(9);
  1741. if r2.r.e<>5 then
  1742. exit(10);
  1743. if r1.arr[4]<>6 then
  1744. exit(13);
  1745. r2.r.a:=10;
  1746. r2.arr[4]:=7;
  1747. if r1.r.a<>1 then
  1748. exit(11);
  1749. if r1.arr[4]<>6 then
  1750. exit(14);
  1751. anonrec.s:='abcdef';
  1752. if anonrec.s<>'abcdef' then
  1753. exit(15);
  1754. result:=0;
  1755. end;
  1756. function testopenarrvalrec(a1: longint; arr: array of trec; a2: longint): longint;
  1757. var
  1758. i: longint;
  1759. begin
  1760. result:=a1+length(arr)+arr[high(arr)].a+a2;
  1761. for i:=low(arr) to high(arr) do
  1762. arr[i].a:=123;
  1763. end;
  1764. function testopenarrconstrec(a1: longint; const arr: array of trec; a2: longint): longint;
  1765. begin
  1766. result:=a1+length(arr)+arr[high(arr)].b+a2;
  1767. end;
  1768. function testopenarrvarrec(a1: longint; var arr: array of trec; a2: longint): longint;
  1769. begin
  1770. result:=a1+length(arr)+arr[high(arr)].c+a2;
  1771. arr[0].d:=987;
  1772. end;
  1773. function testopenarr1rec: longint;
  1774. var
  1775. arr: array[4..10] of trec;
  1776. i: longint;
  1777. begin
  1778. result:=0;
  1779. arr[10].a:=2;
  1780. arr[10].b:=2;
  1781. arr[10].c:=2;
  1782. arr[10].d:=2;
  1783. arr[10].e:=2;
  1784. if testopenarrvalrec(1,arr,3)<>13 then
  1785. exit(1);
  1786. for i:=4 to 9 do
  1787. if arr[i].a<>0.0 then
  1788. exit(2);
  1789. if arr[10].a<>2.0 then
  1790. exit(3);
  1791. if testopenarrconstrec(2,arr,4)<>15 then
  1792. exit(4);
  1793. if testopenarrvarrec(3,arr,5)<>17 then
  1794. exit(5);
  1795. if arr[4].d<>987 then
  1796. exit(6);
  1797. end;
  1798. function testunicodestring: JLString;
  1799. var
  1800. s1, s2: unicodestring;
  1801. sarr: array[0..0] of unicodestring;
  1802. begin
  1803. s1:='abc';
  1804. sarr[0]:=s1;
  1805. funkyl:=0;
  1806. if length(sarr[funky])<>3 then
  1807. begin
  1808. result:='';
  1809. exit;
  1810. end;
  1811. s2:=s1;
  1812. s2:='~ê∂êºîƒ~©¬';
  1813. result:=s2;
  1814. end;
  1815. function testunicodestring2: JLString;
  1816. begin
  1817. result:='\'#13#10'"';
  1818. end;
  1819. function testunicodestring3(a: unicodestring): unicodestring;
  1820. begin
  1821. result:=a+'def';
  1822. end;
  1823. function testunicodestring4(a: unicodestring): unicodestring;
  1824. begin
  1825. // JLSystem.fout.println(JLString('in testunicodestring4'));
  1826. // JLSystem.fout.println(JLString(a));
  1827. result:=a;
  1828. // JLSystem.fout.println(JLString(result));
  1829. result[2]:='x';
  1830. // JLSystem.fout.println(JLString(result));
  1831. result[3]:='2';
  1832. // JLSystem.fout.println(JLString(result));
  1833. end;
  1834. function testunicodestring5: unicodestring;
  1835. var
  1836. arr: array[0..3] of ansichar;
  1837. arr2: array[1..5] of ansichar;
  1838. c: ansichar;
  1839. wc: widechar;
  1840. begin
  1841. arr:='abc'#0;
  1842. arr2:='defgh';
  1843. c:='i';
  1844. wc:='j';
  1845. result:=arr+arr2;
  1846. result:=copy(result,1,length(result))+c;
  1847. result:=result+wc;
  1848. end;
  1849. function testunicodestring6: unicodestring;
  1850. const
  1851. tcstr: string = 'ab';
  1852. var
  1853. arr: array[0..3] of widechar;
  1854. arr2: array[1..5] of widechar;
  1855. swap: ansichar;
  1856. wc: widechar;
  1857. i: longint;
  1858. begin
  1859. arr:='ab';
  1860. arr2:='cdefg';
  1861. swap:='h';
  1862. wc:='i';
  1863. result:=arr+arr2+swap;
  1864. result:=result+wc;
  1865. end;
  1866. function testunicodestring7: unicodestring;
  1867. const
  1868. tcstr: string = 'ab';
  1869. var
  1870. arr: array[0..3] of unicodechar;
  1871. arr2: array[1..5] of unicodechar;
  1872. c: ansichar = 'h';
  1873. wc: unicodechar;
  1874. begin
  1875. funkyl:=1;
  1876. arr:=tcstr;
  1877. arr2:='cdefg';
  1878. wc:='i';
  1879. result:=arr+arr2;
  1880. result:=result+c;
  1881. result:=result+wc;
  1882. result[funky]:='x';
  1883. end;
  1884. { **************** End array test *************** }
  1885. constructor TMyClass.create;
  1886. begin
  1887. end;
  1888. constructor TMyClass.create(l: longint);
  1889. var
  1890. dummy: TMyClass;
  1891. begin
  1892. dummy:=TMyClass.create;
  1893. create(l,l);
  1894. end;
  1895. constructor TMyClass.create(l1,l2: longint);
  1896. begin
  1897. inherited create;
  1898. propintfield:=4;
  1899. if propintfield<>4 then
  1900. jlsystem.fout.println('WRONG!!!!!!!!!!!!!!!!!!!');
  1901. end;
  1902. function TMyClass.sub(a1, a2: longint): longint;
  1903. begin
  1904. result:=a1-a2;
  1905. end;
  1906. function TMyClass.test(l1, l2: longint): longint;
  1907. var
  1908. locall: longint;
  1909. localsub: TMyClass;
  1910. begin
  1911. localsub:=TMyClass.create(1245);
  1912. locall:=localsub.sub(l1,l2);
  1913. result:=locall+1;
  1914. if result>4 then
  1915. result:=-1;
  1916. end;
  1917. class function tmyclass.staticmul3(l: longint): longint; static;
  1918. begin
  1919. result:=l*3;
  1920. end;
  1921. procedure tmyclass.longboolobj(l: jlong; b: boolean; obj: tobject);
  1922. begin
  1923. l:=5;
  1924. b:=true;
  1925. obj:=nil;
  1926. end;
  1927. procedure tmyclass.setintfield(l: jint);
  1928. const
  1929. xxx: longint = 4;
  1930. begin
  1931. intfield:=l;
  1932. longboolobj(xxx,true,self);
  1933. end;
  1934. function tmyclass.getintfield: jint;
  1935. begin
  1936. result:=intfield;
  1937. end;
  1938. procedure tmyclass.setstaticbytefield(b: byte);
  1939. begin
  1940. staticbytefield:=b;
  1941. myrec.a:=b;
  1942. end;
  1943. function tmyclass.getstaticbytefield: byte;
  1944. begin
  1945. result:=staticbytefield;
  1946. end;
  1947. class procedure tmyclass.setstaticbytefieldstatic(b: byte);
  1948. begin
  1949. staticbytefield:=b;
  1950. end;
  1951. class function tmyclass.getstaticbytefieldstatic: byte;
  1952. begin
  1953. result:=staticbytefield;
  1954. end;
  1955. class procedure tmyclass.settestglobal(l: longint);
  1956. begin
  1957. testglobal:=l;
  1958. end;
  1959. class function tmyclass.gettestglobal: longint;
  1960. begin
  1961. result:=testglobal;
  1962. end;
  1963. procedure main(const args: array of string);
  1964. begin
  1965. JLSystem.fout.println('This is the entry point');
  1966. end;
  1967. begin
  1968. myrec.b:=1234;
  1969. TMyClass.rec.c:=5678;
  1970. end.