Esempio n. 1
0
 public void DoubleEpsilon_Compare()
 {
     TestRuntime.AssertNotDevice("Known to fail on devices, see bug #15802");
     // works on some ARM CPU (e.g. iPhone5S) but not others (iPad4 or iPodTouch5)
     Assert.That(Double.Epsilon, Is.Not.EqualTo(0f), "Epsilon");
     Assert.That(-Double.Epsilon, Is.Not.EqualTo(0f), "-Epsilon");
 }
        public void PresentFromBarButtonItem_BadButton()
        {
            if (UIDevice.CurrentDevice.UserInterfaceIdiom != UIUserInterfaceIdiom.Pad)
            {
                Assert.Inconclusive("Requires iPad");
            }

            TestRuntime.AssertNotDevice("ObjectiveC exception crash on devices - bug #3980");

            using (var vc = new UIViewController())
                using (var bbi = new UIBarButtonItem(UIBarButtonSystemItem.Action))
                    using (var pc = new UIPopoverController(vc)) {
#if __MACCATALYST__
                        pc.PresentFromBarButtonItem(bbi, UIPopoverArrowDirection.Down, true);
#else
                        // UIBarButtonItem is itself 'ok' but it's not assigned to a view
#if NET
                        Assert.Throws <ObjCException> (() => pc.PresentFromBarButtonItem(bbi, UIPopoverArrowDirection.Down, true));
#else
                        Assert.Throws <MonoTouchException> (() => pc.PresentFromBarButtonItem(bbi, UIPopoverArrowDirection.Down, true));
#endif
#endif
                        // fails with:
                        // Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UIPopoverController presentPopoverFromBarButtonItem:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.
                    }
        }
Esempio n. 3
0
        public void GetName_DLS_SimOnly()
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.iOS, 7, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertNotDevice("Use local file system (need a smaller sample)");

            using (NSUrl url = new NSUrl(local_dls)) {
                Assert.That(SoundBank.GetName(url), Is.EqualTo("QuickTime Music Synthesizer  "), "Name");
            }
        }
Esempio n. 4
0
        public void SingleEpsilon_ToString()
        {
            TestRuntime.AssertNotDevice("Known to fail on devices, see bug #15802");
            var ci = CultureInfo.InvariantCulture;

#if NET
            Assert.That(Single.Epsilon.ToString(ci), Is.EqualTo("1E-45"), "Epsilon.ToString()");
            Assert.That((-Single.Epsilon).ToString(ci), Is.EqualTo("-1E-45"), "-Epsilon.ToString()");
#else
            Assert.That(Single.Epsilon.ToString(ci), Is.EqualTo("1.401298E-45"), "Epsilon.ToString()");
            Assert.That((-Single.Epsilon).ToString(ci), Is.EqualTo("-1.401298E-45"), "-Epsilon.ToString()");
#endif
        }
Esempio n. 5
0
        public void CreateSessionTest()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Ignoring AVAssetDownloadUrlSession tests: Requires iOS9+");
            }

            TestRuntime.AssertNotDevice("Ignoring CreateSessionTest tests: Requires com.apple.developer.media-asset-download entitlement");

            using (var backgroundConfiguration = NSUrlSessionConfiguration.CreateBackgroundSessionConfiguration("HLS-Identifier")) {
                Assert.DoesNotThrow(() => AVAssetDownloadUrlSession.CreateSession(backgroundConfiguration, null, NSOperationQueue.MainQueue), "Should not throw InvalidCastException");
            }
        }
Esempio n. 6
0
        public void DoubleEpsilon_ToString()
        {
            TestRuntime.AssertNotDevice("Known to fail on devices, see bug #15802");
            var ci = CultureInfo.InvariantCulture;

            // note: unlike Single this works on both my iPhone5S and iPodTouch5
#if NET
            Assert.That(Double.Epsilon.ToString(ci), Is.EqualTo("5E-324"), "Epsilon.ToString()");
            Assert.That((-Double.Epsilon).ToString(ci), Is.EqualTo("-5E-324"), "-Epsilon.ToString()");
#else
            Assert.That(Double.Epsilon.ToString(ci), Is.EqualTo("4.94065645841247E-324"), "Epsilon.ToString()");
            Assert.That((-Double.Epsilon).ToString(ci), Is.EqualTo("-4.94065645841247E-324"), "-Epsilon.ToString()");
#endif
        }
