Skip to content

Commit e7d6408

Browse files
committed
[Mono.Android-Test] Import Mono.Android tests from monodroid/9c5b3712
Import monodroid/tests/runtime from monodroid/9c5b3712. Add a toplevel `make run-all-tests` target to run the tests. `make run-all-tests` requires that `adb` be in $PATH, and uses GNU make(1) features, and... Additionally, tools/scripts/xabuild *must* be used to execute the SignAndroidPackage target, to ensure that the local/"in tree" assemblies are used. There is no "within xbuild" facility to alter where target framework assemblies are resolved from, i.e no MSBuild properties currently control the resolution order, only environment variables, and MSBuild can't *set* environment variables... Sorry potential/future Windows developers.
1 parent 4821159 commit e7d6408

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+4373
-1
lines changed

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,24 @@ prepare:
2121

2222
clean:
2323
$(MSBUILD) /t:Clean
24+
25+
run-all-tests: run-apk-tests
26+
27+
# Test .apk projects must satisfy the following requirements:
28+
# 1. They must have a UnDeploy target
29+
# 2. They must have a Deploy target
30+
# 3. They must have a RunTests target
31+
TEST_APK_PROJECTS = \
32+
src/Mono.Android/Test/Mono.Android-Tests.csproj
33+
34+
# Syntax: $(call RUN_TEST_APK,path/to/project.csproj)
35+
define RUN_TEST_APK
36+
# Must use xabuild to ensure correct assemblies are resolved
37+
tools/scripts/xabuild /t:SignAndroidPackage $(1) && \
38+
$(MSBUILD) /t:UnDeploy $(1) && \
39+
$(MSBUILD) /t:Deploy $(1) && \
40+
$(MSBUILD) /t:RunTests $(1)
41+
endef
42+
43+
run-apk-tests:
44+
$(foreach p, $(TEST_APK_PROJECTS), $(call RUN_TEST_APK, $(p)))

