-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mono.Android-Test] Import Mono.Android tests from monodroid/9c5b3712 (…
…#32) Import monodroid/tests/runtime from monodroid/9c5b3712. Add a toplevel `make run-apk-tests` target to "full stack" tests, in which a .apk is created, installed, and executed on an attached Android device. `make run-apk-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... The $(ADB_TARGET) variable can be used to control on which target Android device the tests will be installed and executed on: # Install & run tests on *only* connected USB device $ make run-apk-tests ADB_TARGET=-d # Install & run tests on *only* connected emulator $ make run-apk-tests ADB_TARGET=-e # Install & run tests on specified device, listed via `adb devices`. $ make run-apk-tests ADB_TARGET="-s 036533824381cfcb" Sorry potential/future Windows developers. *Running* tests will require manual testing or running on OS X or Linux for now... Note: These tests DO NOT PASS. In fact, they *crash*: $ make run-apk-tests ... Target RunTests: Executing: "$HOME/android-toolchain/sdk/platform-tools/adb" shell am instrument -w Mono.Android_Tests/xamarin.android.runtimetests.TestInstrumentation INSTRUMENTATION_RESULT: shortMsg=Process crashed. INSTRUMENTATION_CODE: 0 $ adb logcat ... E mono : Unhandled Exception: E mono : System.ObjectDisposedException: Cannot access a disposed object. E mono : Object name: 'System.Net.Sockets.Socket'. E mono : at System.Net.Sockets.Socket.ThrowIfDisposedAndClosed () <0xa93923f0 + 0x00054> in <filename unknown>:0 E mono : at System.Net.Sockets.Socket.AcceptAsync (System.Net.Sockets.SocketAsyncEventArgs e) <0x9b8f9680 + 0x0001b> in <filename unknown>:0 E mono : at System.Net.EndPointListener.Accept (System.Net.Sockets.Socket socket, System.Net.Sockets.SocketAsyncEventArgs e) <0x9b8f95d0 + 0x0003f> in <filename unknown>:0 E mono : at System.Net.EndPointListener.ProcessAccept (System.Net.Sockets.SocketAsyncEventArgs args) <0x9b8e0340 + 0x0007f> in <filename unknown>:0 E mono : at System.Net.EndPointListener.OnAccept (System.Object sender, System.Net.Sockets.SocketAsyncEventArgs e) <0x9b8e0310 + 0x00017> in <filename unknown>:0 E mono : at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted (System.Net.Sockets.SocketAsyncEventArgs e) <0x9b8e02c8 + 0x0003b> in <filename unknown>:0 E mono : at System.Net.Sockets.SocketAsyncEventArgs.Complete () <0x9b8e02a0 + 0x0001f> in <filename unknown>:0 E mono : at System.Net.Sockets.Socket.<AcceptAsyncCallback>m__0 (System.IAsyncResult ares) <0x9b8dfd40 + 0x002af> in <filename unknown>:0 E mono : at System.Net.Sockets.SocketAsyncResult+<Complete>c__AnonStorey0.<>m__0 (System.Object _) <0xa892f720 + 0x0002b> in <filename unknown>:0 E mono : at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () <0xa938f6b8 + 0x0002f> in <filename unknown>:0 E mono : at System.Threading.ThreadPoolWorkQueue.Dispatch () <0xa938e358 + 0x001bb> in <filename unknown>:0 E mono : at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0xa938e1a8 + 0x00007> in <filename unknown>:0 Looks like a Socket and/or ThreadPool bug in mono.
- Loading branch information
1 parent
4c81668
commit 1b3a76c
Showing
56 changed files
with
4,355 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
libs |
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,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 (); | ||
} | ||
} | ||
} |
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,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")); | ||
} | ||
} | ||
} | ||
} |
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,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 (); | ||
} | ||
} | ||
} | ||
} |
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,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
37
src/Mono.Android/Test/Android.Runtime/JavaCollectionTest.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,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)); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.