Esempio n. 7
0
        // http://bugzilla.xamarin.com/show_bug.cgi?id=1820
        // note: this also test the linker (5.1+) ability not to remove 'unused' XML setters and .ctors used for serialization
        public void Bug1820_GenericList()
        {
#if NET && (__IOS__ || __TVOS__)
            TestRuntime.AssertNotDevice("https://github.com/mono/linker/issues/2266");
#endif
            string   input = @"
				<?xml version=""1.0"" encoding=""UTF-8""?>
				<Response>
				    <DataUpdates>
				        <DataUpdateInfo DataDate=""2009-04-13T00:00:00"" DataType=""Data"" LastUpdatedDate=""2010-12-12T02:53:19.257"" />
				        <DataUpdateInfo DataDate=""2009-04-14T00:00:00"" DataType=""Data"" LastUpdatedDate=""2010-12-12T02:53:19.257"" />
				        <DataUpdateInfo DataDate=""2009-04-15T00:00:00"" DataType=""Data"" LastUpdatedDate=""2010-12-12T01:52:51.047"" />
				    </DataUpdates>
				</Response>
				"                .Trim();
            Response r     = Response.Deserialize(input);
            Assert.That(r.DataUpdates.DataUpdateInfo.Count, Is.EqualTo(3), "Count");
            Assert.That(r.DataUpdates.DataUpdateInfo [0].DataDate.Day, Is.EqualTo(13), "0");
            Assert.That(r.DataUpdates.DataUpdateInfo [1].DataDate.Day, Is.EqualTo(14), "1");
            Assert.That(r.DataUpdates.DataUpdateInfo [2].DataDate.Day, Is.EqualTo(15), "2");
        }
Esempio n. 8
0
        public void Bug2096_Aot()
        {
            var a = new A();

            a.OuterMethod <int> (1);
            a.OuterMethod <DateTime> (DateTime.Now);
            // works with 5.0.2 (5.1)

            var v = new VT();

            a.OuterMethod <VT> (v);
            // works with 5.0.2 (5.1)

            var x = new D();

            a.OuterMethod <D> (x);
#if !__MACOS__
            // fails with 5.0.2 (5.1) when running on devices with
            // Attempting to JIT compile method 'A:InnerMethod<D, long> (D,long)' while running with --aot-only.
            TestRuntime.AssertNotDevice("only fails on devices");
#endif
        }
        public void PresentFromRect_BadView()
        {
            if (UIDevice.CurrentDevice.UserInterfaceIdiom != UIUserInterfaceIdiom.Pad)
            {
                Assert.Inconclusive("Requires iPad");
            }

            TestRuntime.AssertNotDevice("ObjectiveC exception crash on devices - bug #3980");

            using (var vc = new UIViewController())
                using (var bbi = new UIBarButtonItem(UIBarButtonSystemItem.Action))
                    using (var pc = new UIPopoverController(vc)) {
                        // 'vc' has never been shown
#if NET
                        Assert.Throws <ObjCException> (() => pc.PresentFromRect(new CGRect(10, 10, 100, 100), vc.View, UIPopoverArrowDirection.Down, true));
#else
                        Assert.Throws <MonoTouchException> (() => pc.PresentFromRect(new CGRect(10, 10, 100, 100), vc.View, UIPopoverArrowDirection.Down, true));
#endif
                        // fails with:
                        // Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.
                    }
        }
