tcidlparser.pp 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689
  1. unit tcidlparser;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, fpcunit, testregistry, webidldefs, webidlparser, webidlscanner;
  6. Type
  7. { TTestParser }
  8. TTestParser = Class(TTestCase)
  9. private
  10. FContext: TWebIDLContext;
  11. FParser: TWebIDLParser;
  12. FVersion: TWebIDLVersion;
  13. function GetList: TIDLDefinitionList;
  14. procedure SetVersion(AValue: TWebIDLVersion);
  15. Protected
  16. Procedure Setup; override;
  17. Procedure TearDown; override;
  18. Procedure InitSource(Const aSource: UTF8String);
  19. procedure AssertParserError(const Msg: String; const aSource: UTF8String);
  20. Class Procedure AssertEquals(Msg : String; AExpected,AActual : TConstType); overload;
  21. Class Procedure AssertEquals(Msg : String; AExpected,AActual : TAttributeOption); overload;
  22. Class Procedure AssertEquals(Msg : String; AExpected,AActual : TFunctionOption); overload;
  23. Class Procedure AssertEquals(Msg : String; AExpected,AActual : TAttributeOptions); overload;
  24. Class Procedure AssertEquals(Msg : String; AExpected,AActual : TFunctionOptions); overload;
  25. Public
  26. Property Parser : TWebIDLParser Read FParser;
  27. Property Context : TWebIDLContext Read FContext;
  28. Property Definitions : TIDLDefinitionList Read GetList;
  29. Property Version : TWebIDLVersion Read FVersion Write SetVersion;
  30. end;
  31. { TTestEnumParser }
  32. TTestEnumParser = Class(TTestParser)
  33. Public
  34. Procedure TestEnum(Const aSource,AName : UTF8String; AValues : Array of UTF8String);
  35. Published
  36. Procedure TestSingle;
  37. Procedure TestTwo;
  38. Procedure TestMissingIdent;
  39. Procedure TestMissingOpening;
  40. Procedure TestMissingClosing;
  41. Procedure TestMissingSemicolon;
  42. Procedure TestMissingComma;
  43. end;
  44. { TTestTypeDefParser }
  45. TTestTypeDefParser = Class(TTestParser)
  46. private
  47. function DoTestPromise(aDef: UTF8String; AReturnType: String=''): TIDLPromiseTypeDefDefinition;
  48. function DoTestSequence(aDef: UTF8String): TIDLSequenceTypeDefDefinition;
  49. function DoTestRecord(aDef: UTF8String; const aKeyTypeName,
  50. aValueTypeName: String): TIDLRecordDefinition;
  51. function DoTestUnion(aDef: String): TIDLUnionTypeDefDefinition;
  52. Public
  53. function TestTypeDef(const aSource, AName, aType: UTF8String): TIDLTypeDefDefinition;
  54. Published
  55. Procedure TestSimpleBoolean;
  56. Procedure TestSimpleBooleanNull;
  57. Procedure TestSimpleInt;
  58. procedure TestSimpleIntNull;
  59. Procedure TestSimpleLongint;
  60. procedure TestSimpleLongintNull;
  61. Procedure TestSimpleLongLongint;
  62. Procedure TestSimpleLongLongintNull;
  63. Procedure TestSimpleUnsignedShortint;
  64. Procedure TestSimpleUnsignedShortintNull;
  65. Procedure TestSimpleUnsignedLongint;
  66. Procedure TestSimpleUnsignedLongintNull;
  67. Procedure TestSimpleUnsignedLongLongint;
  68. Procedure TestSimpleUnsignedLongLongintNull;
  69. Procedure TestUnrestrictedFloat;
  70. Procedure TestSimpleFloat;
  71. Procedure TestSimpleFloatNull;
  72. Procedure TestSimpleDouble;
  73. Procedure TestSimpleDoubleNull;
  74. Procedure TestSimpleOctet;
  75. Procedure TestSimpleOctetNull;
  76. Procedure TestSimpleByte;
  77. procedure TestSimpleByteNull;
  78. Procedure TestSimpleIdentifier;
  79. Procedure TestSimpleIdentifierNull;
  80. Procedure TestAnyType;
  81. Procedure TestAnyTypeNull;
  82. Procedure TestUnion;
  83. Procedure TestUnionNull;
  84. Procedure TestSequence;
  85. Procedure TestSequenceNull;
  86. Procedure TestPromise;
  87. Procedure TestPromiseVoid;
  88. Procedure TestPromiseNull;
  89. Procedure TestPromiseReturnNull;
  90. Procedure TestRecord;
  91. end;
  92. { TTestBaseInterfaceParser }
  93. TTestBaseInterfaceParser = Class(TTestParser)
  94. private
  95. FCustAttributes: String;
  96. FisMixin: Boolean;
  97. Protected
  98. Procedure Setup; override;
  99. Public
  100. Function ParseInterface(AName,aInheritance : UTF8String; AMembers : Array of UTF8String) : TIDLInterfaceDefinition;
  101. Property isMixin : Boolean Read FisMixin Write FisMixin;
  102. Property CustAttributes : String Read FCustAttributes Write FCustAttributes;
  103. end;
  104. { TTestInterfaceParser }
  105. TTestInterfaceParser = Class(TTestBaseInterfaceParser)
  106. Published
  107. Procedure ParseEmpty;
  108. Procedure ParseEmptyNoBrackets;
  109. Procedure ParseEmptyInheritance;
  110. Procedure ParseMixinEmpty;
  111. Procedure ParseMixinEmptyInheritance;
  112. Procedure ParseCustomAttributes1;
  113. Procedure ParseIFDEFHeader;
  114. end;
  115. { TTestMapLikeInterfaceParser }
  116. TTestMapLikeInterfaceParser = Class(TTestBaseInterfaceParser)
  117. Public
  118. function ParseMapLike(const AKeyTypeName, aValueTypeName: UTF8String; IsReadOnly: Boolean): TIDLMapLikeDefinition;
  119. Published
  120. Procedure Parse;
  121. Procedure ParseReadOnly;
  122. end;
  123. { TTestSetLikeInterfaceParser }
  124. TTestSetLikeInterfaceParser = Class(TTestBaseInterfaceParser)
  125. Public
  126. Function ParseSetLike(const aElementTypeName : UTF8String; IsReadOnly : Boolean) : TIDLSetlikeDefinition;
  127. Published
  128. Procedure Parse;
  129. Procedure ParseReadOnly;
  130. end;
  131. { TTestConstInterfaceParser }
  132. TTestConstInterfaceParser = Class(TTestBaseInterfaceParser)
  133. Public
  134. Function ParseConst(AName,ATypeName,aValue : UTF8String; AType : TConstType) : TIDLConstDefinition;
  135. Published
  136. Procedure ParseConstInt;
  137. Procedure Parse2ConstInt;
  138. Procedure ParseConstIntHex;
  139. Procedure ParseConstLongint;
  140. Procedure ParseConstLongLongint;
  141. Procedure ParseConstUnsignedShortint;
  142. Procedure ParseConstUnsignedLongint;
  143. Procedure ParseConstUnsignedLongLongint;
  144. Procedure ParseConstFloat;
  145. Procedure ParseConstNan;
  146. Procedure ParseConstInfinity;
  147. Procedure ParseConstNegInfinity;
  148. Procedure ParseConstNull;
  149. Procedure ParseConstOctet;
  150. Procedure ParseConstByte;
  151. Procedure ParseConstBooleantrue;
  152. Procedure ParseConstBooleanFalse;
  153. Procedure ParseConstIdentifier;
  154. end;
  155. { TTestAttributeInterfaceParser }
  156. TTestAttributeInterfaceParser = Class(TTestBaseInterfaceParser)
  157. private
  158. Fattr: TIDLAttributeDefinition;
  159. Public
  160. Function ParseAttribute(ADef,AName,ATypeName : UTF8String; Options : TAttributeOptions = []) : TIDLAttributeDefinition;
  161. Property Attr : TIDLAttributeDefinition Read Fattr;
  162. Published
  163. Procedure ParseSimpleAttribute;
  164. Procedure ParseSimpleAttributeWithExtendedAttrs;
  165. Procedure ParseSimpleAttributeLegacyNullToEmptyString;
  166. Procedure ParseSimpleStaticAttribute;
  167. Procedure ParseSimpleStringifierAttribute;
  168. Procedure ParseStringifierNoAttribute;
  169. Procedure ParseSimpleReadonlyAttribute;
  170. Procedure ParseSimpleInheritedAttribute;
  171. Procedure ParseSimpleReadonlyInheritedAttribute;
  172. Procedure ParseSimpleReadonlyStaticAttribute;
  173. Procedure ParseSimpleReadonlyStringifierAttribute;
  174. Procedure ParseComplexReadonlyStaticAttribute;
  175. Procedure ParseSimpleAttributeRequired;
  176. Procedure ParseIdentifierAttribute;
  177. Procedure Parse2IdentifierAttributes;
  178. end;
  179. { TTestSerializerInterfaceParser }
  180. TTestSerializerInterfaceParser = Class(TTestBaseInterfaceParser)
  181. private
  182. FSer: TIDLSerializerDefinition;
  183. Public
  184. Function ParseSerializer(ADef : UTF8String; Attrs : Array of UTF8String) : TIDLSerializerDefinition;
  185. Property Ser : TIDLSerializerDefinition Read FSer;
  186. Published
  187. Procedure TestSimpleIdentifier;
  188. Procedure TestSimpleFunction;
  189. Procedure TestMap;
  190. Procedure TestMapWithInherited;
  191. Procedure TestMapWithGetter;
  192. Procedure TestList;
  193. Procedure TestListWithGetter;
  194. end;
  195. { TTestOperationInterfaceParser }
  196. TTestOperationInterfaceParser = Class(TTestBaseInterfaceParser)
  197. private
  198. FFunc: TIDLFunctionDefinition;
  199. Public
  200. Function ParseFunction(ADef,aName,aReturnType : UTF8String; aArguments : Array of UTF8String) : TIDLFunctionDefinition;
  201. Property Func : TIDLFunctionDefinition Read FFunc;
  202. Published
  203. Procedure TestSimpleFunction;
  204. Procedure TestSimpleGetterFunction;
  205. Procedure TestSimpleGetterFunctionNoName;
  206. Procedure TestSimpleSetterFunction;
  207. Procedure TestSimpleLegacyCallerFunction;
  208. Procedure TestSimpleDeleterFunction;
  209. Procedure TestAttrFunctionFunction;
  210. Procedure TestOptionalDefaultArgFunction;
  211. Procedure TestFunction_ClampArg;
  212. Procedure TestFunction_ArgNameCallback;
  213. end;
  214. { TTestDictionaryParser }
  215. TTestDictionaryParser = Class(TTestParser)
  216. private
  217. FDict: TIDLDictionaryDefinition;
  218. FisPartial: Boolean;
  219. procedure AssertMember(aIndex: Integer; Aname, ATypeName, aDefaultValue: String; aDefaultType: TConstType=ctNull; isRequired: Boolean=False);
  220. Protected
  221. Property isPartial : Boolean Read FisPartial Write FisPartial;
  222. Public
  223. Function ParseDictionary(AName,aInheritance : UTF8String; AMembers : Array of UTF8String) : TIDLDictionaryDefinition;
  224. Property Dict : TIDLDictionaryDefinition read FDict;
  225. Published
  226. Procedure ParseSingleSimpleElement;
  227. Procedure ParseSingleSimpleElementInheritance;
  228. Procedure ParseSingleSimpleElementAttributes;
  229. Procedure ParseSingleSimpleElementAttributes2;
  230. Procedure ParseSingleSimpleElementRequired;
  231. Procedure ParseSingleSimpleElementDefaultString;
  232. Procedure ParseSingleSimpleElementRequiredDefaultString;
  233. Procedure ParseSingleSimpleElementRequiredDefaultEmptyArray;
  234. Procedure ParseSingleSimpleElementRequiredDefaultNull;
  235. Procedure ParseSingleSimpleElementUnsignedLongLong;
  236. Procedure ParseTwoSimpleElements;
  237. Procedure ParseThreeElements;
  238. Procedure ParsePartialSingleSimpleElement;
  239. end;
  240. { TTestFunctionCallbackParser }
  241. TTestFunctionCallbackParser = Class(TTestParser)
  242. private
  243. FFunction: TIDLFunctionDefinition;
  244. Public
  245. function ParseCallback(Const AName, aReturnType: UTF8String; AArguments: array of UTF8String): TIDLFunctionDefinition;
  246. Property Func : TIDLFunctionDefinition Read FFunction;
  247. Published
  248. Procedure ParseNoArgumentsReturnVoid;
  249. Procedure ParseOneArgumentReturnVoid;
  250. Procedure ParseOneUnsignedLongLongArgumentReturnVoid;
  251. Procedure ParseOneUnsignedLongLongArgumentReturnUnsignedLongLong;
  252. Procedure ParseOneArgumentWithAttrsReturnVoid;
  253. Procedure ParseOneOptionalArgumentReturnVoid;
  254. Procedure ParseOneOptionalArgumentWithAttrsReturnVoid;
  255. Procedure ParseTwoArgumentsReturnVoid;
  256. Procedure ParseTwoArgumentsAttrsReturnVoid;
  257. Procedure ParseThreeArgumentsAttrsReturnVoid;
  258. end;
  259. { TTestImplementsParser }
  260. TTestImplementsParser = Class(TTestParser)
  261. private
  262. FImpl: TIDLImplementsDefinition;
  263. Public
  264. Function ParseImplements(Const AName,aImplements: UTF8String) : TIDLImplementsDefinition;
  265. Property Impl: TIDLImplementsDefinition Read FImpl;
  266. Published
  267. Procedure ParseImplementsSimple;
  268. end;
  269. { TTestIncludesParser }
  270. TTestIncludesParser = Class(TTestParser)
  271. private
  272. FImpl: TIDLIncludesDefinition;
  273. Public
  274. Function ParseIncludes(Const AName,aIncludes: UTF8String) : TIDLIncludesDefinition;
  275. Property Impl: TIDLIncludesDefinition Read FImpl;
  276. Published
  277. Procedure ParseIncludesSimple;
  278. end;
  279. { TTestIterableInterfaceParser }
  280. TTestIterableInterfaceParser = Class(TTestBaseInterfaceParser)
  281. private
  282. Fiter: TIDLIterableDefinition;
  283. Public
  284. Function ParseIterable(Const AValueTypeName,AKeyTypeName : UTF8String) : TIDLIterableDefinition;
  285. Property Iter : TIDLIterableDefinition Read FIter;
  286. Published
  287. Procedure ParseSimpleIter;
  288. Procedure ParseKeyValueIter;
  289. end;
  290. implementation
  291. uses typinfo;
  292. { TTestSetLikeInterfaceParser }
  293. function TTestSetLikeInterfaceParser.ParseSetLike(
  294. const aElementTypeName: UTF8String; IsReadOnly: Boolean
  295. ): TIDLSetlikeDefinition;
  296. Var
  297. Id : TIDLInterfaceDefinition;
  298. S : UTF8String;
  299. begin
  300. Version:=V2;
  301. S:=Format('setlike <%s>',[aElementTypeName]);
  302. if isReadOnly then
  303. S:='readonly '+S;
  304. Id:=ParseInterFace('IA','',[S]);
  305. AssertEquals('Correct class',TIDLSetLikeDefinition,Id.Members[0].ClassType);
  306. Result:=Id.Members[0] as TIDLSetLikeDefinition;
  307. AssertNotNull('Have key type',Result.ElementType);
  308. AssertEquals('key type',TIDLTypeDefDefinition, Result.ElementType.ClassType);
  309. AssertEquals('Key type Name',AElementTypeName,Result.ElementType.TypeName);
  310. AssertEquals('Readonly',IsReadOnly,Result.IsReadOnly);
  311. end;
  312. procedure TTestSetLikeInterfaceParser.Parse;
  313. begin
  314. ParseSetLike('short',False);
  315. end;
  316. procedure TTestSetLikeInterfaceParser.ParseReadOnly;
  317. begin
  318. ParseSetLike('short',True);
  319. end;
  320. { TTestMapLikeInterfaceParser }
  321. function TTestMapLikeInterfaceParser.ParseMapLike(const AKeyTypeName,
  322. aValueTypeName: UTF8String; IsReadOnly : Boolean): TIDLMapLikeDefinition;
  323. Var
  324. Id : TIDLInterfaceDefinition;
  325. S : UTF8String;
  326. begin
  327. Version:=V2;
  328. S:=Format('maplike <%s,%s>',[aKeyTypeName,aValueTypeName]);
  329. if isReadOnly then
  330. S:='readonly '+S;
  331. Id:=ParseInterFace('IA','',[S]);
  332. AssertEquals('Correct class',TIDLMapLikeDefinition,Id.Members[0].ClassType);
  333. Result:=Id.Members[0] as TIDLMapLikeDefinition;
  334. AssertNotNull('Have key type',Result.KeyType);
  335. AssertEquals('key type',TIDLTypeDefDefinition, Result.KeyType.ClassType);
  336. AssertEquals('Key type Name',AKeyTypeName,Result.KeyType.TypeName);
  337. AssertNotNull('Have value type',Result.ValueType);
  338. AssertEquals('key value',TIDLTypeDefDefinition, Result.ValueType.ClassType);
  339. AssertEquals('Key value Name',AValueTypeName,Result.ValueType.TypeName);
  340. AssertEquals('Readonly',IsReadOnly,Result.IsReadOnly);
  341. end;
  342. procedure TTestMapLikeInterfaceParser.Parse;
  343. begin
  344. ParseMapLike('short','string',False);
  345. end;
  346. procedure TTestMapLikeInterfaceParser.ParseReadOnly;
  347. begin
  348. ParseMapLike('short','string',True);
  349. end;
  350. { TTestIncludesParser }
  351. function TTestIncludesParser.ParseIncludes(const AName, aIncludes: UTF8String
  352. ): TIDLIncludesDefinition;
  353. Var
  354. Src : UTF8String;
  355. begin
  356. Src:=AName+' includes '+aIncludes+';'+sLineBreak;
  357. InitSource(Src);
  358. Parser.Version:=v2;
  359. Parser.Parse;
  360. AssertEquals('Correct class',TIDLIncludesDefinition,Definitions[0].ClassType);
  361. Result:=Definitions[0] as TIDLIncludesDefinition;
  362. AssertEquals('Correct name ',AName,Result.Name);
  363. AssertEquals('Correct implements ',aIncludes,Result.IncludedInterface);
  364. FImpl:=Result;
  365. end;
  366. procedure TTestIncludesParser.ParseIncludesSimple;
  367. begin
  368. end;
  369. { TTestOperationInterfaceParser }
  370. function TTestOperationInterfaceParser.ParseFunction(ADef, aName,
  371. aReturnType: UTF8String; aArguments: array of UTF8String): TIDLFunctionDefinition;
  372. Var
  373. TN: UTF8String;
  374. P,I,Idx : integer;
  375. Arg : TIDLArgumentDefinition;
  376. ID : TIDLInterfaceDefinition;
  377. begin
  378. ID:=ParseInterface('IA','',[aDef]);
  379. Parser.Parse;
  380. AssertEquals('Correct class',TIDLFunctionDefinition,ID.Members[0].ClassType);
  381. Result:=ID.Members[0] as TIDLFunctionDefinition;
  382. AssertEquals('Name',AName,Result.Name);
  383. AssertNotNull('Have return type',Result.ReturnType);
  384. AssertEquals('Return type name',aReturnType,Result.ReturnType.TypeName);
  385. AssertEquals('Have arguments',Length(aArguments)>0,Result.HasArguments);
  386. AssertEquals('Argument count',Length(aArguments) div 2,Result.Arguments.Count);
  387. I:=0;
  388. While I<Length(aArguments)-1 do
  389. begin
  390. Idx:=I div 2;
  391. Arg:=Result.Argument[idx];
  392. AssertEquals('Argument '+IntToStr(Idx)+' name',aArguments[I+1],Arg.Name);
  393. AssertNotNull('Argument '+IntToStr(Idx)+' have type',Arg.ArgumentType);
  394. TN:=aArguments[I];
  395. P:=Pos(']',TN);
  396. If P>0 then
  397. TN:=Trim(Copy(TN,P+1,Length(TN)-P));
  398. if Pos('optional',TN)=1 then
  399. TN:=Trim(Copy(TN,9,Length(TN)-8));
  400. AssertEquals('Argument '+IntToStr(I div 2)+' type name',TN,Arg.ArgumentType.TypeName);
  401. Inc(I,2);
  402. end;
  403. FFunc:=Result;
  404. end;
  405. procedure TTestOperationInterfaceParser.TestSimpleFunction;
  406. begin
  407. ParseFunction('short A()','A','short',[]);
  408. end;
  409. procedure TTestOperationInterfaceParser.TestSimpleGetterFunction;
  410. begin
  411. AssertEquals('Options',[foGetter],ParseFunction('getter short A()','A','short',[]).Options);
  412. end;
  413. procedure TTestOperationInterfaceParser.TestSimpleGetterFunctionNoName;
  414. var
  415. F: TIDLFunctionDefinition;
  416. begin
  417. F:=ParseFunction('getter double (unsigned long index)','','double',['unsigned long','index']);
  418. AssertEquals('Options',[foGetter],F.Options);
  419. end;
  420. procedure TTestOperationInterfaceParser.TestSimpleSetterFunction;
  421. begin
  422. AssertEquals('Options',[foSetter],ParseFunction('setter short A()','A','short',[]).Options);
  423. end;
  424. procedure TTestOperationInterfaceParser.TestSimpleLegacyCallerFunction;
  425. begin
  426. AssertEquals('Options',[foLegacyCaller],ParseFunction('legacycaller short A()','A','short',[]).Options);
  427. end;
  428. procedure TTestOperationInterfaceParser.TestSimpleDeleterFunction;
  429. begin
  430. AssertEquals('Options',[foDeleter],ParseFunction('deleter short A()','A','short',[]).Options);
  431. end;
  432. procedure TTestOperationInterfaceParser.TestAttrFunctionFunction;
  433. begin
  434. AssertTrue('HasAttribute',ParseFunction('[Me] short A()','A','short',[]).HasSimpleAttribute('Me'));
  435. end;
  436. procedure TTestOperationInterfaceParser.TestOptionalDefaultArgFunction;
  437. begin
  438. ParseFunction('void A(optional short me = 0,optional short you = 0)','A','void',['short','me','short','you'])
  439. end;
  440. procedure TTestOperationInterfaceParser.TestFunction_ClampArg;
  441. var
  442. F: TIDLFunctionDefinition;
  443. Arg: TIDLDefinition;
  444. begin
  445. F:=ParseFunction('void A(optional [Clamp] long long start)','A','void',['long long','start']);
  446. Arg:=F.Arguments[0];
  447. AssertEquals('optional arg is Clamp',true,Arg.HasSimpleAttribute('Clamp'));
  448. end;
  449. procedure TTestOperationInterfaceParser.TestFunction_ArgNameCallback;
  450. begin
  451. ParseFunction('void getAsString(FunctionStringCallback? callback)','getAsString','void',['FunctionStringCallback','callback']);
  452. end;
  453. { TTestSerializerInterfaceParser }
  454. function TTestSerializerInterfaceParser.ParseSerializer(ADef: UTF8String; Attrs: array of UTF8String): TIDLSerializerDefinition;
  455. Var
  456. Id : TIDLInterfaceDefinition;
  457. i : Integer;
  458. begin
  459. Id:=ParseInterFace('IA','',['serializer '+ADef]);
  460. AssertEquals('Correct class',TIDLSerializerDefinition,Id.Members[0].ClassType);
  461. Result:=Id.Members[0] as TIDLSerializerDefinition;
  462. if (Length(Attrs)>0) then
  463. begin
  464. AssertTrue('Kind is object or array',Result.Kind in [skObject,skArray,skSingle]);
  465. AssertEquals('Identifier count',Length(Attrs),Result.Identifiers.Count);
  466. For I:=0 to Length(Attrs)-1 do
  467. AssertEquals('Identifier',Attrs[I],Result.Identifiers[i]);
  468. end
  469. else if (Result.SerializerFunction<>Nil) then
  470. AssertTrue('Kind is function',Result.Kind=skFunction);
  471. FSer:=Result;
  472. end;
  473. procedure TTestSerializerInterfaceParser.TestSimpleIdentifier;
  474. begin
  475. ParseSerializer('= A',['A']);
  476. end;
  477. procedure TTestSerializerInterfaceParser.TestSimpleFunction;
  478. Var
  479. D : TIDLFunctionDefinition;
  480. begin
  481. AssertNotNull(ParseSerializer('string A ()',[]).SerializerFunction);
  482. D:=Ser.SerializerFunction;
  483. AssertEquals('Function name','A',D.Name);
  484. end;
  485. procedure TTestSerializerInterfaceParser.TestMap;
  486. begin
  487. ParseSerializer('= {A, B, C}',['A','B','C']);
  488. AssertTrue('Map',Ser.Kind=skObject);
  489. end;
  490. procedure TTestSerializerInterfaceParser.TestMapWithInherited;
  491. begin
  492. ParseSerializer('= {inherit, B, C}',['inherit','B','C']);
  493. AssertTrue('Map',Ser.Kind=skObject);
  494. end;
  495. procedure TTestSerializerInterfaceParser.TestMapWithGetter;
  496. begin
  497. ParseSerializer('= {getter, B, C}',['getter','B','C']);
  498. AssertTrue('Map',Ser.Kind=skObject);
  499. end;
  500. procedure TTestSerializerInterfaceParser.TestList;
  501. begin
  502. ParseSerializer('= [A, B, C]',['A','B','C']);
  503. AssertTrue('Map',Ser.Kind=skArray);
  504. end;
  505. procedure TTestSerializerInterfaceParser.TestListWithGetter;
  506. begin
  507. ParseSerializer('= [getter, B, C]',['getter','B','C']);
  508. AssertTrue('Map',Ser.Kind=skArray);
  509. end;
  510. { TTestIterableInterfaceParser }
  511. function TTestIterableInterfaceParser.ParseIterable(const AValueTypeName,
  512. AKeyTypeName: UTF8String): TIDLIterableDefinition;
  513. Var
  514. Id : TIDLInterfaceDefinition;
  515. Src : UTF8String;
  516. begin
  517. Src:='iterable <';
  518. if AKeyTypeName<>'' then
  519. Src:=Src+aKeyTypeName+',';
  520. Src:=Src+aValueTypeName+'>';
  521. Id:=ParseInterFace('IA','',[Src]);
  522. AssertEquals('Correct class',TIDLIterableDefinition,Id.Members[0].ClassType);
  523. Result:=Id.Members[0] as TIDLIterableDefinition;
  524. AssertNotNull('Have value type',Result.ValueType);
  525. AssertEquals('Attr type',AValueTypeName,Result.ValueType.TypeName);
  526. if AKeyTypeName='' then
  527. AssertNull('No key type',Result.KeyType)
  528. else
  529. begin
  530. AssertNotNull('Have key type',Result.KeyType);
  531. AssertEquals('Attr type',AKeyTypeName,Result.KeyType.TypeName);
  532. end;
  533. Fiter:=Result;
  534. end;
  535. procedure TTestIterableInterfaceParser.ParseSimpleIter;
  536. begin
  537. ParseIterable('short','');
  538. end;
  539. procedure TTestIterableInterfaceParser.ParseKeyValueIter;
  540. begin
  541. ParseIterable('short','long');
  542. end;
  543. { TTestAttributeInterfaceParser }
  544. function TTestAttributeInterfaceParser.ParseAttribute(ADef, AName,
  545. ATypeName: UTF8String; Options: TAttributeOptions): TIDLAttributeDefinition;
  546. Var
  547. Id : TIDLInterfaceDefinition;
  548. begin
  549. Id:=ParseInterFace('IA','',[aDef]);
  550. AssertEquals('Correct class',TIDLAttributeDefinition,Id.Members[0].ClassType);
  551. Result:=Id.Members[0] as TIDLAttributeDefinition;
  552. AssertEquals('Attr name',AName,Result.Name);
  553. AssertNotNull('Have type',Result.AttributeType);
  554. AssertEquals('Attr type',ATypeName,Result.AttributeType.TypeName);
  555. AssertEquals('Attr options',Options,Result.Options);
  556. FAttr:=Result;
  557. end;
  558. procedure TTestAttributeInterfaceParser.ParseSimpleAttribute;
  559. begin
  560. ParseAttribute('attribute short A','A','short',[]);
  561. end;
  562. procedure TTestAttributeInterfaceParser.ParseSimpleAttributeWithExtendedAttrs;
  563. begin
  564. AssertTrue('Have attribute',ParseAttribute('[Me] attribute short A','A','short',[]).HasSimpleAttribute('Me'));
  565. end;
  566. procedure TTestAttributeInterfaceParser.ParseSimpleAttributeLegacyNullToEmptyString;
  567. begin
  568. ParseAttribute('attribute [LegacyNullToEmptyString] DOMString A','A','DOMString',[]);
  569. end;
  570. procedure TTestAttributeInterfaceParser.ParseSimpleStaticAttribute;
  571. begin
  572. ParseAttribute('static attribute short A','A','short',[aoStatic]);
  573. end;
  574. procedure TTestAttributeInterfaceParser.ParseSimpleStringifierAttribute;
  575. begin
  576. ParseAttribute('stringifier attribute short A','A','short',[aoStringifier]);
  577. end;
  578. procedure TTestAttributeInterfaceParser.ParseStringifierNoAttribute;
  579. var
  580. Id: TIDLInterfaceDefinition;
  581. Def: TIDLAttributeDefinition;
  582. begin
  583. Id:=ParseInterFace('IA','',['stringifier']);
  584. AssertEquals('Correct class',TIDLAttributeDefinition,Id.Members[0].ClassType);
  585. Def:=Id.Members[0] as TIDLAttributeDefinition;
  586. AssertEquals('Attr name','',Def.Name);
  587. AssertNull('Have type',Def.AttributeType);
  588. AssertEquals('Attr options',[aoStringifier],Def.Options);
  589. end;
  590. procedure TTestAttributeInterfaceParser.ParseSimpleReadonlyAttribute;
  591. begin
  592. ParseAttribute('readonly attribute short A','A','short',[aoReadOnly]);
  593. end;
  594. procedure TTestAttributeInterfaceParser.ParseSimpleInheritedAttribute;
  595. begin
  596. ParseAttribute('inherit attribute short A','A','short',[aoInherit]);
  597. end;
  598. procedure TTestAttributeInterfaceParser.ParseSimpleReadonlyInheritedAttribute;
  599. begin
  600. ParseAttribute('inherit readonly attribute short A','A','short',[aoInherit,aoReadonly]);
  601. end;
  602. procedure TTestAttributeInterfaceParser.ParseSimpleReadonlyStaticAttribute;
  603. begin
  604. ParseAttribute('static readonly attribute short A','A','short',[aoStatic,aoReadOnly]);
  605. end;
  606. procedure TTestAttributeInterfaceParser.ParseSimpleReadonlyStringifierAttribute;
  607. begin
  608. ParseAttribute('stringifier readonly attribute short A','A','short',[aoStringifier,aoReadOnly]);
  609. end;
  610. procedure TTestAttributeInterfaceParser.ParseComplexReadonlyStaticAttribute;
  611. begin
  612. ParseAttribute('static readonly attribute unsigned long long A','A','unsigned long long',[aoStatic,aoReadOnly]);
  613. end;
  614. procedure TTestAttributeInterfaceParser.ParseSimpleAttributeRequired;
  615. begin
  616. ParseAttribute('attribute boolean required','required','boolean',[]);
  617. end;
  618. procedure TTestAttributeInterfaceParser.ParseIdentifierAttribute;
  619. begin
  620. ParseAttribute('attribute B A','A','B',[]);
  621. end;
  622. procedure TTestAttributeInterfaceParser.Parse2IdentifierAttributes;
  623. Var
  624. Id : TIDLInterfaceDefinition;
  625. begin
  626. Id:=ParseInterFace('IA','',['attribute B A','readonly attribute C D']);
  627. AssertEquals('Correct class',TIDLAttributeDefinition,Id.Members[0].ClassType);
  628. FAttr:=Id.Members[0] as TIDLAttributeDefinition;
  629. AssertEquals('Attr name','A',FAttr.Name);
  630. AssertNotNull('Have type',FAttr.AttributeType);
  631. AssertEquals('Attr type','B',FAttr.AttributeType.TypeName);
  632. AssertEquals('Attr options',[],FAttr.Options);
  633. FAttr:=Id.Members[1] as TIDLAttributeDefinition;
  634. AssertEquals('Attr name','D',FAttr.Name);
  635. AssertNotNull('Have type',FAttr.AttributeType);
  636. AssertEquals('Attr type','C',FAttr.AttributeType.TypeName);
  637. AssertEquals('Attr options',[aoReadonly],FAttr.Options);
  638. end;
  639. { TTestImplementsParser }
  640. function TTestImplementsParser.ParseImplements(const AName,
  641. aImplements: UTF8String): TIDLImplementsDefinition;
  642. Var
  643. Src : UTF8String;
  644. begin
  645. Src:=AName+' implements '+aImplements+';'+sLineBreak;
  646. InitSource(Src);
  647. Parser.Version:=V1;
  648. Parser.Parse;
  649. AssertEquals('Correct class',TIDLImplementsDefinition,Definitions[0].ClassType);
  650. Result:=Definitions[0] as TIDLImplementsDefinition;
  651. AssertEquals('Correct name ',AName,Result.Name);
  652. AssertEquals('Correct implements ',aImplements,Result.ImplementedInterface);
  653. FImpl:=Result;
  654. end;
  655. procedure TTestImplementsParser.ParseImplementsSimple;
  656. begin
  657. ParseImplements('A','B');
  658. end;
  659. { TTestFunctionCallbackParser }
  660. function TTestFunctionCallbackParser.ParseCallback(const AName,
  661. aReturnType: UTF8String; AArguments: array of UTF8String
  662. ): TIDLFunctionDefinition;
  663. Var
  664. TN,Src : UTF8String;
  665. P,I,Idx : integer;
  666. Arg : TIDLArgumentDefinition;
  667. begin
  668. Src:='callback '+aName+' = '+AReturnType+' (';
  669. I:=0;
  670. While I<Length(aArguments) do
  671. begin
  672. if I>0 then
  673. Src:=Src+', ';
  674. Src:=Src+aArguments[I]+ ' '+aArguments[I+1];
  675. Inc(I,2);
  676. end;
  677. Src:=Src+');'+sLineBreak;
  678. InitSource(Src);
  679. Parser.Parse;
  680. AssertEquals('Correct class',TIDLFunctionDefinition,Definitions[0].ClassType);
  681. Result:=Definitions[0] as TIDLFunctionDefinition;
  682. AssertEquals('Name',AName,Result.Name);
  683. AssertNotNull('Have return type',Result.ReturnType);
  684. AssertEquals('Return type name',aReturnType,Result.ReturnType.TypeName);
  685. AssertEquals('Have arguments',Length(aArguments)>0,Result.HasArguments);
  686. AssertEquals('Argument count',Length(aArguments) div 2,Result.Arguments.Count);
  687. I:=0;
  688. While I<Length(aArguments)-1 do
  689. begin
  690. Idx:=I div 2;
  691. Arg:=Result.Argument[idx];
  692. AssertEquals('Argument '+IntToStr(Idx)+' name',aArguments[I+1],Arg.Name);
  693. AssertNotNull('Argument '+IntToStr(Idx)+' have type',Arg.ArgumentType);
  694. TN:=aArguments[I];
  695. P:=Pos(']',TN);
  696. If P>0 then
  697. TN:=Trim(Copy(TN,P+1,Length(TN)-P));
  698. if Pos('optional',TN)=1 then
  699. TN:=Trim(Copy(TN,9,Length(TN)-8));
  700. AssertEquals('Argument '+IntToStr(I div 2)+' type name',TN,Arg.ArgumentType.TypeName);
  701. Inc(I,2);
  702. end;
  703. FFunction:=Result;
  704. end;
  705. procedure TTestFunctionCallbackParser.ParseNoArgumentsReturnVoid;
  706. begin
  707. ParseCallback('A','void',[]);
  708. end;
  709. procedure TTestFunctionCallbackParser.ParseOneArgumentReturnVoid;
  710. begin
  711. ParseCallback('A','void',['short','A']);
  712. end;
  713. procedure TTestFunctionCallbackParser.ParseOneUnsignedLongLongArgumentReturnVoid;
  714. begin
  715. ParseCallback('A','void',['unsigned long long','A']);
  716. end;
  717. procedure TTestFunctionCallbackParser.ParseOneUnsignedLongLongArgumentReturnUnsignedLongLong;
  718. begin
  719. ParseCallback('A','unsigned long long',['unsigned long long','A']);
  720. end;
  721. procedure TTestFunctionCallbackParser.ParseOneArgumentWithAttrsReturnVoid;
  722. begin
  723. ParseCallback('A','void',['[Me] unsigned long long','A']);
  724. AssertTrue('Have attribute',Func.Arguments[0].HasSimpleAttribute('Me'));
  725. end;
  726. procedure TTestFunctionCallbackParser.ParseOneOptionalArgumentReturnVoid;
  727. begin
  728. ParseCallback('A','void',['optional unsigned long long','A']);
  729. AssertTrue('is optional',Func.Argument[0].IsOptional);
  730. AssertEquals('Type name','unsigned long long',Func.Argument[0].ArgumentType.TypeName);
  731. end;
  732. procedure TTestFunctionCallbackParser.ParseOneOptionalArgumentWithAttrsReturnVoid;
  733. begin
  734. ParseCallback('A','void',['optional [Me] unsigned long long','A']);
  735. AssertTrue('is optional',Func.Argument[0].IsOptional);
  736. AssertEquals('Type name','unsigned long long',Func.Argument[0].ArgumentType.TypeName);
  737. AssertTrue('Have attribute',Func.Arguments[0].HasSimpleAttribute('Me'));
  738. end;
  739. procedure TTestFunctionCallbackParser.ParseTwoArgumentsReturnVoid;
  740. begin
  741. ParseCallback('A','void',['short','B','short','C']);
  742. end;
  743. procedure TTestFunctionCallbackParser.ParseTwoArgumentsAttrsReturnVoid;
  744. begin
  745. ParseCallback('A','void',['[Me] short','B','[Me] short','C']);
  746. AssertTrue('Have attribute',Func.Arguments[0].HasSimpleAttribute('Me'));
  747. AssertTrue('Have attribute',Func.Arguments[1].HasSimpleAttribute('Me'));
  748. end;
  749. procedure TTestFunctionCallbackParser.ParseThreeArgumentsAttrsReturnVoid;
  750. begin
  751. ParseCallback('A','void',['[Me] short','B','[Me] short','C','optional [Me] unsigned long long','D']);
  752. AssertTrue('Have attribute',Func.Arguments[0].HasSimpleAttribute('Me'));
  753. AssertTrue('Have attribute',Func.Arguments[1].HasSimpleAttribute('Me'));
  754. AssertTrue('Have attribute',Func.Arguments[2].HasSimpleAttribute('Me'));
  755. AssertTrue('Have attribute',Func.Argument[2].IsOptional);
  756. end;
  757. { TTestDictionaryParser }
  758. function TTestDictionaryParser.ParseDictionary(AName, aInheritance: UTF8String;
  759. AMembers: array of UTF8String): TIDLDictionaryDefinition;
  760. Var
  761. Src : UTF8String;
  762. I : integer;
  763. begin
  764. Src:='dictionary '+aName+' ';
  765. If IsPartial then
  766. Src:='partial '+Src;
  767. if (aInheritance<>'') then
  768. Src:=Src+': '+aInheritance+' ';
  769. Src:=Src+'{'+sLineBreak;
  770. For I:=0 to Length(AMembers)-1 do
  771. Src:=Src+AMembers[I]+';'+sLineBreak;
  772. Src:=Src+'};'+sLineBreak;
  773. InitSource(Src);
  774. Parser.Parse;
  775. AssertEquals('Correct class',TIDLDictionaryDefinition,Definitions[0].ClassType);
  776. Result:=Definitions[0] as TIDLDictionaryDefinition;
  777. AssertEquals('Name',AName,Result.Name);
  778. AssertEquals('Inheritance : ',aInheritance,Result.ParentName);
  779. AssertEquals('Member count',Length(AMembers),Result.Members.Count);
  780. FDict:=Result;
  781. end;
  782. procedure TTestDictionaryParser.AssertMember(aIndex : Integer; Aname, ATypeName,aDefaultValue : String; aDefaultType : TConstType = ctNull; isRequired : Boolean = False);
  783. Var
  784. m : TIDLDictionaryMemberDefinition;
  785. S : string;
  786. begin
  787. S:=Format('Member %d (Name %s)',[aIndex,AName]);
  788. AssertNotNull(S+' have dict',Dict);
  789. AssertTrue(S+' dict has members',Dict.HasMembers);
  790. AssertTrue(S+' index in range',(aIndex>=0) and (aIndex<Dict.Members.Count));
  791. AssertEquals(S+' element has correct class',TIDLDictionaryMemberDefinition,Dict.Members[aIndex].ClassType);
  792. M:=Dict[aIndex];
  793. AssertEquals(S+' isRequired : ',isRequired,M.IsRequired);
  794. AssertEquals(S+' Name : ',aName,M.Name);
  795. AssertNotNull(S+' Have type',M.MemberType);
  796. AssertEquals(S+' type name',aTypeName,M.MemberType.TypeName);
  797. if (aDefaultValue='') then
  798. AssertNull(S+' Have no default value',M.DefaultValue)
  799. else
  800. begin
  801. AssertNotNull(S+' Have default value',M.DefaultValue);
  802. AssertEquals(S+' default value',aDefaultValue,M.DefaultValue.Value);
  803. AssertEquals(S+' default value type',aDefaultType,M.DefaultValue.ConstType);
  804. end;
  805. end;
  806. procedure TTestDictionaryParser.ParseSingleSimpleElement;
  807. begin
  808. ParseDictionary('A','',['string B']);
  809. AssertMember(0,'B','string','');
  810. end;
  811. procedure TTestDictionaryParser.ParseSingleSimpleElementInheritance;
  812. begin
  813. ParseDictionary('A','C',['string B']);
  814. AssertMember(0,'B','string','');
  815. end;
  816. procedure TTestDictionaryParser.ParseSingleSimpleElementAttributes;
  817. begin
  818. ParseDictionary('A','',['[Replaceable] required string B']);
  819. AssertMember(0,'B','string','',ctNull,True);
  820. AssertTrue('Has attributes',Dict[0].HasAttributes);
  821. AssertEquals('Attribute count',1,Dict[0].Attributes.Count);
  822. AssertEquals('Has attributes','Replaceable',Dict[0].Attributes[0]);
  823. end;
  824. procedure TTestDictionaryParser.ParseSingleSimpleElementAttributes2;
  825. begin
  826. ParseDictionary('A','',['[Replaceable] octet B']);
  827. AssertMember(0,'B','octet','',ctNull,False);
  828. AssertTrue('Has attributes',Dict[0].HasAttributes);
  829. AssertEquals('Attribute count',1,Dict[0].Attributes.Count);
  830. AssertEquals('Has attributes','Replaceable',Dict[0].Attributes[0]);
  831. end;
  832. procedure TTestDictionaryParser.ParseSingleSimpleElementRequired;
  833. begin
  834. ParseDictionary('A','',['required string B']);
  835. AssertMember(0,'B','string','',ctNull,True);
  836. end;
  837. procedure TTestDictionaryParser.ParseSingleSimpleElementDefaultString;
  838. begin
  839. ParseDictionary('A','',['string B = "abc"']);
  840. AssertMember(0,'B','string','abc',ctString);
  841. end;
  842. procedure TTestDictionaryParser.ParseSingleSimpleElementRequiredDefaultString;
  843. begin
  844. ParseDictionary('A','',['required string B = "abc"']);
  845. AssertMember(0,'B','string','abc',ctString,true);
  846. end;
  847. procedure TTestDictionaryParser.ParseSingleSimpleElementRequiredDefaultEmptyArray;
  848. begin
  849. ParseDictionary('A','',['required string B = []']);
  850. AssertMember(0,'B','string','[]',ctEmptyArray,true);
  851. end;
  852. procedure TTestDictionaryParser.ParseSingleSimpleElementRequiredDefaultNull;
  853. begin
  854. ParseDictionary('A','',['string B = null']);
  855. AssertMember(0,'B','string','null',ctNull,False);
  856. end;
  857. procedure TTestDictionaryParser.ParseSingleSimpleElementUnsignedLongLong;
  858. begin
  859. ParseDictionary('A','',['required unsigned long long B']);
  860. AssertMember(0,'B','unsigned long long','',ctNull,True);
  861. end;
  862. procedure TTestDictionaryParser.ParseTwoSimpleElements;
  863. begin
  864. ParseDictionary('A','',['string B','short C']);
  865. AssertMember(0,'B','string','');
  866. AssertMember(1,'C','short','');
  867. end;
  868. procedure TTestDictionaryParser.ParseThreeElements;
  869. begin
  870. ParseDictionary('A','',['string B','short C','required unsigned long long D']);
  871. AssertMember(0,'B','string','');
  872. AssertMember(1,'C','short','');
  873. AssertMember(2,'D','unsigned long long','',ctNull,true);
  874. end;
  875. procedure TTestDictionaryParser.ParsePartialSingleSimpleElement;
  876. begin
  877. isPartial:=True;
  878. ParseDictionary('A','',['string B']);
  879. AssertMember(0,'B','string','');
  880. AssertTrue('Partial',Dict.IsPartial);
  881. end;
  882. { TTestTypeDefParser }
  883. function TTestTypeDefParser.TestTypeDef(const aSource, AName, aType: UTF8String
  884. ): TIDLTypeDefDefinition;
  885. Var
  886. E : TIDLTypeDefDefinition;
  887. begin
  888. InitSource('typedef '+ASource+';');
  889. Parser.Parse;
  890. AssertEquals('Definition count',1,Definitions.Count);
  891. AssertTrue('Correct class',Definitions[0].ClassType.InheritsFrom(TIDLTypeDefDefinition));
  892. E:=Definitions[0] as TIDLTypeDefDefinition;
  893. AssertEquals('Name',AName,E.Name);
  894. AssertEquals('Type name',AType,E.TypeName);
  895. if Pos('?',aSource)=0 then
  896. AssertEquals('Not Null',False,E.AllowNull);
  897. Result:=E;
  898. end;
  899. procedure TTestTypeDefParser.TestSimpleBoolean;
  900. begin
  901. TestTypeDef('boolean A','A','boolean');
  902. end;
  903. procedure TTestTypeDefParser.TestSimpleBooleanNull;
  904. begin
  905. AssertTrue('AllowNull',TestTypeDef('boolean ? A','A','boolean').AllowNull);
  906. end;
  907. procedure TTestTypeDefParser.TestSimpleInt;
  908. begin
  909. TestTypeDef('short A','A','short');
  910. end;
  911. procedure TTestTypeDefParser.TestSimpleIntNull;
  912. begin
  913. AssertTrue('AllowNull',TestTypeDef('short ? A','A','short').AllowNull);
  914. end;
  915. procedure TTestTypeDefParser.TestSimpleLongint;
  916. begin
  917. TestTypeDef('long A','A','long');
  918. end;
  919. procedure TTestTypeDefParser.TestSimpleLongintNull;
  920. begin
  921. AssertTrue('AllowNull',TestTypeDef('long ? A','A','long').AllowNull);
  922. end;
  923. procedure TTestTypeDefParser.TestSimpleLongLongint;
  924. begin
  925. TestTypeDef('long long A','A','long long');
  926. end;
  927. procedure TTestTypeDefParser.TestSimpleLongLongintNull;
  928. begin
  929. AssertTrue('AllowNull',TestTypeDef('long long ? A','A','long long').AllowNull);
  930. end;
  931. procedure TTestTypeDefParser.TestSimpleUnsignedShortint;
  932. begin
  933. TestTypeDef('unsigned short A','A','unsigned short');
  934. end;
  935. procedure TTestTypeDefParser.TestSimpleUnsignedShortintNull;
  936. begin
  937. AssertTrue('AllowNull',TestTypeDef('unsigned short ? A','A','unsigned short').AllowNull);
  938. end;
  939. procedure TTestTypeDefParser.TestSimpleUnsignedLongint;
  940. begin
  941. TestTypeDef('unsigned long A','A','unsigned long');
  942. end;
  943. procedure TTestTypeDefParser.TestSimpleUnsignedLongintNull;
  944. begin
  945. AssertTrue('AllowNull',TestTypeDef('unsigned long ? A','A','unsigned long').AllowNull);
  946. end;
  947. procedure TTestTypeDefParser.TestSimpleUnsignedLongLongint;
  948. begin
  949. TestTypeDef('unsigned long long A','A','unsigned long long');
  950. end;
  951. procedure TTestTypeDefParser.TestSimpleUnsignedLongLongintNull;
  952. begin
  953. AssertTrue('AllowNull',TestTypeDef('unsigned long long ? A','A','unsigned long long').AllowNull);
  954. end;
  955. procedure TTestTypeDefParser.TestUnrestrictedFloat;
  956. begin
  957. TestTypeDef('unrestricted float A','A','unrestricted float');
  958. end;
  959. procedure TTestTypeDefParser.TestSimpleFloat;
  960. begin
  961. TestTypeDef('float A','A','float');
  962. end;
  963. procedure TTestTypeDefParser.TestSimpleFloatNull;
  964. begin
  965. AssertTrue('AllowNull',TestTypeDef('float ? A','A','float').AllowNull)
  966. end;
  967. procedure TTestTypeDefParser.TestSimpleDouble;
  968. begin
  969. TestTypeDef('double A','A','double');
  970. end;
  971. procedure TTestTypeDefParser.TestSimpleDoubleNull;
  972. begin
  973. AssertTrue('AllowNull',TestTypeDef('double ? A','A','double').AllowNull);
  974. end;
  975. procedure TTestTypeDefParser.TestSimpleOctet;
  976. begin
  977. TestTypeDef('octet A','A','octet');
  978. end;
  979. procedure TTestTypeDefParser.TestSimpleOctetNull;
  980. begin
  981. AssertTrue('AllowNull',TestTypeDef('octet ? A','A','octet').AllowNull);
  982. end;
  983. procedure TTestTypeDefParser.TestSimpleByte;
  984. begin
  985. TestTypeDef('byte A','A','byte');
  986. end;
  987. procedure TTestTypeDefParser.TestSimpleByteNull;
  988. begin
  989. AssertTrue('AllowNull',TestTypeDef('byte ? A','A','byte').AllowNull);
  990. end;
  991. procedure TTestTypeDefParser.TestSimpleIdentifier;
  992. begin
  993. TestTypeDef('Zaza A','A','Zaza');
  994. end;
  995. procedure TTestTypeDefParser.TestSimpleIdentifierNull;
  996. begin
  997. AssertTrue('AllowNull',TestTypeDef('Zaza ? A','A','Zaza').AllowNull);
  998. end;
  999. procedure TTestTypeDefParser.TestAnyType;
  1000. begin
  1001. TestTypeDef('any A','A','any');
  1002. end;
  1003. procedure TTestTypeDefParser.TestAnyTypeNull;
  1004. begin
  1005. AssertTrue('AllowNull',TestTypeDef('any ? A','A','any').AllowNull);
  1006. end;
  1007. function TTestTypeDefParser.DoTestUnion(aDef: String): TIDLUnionTypeDefDefinition;
  1008. Var
  1009. D : TIDLTypeDefDefinition;
  1010. U : TIDLUnionTypeDefDefinition;
  1011. begin
  1012. D:=TestTypeDef(aDef,'A','union');
  1013. AssertEquals('Correct class',TIDLUnionTypeDefDefinition,D.ClassType);
  1014. U:=TIDLUnionTypeDefDefinition(D);
  1015. AssertEquals('Union types',2,U.Union.Count);
  1016. AssertNotNull('Have type 1',U.Union[0]);
  1017. AssertEquals('1: Correct class',TIDLTypeDefDefinition,U.Union[0].ClassType);
  1018. D:=TIDLTypeDefDefinition(U.Union[0]);
  1019. AssertEquals('1: Correct type name','byte',D.TypeName);
  1020. AssertNotNull('Have type 2',U.Union[1]);
  1021. AssertEquals('2: Correct class',TIDLTypeDefDefinition,U.Union[1].ClassType);
  1022. D:=TIDLTypeDefDefinition(U.Union[1]);
  1023. AssertEquals('2: Correct type name','octet',D.TypeName);
  1024. Result:=U;
  1025. end;
  1026. procedure TTestTypeDefParser.TestUnion;
  1027. begin
  1028. DoTestUnion('(byte or octet) A');
  1029. end;
  1030. procedure TTestTypeDefParser.TestUnionNull;
  1031. begin
  1032. AssertTrue('Is null',DoTestUnion('(byte or octet) ? A').AllowNull);
  1033. end;
  1034. function TTestTypeDefParser.DoTestSequence(aDef: UTF8String
  1035. ): TIDLSequenceTypeDefDefinition;
  1036. Var
  1037. D : TIDLTypeDefDefinition;
  1038. S : TIDLSequenceTypeDefDefinition;
  1039. begin
  1040. D:=TestTypeDef(aDef ,'A','sequence');
  1041. AssertEquals('Correct class',TIDLSequenceTypeDefDefinition,D.ClassType);
  1042. S:=TIDLSequenceTypeDefDefinition(D);
  1043. AssertNotNull('Have element type',S.ElementType);
  1044. D:=TIDLTypeDefDefinition(S.ElementType);
  1045. AssertEquals('1: Correct type name','byte',D.TypeName);
  1046. Result:=S;
  1047. end;
  1048. function TTestTypeDefParser.DoTestRecord(aDef: UTF8String; const aKeyTypeName,
  1049. aValueTypeName: String): TIDLRecordDefinition;
  1050. Var
  1051. D : TIDLTypeDefDefinition;
  1052. R : TIDLRecordDefinition;
  1053. begin
  1054. Version:=v2;
  1055. D:=TestTypeDef(aDef ,'A','record');
  1056. AssertEquals('Correct class',TIDLRecordDefinition,D.ClassType);
  1057. R:=TIDLRecordDefinition(D);
  1058. AssertNotNull('Have key type',R.KeyType);
  1059. D:=TIDLTypeDefDefinition(R.KeyType);
  1060. AssertEquals('1: Correct type name',aKeyTypeName,D.TypeName);
  1061. AssertNotNull('Have value type',R.ValueType);
  1062. D:=TIDLTypeDefDefinition(R.ValueType);
  1063. AssertEquals('1: Correct type name',aValueTypeName,D.TypeName);
  1064. Result:=R;
  1065. end;
  1066. procedure TTestTypeDefParser.TestSequence;
  1067. begin
  1068. DoTestSequence('sequence<byte> A');
  1069. end;
  1070. procedure TTestTypeDefParser.TestSequenceNull;
  1071. begin
  1072. AssertTrue('Is Null ',DoTestSequence('sequence<byte> ? A').AllowNull);
  1073. end;
  1074. function TTestTypeDefParser.DoTestPromise(aDef: UTF8String; AReturnType : String = ''): TIDLPromiseTypeDefDefinition;
  1075. Var
  1076. D : TIDLTypeDefDefinition;
  1077. S : TIDLPromiseTypeDefDefinition;
  1078. begin
  1079. D:=TestTypeDef(ADef,'A','Promise');
  1080. AssertEquals('Correct class',TIDLPromiseTypeDefDefinition,D.ClassType);
  1081. S:=TIDLPromiseTypeDefDefinition(D);
  1082. AssertNotNull('Have element type',S.ReturnType);
  1083. D:=TIDLTypeDefDefinition(S.ReturnType);
  1084. if aReturnType='' then
  1085. aReturnType:='byte';
  1086. AssertEquals('1: Correct type name',aReturnType,D.TypeName);
  1087. Result:=S;
  1088. end;
  1089. procedure TTestTypeDefParser.TestPromise;
  1090. begin
  1091. DoTestPromise('Promise<byte> A');
  1092. end;
  1093. procedure TTestTypeDefParser.TestPromiseVoid;
  1094. begin
  1095. DoTestPromise('Promise<void> A','void');
  1096. end;
  1097. procedure TTestTypeDefParser.TestPromiseNull;
  1098. begin
  1099. AssertTrue('Is Null',DoTestPromise('Promise<byte> ? A').AllowNull);
  1100. end;
  1101. procedure TTestTypeDefParser.TestPromiseReturnNull;
  1102. begin
  1103. AssertTrue('ReturnType Is Null',DoTestPromise('Promise<byte ?> A').ReturnType.AllowNull);
  1104. end;
  1105. procedure TTestTypeDefParser.TestRecord;
  1106. begin
  1107. DoTestRecord('record <short,string> A','short','string');
  1108. end;
  1109. { TTestInterfaceParser }
  1110. procedure TTestBaseInterfaceParser.Setup;
  1111. begin
  1112. inherited Setup;
  1113. FIsMixin:=False
  1114. end;
  1115. function TTestBaseInterfaceParser.ParseInterface(AName,aInheritance: UTF8String;
  1116. AMembers: array of UTF8String): TIDLInterfaceDefinition;
  1117. Var
  1118. Src : UTF8String;
  1119. I : integer;
  1120. begin
  1121. if IsMixin then
  1122. Src:='interface mixin '+aName+' '
  1123. else
  1124. Src:='interface '+aName+' ';
  1125. if (FCustAttributes<>'') then
  1126. Src:=FCustAttributes+' '+Src;
  1127. if (aInheritance<>'') then
  1128. Src:=Src+': '+aInheritance+' ';
  1129. Src:=Src+'{'+sLineBreak;
  1130. For I:=0 to Length(AMembers)-1 do
  1131. Src:=Src+' '+AMembers[I]+';'+sLineBreak;
  1132. Src:=Src+'};'+sLineBreak;
  1133. InitSource(Src);
  1134. Parser.Parse;
  1135. AssertEquals('Correct class',TIDLInterfaceDefinition,Definitions[0].ClassType);
  1136. Result:=Definitions[0] as TIDLInterfaceDefinition;
  1137. AssertEquals('Name',AName,Result.Name);
  1138. AssertEquals('Inheritance : ',aInheritance,Result.ParentName);
  1139. AssertEquals('Member count',Length(AMembers),Result.Members.Count);
  1140. AssertEquals('Mixin correct',IsMixin,Result.IsMixin);
  1141. end;
  1142. function TTestConstInterfaceParser.ParseConst(AName, ATypeName, aValue: UTF8String;
  1143. AType: TConstType): TIDLConstDefinition;
  1144. Var
  1145. Id : TIDLInterfaceDefinition;
  1146. P : Integer;
  1147. isNull : Boolean;
  1148. begin
  1149. Id:=ParseInterFace('IA','',['const '+aTypeName+' '+AName+' = '+AValue]);
  1150. AssertEquals('Correct class',TIDLConstDefinition,Id.Members[0].ClassType);
  1151. Result:=Id.Members[0] as TIDLConstDefinition;
  1152. AssertEquals('Const Name',AName,Result.Name);
  1153. P:=Pos('?',ATypeName);
  1154. isNull:=P>0;
  1155. if IsNull then
  1156. ATypeName:=Trim(Copy(ATypeName,1,P-1));
  1157. AssertEquals('Const type',ATypeName,Result.TypeName);
  1158. AssertEquals('Const consttype',AType,Result.ConstType);
  1159. AssertEquals('Const value',AValue,Result.Value);
  1160. AssertEquals('Const null allowed',IsNull,Result.AllowNull);
  1161. end;
  1162. procedure TTestInterfaceParser.ParseEmpty;
  1163. begin
  1164. ParseInterface('A','',[]);
  1165. end;
  1166. procedure TTestInterfaceParser.ParseEmptyNoBrackets;
  1167. var
  1168. d: TIDLInterfaceDefinition;
  1169. begin
  1170. InitSource('interface A;'+sLineBreak);
  1171. Parser.Parse;
  1172. AssertEquals('Correct class',TIDLInterfaceDefinition,Definitions[0].ClassType);
  1173. d:=Definitions[0] as TIDLInterfaceDefinition;
  1174. AssertEquals('Name','A',d.Name);
  1175. AssertEquals('Inheritance : ','',d.ParentName);
  1176. AssertEquals('Member count',0,d.Members.Count);
  1177. AssertEquals('Mixin correct',false,d.IsMixin);
  1178. end;
  1179. procedure TTestInterfaceParser.ParseEmptyInheritance;
  1180. begin
  1181. ParseInterface('A','B',[]);
  1182. end;
  1183. procedure TTestInterfaceParser.ParseMixinEmpty;
  1184. begin
  1185. IsMixin:=true;
  1186. Version:=v2;
  1187. ParseInterface('A','',[]);
  1188. end;
  1189. procedure TTestInterfaceParser.ParseMixinEmptyInheritance;
  1190. begin
  1191. IsMixin:=true;
  1192. Version:=v2;
  1193. ParseInterface('A','B',[]);
  1194. end;
  1195. procedure TTestInterfaceParser.ParseCustomAttributes1;
  1196. begin
  1197. CustAttributes:='[Constructor(DOMString type,optional WebGLContextEventInit eventInit)]';
  1198. AssertEquals('Attributes',CustAttributes,ParseInterface('A','B',[]).Attributes.AsString(True));
  1199. end;
  1200. procedure TTestInterfaceParser.ParseIFDEFHeader;
  1201. var
  1202. d: TIDLInterfaceDefinition;
  1203. begin
  1204. InitSource('#ifdef Nothing'+sLineBreak
  1205. +'Skip This'+sLineBreak
  1206. +'#endif'+sLineBreak
  1207. +'interface A;'+sLineBreak);
  1208. Parser.Parse;
  1209. AssertEquals('Correct class',TIDLInterfaceDefinition,Definitions[0].ClassType);
  1210. d:=Definitions[0] as TIDLInterfaceDefinition;
  1211. AssertEquals('Name','A',d.Name);
  1212. AssertEquals('Inheritance : ','',d.ParentName);
  1213. AssertEquals('Member count',0,d.Members.Count);
  1214. AssertEquals('Mixin correct',false,d.IsMixin);
  1215. end;
  1216. procedure TTestConstInterfaceParser.ParseConstInt;
  1217. begin
  1218. ParseConst('A','short','123',ctInteger);
  1219. end;
  1220. procedure TTestConstInterfaceParser.Parse2ConstInt;
  1221. Var
  1222. Id : TIDLInterfaceDefinition;
  1223. CD : TIDLConstDefinition;
  1224. begin
  1225. Id:=ParseInterFace('IA','',['const GLenum READ_BUFFER = 0x0C02','const GLenum UNPACK_ROW_LENGTH = 0x0CF2']);
  1226. AssertEquals('Correct class',TIDLConstDefinition,Id.Members[0].ClassType);
  1227. CD:=Id.Members[0] as TIDLConstDefinition;
  1228. AssertEquals('Const Name','READ_BUFFER',CD.Name);
  1229. AssertEquals('Const type','GLenum',CD.TypeName);
  1230. AssertEquals('Const consttype',ctInteger,CD.ConstType);
  1231. AssertEquals('Const value','0x0C02',CD.Value);
  1232. AssertEquals('Const null allowed',False,CD.AllowNull);
  1233. CD:=Id.Members[1] as TIDLConstDefinition;
  1234. AssertEquals('Const Name','UNPACK_ROW_LENGTH',CD.Name);
  1235. AssertEquals('Const type','GLenum',CD.TypeName);
  1236. AssertEquals('Const consttype',ctInteger,CD.ConstType);
  1237. AssertEquals('Const value','0x0CF2',CD.Value);
  1238. AssertEquals('Const null allowed',False,CD.AllowNull);
  1239. end;
  1240. procedure TTestConstInterfaceParser.ParseConstIntHex;
  1241. begin
  1242. ParseConst('A','short','0xABCDEF',ctInteger);
  1243. end;
  1244. procedure TTestConstInterfaceParser.ParseConstLongint;
  1245. begin
  1246. ParseConst('A','long','123',ctInteger);
  1247. end;
  1248. procedure TTestConstInterfaceParser.ParseConstLongLongint;
  1249. begin
  1250. ParseConst('A','long long','123',ctInteger);
  1251. end;
  1252. procedure TTestConstInterfaceParser.ParseConstUnsignedShortint;
  1253. begin
  1254. ParseConst('A','unsigned short','123',ctInteger);
  1255. end;
  1256. procedure TTestConstInterfaceParser.ParseConstUnsignedLongint;
  1257. begin
  1258. ParseConst('A','unsigned long','123',ctInteger);
  1259. end;
  1260. procedure TTestConstInterfaceParser.ParseConstUnsignedLongLongint;
  1261. begin
  1262. ParseConst('A','unsigned long long','123',ctInteger);
  1263. end;
  1264. procedure TTestConstInterfaceParser.ParseConstFloat;
  1265. begin
  1266. ParseConst('A','float','1.23',ctFloat);
  1267. end;
  1268. procedure TTestConstInterfaceParser.ParseConstNan;
  1269. begin
  1270. ParseConst('A','float','NaN',ctNaN);
  1271. end;
  1272. procedure TTestConstInterfaceParser.ParseConstInfinity;
  1273. begin
  1274. ParseConst('A','float','Infinity',ctInfinity);
  1275. end;
  1276. procedure TTestConstInterfaceParser.ParseConstNegInfinity;
  1277. begin
  1278. ParseConst('A','float','-Infinity',ctNegInfinity);
  1279. end;
  1280. procedure TTestConstInterfaceParser.ParseConstNull;
  1281. begin
  1282. ParseConst('A','short ?','123',ctInteger);
  1283. end;
  1284. procedure TTestConstInterfaceParser.ParseConstOctet;
  1285. begin
  1286. ParseConst('A','octet','123',ctInteger);
  1287. end;
  1288. procedure TTestConstInterfaceParser.ParseConstByte;
  1289. begin
  1290. ParseConst('A','byte','123',ctInteger);
  1291. end;
  1292. procedure TTestConstInterfaceParser.ParseConstBooleantrue;
  1293. begin
  1294. ParseConst('A','boolean','true',ctBoolean);
  1295. end;
  1296. procedure TTestConstInterfaceParser.ParseConstBooleanFalse;
  1297. begin
  1298. ParseConst('A','boolean','false',ctBoolean);
  1299. end;
  1300. procedure TTestConstInterfaceParser.ParseConstIdentifier;
  1301. begin
  1302. ParseConst('A','Zaza','false',ctBoolean);
  1303. end;
  1304. { TTestEnumParser }
  1305. procedure TTestEnumParser.TestEnum(const aSource, AName: UTF8String;
  1306. AValues: array of UTF8String);
  1307. Var
  1308. E : TIDLEnumDefinition;
  1309. i : Integer;
  1310. begin
  1311. InitSource('enum '+ASource+';');
  1312. Parser.Parse;
  1313. AssertEquals('Definition count',1,Definitions.Count);
  1314. AssertEquals('Correct class',TIDLEnumDefinition,Definitions[0].ClassType);
  1315. E:=Definitions[0] as TIDLEnumDefinition;
  1316. AssertEquals('Name',AName,E.Name);
  1317. AssertEquals('Value count',Length(AValues),E.Values.Count);
  1318. For I:=0 to E.Values.Count-1 do
  1319. AssertEquals('Value '+IntToStr(i),AValues[i],E.Values[i]);
  1320. end;
  1321. procedure TTestEnumParser.TestSingle;
  1322. begin
  1323. TestEnum('A { "one" }','A',['one']);
  1324. end;
  1325. procedure TTestEnumParser.TestTwo;
  1326. begin
  1327. TestEnum('A { "one", "two" }','A',['one','two']);
  1328. end;
  1329. procedure TTestEnumParser.TestMissingIdent;
  1330. begin
  1331. AssertParserError('No ident','enum { "one" };');
  1332. end;
  1333. procedure TTestEnumParser.TestMissingOpening;
  1334. begin
  1335. AssertParserError('No {','enum A "one" };');
  1336. end;
  1337. procedure TTestEnumParser.TestMissingClosing;
  1338. begin
  1339. AssertParserError('No }','enum A { "one" ;');
  1340. end;
  1341. procedure TTestEnumParser.TestMissingSemicolon;
  1342. begin
  1343. AssertParserError('No ; ','enum A { "one" }');
  1344. end;
  1345. procedure TTestEnumParser.TestMissingComma;
  1346. begin
  1347. AssertParserError('No ; ','enum A { "one" "two"}');
  1348. end;
  1349. { TTestParser }
  1350. function TTestParser.GetList: TIDLDefinitionList;
  1351. begin
  1352. Result:=Context.Definitions;
  1353. end;
  1354. procedure TTestParser.SetVersion(AValue: TWebIDLVersion);
  1355. begin
  1356. if FVersion=AValue then Exit;
  1357. FVersion:=AValue;
  1358. if Assigned(FParser) then
  1359. FParser.Version:=aValue;
  1360. end;
  1361. procedure TTestParser.Setup;
  1362. begin
  1363. FContext:=TWebIDLContext.Create;
  1364. FVersion:=v1;
  1365. inherited Setup;
  1366. end;
  1367. procedure TTestParser.TearDown;
  1368. begin
  1369. FreeAndNil(FParser);
  1370. FreeAndNil(FContext);
  1371. inherited TearDown;
  1372. end;
  1373. procedure TTestParser.InitSource(const aSource: UTF8String);
  1374. begin
  1375. Writeln(TestName+' source : ');
  1376. Writeln(aSource);
  1377. FParser:=TWebIDLParser.Create(Context,aSource);
  1378. FParser.Version:=Version;
  1379. end;
  1380. procedure TTestParser.AssertParserError(const Msg: String;
  1381. const aSource: UTF8String);
  1382. begin
  1383. InitSource(aSource);
  1384. AssertException(Msg,EWebIDLParser,@Parser.Parse);
  1385. end;
  1386. class procedure TTestParser.AssertEquals(Msg: String; AExpected,
  1387. AActual: TConstType);
  1388. begin
  1389. AssertEQuals(Msg,GetEnumName(TypeInfo(TConstType),Ord(AExpected)),GetEnumName(TypeInfo(TConstType),Ord(AActual)));
  1390. end;
  1391. class procedure TTestParser.AssertEquals(Msg: String; AExpected,
  1392. AActual: TAttributeOption);
  1393. begin
  1394. AssertEquals(Msg,GetEnumName(TypeInfo(TAttributeOption),Ord(AExpected)),GetEnumName(TypeInfo(TAttributeOption),Ord(AActual)));
  1395. end;
  1396. class procedure TTestParser.AssertEquals(Msg: String; AExpected, AActual: TFunctionOption);
  1397. begin
  1398. AssertEquals(Msg,GetEnumName(TypeInfo(TFunctionOption),Ord(AExpected)),GetEnumName(TypeInfo(TFunctionOption),Ord(AActual)));
  1399. end;
  1400. class procedure TTestParser.AssertEquals(Msg: String; AExpected,
  1401. AActual: TAttributeOptions);
  1402. begin
  1403. AssertEquals(Msg,SetToString(PTypeInfo(TypeInfo(TAttributeOptions)),Integer(AExpected),True),
  1404. SetToString(PTypeInfo(TypeInfo(TAttributeOptions)),Integer(AActual),True));
  1405. end;
  1406. class procedure TTestParser.AssertEquals(Msg: String; AExpected,
  1407. AActual: TFunctionOptions);
  1408. begin
  1409. AssertEquals(Msg,SetToString(PTypeInfo(TypeInfo(TFunctionOptions)),Integer(AExpected),True),
  1410. SetToString(PTypeInfo(TypeInfo(TFunctionOptions)),Integer(AActual),True));
  1411. end;
  1412. initialization
  1413. RegisterTests([TTestEnumParser,
  1414. TTestInterfaceParser,
  1415. TTestConstInterfaceParser,
  1416. TTestTypeDefParser,
  1417. TTestDictionaryParser,
  1418. TTestFunctionCallbackParser,
  1419. TTestImplementsParser,
  1420. TTestIncludesParser,
  1421. TTestAttributeInterfaceParser,
  1422. TTestIterableInterfaceParser,
  1423. TTestSerializerInterfaceParser,
  1424. TTestOperationInterfaceParser,
  1425. TTestMapLikeInterfaceParser,
  1426. TTestSetLikeInterfaceParser]);
  1427. end.