diff --git a/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/TestPredefinedCases.java b/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/TestPredefinedCases.java index 095d95b..e882c2b 100644 --- a/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/TestPredefinedCases.java +++ b/src/main/java/edu/lu/uni/serval/fixminer/akka/ediff/TestPredefinedCases.java @@ -240,4 +240,365 @@ public class TestPredefinedCases { } + + + + + + @Test + public void testContinueCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_continue_example_1.c"); + File revFile = new File("src/main/resource/testFiles/continue_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD while@@i -- > 0 x = f i x == 1 y += x * x @TO@ i -- > 1 x = f i x == 0 y += x * x @AT@ 6 @LENGTH@ 34\n" + + "---UPD condition@@i -- > 0 @TO@ i -- > 1 @AT@ 6 @LENGTH@ 12\n" + + "------UPD expr@@i -- > 0 @TO@ i -- > 1 @AT@ 8 @LENGTH@ 8\n" + + "---------UPD literal@@0 @TO@ 1 @AT@ 14 @LENGTH@ 1\n" + + "---UPD block@@x = f i x == 1 y += x * x @TO@ x = f i x == 0 y += x * x @AT@ 17 @LENGTH@ 80\n" + + "------UPD if@@x == 1 @TO@ x == 0 @AT@ 42 @LENGTH@ 6\n" + + "---------UPD condition@@x == 1 @TO@ x == 0 @AT@ 42 @LENGTH@ 11\n" + + "------------UPD expr@@x == 1 @TO@ x == 0 @AT@ 44 @LENGTH@ 6\n" + + "---------------UPD literal@@1 @TO@ 0 @AT@ 49 @LENGTH@ 1\n"); + + } + + @Test + public void testReturnCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_return_example_1.c"); + File revFile = new File("src/main/resource/testFiles/return_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD return@@( s * ( long long ) s ) @TO@ ( s * ( long int ) s ) @AT@ 0 @LENGTH@ 28\n" + + "---UPD expr@@( s * ( long long ) s ) @TO@ ( s * ( long int ) s ) @AT@ 6 @LENGTH@ 23\n" + + "------UPD name@@long @TO@ int @AT@ 18 @LENGTH@ 4\n"); + + } + + @Test + public void testSwitchCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_switch_example_1.c"); + File revFile = new File("src/main/resource/testFiles/switch_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD if@@i > 0 i - 1 n ++ 0 z ++ 2 p -- 0 @TO@ i > 0 i - 1 n ++ 0 z ++ 1 p ++ 0 @AT@ 3 @LENGTH@ 32\n" + + "---UPD then@@i - 1 n ++ 0 z ++ 2 p -- @TO@ i - 1 n ++ 0 z ++ 1 p ++ @AT@ 22 @LENGTH@ 24\n" + + "------UPD block@@i - 1 n ++ 0 z ++ 2 p -- @TO@ i - 1 n ++ 0 z ++ 1 p ++ @AT@ 22 @LENGTH@ 24\n" + + "---------UPD switch@@i - 1 n ++ 0 z ++ 2 p -- @TO@ i - 1 n ++ 0 z ++ 1 p ++ @AT@ 22 @LENGTH@ 24\n" + + "------------UPD block@@- 1 n ++ 0 z ++ 2 p -- @TO@ - 1 n ++ 0 z ++ 1 p ++ @AT@ 32 @LENGTH@ 148\n" + + "---------------UPD case@@2 @TO@ 1 @AT@ 148 @LENGTH@ 9\n" + + "------------------UPD expr@@2 @TO@ 1 @AT@ 153 @LENGTH@ 1\n" + + "---------------------UPD literal@@2 @TO@ 1 @AT@ 153 @LENGTH@ 1\n" + + "---------------UPD expr_stmt@@p -- @TO@ p ++ @AT@ 169 @LENGTH@ 4\n" + + "------------------UPD expr@@p -- @TO@ p ++ @AT@ 169 @LENGTH@ 4\n" + + "---------------------UPD operator@@-- @TO@ ++ @AT@ 170 @LENGTH@ 2\n" + + "---------------INS break@@ @TO@ block@@- 1 n ++ 0 z ++ 2 p -- @AT@ 186 @LENGTH@ 0\n"); + + } + +// @Test +// public void testExternCase1() throws IOException { +// Properties appProps = new Properties(); +// appProps.load(new FileInputStream("src/main/resource/app.properties")); +// String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); +// +// File prevFile =new File("src/main/resource/testFiles/prev_extern_example_1.c"); +// File revFile = new File("src/main/resource/testFiles/extern_example_1.c"); +// +// +// +// +// EDiffHunkParser parser = new EDiffHunkParser(); +// +// List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); +// hierarchicalActionSets.size(); +// Assert.assertEquals(hierarchicalActionSets.size(),1); +// +// Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD switch@@i - 1 n ++ 0 z ++ 2 p -- @TO@ i - 1 n ++ 0 z ++ 1 p ++ @AT@ 6 @LENGTH@ 24\n" + +// "---UPD block@@- 1 n ++ 0 z ++ 2 p -- @TO@ - 1 n ++ 0 z ++ 1 p ++ @AT@ 11 @LENGTH@ 127\n" + +// "------UPD case@@2 @TO@ 1 @AT@ 99 @LENGTH@ 9\n" + +// "---------UPD expr@@2 @TO@ 1 @AT@ 104 @LENGTH@ 1\n" + +// "------------UPD literal@@2 @TO@ 1 @AT@ 104 @LENGTH@ 1\n" + +// "------UPD expr_stmt@@p -- @TO@ p ++ @AT@ 116 @LENGTH@ 4\n" + +// "---------UPD expr@@p -- @TO@ p ++ @AT@ 116 @LENGTH@ 4\n" + +// "------------UPD operator@@-- @TO@ ++ @AT@ 117 @LENGTH@ 2\n"); +// +// } + + @Test + public void testFunctionCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_function_example_1.c"); + File revFile = new File("src/main/resource/testFiles/function_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD function@@int func a b c int a int b int c @TO@ int func a b c int a int c int b @AT@ 122 @LENGTH@ 32\n" + + "---MOV decl_stmt@@int b @TO@ function@@int func a b c int a int b int c @AT@ 153 @LENGTH@ 5\n"); + + } + + @Test + public void testStaticCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_static_example_1.c"); + File revFile = new File("src/main/resource/testFiles/static_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD decl_stmt@@static const int rpm_ranges [] 2000 4000 8000 16000 @TO@ static const string rpm_ranges [] 1000 4000 8000 16000 @AT@ 95 @LENGTH@ 51\n" + + "---UPD decl@@static const int rpm_ranges [] 2000 4000 8000 16000 @TO@ static const string rpm_ranges [] 1000 4000 8000 16000 @AT@ 95 @LENGTH@ 51\n" + + "------UPD type@@const int @TO@ const string @AT@ 102 @LENGTH@ 9\n" + + "---------UPD name@@int @TO@ string @AT@ 108 @LENGTH@ 3\n" + + "------UPD init@@2000 4000 8000 16000 @TO@ 1000 4000 8000 16000 @AT@ 127 @LENGTH@ 20\n" + + "---------UPD expr@@2000 4000 8000 16000 @TO@ 1000 4000 8000 16000 @AT@ 127 @LENGTH@ 20\n" + + "------------UPD block@@2000 4000 8000 16000 @TO@ 1000 4000 8000 16000 @AT@ 127 @LENGTH@ 28\n" + + "---------------UPD expr@@2000 @TO@ 1000 @AT@ 129 @LENGTH@ 4\n" + + "------------------UPD literal@@2000 @TO@ 1000 @AT@ 129 @LENGTH@ 4\n"); + + } + + @Test + public void testTypedefCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_typedef_example_1.c"); + File revFile = new File("src/main/resource/testFiles/typedef_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD typedef@@club char name ] GROUP @TO@ club char name ] int size year GROUP @AT@ 123 @LENGTH@ 50\n" + + "---UPD type@@club char name ] @TO@ club char name ] int size year @AT@ 138 @LENGTH@ 16\n" + + "------UPD struct@@club char name ] @TO@ club char name ] int size year @AT@ 138 @LENGTH@ 16\n" + + "---------UPD block@@char name ] @TO@ char name ] int size year @AT@ 143 @LENGTH@ 23\n" + + "------------INS decl_stmt@@int size year @TO@ block@@char name ] @AT@ 168 @LENGTH@ 13\n" + + "---------------INS decl@@int size @TO@ decl_stmt@@int size year @AT@ 168 @LENGTH@ 8\n" + + "------------------INS type@@int @TO@ decl@@int size @AT@ 168 @LENGTH@ 3\n" + + "---------------------INS name@@int @TO@ type@@int @AT@ 168 @LENGTH@ 3\n" + + "------------------INS name@@size @TO@ decl@@int size @AT@ 172 @LENGTH@ 4\n" + + "---------------INS name@@year @TO@ decl_stmt@@int size year @AT@ 178 @LENGTH@ 4\n"); + + } + + @Test + public void testArrayCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_array_example_1.c"); + File revFile = new File("src/main/resource/testFiles/array_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD struct@@arr int a ] ] = 29 ] = 15 test @TO@ arr int a ] ] = 29 ] = 15 ] = 30 test @AT@ 0 @LENGTH@ 59\n" + + "---UPD block@@int a ] ] = 29 ] = 15 @TO@ int a ] ] = 29 ] = 15 ] = 30 @AT@ 10 @LENGTH@ 43\n" + + "------UPD decl_stmt@@int a ] ] = 29 ] = 15 @TO@ int a ] ] = 29 ] = 15 ] = 30 @AT@ 16 @LENGTH@ 21\n" + + "---------UPD decl@@int a ] ] = 29 ] = 15 @TO@ int a ] ] = 29 ] = 15 ] = 30 @AT@ 16 @LENGTH@ 21\n" + + "------------UPD init@@] = 29 ] = 15 @TO@ ] = 29 ] = 15 ] = 30 @AT@ 27 @LENGTH@ 13\n" + + "---------------UPD expr@@] = 29 ] = 15 @TO@ ] = 29 ] = 15 ] = 30 @AT@ 27 @LENGTH@ 13\n" + + "------------------UPD block@@] = 29 ] = 15 @TO@ ] = 29 ] = 15 ] = 30 @AT@ 27 @LENGTH@ 23\n" + + "---------------------INS expr@@] = 30 @TO@ block@@] = 29 ] = 15 @AT@ 49 @LENGTH@ 6\n" + + "------------------------INS index@@] @TO@ expr@@] = 30 @AT@ 49 @LENGTH@ 4\n" + + "---------------------------INS expr@@[3 @TO@ index@@] @AT@ 50 @LENGTH@ 2\n" + + "------------------------------INS literal@@[3 @TO@ expr@@[3 @AT@ 50 @LENGTH@ 2\n" + + "------------------------INS operator@@= @TO@ expr@@] = 30 @AT@ 53 @LENGTH@ 1\n" + + "------------------------INS literal@@30 @TO@ expr@@] = 30 @AT@ 55 @LENGTH@ 2\n"); + + } + + @Test + public void testBitfieldCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_bitfield_example_1.c"); + File revFile = new File("src/main/resource/testFiles/bitfield_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD struct@@employee char name ] int a 10 long cls temp @TO@ employee char name ] int a 5 long cls temp @AT@ 0 @LENGTH@ 74\n" + + "---UPD block@@char name ] int a 10 long cls @TO@ char name ] int a 5 long cls @AT@ 15 @LENGTH@ 53\n" + + "------UPD decl_stmt@@int a 10 @TO@ int a 5 @AT@ 40 @LENGTH@ 8\n" + + "---------UPD decl@@int a 10 @TO@ int a 5 @AT@ 40 @LENGTH@ 8\n" + + "------------UPD range@@10 @TO@ 5 @AT@ 48 @LENGTH@ 2\n" + + "---------------UPD expr@@10 @TO@ 5 @AT@ 48 @LENGTH@ 2\n" + + "------------------UPD literal@@10 @TO@ 5 @AT@ 48 @LENGTH@ 2\n"); + + } + + + + + @Test + public void testTernaryCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_ternary_example_1.c"); + File revFile = new File("src/main/resource/testFiles/ternary_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD function@@static int rpm_range_to_reg int range int i a x z @TO@ static int rpm_range_to_reg int range int i a x y @AT@ 0 @LENGTH@ 49\n" + + "---UPD block@@int i a x z @TO@ int i a x y @AT@ 38 @LENGTH@ 31\n" + + "------UPD return@@a x z @TO@ a x y @AT@ 49 @LENGTH@ 18\n" + + "---------UPD expr@@a x z @TO@ a x y @AT@ 56 @LENGTH@ 5\n" + + "------------UPD ternary@@a x z @TO@ a x y @AT@ 56 @LENGTH@ 5\n" + + "---------------UPD else@@z @TO@ y @AT@ 64 @LENGTH@ 1\n" + + "------------------UPD expr@@z @TO@ y @AT@ 64 @LENGTH@ 1\n" + + "---------------------UPD name@@z @TO@ y @AT@ 64 @LENGTH@ 1\n"); + + } + + @Test + public void testDereferenceCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_dereference_example_1.c"); + File revFile = new File("src/main/resource/testFiles/dereference_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD function@@static struct max6639_data * max6639_update_device struct device * dev struct max6639_data * data dev_get_drvdata dev struct i2c_client * client data -> client @TO@ static struct max6639_data * max6639_update_device struct device * dev struct max6639_data * data dev_get_drvdata dev struct i2c_client * client test -> client @AT@ 0 @LENGTH@ 159\n" + + "---UPD block@@struct max6639_data * data dev_get_drvdata dev struct i2c_client * client data -> client @TO@ struct max6639_data * data dev_get_drvdata dev struct i2c_client * client test -> client @AT@ 69 @LENGTH@ 98\n" + + "------UPD decl_stmt@@struct i2c_client * client data -> client @TO@ struct i2c_client * client test -> client @AT@ 123 @LENGTH@ 41\n" + + "---------UPD decl@@struct i2c_client * client data -> client @TO@ struct i2c_client * client test -> client @AT@ 123 @LENGTH@ 41\n" + + "------------UPD init@@data -> client @TO@ test -> client @AT@ 151 @LENGTH@ 14\n" + + "---------------UPD expr@@data -> client @TO@ test -> client @AT@ 151 @LENGTH@ 14\n" + + "------------------UPD name@@data -> client @TO@ test -> client @AT@ 151 @LENGTH@ 14\n" + + "---------------------UPD name@@data @TO@ test @AT@ 151 @LENGTH@ 4\n"); + + } + + @Test + public void testSizeofCase1() throws IOException { + Properties appProps = new Properties(); + appProps.load(new FileInputStream("src/main/resource/app.properties")); + String srcMLPath = appProps.getProperty("srcMLPath","FORKJOIN"); + + File prevFile =new File("src/main/resource/testFiles/prev_sizeof_example_1.c"); + File revFile = new File("src/main/resource/testFiles/sizeof_example_1.c"); + + + + + EDiffHunkParser parser = new EDiffHunkParser(); + + List hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath); + hierarchicalActionSets.size(); + Assert.assertEquals(hierarchicalActionSets.size(),1); + + Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD function@@int main printf \"%lu\\n\" char printf \"%lu\\n\" int printf \"%lu\\n\" float printf \"%lu\" double 0 @TO@ int main printf \"%lu\\n\" char printf \"%lu\\n\" int printf \"%lu\\n\" float printf \"%lu\" int 0 @AT@ 19 @LENGTH@ 90\n" + + "---UPD block@@printf \"%lu\\n\" char printf \"%lu\\n\" int printf \"%lu\\n\" float printf \"%lu\" double 0 @TO@ printf \"%lu\\n\" char printf \"%lu\\n\" int printf \"%lu\\n\" float printf \"%lu\" int 0 @AT@ 31 @LENGTH@ 164\n" + + "------UPD expr_stmt@@printf \"%lu\" double @TO@ printf \"%lu\" int @AT@ 146 @LENGTH@ 19\n" + + "---------UPD expr@@printf \"%lu\" double @TO@ printf \"%lu\" int @AT@ 146 @LENGTH@ 19\n" + + "------------UPD call@@printf \"%lu\" double @TO@ printf \"%lu\" int @AT@ 146 @LENGTH@ 19\n" + + "---------------UPD argument_list@@\"%lu\" double @TO@ \"%lu\" int @AT@ 152 @LENGTH@ 24\n" + + "------------------UPD argument@@double @TO@ int @AT@ 166 @LENGTH@ 6\n" + + "---------------------UPD expr@@double @TO@ int @AT@ 166 @LENGTH@ 6\n" + + "------------------------UPD sizeof@@double @TO@ int @AT@ 166 @LENGTH@ 6\n" + + "---------------------------UPD argument_list@@double @TO@ int @AT@ 166 @LENGTH@ 9\n" + + "------------------------------UPD argument@@double @TO@ int @AT@ 167 @LENGTH@ 6\n" + + "---------------------------------UPD expr@@double @TO@ int @AT@ 167 @LENGTH@ 6\n" + + "------------------------------------UPD name@@double @TO@ int @AT@ 167 @LENGTH@ 6\n"); + + } }