6060import static org .sonar .plugins .communitydelphi .api .type .StructKind .RECORD ;
6161import static org .sonar .plugins .communitydelphi .api .type .TypeFactory .untypedType ;
6262
63+ import au .com .integradev .delphi .DelphiProperties ;
64+ import au .com .integradev .delphi .compiler .Toolchain ;
6365import au .com .integradev .delphi .type .factory .ArrayOption ;
6466import au .com .integradev .delphi .type .factory .TypeFactoryImpl ;
6567import au .com .integradev .delphi .type .parameter .FormalParameter ;
7274import java .util .List ;
7375import java .util .Set ;
7476import java .util .stream .Collectors ;
77+ import org .junit .jupiter .api .BeforeEach ;
7578import org .junit .jupiter .api .Test ;
79+ import org .junit .jupiter .params .ParameterizedTest ;
80+ import org .junit .jupiter .params .provider .EnumSource ;
7681import org .sonar .plugins .communitydelphi .api .ast .FormalParameterNode .FormalParameterData ;
7782import org .sonar .plugins .communitydelphi .api .symbol .Invocable ;
7883import org .sonar .plugins .communitydelphi .api .symbol .scope .DelphiScope ;
8388import org .sonar .plugins .communitydelphi .api .type .TypeFactory ;
8489
8590class InvocationResolverTest {
86- private static final TypeFactory FACTORY = TypeFactoryUtils . defaultFactory () ;
91+ private TypeFactory factory ;
8792 private Set <InvocationCandidate > resolved ;
8893
94+ @ BeforeEach
95+ void setup () {
96+ factory = TypeFactoryUtils .defaultFactory ();
97+ }
98+
8999 private void assertResolved (Type argumentType , Type winnerType , Type loserType ) {
90100 assertResolved (List .of (argumentType ), List .of (winnerType ), List .of (loserType ));
91101 }
92102
93- private static Type type (IntrinsicType intrinsic ) {
94- return FACTORY .getIntrinsic (intrinsic );
103+ private Type type (IntrinsicType intrinsic ) {
104+ return factory .getIntrinsic (intrinsic );
95105 }
96106
97- private static Type subrange (String image , int min , int max ) {
98- return FACTORY .subrange (image , BigInteger .valueOf (min ), BigInteger .valueOf (max ));
107+ private Type subrange (String image , int min , int max ) {
108+ return factory .subrange (image , BigInteger .valueOf (min ), BigInteger .valueOf (max ));
99109 }
100110
101- private static Type subrange (String image , Type type ) {
102- return FACTORY .subrange (image , type );
111+ private Type subrange (String image , Type type ) {
112+ return factory .subrange (image , type );
103113 }
104114
105115 private void assertResolved (
@@ -181,28 +191,36 @@ void testIntegerTypes() {
181191 assertResolved (type (INTEGER ), type (WORD ), type (BYTE ));
182192 assertResolved (type (SHORTINT ), type (NATIVEINT ), type (NATIVEUINT ));
183193
184- Type hwnd = FACTORY .strongAlias ("HWND" , type (NATIVEUINT ));
194+ Type hwnd = factory .strongAlias ("HWND" , type (NATIVEUINT ));
185195 assertResolved (
186196 List .of (hwnd , type (NATIVEUINT ), type (SHORTINT ), type (SHORTINT )),
187197 List .of (hwnd , type (NATIVEUINT ), type (NATIVEINT ), type (NATIVEINT )),
188198 List .of (hwnd , type (NATIVEUINT ), type (NATIVEUINT ), type (NATIVEINT )));
189199
190200 assertResolved (type (BYTE ), type (INTEGER ), type (DOUBLE ));
191201
192- assertResolved (FACTORY .strongAlias ("MyWord" , type (LONGWORD )), type (INT64 ), type (INTEGER ));
193- assertResolved (type (LONGWORD ), FACTORY .strongAlias ("MyInt64" , type (INT64 )), type (INTEGER ));
202+ assertResolved (factory .strongAlias ("MyWord" , type (LONGWORD )), type (INT64 ), type (INTEGER ));
203+ assertResolved (type (LONGWORD ), factory .strongAlias ("MyInt64" , type (INT64 )), type (INTEGER ));
194204 }
195205
196- @ Test
197- void testFloatingPointTypes () {
206+ @ ParameterizedTest
207+ @ EnumSource (
208+ value = Toolchain .class ,
209+ names = {"DCC32" , "DCC64" })
210+ void testRealTypes (Toolchain toolchain ) {
211+ factory = new TypeFactoryImpl (toolchain , DelphiProperties .COMPILER_VERSION_DEFAULT );
198212 assertResolved (type (EXTENDED ), type (DOUBLE ), type (SINGLE ));
199213 assertResolved (type (EXTENDED ), type (REAL ), type (SINGLE ));
200214 assertResolved (type (DOUBLE ), type (EXTENDED ), type (SINGLE ));
201215 assertResolved (type (REAL ), type (EXTENDED ), type (SINGLE ));
202216 }
203217
204- @ Test
205- void testMixedToFloatingPointTypes () {
218+ @ ParameterizedTest
219+ @ EnumSource (
220+ value = Toolchain .class ,
221+ names = {"DCC32" , "DCC64" })
222+ void testMixedToRealTypes (Toolchain toolchain ) {
223+ factory = new TypeFactoryImpl (toolchain , DelphiProperties .COMPILER_VERSION_DEFAULT );
206224 assertResolved (
207225 List .of (type (EXTENDED ), type (INTEGER )),
208226 List .of (type (EXTENDED ), type (EXTENDED )),
@@ -217,8 +235,12 @@ void testMixedToFloatingPointTypes() {
217235 List .of (type (EXTENDED ), type (EXTENDED )));
218236 }
219237
220- @ Test
221- void testIntegerToFloatingPointTypes () {
238+ @ ParameterizedTest
239+ @ EnumSource (
240+ value = Toolchain .class ,
241+ names = {"DCC32" , "DCC64" })
242+ void testIntegerToRealTypes (Toolchain toolchain ) {
243+ factory = new TypeFactoryImpl (toolchain , DelphiProperties .COMPILER_VERSION_DEFAULT );
222244 assertResolved (
223245 List .of (type (SHORTINT ), type (SHORTINT )),
224246 List .of (type (INTEGER ), type (INTEGER )),
@@ -236,12 +258,12 @@ void testIntegerToFloatingPointTypes() {
236258 @ Test
237259 void testTextTypes () {
238260 assertResolved (
239- FACTORY .strongAlias ("MyString" , type (UNICODESTRING )),
261+ factory .strongAlias ("MyString" , type (UNICODESTRING )),
240262 type (UNICODESTRING ),
241263 type (SHORTSTRING ));
242264 assertResolved (
243265 type (UNICODESTRING ),
244- FACTORY .strongAlias ("MyString" , type (UNICODESTRING )),
266+ factory .strongAlias ("MyString" , type (UNICODESTRING )),
245267 type (SHORTSTRING ));
246268 assertResolved (
247269 List .of (type (ANSICHAR ), type (ANSICHAR )),
@@ -291,8 +313,8 @@ void testTextTypes() {
291313 assertResolved (type (ANSISTRING ), type (VARIANT ), type (SHORTSTRING ));
292314 assertResolved (type (SHORTSTRING ), type (ANSISTRING ), type (VARIANT ));
293315
294- assertResolved (type (PANSICHAR ), type (ANSISTRING ), FACTORY .ansiString (CodePages .CP_1252 ));
295- assertResolved (type (PANSICHAR ), FACTORY .ansiString (CodePages .CP_1252 ), type (UNICODESTRING ));
316+ assertResolved (type (PANSICHAR ), type (ANSISTRING ), factory .ansiString (CodePages .CP_1252 ));
317+ assertResolved (type (PANSICHAR ), factory .ansiString (CodePages .CP_1252 ), type (UNICODESTRING ));
296318 assertResolved (type (PANSICHAR ), type (UNICODESTRING ), type (WIDESTRING ));
297319 assertResolved (type (PANSICHAR ), type (WIDESTRING ), type (SHORTSTRING ));
298320
@@ -302,12 +324,17 @@ void testTextTypes() {
302324 assertIncompatible (type (PWIDECHAR ), type (SHORTSTRING ));
303325 }
304326
305- @ Test
306- void testVariantTypes () {
327+ @ ParameterizedTest
328+ @ EnumSource (
329+ value = Toolchain .class ,
330+ names = {"DCC32" , "DCC64" })
331+ void testVariantTypes (Toolchain toolchain ) {
332+ factory = new TypeFactoryImpl (toolchain , DelphiProperties .COMPILER_VERSION_DEFAULT );
333+
307334 Type incompatibleType = TypeMocker .struct ("Incompatible" , RECORD );
308- Type enumeration = ((TypeFactoryImpl ) FACTORY ).enumeration ("E" , DelphiScope .unknownScope ());
335+ Type enumeration = ((TypeFactoryImpl ) factory ).enumeration ("E" , DelphiScope .unknownScope ());
309336 Type dynamicArray =
310- ((TypeFactoryImpl ) FACTORY ).array (null , type (INTEGER ), Set .of (ArrayOption .DYNAMIC ));
337+ ((TypeFactoryImpl ) factory ).array (null , type (INTEGER ), Set .of (ArrayOption .DYNAMIC ));
311338
312339 assertResolved (
313340 List .of (type (UNICODESTRING ), incompatibleType , type (BOOLEAN )),
@@ -318,9 +345,9 @@ void testVariantTypes() {
318345 assertResolved (type (SHORTSTRING ), type (ANSISTRING ), type (VARIANT ));
319346 assertResolved (type (ANSISTRING ), type (VARIANT ), type (SHORTSTRING ));
320347 assertResolved (type (ANSISTRING ), type (UNICODESTRING ), type (VARIANT ));
321- assertResolved (type (ANSISTRING ), FACTORY .ansiString (CodePages .CP_UTF8 ), type (VARIANT ));
322- assertResolved (type (ANSISTRING ), FACTORY .ansiString (CodePages .CP_1252 ), type (VARIANT ));
323- assertResolved (FACTORY .ansiString (1251 ), FACTORY .ansiString (1252 ), type (VARIANT ));
348+ assertResolved (type (ANSISTRING ), factory .ansiString (CodePages .CP_UTF8 ), type (VARIANT ));
349+ assertResolved (type (ANSISTRING ), factory .ansiString (CodePages .CP_1252 ), type (VARIANT ));
350+ assertResolved (factory .ansiString (1251 ), factory .ansiString (1252 ), type (VARIANT ));
324351
325352 assertResolved (
326353 List .of (type (VARIANT ), type (BYTE )),
@@ -404,16 +431,16 @@ void testInheritedTypes() {
404431 @ Test
405432 void testVarParameters () {
406433 Type openArray =
407- ((TypeFactoryImpl ) FACTORY ).array (null , type (INTEGER ), Set .of (ArrayOption .OPEN ));
434+ ((TypeFactoryImpl ) factory ).array (null , type (INTEGER ), Set .of (ArrayOption .OPEN ));
408435 Type dynamicArray =
409- ((TypeFactoryImpl ) FACTORY ).array (null , type (INTEGER ), Set .of (ArrayOption .DYNAMIC ));
436+ ((TypeFactoryImpl ) factory ).array (null , type (INTEGER ), Set .of (ArrayOption .DYNAMIC ));
410437
411438 assertResolvedVar (type (INTEGER ), untypedType ());
412439 assertResolvedVar (dynamicArray , openArray );
413440 assertResolvedVar (type (INTEGER ), openArray );
414- assertResolvedVar (FACTORY .untypedPointer (), FACTORY .untypedPointer ());
441+ assertResolvedVar (factory .untypedPointer (), factory .untypedPointer ());
415442 assertResolvedVar (
416- FACTORY .pointerTo (null , type (INTEGER )), FACTORY .pointerTo (null , type (SHORTINT )));
417- assertResolvedVar (FACTORY .fileOf (type (INTEGER )), FACTORY .untypedFile ());
443+ factory .pointerTo (null , type (INTEGER )), factory .pointerTo (null , type (SHORTINT )));
444+ assertResolvedVar (factory .fileOf (type (INTEGER )), factory .untypedFile ());
418445 }
419446}
0 commit comments