source: josm/trunk/tools/japicc/modules/Internals/RegTests.pm @ 12872

Last change on this file since 12872 was 12872, checked in by Don-vip, 3 years ago

update to JAPICC 2.3

File size: 66.7 KB
Line 
1###########################################################################
2# A module with regression test suite
3#
4# Copyright (C) 2016-2017 Andrey Ponomarenko's ABI Laboratory
5#
6# Written by Andrey Ponomarenko
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License or the GNU Lesser
10# General Public License as published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# and the GNU Lesser General Public License along with this program.
19# If not, see <http://www.gnu.org/licenses/>.
20###########################################################################
21use strict;
22use File::Copy qw(copy);
23
24sub testTool()
25{
26    printMsg("INFO", "\nVerifying detectable Java library changes");
27   
28    printMsg("INFO", "Creating test library ...");
29    my $LibName = "libsample_java";
30    if(-d $LibName) {
31        rmtree($LibName);
32    }
33   
34    my $PackageName = "TestPackage";
35    my $Path_v1 = "$LibName/$PackageName.v1/$PackageName";
36    mkpath($Path_v1);
37   
38    my $Path_v2 = "$LibName/$PackageName.v2/$PackageName";
39    mkpath($Path_v2);
40   
41    my $TestsPath = "$LibName/Tests";
42    mkpath($TestsPath);
43   
44    # FirstCheckedException
45    my $FirstCheckedException = "package $PackageName;
46    public class FirstCheckedException extends Exception {
47    }";
48    writeFile($Path_v1."/FirstCheckedException.java", $FirstCheckedException);
49    writeFile($Path_v2."/FirstCheckedException.java", $FirstCheckedException);
50   
51    # SecondCheckedException
52    my $SecondCheckedException = "package $PackageName;
53    public class SecondCheckedException extends Exception {
54    }";
55    writeFile($Path_v1."/SecondCheckedException.java", $SecondCheckedException);
56    writeFile($Path_v2."/SecondCheckedException.java", $SecondCheckedException);
57   
58    # FirstUncheckedException
59    my $FirstUncheckedException = "package $PackageName;
60    public class FirstUncheckedException extends RuntimeException {
61    }";
62    writeFile($Path_v1."/FirstUncheckedException.java", $FirstUncheckedException);
63    writeFile($Path_v2."/FirstUncheckedException.java", $FirstUncheckedException);
64   
65    # SecondUncheckedException
66    my $SecondUncheckedException = "package $PackageName;
67    public class SecondUncheckedException extends RuntimeException {
68    }";
69    writeFile($Path_v1."/SecondUncheckedException.java", $SecondUncheckedException);
70    writeFile($Path_v2."/SecondUncheckedException.java", $SecondUncheckedException);
71   
72    # BaseAbstractClass
73    my $BaseAbstractClass = "package $PackageName;
74    public abstract class BaseAbstractClass {
75        public Integer field;
76        public Integer someMethod(Integer param) { return param; }
77        public abstract Integer abstractMethod(Integer param);
78    }";
79    writeFile($Path_v1."/BaseAbstractClass.java", $BaseAbstractClass);
80    writeFile($Path_v2."/BaseAbstractClass.java", $BaseAbstractClass);
81   
82    # BaseClass
83    my $BaseClass = "package $PackageName;
84    public class BaseClass {
85        public Integer field;
86        public Integer method(Integer param) { return param; }
87    }";
88    writeFile($Path_v1."/BaseClass.java", $BaseClass);
89    writeFile($Path_v2."/BaseClass.java", $BaseClass);
90   
91    # BaseClass2
92    my $BaseClass2 = "package $PackageName;
93    public class BaseClass2 {
94        public Integer field2;
95        public Integer method2(Integer param) { return param; }
96    }";
97    writeFile($Path_v1."/BaseClass2.java", $BaseClass2);
98    writeFile($Path_v2."/BaseClass2.java", $BaseClass2);
99   
100    # BaseInterface
101    my $BaseInterface = "package $PackageName;
102    public interface BaseInterface {
103        public Integer field = 100;
104        public Integer method(Integer param);
105    }";
106    writeFile($Path_v1."/BaseInterface.java", $BaseInterface);
107    writeFile($Path_v2."/BaseInterface.java", $BaseInterface);
108   
109    # BaseInterface2
110    my $BaseInterface2 = "package $PackageName;
111    public interface BaseInterface2 {
112        public Integer field2 = 100;
113        public Integer method2(Integer param);
114    }";
115    writeFile($Path_v1."/BaseInterface2.java", $BaseInterface2);
116    writeFile($Path_v2."/BaseInterface2.java", $BaseInterface2);
117   
118    # BaseConstantInterface
119    my $BaseConstantInterface = "package $PackageName;
120    public interface BaseConstantInterface {
121        public Integer CONSTANT = 10;
122        public Integer CONSTANT2 = 100;
123    }";
124    writeFile($Path_v1."/BaseConstantInterface.java", $BaseConstantInterface);
125    writeFile($Path_v2."/BaseConstantInterface.java", $BaseConstantInterface);
126   
127    if(cmpVersions($In::Opt{"CompilerVer"}, "1.5")>=0)
128    {
129        # GenericClass1
130        writeFile($Path_v1."/GenericClass1.java",
131        "package $PackageName;
132        public class GenericClass1<T> {
133            public Integer method(T param) { return 0; }
134        }");
135        writeFile($Path_v2."/GenericClass1.java",
136        "package $PackageName;
137        public class GenericClass1<T> {
138            public Integer method(T param) { return 0; }
139        }");
140       
141        # GenericClass2
142        writeFile($Path_v1."/GenericClass2.java",
143        "package $PackageName;
144        public class GenericClass2<T> {
145            public void method() { }
146        }");
147        writeFile($Path_v2."/GenericClass2.java",
148        "package $PackageName;
149        public class GenericClass2<T> {
150            public void method() { }
151        }");
152       
153        # Class became generic
154        writeFile($Path_v1."/ClassBecameGeneric.java",
155        "package $PackageName;
156        public abstract class ClassBecameGeneric {
157            public ClassBecameGeneric() {}
158            public abstract ClassBecameGeneric doSomething();
159        }");
160        writeFile($Path_v2."/ClassBecameGeneric.java",
161        "package $PackageName;
162        public abstract class ClassBecameGeneric<T> {
163            public ClassBecameGeneric() {}
164            public abstract T doSomething();
165        }");
166       
167        writeFile($TestsPath."/Test_ClassBecameGeneric.java",
168        "import $PackageName.*;
169        class GenerifyingClassDerived extends ClassBecameGeneric {
170            public ClassBecameGeneric doSomething() { return new GenerifyingClassDerived(); }
171            public static void main(String[] args) { }
172        }
173        public class Test_ClassBecameGeneric
174        {
175            public static void main(String[] args) {
176                GenerifyingClassDerived X = new GenerifyingClassDerived();
177                ClassBecameGeneric Res = X.doSomething();
178            }
179        }");
180       
181        # Class became raw
182        writeFile($Path_v1."/ClassBecameRaw.java",
183        "package $PackageName;
184        public class ClassBecameRaw<T extends String> {
185            public void method(T param) { }
186        }");
187        writeFile($Path_v2."/ClassBecameRaw.java",
188        "package $PackageName;
189        public class ClassBecameRaw {
190            public void method(String param) { }
191        }");
192       
193        writeFile($TestsPath."/Test_ClassBecameRaw.java",
194        "import $PackageName.*;
195        public class Test_ClassBecameRaw
196        {
197            public static void main(String[] args) {
198                ClassBecameRaw<String> X = new ClassBecameRaw<String>();
199                X.method(\"XXX\");
200            }
201        }");
202       
203        # Interface became generic
204        writeFile($Path_v1."/InterfaceBecameGeneric.java",
205        "package $PackageName;
206        public interface InterfaceBecameGeneric {
207            public void method();
208        }");
209        writeFile($Path_v2."/InterfaceBecameGeneric.java",
210        "package $PackageName;
211        public interface InterfaceBecameGeneric<T> {
212            public void method();
213        }");
214       
215        # Interface became raw
216        writeFile($Path_v1."/InterfaceBecameRaw.java",
217        "package $PackageName;
218        public interface InterfaceBecameRaw<T> {
219            public void method();
220        }");
221        writeFile($Path_v2."/InterfaceBecameRaw.java",
222        "package $PackageName;
223        public interface InterfaceBecameRaw {
224            public void method();
225        }");
226       
227        writeFile($TestsPath."/Test_InterfaceBecameRaw.java",
228        "import $PackageName.*;
229        class InterfaceBecameRawDerived implements InterfaceBecameRaw<String> {
230            public void method() { }
231            public static void main(String[] args) { }
232        }
233        public class Test_InterfaceBecameRaw
234        {
235            public static void main(String[] args) {
236                InterfaceBecameRawDerived X = new InterfaceBecameRawDerived();
237                X.method();
238            }
239        }");
240       
241        # Changed generic super-class
242        writeFile($Path_v1."/GenericSuperClassChanged.java",
243        "package $PackageName;
244        public class GenericSuperClassChanged extends GenericClass1<String> {
245            public Integer method() { return 0; }
246        }");
247        writeFile($Path_v2."/GenericSuperClassChanged.java",
248        "package $PackageName;
249        public class GenericSuperClassChanged extends GenericClass1<Integer> {
250            public Integer method() { return 0; }
251        }");
252       
253        # Extending class with generic parameters
254        writeFile($Path_v1."/ExtendingClassWithGeneric.java",
255        "package $PackageName;
256        public class ExtendingClassWithGeneric {
257            public void method() { }
258        }");
259        writeFile($Path_v2."/ExtendingClassWithGeneric.java",
260        "package $PackageName;
261        public class ExtendingClassWithGeneric extends GenericClass2<String>
262        {
263        }");
264       
265        # Renamed generic parameter
266        writeFile($Path_v1."/RenamedGenericParameter.java",
267        "package $PackageName;
268        public class RenamedGenericParameter<A extends String> {
269            public void method(A param) { }
270        }");
271        writeFile($Path_v2."/RenamedGenericParameter.java",
272        "package $PackageName;
273        public class RenamedGenericParameter<B extends String> {
274            public void method(B param) { }
275        }");
276       
277        # Changed field type by introducing of a generic parameter
278        writeFile($Path_v1."/ChangedFieldTypeByGenericParam.java",
279        "package $PackageName;
280        public class ChangedFieldTypeByGenericParam {
281            public ChangedFieldTypeByGenericParam(String param) { f=param; }
282            public void method() { }
283            public String f;
284        }");
285        writeFile($Path_v2."/ChangedFieldTypeByGenericParam.java",
286        "package $PackageName;
287        public class ChangedFieldTypeByGenericParam<T> {
288            public ChangedFieldTypeByGenericParam(T param) { f=param; }
289            public void method() { }
290            public T f;
291        }");
292       
293        writeFile($Path_v1."/TestGeneric.java",
294        "package $PackageName;
295        public class TestGeneric {
296            public ChangedFieldTypeByGenericParam get1() { return new ChangedFieldTypeByGenericParam(\"XXX\"); }
297            public ChangedFieldTypeByGenericParam get2() { return new ChangedFieldTypeByGenericParam(\"XXX\"); }
298        }");
299        writeFile($Path_v2."/TestGeneric.java",
300        "package $PackageName;
301        public class TestGeneric {
302            public ChangedFieldTypeByGenericParam<String>  get1() { return new ChangedFieldTypeByGenericParam<String>(\"XXX\"); }
303            public ChangedFieldTypeByGenericParam<Integer> get2() { return new ChangedFieldTypeByGenericParam<Integer>(0); }
304        }");
305       
306        writeFile($TestsPath."/Test_ChangedFieldTypeByGenericParam.java",
307        "import $PackageName.*;
308        public class Test_ChangedFieldTypeByGenericParam
309        {
310            public static void main(String[] args)
311            {
312                TestGeneric X = new TestGeneric();
313                ChangedFieldTypeByGenericParam Res1 = X.get1();
314                ChangedFieldTypeByGenericParam Res2 = X.get2();
315                Res1.f = Res2.f;
316            }
317        }");
318       
319        # Changed constructor after generifying
320        writeFile($Path_v1."/ChangedCtorAfterGenerifying.java",
321        "package $PackageName;
322        public class ChangedCtorAfterGenerifying {
323            public ChangedCtorAfterGenerifying(String param) { }
324            public String f;
325        }");
326        writeFile($Path_v2."/ChangedCtorAfterGenerifying.java",
327        "package $PackageName;
328        public class ChangedCtorAfterGenerifying<T> {
329            public ChangedCtorAfterGenerifying(T param) { }
330            public T f;
331        }");
332       
333        writeFile($TestsPath."/Test_ChangedCtorAfterGenerifying.java",
334        "import $PackageName.*;
335        public class Test_ChangedCtorAfterGenerifying
336        {
337            public static void main(String[] args) {
338                ChangedCtorAfterGenerifying X = new ChangedCtorAfterGenerifying(\"XXX\");
339            }
340        }");
341       
342        # Array to variable arity
343        writeFile($Path_v1."/ArrayToVariableArity.java",
344        "package $PackageName;
345        public class ArrayToVariableArity {
346            public void method(Integer x, String[] y) { }
347        }");
348        writeFile($Path_v2."/ArrayToVariableArity.java",
349        "package $PackageName;
350        public class ArrayToVariableArity {
351            public void method(Integer x, String... y) { }
352        }");
353       
354        writeFile($TestsPath."/Test_ArrayToVariableArity.java",
355        "import $PackageName.*;
356        public class Test_ArrayToVariableArity
357        {
358            public static void main(String[] args) {
359                ArrayToVariableArity X = new ArrayToVariableArity();
360                X.method(0, new String[]{\"a\", \"b\"});
361            }
362        }");
363       
364        # Variable arity to array
365        writeFile($Path_v1."/VariableArityToArray.java",
366        "package $PackageName;
367        public class VariableArityToArray {
368            public void method(Integer x, String... y) { }
369        }");
370        writeFile($Path_v2."/VariableArityToArray.java",
371        "package $PackageName;
372        public class VariableArityToArray {
373            public void method(Integer x, String[] y) { }
374        }");
375       
376        writeFile($TestsPath."/Test_VariableArityToArray.java",
377        "import $PackageName.*;
378        public class Test_VariableArityToArray
379        {
380            public static void main(String[] args) {
381                VariableArityToArray X = new VariableArityToArray();
382                X.method(0, \"a\", \"b\");
383            }
384        }");
385       
386        # Removed_Annotation
387        writeFile($Path_v1."/RemovedAnnotation.java",
388        "package $PackageName;
389        public \@interface RemovedAnnotation {
390        }");
391       
392        writeFile($TestsPath."/Test_RemovedAnnotation.java",
393        "import $PackageName.*;
394        public class Test_RemovedAnnotation {
395            public static void main(String[] args) {
396                testMethod();
397            }
398           
399            \@RemovedAnnotation
400            static void testMethod() {
401            }
402        }");
403       
404        # Beta Annotation
405        writeFile($Path_v1."/Beta.java",
406        "package $PackageName;
407        public \@interface Beta {
408        }");
409       
410        writeFile($Path_v2."/Beta.java",
411        "package $PackageName;
412        public \@interface Beta {
413        }");
414       
415        # Removed_Method (Beta method)
416        writeFile($Path_v1."/RemovedBetaMethod.java",
417        "package $PackageName;
418        public class RemovedBetaMethod
419        {
420            \@Beta
421            public Integer someMethod() {
422                return 0;
423            }
424        }");
425        writeFile($Path_v2."/RemovedBetaMethod.java",
426        "package $PackageName;
427        public class RemovedBetaMethod {
428        }");
429       
430        # Removed_Method (from Beta class)
431        writeFile($Path_v1."/RemovedMethodFromBetaClass.java",
432        "package $PackageName;
433        \@Beta
434        public class RemovedMethodFromBetaClass
435        {
436            public Integer someMethod() {
437                return 0;
438            }
439        }");
440        writeFile($Path_v2."/RemovedMethodFromBetaClass.java",
441        "package $PackageName;
442        \@Beta
443        public class RemovedMethodFromBetaClass {
444        }");
445       
446        # Removed_Class (Beta)
447        writeFile($Path_v1."/RemovedBetaClass.java",
448        "package $PackageName;
449        \@Beta
450        public class RemovedBetaClass
451        {
452            public Integer someMethod() {
453                return 0;
454            }
455        }");
456    }
457   
458    # Abstract_Method_Added_Checked_Exception
459    writeFile($Path_v1."/AbstractMethodAddedCheckedException.java",
460    "package $PackageName;
461    public abstract class AbstractMethodAddedCheckedException {
462        public abstract Integer someMethod() throws FirstCheckedException;
463    }");
464    writeFile($Path_v2."/AbstractMethodAddedCheckedException.java",
465    "package $PackageName;
466    public abstract class AbstractMethodAddedCheckedException {
467        public abstract Integer someMethod() throws FirstCheckedException, SecondCheckedException;
468    }");
469   
470    # Abstract_Method_Removed_Checked_Exception
471    writeFile($Path_v1."/AbstractMethodRemovedCheckedException.java",
472    "package $PackageName;
473    public abstract class AbstractMethodRemovedCheckedException {
474        public abstract Integer someMethod() throws FirstCheckedException, SecondCheckedException;
475    }");
476    writeFile($Path_v2."/AbstractMethodRemovedCheckedException.java",
477    "package $PackageName;
478    public abstract class AbstractMethodRemovedCheckedException {
479        public abstract Integer someMethod() throws FirstCheckedException;
480    }");
481   
482    # NonAbstract_Method_Added_Checked_Exception
483    writeFile($Path_v1."/NonAbstractMethodAddedCheckedException.java",
484    "package $PackageName;
485    public class NonAbstractMethodAddedCheckedException {
486        public Integer someMethod() throws FirstCheckedException {
487            return 10;
488        }
489    }");
490    writeFile($Path_v2."/NonAbstractMethodAddedCheckedException.java",
491    "package $PackageName;
492    public class NonAbstractMethodAddedCheckedException {
493        public Integer someMethod() throws FirstCheckedException, SecondCheckedException {
494            return 10;
495        }
496    }");
497   
498    # NonAbstract_Method_Removed_Checked_Exception
499    writeFile($Path_v1."/NonAbstractMethodRemovedCheckedException.java",
500    "package $PackageName;
501    public class NonAbstractMethodRemovedCheckedException {
502        public Integer someMethod() throws FirstCheckedException, SecondCheckedException {
503            return 10;
504        }
505    }");
506    writeFile($Path_v2."/NonAbstractMethodRemovedCheckedException.java",
507    "package $PackageName;
508    public class NonAbstractMethodRemovedCheckedException {
509        public Integer someMethod() throws FirstCheckedException {
510            return 10;
511        }
512    }");
513   
514    # Added_Unchecked_Exception
515    writeFile($Path_v1."/AddedUncheckedException.java",
516    "package $PackageName;
517    public class AddedUncheckedException {
518        public Integer someMethod() throws FirstUncheckedException {
519            return 10;
520        }
521    }");
522    writeFile($Path_v2."/AddedUncheckedException.java",
523    "package $PackageName;
524    public class AddedUncheckedException {
525        public Integer someMethod() throws FirstUncheckedException, SecondUncheckedException, NullPointerException {
526            return 10;
527        }
528    }");
529   
530    # Removed_Unchecked_Exception
531    writeFile($Path_v1."/RemovedUncheckedException.java",
532    "package $PackageName;
533    public class RemovedUncheckedException {
534        public Integer someMethod() throws FirstUncheckedException, SecondUncheckedException, NullPointerException {
535            return 10;
536        }
537    }");
538    writeFile($Path_v2."/RemovedUncheckedException.java",
539    "package $PackageName;
540    public class RemovedUncheckedException {
541        public Integer someMethod() throws FirstUncheckedException {
542            return 10;
543        }
544    }");
545   
546    # Changed_Method_Return_From_Void
547    writeFile($Path_v1."/ChangedMethodReturnFromVoid.java",
548    "package $PackageName;
549    public class ChangedMethodReturnFromVoid {
550        public void changedMethod(Integer param1) { }
551    }");
552    writeFile($Path_v2."/ChangedMethodReturnFromVoid.java",
553    "package $PackageName;
554    public class ChangedMethodReturnFromVoid {
555        public Integer changedMethod(Integer param1){
556            return param1;
557        }
558    }");
559   
560    writeFile($TestsPath."/Test_ChangedMethodReturnFromVoid.java",
561    "import $PackageName.*;
562    public class Test_ChangedMethodReturnFromVoid {
563        public static void main(String[] args) {
564            ChangedMethodReturnFromVoid X = new ChangedMethodReturnFromVoid();
565            X.changedMethod(1);
566        }
567    }");
568   
569    # Changed_Method_Return
570    writeFile($Path_v1."/ChangedMethodReturn.java",
571    "package $PackageName;
572    public class ChangedMethodReturn {
573        public Integer changedMethod(Integer param) { return 0; }
574    }");
575    writeFile($Path_v2."/ChangedMethodReturn.java",
576    "package $PackageName;
577    public class ChangedMethodReturn {
578        public String changedMethod(Integer param) { return \"XXX\"; }
579    }");
580   
581    writeFile($TestsPath."/Test_ChangedMethodReturn.java",
582    "import $PackageName.*;
583    public class Test_ChangedMethodReturn {
584        public static void main(String[] args) {
585            ChangedMethodReturn X = new ChangedMethodReturn();
586            Integer Res = X.changedMethod(0);
587        }
588    }");
589   
590    # Added_Method
591    writeFile($Path_v1."/AddedMethod.java",
592    "package $PackageName;
593    public class AddedMethod {
594        public Integer field = 100;
595    }");
596    writeFile($Path_v2."/AddedMethod.java",
597    "package $PackageName;
598    public class AddedMethod {
599        public Integer field = 100;
600        public Integer addedMethod(Integer param1, String[] param2) { return param1; }
601        public static String[] addedStaticMethod(String[] param) { return param; }
602    }");
603   
604    # Added_Method (Constructor)
605    writeFile($Path_v1."/AddedConstructor.java",
606    "package $PackageName;
607    public class AddedConstructor {
608        public Integer field = 100;
609    }");
610    writeFile($Path_v2."/AddedConstructor.java",
611    "package $PackageName;
612    public class AddedConstructor {
613        public Integer field = 100;
614        public AddedConstructor() { }
615        public AddedConstructor(Integer x, String y) { }
616    }");
617   
618    # Class_Added_Field
619    writeFile($Path_v1."/ClassAddedField.java",
620    "package $PackageName;
621    public class ClassAddedField {
622        public Integer otherField;
623    }");
624    writeFile($Path_v2."/ClassAddedField.java",
625    "package $PackageName;
626    public class ClassAddedField {
627        public Integer addedField;
628        public Integer otherField;
629    }");
630   
631    # Interface_Added_Field
632    writeFile($Path_v1."/InterfaceAddedField.java",
633    "package $PackageName;
634    public interface InterfaceAddedField {
635        public Integer method();
636    }");
637    writeFile($Path_v2."/InterfaceAddedField.java",
638    "package $PackageName;
639    public interface InterfaceAddedField {
640        public Integer addedField = 100;
641        public Integer method();
642    }");
643   
644    # Removed_NonConstant_Field (Class)
645    writeFile($Path_v1."/ClassRemovedField.java",
646    "package $PackageName;
647    public class ClassRemovedField {
648        public Integer removedField;
649        public Integer otherField;
650    }");
651    writeFile($Path_v2."/ClassRemovedField.java",
652    "package $PackageName;
653    public class ClassRemovedField {
654        public Integer otherField;
655    }");
656   
657    writeFile($TestsPath."/Test_ClassRemovedField.java",
658    "import $PackageName.*;
659    public class Test_ClassRemovedField {
660        public static void main(String[] args) {
661            ClassRemovedField X = new ClassRemovedField();
662            Integer Copy = X.removedField;
663        }
664    }");
665   
666    # Removed_Constant_Field (Interface)
667    writeFile($Path_v1."/InterfaceRemovedConstantField.java",
668    "package $PackageName;
669    public interface InterfaceRemovedConstantField {
670        public String someMethod();
671        public int removedField_Int = 1000;
672        public String removedField_Str = \"Value\";
673    }");
674    writeFile($Path_v2."/InterfaceRemovedConstantField.java",
675    "package $PackageName;
676    public interface InterfaceRemovedConstantField {
677        public String someMethod();
678    }");
679   
680    # Removed_NonConstant_Field (Interface)
681    writeFile($Path_v1."/InterfaceRemovedField.java",
682    "package $PackageName;
683    public interface InterfaceRemovedField {
684        public String someMethod();
685        public BaseClass removedField = new BaseClass();
686    }");
687    writeFile($Path_v2."/InterfaceRemovedField.java",
688    "package $PackageName;
689    public interface InterfaceRemovedField {
690        public String someMethod();
691    }");
692   
693    # Renamed_Field
694    writeFile($Path_v1."/RenamedField.java",
695    "package $PackageName;
696    public class RenamedField {
697        public String oldName;
698    }");
699    writeFile($Path_v2."/RenamedField.java",
700    "package $PackageName;
701    public class RenamedField {
702        public String newName;
703    }");
704   
705    # Renamed_Constant_Field
706    writeFile($Path_v1."/RenamedConstantField.java",
707    "package $PackageName;
708    public class RenamedConstantField {
709        public final String oldName = \"Value\";
710    }");
711    writeFile($Path_v2."/RenamedConstantField.java",
712    "package $PackageName;
713    public class RenamedConstantField {
714        public final String newName = \"Value\";
715    }");
716   
717    # Changed_Field_Type
718    writeFile($Path_v1."/ChangedFieldType.java",
719    "package $PackageName;
720    public class ChangedFieldType {
721        public String fieldName;
722    }");
723    writeFile($Path_v2."/ChangedFieldType.java",
724    "package $PackageName;
725    public class ChangedFieldType {
726        public Integer fieldName;
727    }");
728   
729    writeFile($TestsPath."/Test_ChangedFieldType.java",
730    "import $PackageName.*;
731    public class Test_ChangedFieldType {
732        public static void main(String[] args) {
733            ChangedFieldType X = new ChangedFieldType();
734            String R = X.fieldName;
735        }
736    }");
737   
738    # Changed_Field_Access
739    writeFile($Path_v1."/ChangedFieldAccess.java",
740    "package $PackageName;
741    public class ChangedFieldAccess {
742        public String fieldName;
743    }");
744    writeFile($Path_v2."/ChangedFieldAccess.java",
745    "package $PackageName;
746    public class ChangedFieldAccess {
747        private String fieldName;
748    }");
749   
750    # Changed_Final_Field_Value
751    writeFile($Path_v1."/ChangedFinalFieldValue.java",
752    "package $PackageName;
753    public class ChangedFinalFieldValue {
754        public final int field = 1;
755        public final String field2 = \" \";
756    }");
757    writeFile($Path_v2."/ChangedFinalFieldValue.java",
758    "package $PackageName;
759    public class ChangedFinalFieldValue {
760        public final int field = 2;
761        public final String field2 = \"newValue\";
762    }");
763   
764    # NonConstant_Field_Became_Static
765    writeFile($Path_v1."/NonConstantFieldBecameStatic.java",
766    "package $PackageName;
767    public class NonConstantFieldBecameStatic {
768        public String fieldName;
769    }");
770    writeFile($Path_v2."/NonConstantFieldBecameStatic.java",
771    "package $PackageName;
772    public class NonConstantFieldBecameStatic {
773        public static String fieldName;
774    }");
775   
776    writeFile($TestsPath."/Test_NonConstantFieldBecameStatic.java",
777    "import $PackageName.*;
778    public class Test_NonConstantFieldBecameStatic {
779        public static void main(String[] args) {
780            NonConstantFieldBecameStatic X = new NonConstantFieldBecameStatic();
781            String R = X.fieldName;
782        }
783    }");
784   
785    # NonConstant_Field_Became_NonStatic
786    writeFile($Path_v1."/NonConstantFieldBecameNonStatic.java",
787    "package $PackageName;
788    public class NonConstantFieldBecameNonStatic {
789        public static String fieldName;
790    }");
791    writeFile($Path_v2."/NonConstantFieldBecameNonStatic.java",
792    "package $PackageName;
793    public class NonConstantFieldBecameNonStatic {
794        public String fieldName;
795    }");
796   
797    # Constant_Field_Became_NonStatic
798    writeFile($Path_v1."/ConstantFieldBecameNonStatic.java",
799    "package $PackageName;
800    public class ConstantFieldBecameNonStatic {
801        public final static String fieldName = \"Value\";
802    }");
803    writeFile($Path_v2."/ConstantFieldBecameNonStatic.java",
804    "package $PackageName;
805    public class ConstantFieldBecameNonStatic {
806        public final String fieldName = \"Value\";
807    }");
808   
809    # Field_Became_Final
810    writeFile($Path_v1."/FieldBecameFinal.java",
811    "package $PackageName;
812    public class FieldBecameFinal {
813        public String fieldName;
814    }");
815    writeFile($Path_v2."/FieldBecameFinal.java",
816    "package $PackageName;
817    public class FieldBecameFinal {
818        public final String fieldName = \"Value\";
819    }");
820   
821    # Field_Became_NonFinal
822    writeFile($Path_v1."/FieldBecameNonFinal.java",
823    "package $PackageName;
824    public class FieldBecameNonFinal {
825        public final String fieldName = \"Value\";
826    }");
827    writeFile($Path_v2."/FieldBecameNonFinal.java",
828    "package $PackageName;
829    public class FieldBecameNonFinal {
830        public String fieldName;
831    }");
832   
833    # Removed_Method
834    writeFile($Path_v1."/RemovedMethod.java",
835    "package $PackageName;
836    public class RemovedMethod {
837        public Integer field = 100;
838        public Integer removedMethod(Integer param1, String param2) { return param1; }
839        public static Integer removedStaticMethod(Integer param) { return param; }
840    }");
841    writeFile($Path_v2."/RemovedMethod.java",
842    "package $PackageName;
843    public class RemovedMethod {
844        public Integer field = 100;
845    }");
846   
847    # Removed protected method from final class
848    writeFile($Path_v1."/RemovedProtectedMethodFromFinalClass.java",
849    "package $PackageName;
850    public final class RemovedProtectedMethodFromFinalClass {
851        protected void removedMethod(Integer param) { }
852    }");
853    writeFile($Path_v2."/RemovedProtectedMethodFromFinalClass.java",
854    "package $PackageName;
855    public final class RemovedProtectedMethodFromFinalClass {
856    }");
857   
858    # Removed_Method (move up to java.lang.Object)
859    writeFile($Path_v1."/MoveUpToJavaLangObject.java",
860    "package $PackageName;
861    public class MoveUpToJavaLangObject extends java.lang.Object {
862        public int hashCode() { return 0; }
863    }");
864    writeFile($Path_v2."/MoveUpToJavaLangObject.java",
865    "package $PackageName;
866    public class MoveUpToJavaLangObject extends java.lang.Object {
867    }");
868   
869    writeFile($TestsPath."/Test_MoveUpToJavaLangObject.java",
870    "import $PackageName.*;
871    public class Test_MoveUpToJavaLangObject {
872        public static void main(String[] args) {
873            MoveUpToJavaLangObject X = new MoveUpToJavaLangObject();
874            int R = X.hashCode();
875        }
876    }");
877   
878    # Removed_Method (Deprecated)
879    writeFile($Path_v1."/RemovedDeprecatedMethod.java",
880    "package $PackageName;
881    public class RemovedDeprecatedMethod {
882        public Integer field = 100;
883        public Integer otherMethod(Integer param) { return param; }
884        \@Deprecated
885        public Integer removedMethod(Integer param1, String param2) { return param1; }
886    }");
887    writeFile($Path_v2."/RemovedDeprecatedMethod.java",
888    "package $PackageName;
889    public class RemovedDeprecatedMethod {
890        public Integer field = 100;
891        public Integer otherMethod(Integer param) { return param; }
892    }");
893   
894    # Interface_Removed_Abstract_Method
895    writeFile($Path_v1."/InterfaceRemovedAbstractMethod.java",
896    "package $PackageName;
897    public interface InterfaceRemovedAbstractMethod extends BaseInterface, BaseInterface2 {
898        public void removedMethod(Integer param1, java.io.ObjectOutput param2);
899        public void someMethod(Integer param);
900    }");
901    writeFile($Path_v2."/InterfaceRemovedAbstractMethod.java",
902    "package $PackageName;
903    public interface InterfaceRemovedAbstractMethod extends BaseInterface, BaseInterface2 {
904        public void someMethod(Integer param);
905    }");
906   
907    # Interface_Removed_Abstract_Method (Last)
908    writeFile($Path_v1."/InterfaceRemovedLastAbstractMethod.java",
909    "package $PackageName;
910    public interface InterfaceRemovedLastAbstractMethod {
911        public void removedMethod(Integer param);
912    }");
913    writeFile($Path_v2."/InterfaceRemovedLastAbstractMethod.java",
914    "package $PackageName;
915    public interface InterfaceRemovedLastAbstractMethod {
916    }");
917   
918    writeFile($TestsPath."/Test_InterfaceRemovedLastAbstractMethod.java",
919    "import $PackageName.*;
920    class InterfaceRemovedLastAbstractMethodDerived implements InterfaceRemovedLastAbstractMethod
921    {
922        public void removedMethod(Integer param) { }
923        public static void main(String[] args) { }
924    };
925   
926    public class Test_InterfaceRemovedLastAbstractMethod
927    {
928        public static void main(String[] args)
929        {
930            InterfaceRemovedLastAbstractMethod Obj = new InterfaceRemovedLastAbstractMethodDerived();
931            Obj.removedMethod(0);
932        }
933    }");
934   
935    # Interface_Added_Abstract_Method
936    writeFile($Path_v1."/InterfaceAddedAbstractMethod.java",
937    "package $PackageName;
938    public interface InterfaceAddedAbstractMethod extends BaseInterface, BaseInterface2 {
939        public void someMethod(Integer param);
940    }");
941    writeFile($Path_v2."/InterfaceAddedAbstractMethod.java",
942    "package $PackageName;
943    public interface InterfaceAddedAbstractMethod extends BaseInterface, BaseInterface2 {
944        public void someMethod(Integer param);
945        public Integer addedMethod(Integer param);
946    }");
947   
948    # Interface_Added_Default_Method
949    writeFile($Path_v1."/InterfaceAddedDefaultMethod.java",
950    "package $PackageName;
951    public interface InterfaceAddedDefaultMethod {
952        public void someMethod(Integer param);
953    }");
954    writeFile($Path_v2."/InterfaceAddedDefaultMethod.java",
955    "package $PackageName;
956    public interface InterfaceAddedDefaultMethod {
957        public void someMethod(Integer param);
958        default Integer addedMethod(Integer param) { return 0; }
959    }");
960   
961    # Method_Became_NonDefault
962    writeFile($Path_v1."/MethodBecameNonDefault.java",
963    "package $PackageName;
964    public interface MethodBecameNonDefault {
965        default Integer someMethod(Integer param) { return 0; }
966    }");
967    writeFile($Path_v2."/MethodBecameNonDefault.java",
968    "package $PackageName;
969    public interface MethodBecameNonDefault {
970        public Integer someMethod(Integer param);
971    }");
972   
973    writeFile($TestsPath."/Test_MethodBecameNonDefault.java",
974    "import $PackageName.*;
975    class Class_MethodBecameNonDefault implements MethodBecameNonDefault {
976        public static void main(String[] args) { }
977    };
978   
979    public class Test_MethodBecameNonDefault
980    {
981        public static void main(String[] args)
982        {
983            Class_MethodBecameNonDefault Obj = new Class_MethodBecameNonDefault();
984            Integer Res = Obj.someMethod(0);
985        }
986    }");
987   
988    # Class_Became_Interface
989    writeFile($Path_v1."/ClassBecameInterface.java",
990    "package $PackageName;
991    public class ClassBecameInterface extends BaseClass {
992        public Integer someMethod(Integer param) {
993            return param;
994        }
995    }");
996    writeFile($Path_v2."/ClassBecameInterface.java",
997    "package $PackageName;
998    public interface ClassBecameInterface extends BaseInterface, BaseInterface2 {
999        public Integer someMethod(Integer param);
1000    }");
1001   
1002    # Added_Super_Class
1003    writeFile($Path_v1."/AddedSuperClass.java",
1004    "package $PackageName;
1005    public class AddedSuperClass {
1006        public Integer someMethod(Integer param) {
1007            return param;
1008        }
1009    }");
1010    writeFile($Path_v2."/AddedSuperClass.java",
1011    "package $PackageName;
1012    public class AddedSuperClass extends BaseClass {
1013        public Integer someMethod(Integer param) {
1014            return param;
1015        }
1016    }");
1017   
1018    # Abstract_Class_Added_Super_Abstract_Class
1019    writeFile($Path_v1."/AbstractClassAddedSuperAbstractClass.java",
1020    "package $PackageName;
1021    public abstract class AbstractClassAddedSuperAbstractClass {
1022        public Integer someMethod(Integer param) {
1023            return param;
1024        }
1025    }");
1026    writeFile($Path_v2."/AbstractClassAddedSuperAbstractClass.java",
1027    "package $PackageName;
1028    public abstract class AbstractClassAddedSuperAbstractClass extends BaseAbstractClass {
1029        public Integer someMethod(Integer param) {
1030            return param;
1031        }
1032    }");
1033   
1034    # Removed_Super_Class
1035    writeFile($Path_v1."/RemovedSuperClass.java",
1036    "package $PackageName;
1037    public class RemovedSuperClass extends BaseClass {
1038        public Integer someMethod(Integer param) {
1039            return param;
1040        }
1041    }");
1042    writeFile($Path_v2."/RemovedSuperClass.java",
1043    "package $PackageName;
1044    public class RemovedSuperClass {
1045        public Integer someMethod(Integer param) {
1046            return param;
1047        }
1048    }");
1049   
1050    # Changed_Super_Class
1051    writeFile($Path_v1."/ChangedSuperClass.java",
1052    "package $PackageName;
1053    public class ChangedSuperClass extends BaseClass {
1054        public Integer someMethod(Integer param) {
1055            return param;
1056        }
1057    }");
1058    writeFile($Path_v2."/ChangedSuperClass.java",
1059    "package $PackageName;
1060    public class ChangedSuperClass extends BaseClass2 {
1061        public Integer someMethod(Integer param) {
1062            return param;
1063        }
1064    }");
1065   
1066    # Abstract_Class_Added_Super_Interface
1067    writeFile($Path_v1."/AbstractClassAddedSuperInterface.java",
1068    "package $PackageName;
1069    public abstract class AbstractClassAddedSuperInterface implements BaseInterface {
1070        public Integer method(Integer param) {
1071            return param;
1072        }
1073    }");
1074    writeFile($Path_v2."/AbstractClassAddedSuperInterface.java",
1075    "package $PackageName;
1076    public abstract class AbstractClassAddedSuperInterface implements BaseInterface, BaseInterface2 {
1077        public Integer method(Integer param) {
1078            return param;
1079        }
1080    }");
1081   
1082    # Abstract_Class_Added_Super_Interface_With_Implemented_Methods
1083    writeFile($Path_v1."/AbstractClassAddedSuperInterfaceWithImplementedMethods.java",
1084    "package $PackageName;
1085    public abstract class AbstractClassAddedSuperInterfaceWithImplementedMethods implements BaseInterface {
1086        public Integer method(Integer param) {
1087            return param;
1088        }
1089        public Integer method2(Integer param) {
1090            return param;
1091        }
1092    }");
1093    writeFile($Path_v2."/AbstractClassAddedSuperInterfaceWithImplementedMethods.java",
1094    "package $PackageName;
1095    public abstract class AbstractClassAddedSuperInterfaceWithImplementedMethods implements BaseInterface, BaseInterface2 {
1096        public Integer method(Integer param) {
1097            return param;
1098        }
1099        public Integer method2(Integer param) {
1100            return param;
1101        }
1102    }");
1103   
1104    # Class_Removed_Super_Interface
1105    writeFile($Path_v1."/ClassRemovedSuperInterface.java",
1106    "package $PackageName;
1107    public class ClassRemovedSuperInterface implements BaseInterface, BaseInterface2 {
1108        public Integer method(Integer param) {
1109            return param;
1110        }
1111        public Integer method2(Integer param) {
1112            return param;
1113        }
1114    }");
1115    writeFile($Path_v2."/ClassRemovedSuperInterface.java",
1116    "package $PackageName;
1117    public class ClassRemovedSuperInterface implements BaseInterface {
1118        public Integer method(Integer param) {
1119            return param;
1120        }
1121        public Integer method2(Integer param) {
1122            return param;
1123        }
1124    }");
1125   
1126    writeFile($TestsPath."/Test_ClassRemovedSuperInterface.java",
1127    "import $PackageName.*;
1128    public class Test_ClassRemovedSuperInterface
1129    {
1130        public static void main(String[] args)
1131        {
1132            ClassRemovedSuperInterface Obj = new ClassRemovedSuperInterface();
1133            Integer Res = Obj.method2(0);
1134        }
1135    }");
1136   
1137    # Interface_Added_Super_Interface
1138    writeFile($Path_v1."/InterfaceAddedSuperInterface.java",
1139    "package $PackageName;
1140    public interface InterfaceAddedSuperInterface extends BaseInterface {
1141        public Integer someMethod(Integer param);
1142    }");
1143    writeFile($Path_v2."/InterfaceAddedSuperInterface.java",
1144    "package $PackageName;
1145    public interface InterfaceAddedSuperInterface extends BaseInterface, BaseInterface2 {
1146        public Integer someMethod(Integer param);
1147    }");
1148   
1149    # Interface_Added_Super_Constant_Interface
1150    writeFile($Path_v1."/InterfaceAddedSuperConstantInterface.java",
1151    "package $PackageName;
1152    public interface InterfaceAddedSuperConstantInterface extends BaseInterface {
1153        public Integer someMethod(Integer param);
1154    }");
1155    writeFile($Path_v2."/InterfaceAddedSuperConstantInterface.java",
1156    "package $PackageName;
1157    public interface InterfaceAddedSuperConstantInterface extends BaseInterface, BaseConstantInterface {
1158        public Integer someMethod(Integer param);
1159    }");
1160   
1161    # Interface_Removed_Super_Interface
1162    writeFile($Path_v1."/InterfaceRemovedSuperInterface.java",
1163    "package $PackageName;
1164    public interface InterfaceRemovedSuperInterface extends BaseInterface, BaseInterface2 {
1165        public Integer someMethod(Integer param);
1166    }");
1167    writeFile($Path_v2."/InterfaceRemovedSuperInterface.java",
1168    "package $PackageName;
1169    public interface InterfaceRemovedSuperInterface extends BaseInterface {
1170        public Integer someMethod(Integer param);
1171    }");
1172   
1173    # Interface_Removed_Super_Constant_Interface
1174    writeFile($Path_v1."/InterfaceRemovedSuperConstantInterface.java",
1175    "package $PackageName;
1176    public interface InterfaceRemovedSuperConstantInterface extends BaseInterface, BaseConstantInterface {
1177        public Integer someMethod(Integer param);
1178    }");
1179    writeFile($Path_v2."/InterfaceRemovedSuperConstantInterface.java",
1180    "package $PackageName;
1181    public interface InterfaceRemovedSuperConstantInterface extends BaseInterface {
1182        public Integer someMethod(Integer param);
1183    }");
1184   
1185    # Interface_Became_Class
1186    writeFile($Path_v1."/InterfaceBecameClass.java",
1187    "package $PackageName;
1188    public interface InterfaceBecameClass extends BaseInterface, BaseInterface2 {
1189        public Integer someMethod(Integer param);
1190    }");
1191    writeFile($Path_v2."/InterfaceBecameClass.java",
1192    "package $PackageName;
1193    public class InterfaceBecameClass extends BaseClass {
1194        public Integer someMethod(Integer param) {
1195            return param;
1196        }
1197    }");
1198   
1199    # Removed_Class
1200    writeFile($Path_v1."/RemovedClass.java",
1201    "package $PackageName;
1202    public class RemovedClass extends BaseClass {
1203        public Integer someMethod(Integer param){
1204            return param;
1205        }
1206    }");
1207   
1208    # Removed_Class (w/o methods)
1209    writeFile($Path_v1."/RemovedFieldClass.java",
1210    "package $PackageName;
1211    public class RemovedFieldClass {
1212        public Integer field;
1213    }");
1214   
1215    writeFile($TestsPath."/Test_RemovedFieldClass.java",
1216    "import $PackageName.*;
1217    public class Test_RemovedFieldClass
1218    {
1219        public static void main(String[] args)
1220        {
1221            RemovedFieldClass X = new RemovedFieldClass();
1222            Integer Copy = X.field;
1223        }
1224    }");
1225   
1226    # Removed_Class (with static fields, private constructor)
1227    writeFile($Path_v1."/RemovedClassWithStaticField.java",
1228    "package $PackageName;
1229    public class RemovedClassWithStaticField
1230    {
1231        private RemovedClassWithStaticField(){}
1232        public static Integer cnt = 0;
1233    }");
1234   
1235    writeFile($TestsPath."/Test_RemovedClassWithStaticField.java",
1236    "import $PackageName.*;
1237    public class Test_RemovedClassWithStaticField
1238    {
1239        public static void main(String[] args)
1240        {
1241            Integer Copy = RemovedClassWithStaticField.cnt;
1242        }
1243    }");
1244   
1245    # Removed_Field (static field, private constructor)
1246    writeFile($Path_v1."/RemovedStaticFieldFromClassWithPrivateCtor.java",
1247    "package $PackageName;
1248    public class RemovedStaticFieldFromClassWithPrivateCtor
1249    {
1250        private RemovedStaticFieldFromClassWithPrivateCtor(){}
1251        public static Integer cnt = 0;
1252    }");
1253   
1254    writeFile($Path_v2."/RemovedStaticFieldFromClassWithPrivateCtor.java",
1255    "package $PackageName;
1256    public class RemovedStaticFieldFromClassWithPrivateCtor
1257    {
1258        private RemovedStaticFieldFromClassWithPrivateCtor(){}
1259    }");
1260   
1261    writeFile($TestsPath."/Test_RemovedStaticFieldFromClassWithPrivateCtor.java",
1262    "import $PackageName.*;
1263    public class Test_RemovedStaticFieldFromClassWithPrivateCtor
1264    {
1265        public static void main(String[] args)
1266        {
1267            Integer Copy = RemovedStaticFieldFromClassWithPrivateCtor.cnt;
1268        }
1269    }");
1270   
1271    # Removed_Constant_Field
1272    writeFile($Path_v1."/ClassRemovedStaticConstantField.java",
1273    "package $PackageName;
1274    public class ClassRemovedStaticConstantField
1275    {
1276        public static int removedField_Int = 1000;
1277        public static String removedField_Str = \"Value\";
1278    }");
1279    writeFile($Path_v2."/ClassRemovedStaticConstantField.java",
1280    "package $PackageName;
1281    public class ClassRemovedStaticConstantField {
1282    }");
1283   
1284    writeFile($TestsPath."/Test_ClassRemovedStaticConstantField.java",
1285    "import $PackageName.*;
1286    public class Test_ClassRemovedStaticConstantField
1287    {
1288        public static void main(String[] args)
1289        {
1290            Integer Copy = ClassRemovedStaticConstantField.removedField_Int;
1291        }
1292    }");
1293   
1294    # Removed_Class (Deprecated)
1295    writeFile($Path_v1."/RemovedDeprecatedClass.java",
1296    "package $PackageName;
1297    \@Deprecated
1298    public class RemovedDeprecatedClass {
1299        public Integer someMethod(Integer param){
1300            return param;
1301        }
1302    }");
1303   
1304    # Removed_Interface
1305    writeFile($Path_v1."/RemovedInterface.java",
1306    "package $PackageName;
1307    public interface RemovedInterface extends BaseInterface, BaseInterface2 {
1308        public Integer someMethod(Integer param);
1309    }");
1310   
1311    # NonAbstract_Class_Added_Abstract_Method
1312    writeFile($Path_v1."/NonAbstractClassAddedAbstractMethod.java",
1313    "package $PackageName;
1314    public class NonAbstractClassAddedAbstractMethod {
1315        public Integer someMethod(Integer param1, String[] param2) {
1316            return param1;
1317        };
1318    }");
1319    writeFile($Path_v2."/NonAbstractClassAddedAbstractMethod.java",
1320    "package $PackageName;
1321    public abstract class NonAbstractClassAddedAbstractMethod {
1322        public Integer someMethod(Integer param1, String[] param2) {
1323            return param1;
1324        };
1325        public abstract Integer addedMethod(Integer param);
1326    }");
1327   
1328    # Abstract_Class_Added_Abstract_Method
1329    writeFile($Path_v1."/AbstractClassAddedAbstractMethod.java",
1330    "package $PackageName;
1331    public abstract class AbstractClassAddedAbstractMethod {
1332        public Integer someMethod(Integer param1, String[] param2) {
1333            return param1;
1334        };
1335    }");
1336    writeFile($Path_v2."/AbstractClassAddedAbstractMethod.java",
1337    "package $PackageName;
1338    public abstract class AbstractClassAddedAbstractMethod {
1339        public Integer someMethod(Integer param1, String[] param2) {
1340            return param1;
1341        };
1342        public abstract Integer addedMethod(Integer param);
1343    }");
1344   
1345    # Class_Became_Abstract
1346    writeFile($Path_v1."/ClassBecameAbstract.java",
1347    "package $PackageName;
1348    public class ClassBecameAbstract {
1349        public Integer someMethod(Integer param1, String[] param2) {
1350            return param1;
1351        };
1352    }");
1353    writeFile($Path_v2."/ClassBecameAbstract.java",
1354    "package $PackageName;
1355    public abstract class ClassBecameAbstract {
1356        public Integer someMethod(Integer param1, String[] param2) {
1357            return param1;
1358        };
1359        public abstract Integer addedMethod(Integer param);
1360    }");
1361   
1362    # Class_Became_Final
1363    writeFile($Path_v1."/ClassBecameFinal.java",
1364    "package $PackageName;
1365    public class ClassBecameFinal {
1366        public Integer someMethod(Integer param1, String[] param2) {
1367            return param1;
1368        };
1369    }");
1370    writeFile($Path_v2."/ClassBecameFinal.java",
1371    "package $PackageName;
1372    public final class ClassBecameFinal {
1373        public Integer someMethod(Integer param1, String[] param2) {
1374            return param1;
1375        };
1376    }");
1377   
1378    # Class_Removed_Abstract_Method
1379    writeFile($Path_v1."/ClassRemovedAbstractMethod.java",
1380    "package $PackageName;
1381    public abstract class ClassRemovedAbstractMethod {
1382        public Integer someMethod(Integer param1, String[] param2) {
1383            return param1;
1384        };
1385        public abstract void removedMethod(Integer param);
1386    }");
1387    writeFile($Path_v2."/ClassRemovedAbstractMethod.java",
1388    "package $PackageName;
1389    public abstract class ClassRemovedAbstractMethod {
1390        public Integer someMethod(Integer param1, String[] param2) {
1391            return param1;
1392        };
1393    }");
1394   
1395    writeFile($TestsPath."/Test_ClassRemovedAbstractMethod.java",
1396    "import $PackageName.*;
1397    class ClassRemovedAbstractMethodDerived extends ClassRemovedAbstractMethod
1398    {
1399        public void removedMethod(Integer param) { }
1400        public static void main(String[] args) { }
1401    };
1402   
1403    public class Test_ClassRemovedAbstractMethod
1404    {
1405        public static void main(String[] args)
1406        {
1407            ClassRemovedAbstractMethod Obj = new ClassRemovedAbstractMethodDerived();
1408            Obj.removedMethod(0);
1409        }
1410    }");
1411   
1412    # Class_Method_Became_Abstract
1413    writeFile($Path_v1."/ClassMethodBecameAbstract.java",
1414    "package $PackageName;
1415    public abstract class ClassMethodBecameAbstract {
1416        public Integer someMethod(Integer param1, String[] param2) {
1417            return param1;
1418        };
1419        public Integer someMethod(Integer param){
1420            return param;
1421        };
1422    }");
1423    writeFile($Path_v2."/ClassMethodBecameAbstract.java",
1424    "package $PackageName;
1425    public abstract class ClassMethodBecameAbstract {
1426        public Integer someMethod(Integer param1, String[] param2) {
1427            return param1;
1428        };
1429        public abstract Integer someMethod(Integer param);
1430    }");
1431   
1432    # Class_Method_Became_NonAbstract
1433    writeFile($Path_v1."/ClassMethodBecameNonAbstract.java",
1434    "package $PackageName;
1435    public abstract class ClassMethodBecameNonAbstract {
1436        public Integer someMethod(Integer param1, String[] param2) {
1437            return param1;
1438        };
1439        public abstract Integer someMethod(Integer param);
1440    }");
1441    writeFile($Path_v2."/ClassMethodBecameNonAbstract.java",
1442    "package $PackageName;
1443    public abstract class ClassMethodBecameNonAbstract {
1444        public Integer someMethod(Integer param1, String[] param2) {
1445            return param1;
1446        };
1447        public Integer someMethod(Integer param){
1448            return param;
1449        };
1450    }");
1451   
1452    # Method_Became_Static
1453    writeFile($Path_v1."/MethodBecameStatic.java",
1454    "package $PackageName;
1455    public class MethodBecameStatic {
1456        public Integer someMethod(Integer param) {
1457            return param;
1458        };
1459    }");
1460    writeFile($Path_v2."/MethodBecameStatic.java",
1461    "package $PackageName;
1462    public class MethodBecameStatic {
1463        public static Integer someMethod(Integer param) {
1464            return param;
1465        };
1466    }");
1467   
1468    # Method_Became_NonStatic
1469    writeFile($Path_v1."/MethodBecameNonStatic.java",
1470    "package $PackageName;
1471    public class MethodBecameNonStatic {
1472        public static Integer someMethod(Integer param) {
1473            return param;
1474        };
1475    }");
1476    writeFile($Path_v2."/MethodBecameNonStatic.java",
1477    "package $PackageName;
1478    public class MethodBecameNonStatic {
1479        public Integer someMethod(Integer param) {
1480            return param;
1481        };
1482    }");
1483   
1484    # Static_Method_Became_Final
1485    writeFile($Path_v2."/StaticMethodBecameFinal.java",
1486    "package $PackageName;
1487    public class StaticMethodBecameFinal {
1488        public static Integer someMethod(Integer param) {
1489            return param;
1490        };
1491    }");
1492    writeFile($Path_v1."/StaticMethodBecameFinal.java",
1493    "package $PackageName;
1494    public class StaticMethodBecameFinal {
1495        public static final Integer someMethod(Integer param) {
1496            return param;
1497        };
1498    }");
1499   
1500    writeFile($TestsPath."/Test_StaticMethodBecameFinal.java",
1501    "import $PackageName.*;
1502    public class Test_StaticMethodBecameFinal
1503    {
1504        public static void main(String[] args)
1505        {
1506            Integer R = StaticMethodBecameFinal.someMethod(0);
1507        }
1508    }");
1509   
1510    # NonStatic_Method_Became_Final
1511    writeFile($Path_v1."/NonStaticMethodBecameFinal.java",
1512    "package $PackageName;
1513    public class NonStaticMethodBecameFinal {
1514        public Integer someMethod(Integer param) {
1515            return param;
1516        };
1517    }");
1518    writeFile($Path_v2."/NonStaticMethodBecameFinal.java",
1519    "package $PackageName;
1520    public class NonStaticMethodBecameFinal {
1521        public final Integer someMethod(Integer param) {
1522            return param;
1523        };
1524    }");
1525   
1526    # Method_Became_Abstract
1527    writeFile($Path_v1."/MethodBecameAbstract.java",
1528    "package $PackageName;
1529    public abstract class MethodBecameAbstract {
1530        public Integer someMethod(Integer param) {
1531            return param;
1532        };
1533    }");
1534    writeFile($Path_v2."/MethodBecameAbstract.java",
1535    "package $PackageName;
1536    public abstract class MethodBecameAbstract {
1537        public abstract Integer someMethod(Integer param);
1538    }");
1539   
1540    # Method_Became_NonAbstract
1541    writeFile($Path_v1."/MethodBecameNonAbstract.java",
1542    "package $PackageName;
1543    public abstract class MethodBecameNonAbstract {
1544        public abstract Integer someMethod(Integer param);
1545    }");
1546    writeFile($Path_v2."/MethodBecameNonAbstract.java",
1547    "package $PackageName;
1548    public abstract class MethodBecameNonAbstract {
1549        public Integer someMethod(Integer param) {
1550            return param;
1551        };
1552    }");
1553   
1554    # Changed_Method_Access
1555    writeFile($Path_v1."/ChangedMethodAccess.java",
1556    "package $PackageName;
1557    public class ChangedMethodAccess {
1558        public Integer someMethod(Integer param) {
1559            return param;
1560        };
1561    }");
1562    writeFile($Path_v2."/ChangedMethodAccess.java",
1563    "package $PackageName;
1564    public class ChangedMethodAccess {
1565        protected Integer someMethod(Integer param) {
1566            return param;
1567        };
1568    }");
1569   
1570    # Method_Became_Synchronized
1571    writeFile($Path_v1."/MethodBecameSynchronized.java",
1572    "package $PackageName;
1573    public class MethodBecameSynchronized {
1574        public Integer someMethod(Integer param) {
1575            return param;
1576        };
1577    }");
1578    writeFile($Path_v2."/MethodBecameSynchronized.java",
1579    "package $PackageName;
1580    public class MethodBecameSynchronized {
1581        public synchronized Integer someMethod(Integer param) {
1582            return param;
1583        };
1584    }");
1585   
1586    # Method_Became_NonSynchronized
1587    writeFile($Path_v1."/MethodBecameNonSynchronized.java",
1588    "package $PackageName;
1589    public class MethodBecameNonSynchronized {
1590        public synchronized Integer someMethod(Integer param) {
1591            return param;
1592        };
1593    }");
1594    writeFile($Path_v2."/MethodBecameNonSynchronized.java",
1595    "package $PackageName;
1596    public class MethodBecameNonSynchronized {
1597        public Integer someMethod(Integer param) {
1598            return param;
1599        };
1600    }");
1601   
1602    # Class_Overridden_Method
1603    writeFile($Path_v1."/OverriddenMethod.java",
1604    "package $PackageName;
1605    public class OverriddenMethod extends BaseClass {
1606        public Integer someMethod(Integer param) { return param; }
1607    }");
1608    writeFile($Path_v2."/OverriddenMethod.java",
1609    "package $PackageName;
1610    public class OverriddenMethod extends BaseClass {
1611        public Integer someMethod(Integer param) { return param; }
1612        public Integer method(Integer param) { return 2*param; }
1613    }");
1614   
1615    # Class_Method_Moved_Up_Hierarchy
1616    writeFile($Path_v1."/ClassMethodMovedUpHierarchy.java",
1617    "package $PackageName;
1618    public class ClassMethodMovedUpHierarchy extends BaseClass {
1619        public Integer someMethod(Integer param) { return param; }
1620        public Integer method(Integer param) { return 2*param; }
1621    }");
1622    writeFile($Path_v2."/ClassMethodMovedUpHierarchy.java",
1623    "package $PackageName;
1624    public class ClassMethodMovedUpHierarchy extends BaseClass {
1625        public Integer someMethod(Integer param) { return param; }
1626    }");
1627   
1628    # Class_Method_Moved_Up_Hierarchy (Interface Method) - should not be reported
1629    writeFile($Path_v1."/InterfaceMethodMovedUpHierarchy.java",
1630    "package $PackageName;
1631    public interface InterfaceMethodMovedUpHierarchy extends BaseInterface {
1632        public Integer method(Integer param);
1633        public Integer method2(Integer param);
1634    }");
1635    writeFile($Path_v2."/InterfaceMethodMovedUpHierarchy.java",
1636    "package $PackageName;
1637    public interface InterfaceMethodMovedUpHierarchy extends BaseInterface {
1638        public Integer method2(Integer param);
1639    }");
1640   
1641    # Class_Method_Moved_Up_Hierarchy (Abstract Method) - should not be reported
1642    writeFile($Path_v1."/AbstractMethodMovedUpHierarchy.java",
1643    "package $PackageName;
1644    public abstract class AbstractMethodMovedUpHierarchy implements BaseInterface {
1645        public abstract Integer method(Integer param);
1646        public abstract Integer method2(Integer param);
1647    }");
1648    writeFile($Path_v2."/AbstractMethodMovedUpHierarchy.java",
1649    "package $PackageName;
1650    public abstract class AbstractMethodMovedUpHierarchy implements BaseInterface {
1651        public abstract Integer method2(Integer param);
1652    }");
1653   
1654    # Use
1655    writeFile($Path_v1."/Use.java",
1656    "package $PackageName;
1657    public class Use
1658    {
1659        public FieldBecameFinal field;
1660        public void someMethod(FieldBecameFinal[] param) { };
1661        public void someMethod(Use param) { };
1662        public Integer someMethod(AbstractClassAddedSuperAbstractClass param) {
1663            return 0;
1664        }
1665        public Integer someMethod(AbstractClassAddedAbstractMethod param) {
1666            return 0;
1667        }
1668        public Integer someMethod(InterfaceAddedAbstractMethod param) {
1669            return 0;
1670        }
1671        public Integer someMethod(InterfaceAddedSuperInterface param) {
1672            return 0;
1673        }
1674        public Integer someMethod(AbstractClassAddedSuperInterface param) {
1675            return 0;
1676        }
1677        public Integer someMethod(AbstractClassAddedSuperInterfaceWithImplementedMethods param) {
1678            return 0;
1679        }
1680        public Integer someMethod(InterfaceRemovedLastAbstractMethod param) {
1681            return 0;
1682        }
1683       
1684    }");
1685    writeFile($Path_v2."/Use.java",
1686    "package $PackageName;
1687    public class Use
1688    {
1689        public FieldBecameFinal field;
1690        public void someMethod(FieldBecameFinal[] param) { };
1691        public void someMethod(Use param) { };
1692        public Integer someMethod(AbstractClassAddedSuperAbstractClass param) {
1693            return param.abstractMethod(100)+param.field;
1694        }
1695        public Integer someMethod(AbstractClassAddedAbstractMethod param) {
1696            return param.addedMethod(100);
1697        }
1698        public Integer someMethod(InterfaceAddedAbstractMethod param) {
1699            return param.addedMethod(100);
1700        }
1701        public Integer someMethod(InterfaceAddedSuperInterface param) {
1702            return param.method2(100);
1703        }
1704        public Integer someMethod(AbstractClassAddedSuperInterface param) {
1705            return param.method2(100);
1706        }
1707        public Integer someMethod(AbstractClassAddedSuperInterfaceWithImplementedMethods param) {
1708            return param.method2(100);
1709        }
1710        public Integer someMethod(InterfaceRemovedLastAbstractMethod param) {
1711            return 0;
1712        }
1713    }");
1714   
1715    # Added_Package
1716    writeFile($Path_v2."/AddedPackage/AddedPackageClass.java",
1717    "package $PackageName.AddedPackage;
1718    public class AddedPackageClass {
1719        public Integer field;
1720        public void someMethod(Integer param) { };
1721    }");
1722   
1723    # Removed_Package
1724    writeFile($Path_v1."/RemovedPackage/RemovedPackageClass.java",
1725    "package $PackageName.RemovedPackage;
1726    public class RemovedPackageClass {
1727        public Integer field;
1728        public void someMethod(Integer param) { };
1729    }");
1730    my $BuildRoot1 = getDirname($Path_v1);
1731    my $BuildRoot2 = getDirname($Path_v2);
1732    if(compileJavaLib($LibName, $BuildRoot1, $BuildRoot2))
1733    {
1734        runTests($TestsPath, $PackageName, getAbsPath($BuildRoot1), getAbsPath($BuildRoot2));
1735        runChecker($LibName, $BuildRoot1, $BuildRoot2);
1736    }
1737}
1738
1739sub checkJavaCompiler($)
1740{ # check javac: compile simple program
1741    my $Cmd = $_[0];
1742   
1743    if(not $Cmd) {
1744        return;
1745    }
1746   
1747    my $TmpDir = $In::Opt{"Tmp"};
1748   
1749    writeFile($TmpDir."/test_javac/Simple.java",
1750    "public class Simple {
1751        public Integer f;
1752        public void method(Integer p) { };
1753    }");
1754    chdir($TmpDir."/test_javac");
1755    system("$Cmd Simple.java 2>errors.txt");
1756    chdir($In::Opt{"OrigDir"});
1757    if($?)
1758    {
1759        my $Msg = "something is going wrong with the Java compiler (javac):\n";
1760        my $Err = readFile($TmpDir."/test_javac/errors.txt");
1761        $Msg .= $Err;
1762        if($Err=~/elf\/start\.S/ and $Err=~/undefined\s+reference\s+to/)
1763        { # /usr/lib/gcc/i586-suse-linux/4.5/../../../crt1.o: In function _start:
1764          # /usr/src/packages/BUILD/glibc-2.11.3/csu/../sysdeps/i386/elf/start.S:115: undefined reference to main
1765            $Msg .= "\nDid you install a JDK-devel package?";
1766        }
1767        exitStatus("Error", $Msg);
1768    }
1769}
1770
1771sub runTests($$$$)
1772{
1773    my ($TestsPath, $PackageName, $Path_v1, $Path_v2) = @_;
1774   
1775    printMsg("INFO", "Running tests ...");
1776   
1777    # compile with old version of package
1778    my $JavacCmd = getCmdPath("javac");
1779    if(not $JavacCmd) {
1780        exitStatus("Not_Found", "can't find \"javac\" compiler");
1781    }
1782   
1783    my $JavaCmd = getCmdPath("java");
1784    if(not $JavaCmd) {
1785        exitStatus("Not_Found", "can't find \"java\" command");
1786    }
1787   
1788    chdir($TestsPath);
1789    system($JavacCmd." -classpath \"".$Path_v1."\" -g *.java");
1790    chdir($In::Opt{"OrigDir"});
1791   
1792    foreach my $TestSrc (cmdFind($TestsPath, "", "*\\.java"))
1793    { # remove test source
1794        unlink($TestSrc);
1795    }
1796   
1797    my $TEST_REPORT = "";
1798   
1799    foreach my $TestPath (cmdFind($TestsPath, "", "*\\.class", 1))
1800    { # run tests
1801        my $Name = getFilename($TestPath);
1802        $Name=~s/\.class\Z//g;
1803       
1804        chdir($TestsPath);
1805        system($JavaCmd." -classpath \"".join_A($Path_v2, ".")."\" $Name >result.txt 2>&1");
1806        chdir($In::Opt{"OrigDir"});
1807       
1808        my $Result = readFile($TestsPath."/result.txt");
1809        unlink($TestsPath."/result.txt");
1810        $TEST_REPORT .= "TEST CASE: $Name\n";
1811        if($Result) {
1812            $TEST_REPORT .= "RESULT: FAILED\n";
1813            $TEST_REPORT .= "OUTPUT:\n$Result\n";
1814        }
1815        else {
1816            $TEST_REPORT .= "RESULT: SUCCESS\n";
1817        }
1818        $TEST_REPORT .= "\n";
1819    }
1820   
1821    my $Journal = $TestsPath."/Journal.txt";
1822    writeFile($Journal, $TEST_REPORT);
1823    printMsg("INFO", "See journal with test results: $Journal");
1824}
1825
1826sub compileJavaLib($$$)
1827{
1828    my ($LibName, $BuildRoot1, $BuildRoot2) = @_;
1829   
1830    my $JavacCmd = getCmdPath("javac");
1831    if(not $JavacCmd) {
1832        exitStatus("Not_Found", "can't find \"javac\" compiler");
1833    }
1834   
1835    checkJavaCompiler($JavacCmd);
1836   
1837    my $JarCmd = getCmdPath("jar");
1838    if(not $JarCmd) {
1839        exitStatus("Not_Found", "can't find \"jar\" command");
1840    }
1841   
1842    # space before value, new line
1843    writeFile("$BuildRoot1/MANIFEST.MF", "Implementation-Version: 1.0\n");
1844    writeFile("$BuildRoot2/MANIFEST.MF", "Implementation-Version: 2.0\n");
1845   
1846    my (%SrcDir1, %SrcDir2) = ();
1847    foreach my $Path (cmdFind($BuildRoot1, "f", "*\\.java")) {
1848        $SrcDir1{getDirname($Path)} = 1;
1849    }
1850    foreach my $Path (cmdFind($BuildRoot2, "f", "*\\.java")) {
1851        $SrcDir2{getDirname($Path)} = 1;
1852    }
1853    # build classes v.1
1854    foreach my $Dir (keys(%SrcDir1))
1855    {
1856        chdir($Dir);
1857        system("$JavacCmd -g *.java");
1858        chdir($In::Opt{"OrigDir"});
1859        if($?) {
1860            exitStatus("Error", "can't compile classes v.1");
1861        }
1862    }
1863    # create java archive v.1
1864    chdir($BuildRoot1);
1865    system("$JarCmd -cmf MANIFEST.MF $LibName.jar TestPackage");
1866    chdir($In::Opt{"OrigDir"});
1867   
1868    # build classes v.2
1869    foreach my $Dir (keys(%SrcDir2))
1870    {
1871        chdir($Dir);
1872        system("$JavacCmd -g *.java");
1873        chdir($In::Opt{"OrigDir"});
1874        if($?) {
1875            exitStatus("Error", "can't compile classes v.2");
1876        }
1877    }
1878    # create java archive v.2
1879    chdir($BuildRoot2);
1880    system("$JarCmd -cmf MANIFEST.MF $LibName.jar TestPackage");
1881    chdir($In::Opt{"OrigDir"});
1882   
1883    foreach my $SrcPath (cmdFind($BuildRoot1, "", "*\\.java")) {
1884        unlink($SrcPath);
1885    }
1886    foreach my $SrcPath (cmdFind($BuildRoot2, "", "*\\.java")) {
1887        unlink($SrcPath);
1888    }
1889    return 1;
1890}
1891
1892sub runChecker($$$)
1893{
1894    my ($LibName, $Path1, $Path2) = @_;
1895   
1896    writeFile("$LibName/v1.xml", "
1897        <version>
1898            1.0
1899        </version>
1900        <archives>
1901            ".getAbsPath($Path1)."
1902        </archives>\n");
1903   
1904    writeFile("$LibName/v2.xml", "
1905        <version>
1906            2.0
1907        </version>
1908        <archives>
1909            ".getAbsPath($Path2)."
1910        </archives>\n");
1911   
1912    my $Cmd = "perl $0 -l $LibName $LibName/v1.xml $LibName/v2.xml";
1913    if($In::Opt{"Quick"}) {
1914        $Cmd .= " -quick";
1915    }
1916    if(defined $In::Opt{"SkipDeprecated"}) {
1917        $Cmd .= " -skip-deprecated";
1918    }
1919    if(defined $In::Opt{"OldStyle"}) {
1920        $Cmd .= " -old-style";
1921    }
1922   
1923    my $TmpDir = $In::Opt{"Tmp"};
1924   
1925    writeFile($TmpDir."/skip-annotations.list", "TestPackage.Beta");
1926    $Cmd .= " -skip-annotations-list ".$TmpDir."/skip-annotations.list";
1927    if($In::Opt{"Debug"})
1928    {
1929        $Cmd .= " -debug";
1930        printMsg("INFO", "Executing $Cmd");
1931    }
1932   
1933    my $Report = "compat_reports/$LibName/1.0_to_2.0/compat_report.html";
1934   
1935    if(-f $Report) {
1936        unlink($Report);
1937    }
1938   
1939    system($Cmd);
1940   
1941    if(not -f $Report) {
1942        exitStatus("Error", "analysis has failed");
1943    }
1944   
1945    # Binary
1946    my $BReport = readAttributes($Report, 0);
1947    my $NProblems = $BReport->{"type_problems_high"}+$BReport->{"type_problems_medium"};
1948    $NProblems += $BReport->{"method_problems_high"}+$BReport->{"method_problems_medium"};
1949    $NProblems += $BReport->{"removed"};
1950   
1951    # Source
1952    my $SReport = readAttributes($Report, 1);
1953    $NProblems += $SReport->{"type_problems_high"}+$SReport->{"type_problems_medium"};
1954    $NProblems += $SReport->{"method_problems_high"}+$SReport->{"method_problems_medium"};
1955    $NProblems += $SReport->{"removed"};
1956   
1957    if($NProblems>=100) {
1958        printMsg("INFO", "Test result: SUCCESS ($NProblems breaks found)\n");
1959    }
1960    else {
1961        printMsg("ERROR", "Test result: FAILED ($NProblems breaks found)\n");
1962    }
1963}
1964
1965return 1;
Note: See TracBrowser for help on using the repository browser.