-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Tools.Aidl-Tests] Add unit tests (#5756)
Context: #5726 We have someone willing to contribute fixes for `Xamarin.Android.Tools.Aidl.dll` (yay!). However, we no longer have any expertise with AIDL available on the team, and there are no unit tests for this area. This makes us very reluctant to make changes which could potentially break the currently working aspects of AIDL. Add a new `tests/Xamarin.Android.Tools.Aidl-Tests` unit test project and seed it with a few examples from our repo and a few large examples from other OSS repos. Note: this does *not* mean that the behavior tested by these tests is necessarily *correct*. It simply reflects what the code does *today*, in order that we can see any changes made by future PR's. ~~ Note ~~ The format for test data files is delimited by 4 pound signs as: <input> #### <output> Test results can be generated by: - Placing the input in a test file - Enabling the `GENERATE_OUTPUT` define at the top of `AidlCompilerTestBase.cs` - Running the test - The test file in `bin/TestData` will now contain the test output which can be copied back to the original test data file.
- Loading branch information
Showing
15 changed files
with
16,648 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests/Xamarin.Android.Tools.Aidl-Tests/AidlCompilerTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//#define GENERATE_OUTPUT | ||
// This define will overwrite the files in /bin/TestData. | ||
// You will still need to copy them back to the original /TestData. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using NUnit.Framework; | ||
using Xamarin.Android.Tools.Aidl; | ||
|
||
namespace Xamarin.Android.Tools.Aidl_Tests | ||
{ | ||
public class AidlCompilerTestBase | ||
{ | ||
protected void RunTest (string name) | ||
{ | ||
var root = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location); | ||
var file = Path.Combine (root, "TestData", name + ".txt"); | ||
var text = File.ReadAllText (file); | ||
|
||
(var input, var expected_output) = SplitTestFile (text); | ||
|
||
var compiler = new AidlCompiler (); | ||
var results = compiler.Run (input, out var output); | ||
|
||
Assert.False (results.LogMessages.Any ()); | ||
|
||
#if GENERATE_OUTPUT | ||
using (var sw = new StreamWriter (file)) { | ||
sw.WriteLine (input); | ||
sw.WriteLine (); | ||
sw.WriteLine ("####"); | ||
sw.WriteLine (); | ||
sw.WriteLine (output); | ||
} | ||
|
||
Assert.Ignore ("Generating output for this test."); | ||
#endif // GENERATE_OUTPUT | ||
|
||
Assert.AreEqual (StripLineEndings (expected_output), StripLineEndings (output)); | ||
} | ||
|
||
(string input, string output) SplitTestFile (string text) | ||
{ | ||
var index = text.IndexOf ("####"); | ||
|
||
if (index < 0) { | ||
#if GENERATE_OUTPUT | ||
return (text, null); | ||
#endif // GENERATE_OUTPUT | ||
throw new Exception ("No expected output found."); | ||
} | ||
|
||
var input = text.Substring (0, index).Trim (); | ||
var output = text.Substring (index + 4).Trim (); | ||
|
||
return (input, output); | ||
} | ||
|
||
string StripLineEndings (string input) => input.Replace ("\n", "").Replace ("\r", "").Trim (); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Xamarin.Android.Tools.Aidl-Tests/AidlCompilerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace Xamarin.Android.Tools.Aidl_Tests | ||
{ | ||
[TestFixture] | ||
public class AidlCompilerTests : AidlCompilerTestBase | ||
{ | ||
[Test] | ||
public void ListAndMap () => RunTest (nameof (ListAndMap)); | ||
|
||
[Test] | ||
public void NamespaceResolution () => RunTest (nameof (NamespaceResolution)); | ||
|
||
[Test] | ||
public void PrimitiveTypes () => RunTest (nameof (PrimitiveTypes)); | ||
|
||
[Test] | ||
public void FaceService () => RunTest (nameof (FaceService)); | ||
|
||
[Test] | ||
public void IUpdateEngine () => RunTest (nameof (IUpdateEngine)); | ||
|
||
[Test] | ||
public void ITelephony () => RunTest (nameof (ITelephony)); | ||
} | ||
} |
Oops, something went wrong.