Esempio n. 10
0
        public void GetInstrumentInfo_DLS_SimOnly()
        {
            TestRuntime.AssertSystemVersion(ApplePlatform.iOS, 7, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertNotDevice("Use local file system (need a smaller sample)");

            using (NSUrl url = new NSUrl(local_dls)) {
                var info = SoundBank.GetInstrumentInfo(url);
                Assert.That(info.Length, Is.EqualTo(235), "Length");

                var first = info [0];
                Assert.That(first.Dictionary.Count, Is.EqualTo((nuint)4), "first.Count");
                Assert.That(first.Name, Is.EqualTo("Piano 1     "), "first.name");
                Assert.That(first.MSB, Is.EqualTo(121), "first.MSB");
                Assert.That(first.LSB, Is.EqualTo(0), "first.LSB");
                Assert.That(first.Program, Is.EqualTo(0), "first.program");

                var last = info [234].Dictionary;
                Assert.That(last.Count, Is.EqualTo((nuint)4), "last.Count");
                Assert.That(last [InstrumentInfo.NameKey].ToString(), Is.EqualTo("SFX         "), "last.Name");
                Assert.That((last [InstrumentInfo.MSBKey] as NSNumber).Int32Value, Is.EqualTo(120), "last.MSB");
                Assert.That((last [InstrumentInfo.LSBKey] as NSNumber).Int32Value, Is.EqualTo(0), "last.LSB");
                Assert.That((last [InstrumentInfo.ProgramKey] as NSNumber).Int32Value, Is.EqualTo(56), "last.Program");
            }
        }
Esempio n. 11
0
        public void ManagedExceptionPassthrough()
        {
            Exception thrownException = null;

#if !__WATCHOS__ && !__MACOS__
            TestRuntime.AssertNotDevice("This test requires wrapper functions, which are not enabled for monotouch-test on device.");
#endif

#if !DEBUG && !__WATCHOS__
            Assert.Ignore("This test only works in debug mode in the simulator.");
#endif
            var hasDebugger = global::System.Diagnostics.Debugger.IsAttached;

            InstallHandlers();
            try {
                using (var e = new ManagedExceptionTest()) {
                    try {
                        objcTargetMode    = MarshalObjectiveCExceptionMode.ThrowManagedException;
                        managedTargetMode = MarshalManagedExceptionMode.ThrowObjectiveCException;
                        e.InvokeManagedExceptionThrower();
                        Assert.Fail("no exception thrown 1");
                    } catch (Exception ex) {
                        thrownException = ex;
                    }
                    Assert.AreSame(e.Exception, thrownException, "exception");
                    Assert.That(thrownException.Message, Does.StartWith("3,14"), "1 thrown message");
                    Assert.AreSame(typeof(ApplicationException), thrownException.GetType(), "1 thrown type");
                    if (hasDebugger)
                    {
                        Assert.AreEqual(0, objcEventArgs.Count, "1 objc exception");
                    }
                    else
                    {
                        Assert.AreEqual(1, objcEventArgs.Count, "1 objc exception");
                        Assert.AreEqual(defaultObjectiveCExceptionMode, objcEventArgs [0].ExceptionMode, "1 objc mode");
                        Assert.AreEqual("System.ApplicationException", objcEventArgs [0].Exception.Name, "1 objc reason");
                        Assert.That(objcEventArgs [0].Exception.Reason, Does.StartWith("3,14"), "1 objc message");
                    }
                    if (hasDebugger)
                    {
                        Assert.AreEqual(0, managedEventArgs.Count, "1 managed count");
                    }
                    else
                    {
                        Assert.AreEqual(1, managedEventArgs.Count, "1 managed count");
                        Assert.AreEqual(defaultManagedExceptionMode, managedEventArgs [0].ExceptionMode, "1 managed mode");
                        Assert.AreSame(thrownException, managedEventArgs [0].Exception, "1 managed exception");
                    }

                    ClearExceptionData();
                    try {
                        objcTargetMode    = MarshalObjectiveCExceptionMode.ThrowManagedException;
                        managedTargetMode = MarshalManagedExceptionMode.ThrowObjectiveCException;
                        e.InvokeManagedExceptionThrowerAndRethrow();
                        Assert.Fail("no exception thrown 2");
                    } catch (Exception ex) {
                        thrownException = ex;
                    }
                    if (hasDebugger)
                    {
                        Assert.AreSame(e.Exception, thrownException, "exception");
                    }
                    else
                    {
                        Assert.AreNotSame(e.Exception, thrownException, "exception");
                        Assert.AreSame(typeof(ObjCException), thrownException.GetType(), "2 thrown type");
                        Assert.AreEqual("Caught exception", ((ObjCException)thrownException).Name, "2 thrown name");
                        Assert.That(((ObjCException)thrownException).Reason, Does.StartWith("exception was rethrown"), "2 thrown reason");
                    }
                    if (hasDebugger)
                    {
                        Assert.AreEqual(0, objcEventArgs.Count, "2 objc exception");
                    }
                    else
                    {
                        Assert.AreEqual(1, objcEventArgs.Count, "2 objc exception");
                        Assert.AreEqual(defaultObjectiveCExceptionMode, objcEventArgs [0].ExceptionMode, "2 objc mode");
                        Assert.AreEqual("Caught exception", objcEventArgs [0].Exception.Name, "2 objc reason");
                        Assert.That(objcEventArgs [0].Exception.Reason, Does.StartWith("exception was rethrown"), "2 objc message");
                    }
                    if (hasDebugger)
                    {
                        Assert.AreEqual(0, managedEventArgs.Count, "2 managed count");
                    }
                    else
                    {
                        Assert.AreEqual(1, managedEventArgs.Count, "2 managed count");
                        Assert.AreEqual(defaultManagedExceptionMode, managedEventArgs [0].ExceptionMode, "2 managed mode");
                        Assert.AreSame(e.Exception, managedEventArgs [0].Exception, "2 managed exception");
                    }

                    ClearExceptionData();
                    if (!hasDebugger)
                    {
                        objcTargetMode    = MarshalObjectiveCExceptionMode.ThrowManagedException;
                        managedTargetMode = MarshalManagedExceptionMode.ThrowObjectiveCException;
                        e.InvokeManagedExceptionThrowerAndCatch();                          // no exception.
                        Assert.AreEqual(0, objcEventArgs.Count, "3 objc exception");
                        Assert.AreEqual(1, managedEventArgs.Count, "3 managed count");
                        Assert.AreEqual(defaultManagedExceptionMode, managedEventArgs [0].ExceptionMode, "3 managed mode");
                        Assert.AreSame(e.Exception, managedEventArgs [0].Exception, "3 managed exception");
                    }
                }
            } finally {
                UninstallHandlers();
            }
        }