From ff5b18750574b00925b6cff87816c87b55478985 Mon Sep 17 00:00:00 2001 From: Martin Karing Date: Sat, 11 Aug 2018 11:06:07 +0200 Subject: [PATCH] Added unit test to verify issue #1 The renaming analysis fails in case a text block contains a [ but no closing ]. --- .editorconfig | 1 + Confuser2.sln | 17 ++++++- Tests/WpfRenaming.Test/ProcessWpfTest.cs | 44 +++++++++++++++++++ .../WpfRenaming.Test/WpfRenaming.Test.csproj | 22 ++++++++++ Tests/WpfRenaming/UserControl1.xaml | 19 ++++++++ Tests/WpfRenaming/UserControl1.xaml.cs | 28 ++++++++++++ Tests/WpfRenaming/WpfRenaming.csproj | 9 ++++ global.json | 5 +++ 8 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 Tests/WpfRenaming.Test/ProcessWpfTest.cs create mode 100644 Tests/WpfRenaming.Test/WpfRenaming.Test.csproj create mode 100644 Tests/WpfRenaming/UserControl1.xaml create mode 100644 Tests/WpfRenaming/UserControl1.xaml.cs create mode 100644 Tests/WpfRenaming/WpfRenaming.csproj create mode 100644 global.json diff --git a/.editorconfig b/.editorconfig index fb672b6..92da776 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,6 +15,7 @@ indent_style = space [*.xml] [*.xaml] +indent_size = 2 indent_style = space [*.{cs,vb}] diff --git a/Confuser2.sln b/Confuser2.sln index 8b552fd..49e5e3a 100644 --- a/Confuser2.sln +++ b/Confuser2.sln @@ -32,6 +32,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig appveyor.yml = appveyor.yml + global.json = global.json LICENSE.md = LICENSE.md README.md = README.md EndProjectSection @@ -42,7 +43,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntiTamper", "Tests\AntiTam EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntiTamper.Test", "Tests\AntiTamper.Test\AntiTamper.Test.csproj", "{3F5558BD-7B94-4CB0-A46C-A7252B5BCA17}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Confuser.MSBuild.Tasks", "Confuser.MSBuild.Tasks\Confuser.MSBuild.Tasks.csproj", "{91B12706-DC6A-45DE-97F1-FAF0901FF6AF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Confuser.MSBuild.Tasks", "Confuser.MSBuild.Tasks\Confuser.MSBuild.Tasks.csproj", "{91B12706-DC6A-45DE-97F1-FAF0901FF6AF}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfRenaming", "Tests\WpfRenaming\WpfRenaming.csproj", "{BA9D2748-1342-41A3-87F2-343E82D99813}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfRenaming.Test", "Tests\WpfRenaming.Test\WpfRenaming.Test.csproj", "{30B8883F-A0A2-4256-ADCF-A790525D3696}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -106,6 +111,14 @@ Global {91B12706-DC6A-45DE-97F1-FAF0901FF6AF}.Debug|Any CPU.Build.0 = Debug|Any CPU {91B12706-DC6A-45DE-97F1-FAF0901FF6AF}.Release|Any CPU.ActiveCfg = Release|Any CPU {91B12706-DC6A-45DE-97F1-FAF0901FF6AF}.Release|Any CPU.Build.0 = Release|Any CPU + {BA9D2748-1342-41A3-87F2-343E82D99813}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BA9D2748-1342-41A3-87F2-343E82D99813}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BA9D2748-1342-41A3-87F2-343E82D99813}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BA9D2748-1342-41A3-87F2-343E82D99813}.Release|Any CPU.Build.0 = Release|Any CPU + {30B8883F-A0A2-4256-ADCF-A790525D3696}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30B8883F-A0A2-4256-ADCF-A790525D3696}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30B8883F-A0A2-4256-ADCF-A790525D3696}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30B8883F-A0A2-4256-ADCF-A790525D3696}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -116,6 +129,8 @@ Global {73226E13-1701-424E-A4F2-3E4D575A1DD0} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB} {6A2BA6F7-3399-4890-9453-2D5BE8EEBBA9} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB} {3F5558BD-7B94-4CB0-A46C-A7252B5BCA17} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB} + {BA9D2748-1342-41A3-87F2-343E82D99813} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB} + {30B8883F-A0A2-4256-ADCF-A790525D3696} = {356BDB31-853E-43BB-8F9A-D8AC08F69EBB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0D937D9E-E04B-4A68-B639-D4260473A388} diff --git a/Tests/WpfRenaming.Test/ProcessWpfTest.cs b/Tests/WpfRenaming.Test/ProcessWpfTest.cs new file mode 100644 index 0000000..5dfd002 --- /dev/null +++ b/Tests/WpfRenaming.Test/ProcessWpfTest.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using Confuser.Core; +using Confuser.Core.Project; +using Confuser.UnitTest; +using Xunit; +using Xunit.Abstractions; + +namespace WpfRenaming.Test { + public class ProcessWpfTest { + private readonly ITestOutputHelper outputHelper; + + public ProcessWpfTest(ITestOutputHelper outputHelper) => + this.outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper)); + + /// + [Fact] + [Trait("Category", "Analysis")] + [Trait("Protection", "rename")] + public async Task ProcessWithoutObfuscationTest() { + var baseDir = Environment.CurrentDirectory; + var outputDir = Path.Combine(baseDir, "testtmp"); + var inputFile = Path.Combine(baseDir, "WpfRenaming.dll"); + var outputFile = Path.Combine(outputDir, "WpfRenaming.dll"); + FileUtilities.ClearOutput(outputFile); + var proj = new ConfuserProject { + BaseDirectory = baseDir, + OutputDirectory = outputDir + }; + proj.Add(new ProjectModule() { Path = inputFile }); + + + var parameters = new ConfuserParameters { + Project = proj, + Logger = new XunitLogger(outputHelper) + }; + + await ConfuserEngine.Run(parameters); + + Assert.True(File.Exists(outputFile)); + } + } +} diff --git a/Tests/WpfRenaming.Test/WpfRenaming.Test.csproj b/Tests/WpfRenaming.Test/WpfRenaming.Test.csproj new file mode 100644 index 0000000..40f3558 --- /dev/null +++ b/Tests/WpfRenaming.Test/WpfRenaming.Test.csproj @@ -0,0 +1,22 @@ + + + + net461 + false + + + + + + + + + + + + + + + + + diff --git a/Tests/WpfRenaming/UserControl1.xaml b/Tests/WpfRenaming/UserControl1.xaml new file mode 100644 index 0000000..a771a63 --- /dev/null +++ b/Tests/WpfRenaming/UserControl1.xaml @@ -0,0 +1,19 @@ + + + [1234567 + + + + + + + + + diff --git a/Tests/WpfRenaming/UserControl1.xaml.cs b/Tests/WpfRenaming/UserControl1.xaml.cs new file mode 100644 index 0000000..776ff44 --- /dev/null +++ b/Tests/WpfRenaming/UserControl1.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WpfRenaming +{ + /// + /// Interaktionslogik für UserControl1.xaml + /// + public partial class UserControl1 : UserControl + { + public UserControl1() + { + InitializeComponent(); + } + } +} diff --git a/Tests/WpfRenaming/WpfRenaming.csproj b/Tests/WpfRenaming/WpfRenaming.csproj new file mode 100644 index 0000000..523b58a --- /dev/null +++ b/Tests/WpfRenaming/WpfRenaming.csproj @@ -0,0 +1,9 @@ + + + + net461 + true + Custom + + + \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000..1d6d6d2 --- /dev/null +++ b/global.json @@ -0,0 +1,5 @@ +{ + "msbuild-sdks": { + "MSBuild.Sdk.Extras": "1.6.46" + } +} \ No newline at end of file