Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mono.Android-Test] Import Mono.Android tests from monodroid/9c5b3712 #32

Merged
merged 1 commit into from
May 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ prepare:
(cd external/Java.Interop && nuget restore)


run-all-tests: run-nunit-tests
run-all-tests: run-nunit-tests run-apk-tests

clean:
$(MSBUILD) /t:Clean


# $(call RUN_NUNIT_TEST,filename,log-lref?)
define RUN_NUNIT_TEST
MONO_TRACE_LISTENER=Console.Out \
Expand All @@ -43,3 +42,22 @@ endef

run-nunit-tests: $(NUNIT_TESTS)
$(foreach t,$(NUNIT_TESTS), $(call RUN_NUNIT_TEST,$(t),1))

# Test .apk projects must satisfy the following requirements:
# 1. They must have a UnDeploy target
# 2. They must have a Deploy target
# 3. They must have a RunTests target
TEST_APK_PROJECTS = \
src/Mono.Android/Test/Mono.Android-Tests.csproj

# Syntax: $(call RUN_TEST_APK,path/to/project.csproj)
define RUN_TEST_APK
# Must use xabuild to ensure correct assemblies are resolved
tools/scripts/xabuild /t:SignAndroidPackage $(1) && \
$(MSBUILD) /t:UnDeploy $(1) && \
$(MSBUILD) /t:Deploy $(1) && \
$(MSBUILD) /t:RunTests $(1) $(if $(ADB_TARGET),"/p:AdbTarget=$(ADB_TARGET)",)
endef

run-apk-tests:
$(foreach p, $(TEST_APK_PROJECTS), $(call RUN_TEST_APK, $(p)))
15 changes: 15 additions & 0 deletions Xamarin.Android.sln
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.ProjectTools", "src
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Build.Tests", "src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj", "{53E4ABF0-1085-45F9-B964-DCAE4B819998}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Android-Tests", "src\Mono.Android\Test\Mono.Android-Tests.csproj", "{40EAD437-216B-4DF4-8258-3F47E1672C3A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AnyCPU = Debug|AnyCPU
Expand Down Expand Up @@ -238,6 +240,18 @@ Global
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.Build.0 = Release|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
Expand Down Expand Up @@ -266,6 +280,7 @@ Global
{4D603AA3-3BFD-43C8-8050-0CD6C2601126} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
{2DD1EE75-6D8D-4653-A800-0A24367F7F38} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
{53E4ABF0-1085-45F9-B964-DCAE4B819998} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
{40EAD437-216B-4DF4-8258-3F47E1672C3A} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
Expand Down
1 change: 1 addition & 0 deletions src/Mono.Android/Test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libs
89 changes: 89 additions & 0 deletions src/Mono.Android/Test/Android.App/ApplicationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;

using NUnit.Framework;

namespace Android.AppTests
{
[TestFixture]
public class ApplicationTest
{
[Test]
public void ApplicationContextIsApp ()
{
Assert.IsTrue (Application.Context is App);
Assert.IsTrue (App.Created);
}

[Test]
public void SynchronizationContext_Is_ThreadingSynchronizationContextCurrent ()
{
bool same = false;
Application.SynchronizationContext.Send (_ => {
var c = System.Threading.SynchronizationContext.Current;
same = object.ReferenceEquals (c, Application.SynchronizationContext);
}, null);
Assert.IsTrue (same);
}

[Test]
public void SynchronizationContext_Post_DoesNotBlock ()
{
// To ensure we're on the main thread:
bool sendFinishedBeforePost = false;
Application.SynchronizationContext.Send (_ => {
bool postWasExecuted = false;
Application.SynchronizationContext.Post (_2 => {
postWasExecuted = true;
}, null);
if (!postWasExecuted)
sendFinishedBeforePost = true;
}, null);
Assert.IsTrue (sendFinishedBeforePost);
}

[Test]
public void EnsureAndroidManifestIsUpdated ()
{
var klass = Java.Lang.Class.FromType (typeof (RenamedActivity));
var context = Application.Context;
using (var n = new ComponentName (context, klass)) {
var activityInfo = context.PackageManager.GetActivityInfo (n, 0);
var configChanges = activityInfo.ConfigChanges;
Assert.AreEqual (ConfigChanges.KeyboardHidden, configChanges);
}
}
}

public class App : Application {

public static bool Created;

public App (IntPtr handle, JniHandleOwnership transfer)
: base (handle, transfer)
{
Created = true;
}

public override void OnCreate ()
{
base.OnCreate ();
}
}

[Activity]
public class RenamedActivity : Activity {

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

Finish ();
}
}
}
21 changes: 21 additions & 0 deletions src/Mono.Android/Test/Android.Content/IntentTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

using Android.Content;

using NUnit.Framework;

namespace Android.ContentTests
{
[TestFixture]
public class IntentTest
{
[Test]
public void PutCharSequenceArrayListExtra_NullValue ()
{
using (var intent = new Intent ()) {
intent.PutCharSequenceArrayListExtra ("null", null);
Assert.AreEqual (null, intent.GetCharSequenceArrayListExtra ("null"));
}
}
}
}
32 changes: 32 additions & 0 deletions src/Mono.Android/Test/Android.OS/HandlerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Threading;
using Android.OS;

using NUnit.Framework;

namespace Xamarin.Android.RuntimeTests {

[TestFixture]
public class HandlerTest {

[Test]
public void RemoveDisposedInstance ()
{
using (var t = new HandlerThread ("RemoveDisposedInstance")) {
t.Start ();
using (var h = new Handler (t.Looper)) {
var e = new ManualResetEvent (false);
Java.Lang.Runnable r = null;
r = new Java.Lang.Runnable (() => {
e.Set ();
r.Dispose ();
});
h.Post (r.Run);
e.WaitOne ();
}

t.QuitSafely ();
}
}
}
}
21 changes: 21 additions & 0 deletions src/Mono.Android/Test/Android.Runtime/CharSequenceTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

using Android.Runtime;

using NUnit.Framework;

namespace Android.RuntimeTests {

[TestFixture]
public class CharSequenceTest {

[Test]
public void ToLocalJniHandle ()
{
using (var s = new Java.Lang.String ("s")) {
var p = CharSequence.ToLocalJniHandle (s);
JNIEnv.DeleteLocalRef (p);
}
}
}
}
37 changes: 37 additions & 0 deletions src/Mono.Android/Test/Android.Runtime/JavaCollectionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Android.Runtime;

using NUnit.Framework;

namespace Android.RuntimeTests
{
[TestFixture]
public class JavaCollectionTest
{
[Test]
public void CopyTo ()
{
using (var al = new Java.Util.ArrayList ()) {
al.Add (1);
al.Add (2);
al.Add (3);

using (var c = new JavaCollection (al.Handle, JniHandleOwnership.DoNotTransfer)) {
var to = new int[3];
c.CopyTo (to, 0);
Assert.IsTrue (new[]{1,2,3}.SequenceEqual (to));
}

using (var c = new JavaCollection<int> (al.Handle, JniHandleOwnership.DoNotTransfer)) {
var to = new int[3];
c.CopyTo (to, 0);
Assert.IsTrue (new[]{1,2,3}.SequenceEqual (to));
}
}
}
}
}

Loading