Xamarin.Android.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "api-xml-adjuster", "tools\a
5555
EndProject
5656
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.NUnitLite", "src\Xamarin.Android.NUnitLite\Xamarin.Android.NUnitLite.csproj", "{4D603AA3-3BFD-43C8-8050-0CD6C2601126}"
5757
EndProject
58+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core-Tests", "Core-Tests", "{E8C38B79-1821-4D39-A845-3EF1BAC8C47E}"
59+
EndProject
60+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Android-Tests", "src\Mono.Android\Test\Mono.Android-Tests.csproj", "{40EAD437-216B-4DF4-8258-3F47E1672C3A}"
61+
EndProject
5862
Global
5963
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6064
Debug|AnyCPU = Debug|AnyCPU
@@ -208,6 +212,18 @@ Global
208212
{4D603AA3-3BFD-43C8-8050-0CD6C2601126}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
209213
{4D603AA3-3BFD-43C8-8050-0CD6C2601126}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
210214
{4D603AA3-3BFD-43C8-8050-0CD6C2601126}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
215+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
216+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.Build.0 = Debug|Any CPU
217+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.ActiveCfg = Release|Any CPU
218+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.Build.0 = Release|Any CPU
219+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
220+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
221+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
222+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
223+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU
224+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
225+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
226+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
211227
EndGlobalSection
212228
GlobalSection(NestedProjects) = preSolution
213229
{8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
@@ -234,6 +250,7 @@ Global
234250
{53EE4C57-1C03-405A-8243-8DA539546C88} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
235251
{8A6CB07C-E493-4A4F-AB94-038645A27118} = {864062D3-A415-4A6F-9324-5820237BA058}
236252
{4D603AA3-3BFD-43C8-8050-0CD6C2601126} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
253+
{40EAD437-216B-4DF4-8258-3F47E1672C3A} = {E8C38B79-1821-4D39-A845-3EF1BAC8C47E}
237254
EndGlobalSection
238255
GlobalSection(MonoDevelopProperties) = preSolution
239256
Policies = $0

src/Mono.Android.Export/Mono.Android.Export.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,18 @@
4848
<HintPath>$(OutputPath)..\v1.0\System.Xml.dll</HintPath>
4949
<Private>False</Private>
5050
</Reference>
51+
<Reference Include="Java.Interop">
52+
<HintPath>$(OutputPath)..\v1.0\Java.Interop.dll</HintPath>
53+
<Private>False</Private>
54+
</Reference>
55+
<Reference Include="System.Runtime">
56+
<HintPath>$(OutputPath)..\v1.0\Facades\System.Runtime.dll</HintPath>
57+
<Private>False</Private>
58+
</Reference>
5159
</ItemGroup>
5260
<ItemGroup>
5361
<Compile Include="Properties\AssemblyInfo.cs" />
62+
<Compile Include="CallbackCode.cs" />
5463
<Compile Include="Mono.CodeGeneration\CodeAdd.cs" />
5564
<Compile Include="Mono.CodeGeneration\CodeAnd.cs" />
5665
<Compile Include="Mono.CodeGeneration\CodeArgument.cs" />

src/Mono.Android/Test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libs
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
3+
using Android.App;
4+
using Android.Content;
5+
using Android.Content.PM;
6+
using Android.OS;
7+
using Android.Runtime;
8+
9+
using NUnit.Framework;
10+
11+
namespace Android.AppTests
12+
{
13+
[TestFixture]
14+
public class ApplicationTest
15+
{
16+
[Test]
17+
public void ApplicationContextIsApp ()
18+
{
19+
Assert.IsTrue (Application.Context is App);
20+
Assert.IsTrue (App.Created);
21+
}
22+
23+
[Test]
24+
public void SynchronizationContext_Is_ThreadingSynchronizationContextCurrent ()
25+
{
26+
bool same = false;
27+
Application.SynchronizationContext.Send (_ => {
28+
var c = System.Threading.SynchronizationContext.Current;
29+
same = object.ReferenceEquals (c, Application.SynchronizationContext);
30+
}, null);
31+
Assert.IsTrue (same);
32+
}
33+
34+
[Test]
35+
public void SynchronizationContext_Post_DoesNotBlock ()
36+
{
37+
// To ensure we're on the main thread:
38+
bool sendFinishedBeforePost = false;
39+
Application.SynchronizationContext.Send (_ => {
40+
bool postWasExecuted = false;
41+
Application.SynchronizationContext.Post (_2 => {
42+
postWasExecuted = true;
43+
}, null);
44+
if (!postWasExecuted)
45+
sendFinishedBeforePost = true;
46+
}, null);
47+
Assert.IsTrue (sendFinishedBeforePost);
48+
}
49+
50+
[Test]
51+
public void EnsureAndroidManifestIsUpdated ()
52+
{
53+
var klass = Java.Lang.Class.FromType (typeof (RenamedActivity));
54+
var context = Application.Context;
55+
using (var n = new ComponentName (context, klass)) {
56+
var activityInfo = context.PackageManager.GetActivityInfo (n, 0);
57+
var configChanges = activityInfo.ConfigChanges;
58+
Assert.AreEqual (ConfigChanges.KeyboardHidden, configChanges);
59+
}
60+
}
61+
}
62+
63+
public class App : Application {
64+
65+
public static bool Created;
66+
67+
public App (IntPtr handle, JniHandleOwnership transfer)
68+
: base (handle, transfer)
69+
{
70+
Created = true;
71+
}
72+
73+
public override void OnCreate ()
74+
{
75+
base.OnCreate ();
76+
}
77+
}
78+
79+
[Activity]
80+
public class RenamedActivity : Activity {
81+
82+
protected override void OnCreate (Bundle bundle)
83+
{
84+
base.OnCreate (bundle);
85+
86+
Finish ();
87+
}
88+
}
89+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
using Android.Content;
4+
5+
using NUnit.Framework;
6+
7+
namespace Android.ContentTests
8+
{
9+
[TestFixture]
10+
public class IntentTest
11+
{
12+
[Test]
13+
public void PutCharSequenceArrayListExtra_NullValue ()
14+
{
15+
using (var intent = new Intent ()) {
16+
intent.PutCharSequenceArrayListExtra ("null", null);
17+
Assert.AreEqual (null, intent.GetCharSequenceArrayListExtra ("null"));
18+
}
19+
}
20+
}
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Threading;
3+
using Android.OS;
4+
5+
using NUnit.Framework;
6+
7+
namespace Xamarin.Android.RuntimeTests {
8+
9+
[TestFixture]
10+
public class HandlerTest {
11+
12+
[Test]
13+
public void RemoveDisposedInstance ()
14+
{
15+
using (var t = new HandlerThread ("RemoveDisposedInstance")) {
16+
t.Start ();
17+
using (var h = new Handler (t.Looper)) {
18+
var e = new ManualResetEvent (false);
19+
Java.Lang.Runnable r = null;
20+
r = new Java.Lang.Runnable (() => {
21+
e.Set ();
22+
r.Dispose ();
23+
});
24+
h.Post (r.Run);
25+
e.WaitOne ();
26+
}
27+
28+
t.QuitSafely ();
29+
}
30+
}
31+
}
32+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
using Android.Runtime;
4+
5+
using NUnit.Framework;
6+
7+
namespace Android.RuntimeTests {
8+
9+
[TestFixture]
10+
public class CharSequenceTest {
11+
12+
[Test]
13+
public void ToLocalJniHandle ()
14+
{
15+
using (var s = new Java.Lang.String ("s")) {
16+
var p = CharSequence.ToLocalJniHandle (s);
17+
JNIEnv.DeleteLocalRef (p);
18+
}
19+
}
20+
}
21+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
using Android.Runtime;
6+
7+
using NUnit.Framework;
8+
9+
namespace Android.RuntimeTests
10+
{
11+
[TestFixture]
12+
public class JavaCollectionTest
13+
{
14+
[Test]
15+
public void CopyTo ()
16+
{
17+
using (var al = new Java.Util.ArrayList ()) {
18+
al.Add (1);
19+
al.Add (2);
20+
al.Add (3);
21+
22+
using (var c = new JavaCollection (al.Handle, JniHandleOwnership.DoNotTransfer)) {
23+
var to = new int[3];
24+
c.CopyTo (to, 0);
25+
Assert.IsTrue (new[]{1,2,3}.SequenceEqual (to));
26+
}
27+
28+
using (var c = new JavaCollection<int> (al.Handle, JniHandleOwnership.DoNotTransfer)) {
29+
var to = new int[3];
30+
c.CopyTo (to, 0);
31+
Assert.IsTrue (new[]{1,2,3}.SequenceEqual (to));
32+
}
33+
}
34+
}
35+
}
36+
}
37+

0 commit comments

Comments
 (0)