public void DefaultCtor()
 {
     using (var stpf = new UISimpleTextPrintFormatter()) {
         Assert.That(stpf.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
         if (TestRuntime.CheckXcodeVersion(11, 0))
         {
             Assert.NotNull(stpf.Color, "Color");
             Assert.Null(stpf.Font, "Font");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Natural), "TextAlignment");
         }
         else if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false))
         {
             Assert.Null(stpf.Color, "Color");
             Assert.Null(stpf.Font, "Font");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Natural), "TextAlignment");
         }
         else
         {
             Assert.That(stpf.Color, Is.EqualTo(UIColor.Black), "Color");
             Assert.NotNull(stpf.Font, "Font");
             Assert.That(stpf.TextAlignment, Is.EqualTo(UITextAlignment.Left), "TextAlignment");
         }
         Assert.That(stpf.Text, Is.Empty, "Text");
     }
 }
Beispiel #2
0
        void Trust_Leaf_Only(SecTrust trust, SecPolicy policy)
        {
            Assert.That(CFGetRetainCount(trust.Handle), Is.EqualTo((nint)1), "RetainCount(trust)");
            Assert.That(CFGetRetainCount(policy.Handle), Is.EqualTo((nint)2), "RetainCount(policy)");
            // that certificate stopped being valid on September 30th, 2013 so we validate it with a date earlier than that
            trust.SetVerifyDate(new DateTime(635108745218945450, DateTimeKind.Utc));
            // the system was able to construct the chain based on the single certificate
            var expectedTrust = SecTrustResult.RecoverableTrustFailure;

#if __MACOS__
            if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 9))
            {
                expectedTrust = SecTrustResult.Unspecified;
            }
#endif
            Assert.That(Evaluate(trust, true), Is.EqualTo(expectedTrust), "Evaluate");

#if __MACOS__
            var hasNetworkFetchAllowed = TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 9);
#else
            var hasNetworkFetchAllowed = TestRuntime.CheckXcodeVersion(5, 0);
#endif
            if (hasNetworkFetchAllowed)
            {
                Assert.True(trust.NetworkFetchAllowed, "NetworkFetchAllowed-1");
                trust.NetworkFetchAllowed = false;
                Assert.False(trust.NetworkFetchAllowed, "NetworkFetchAllowed-2");

                trust.SetPolicy(policy);

                var policies = trust.GetPolicies();
                Assert.That(policies.Length, Is.EqualTo(1), "Policies.Length");
                Assert.That(policies [0].Handle, Is.EqualTo(policy.Handle), "Handle");
            }
        }
        public void CompareConstantEnum()
        {
            Compare(AVMediaType.Audio, AVMediaTypes.Audio);
            Compare(AVMediaType.ClosedCaption, AVMediaTypes.ClosedCaption);
            Compare(AVMediaType.Metadata, AVMediaTypes.Metadata);
            Compare(AVMediaType.Muxed, AVMediaTypes.Muxed);
            Compare(AVMediaType.Subtitle, AVMediaTypes.Subtitle);
            Compare(AVMediaType.Text, AVMediaTypes.Text);
            Compare(AVMediaType.Timecode, AVMediaTypes.Timecode);
            Compare(AVMediaType.Video, AVMediaTypes.Video);

            if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 9, 0))
            {
                Compare(AVMediaType.MetadataObject, AVMediaTypes.MetadataObject);
            }

            // obsoleted in iOS 6, removed in iOS12
            if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 12, 0))
            {
                Assert.Null(AVMediaType.TimedMetadata, "AVMediaTypeTimedMetadata");
            }
            else
            {
                Compare(AVMediaType.TimedMetadata, AVMediaTypes.TimedMetadata);
            }
        }
Beispiel #4
0
        public void DatagramDefaults()
        {
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 8, throwIfOtherPlatform: false);

#if __MACOS__
            nint dsize = TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 10) ? 1327 : 1387;
#else
            nint dsize = TestRuntime.CheckXcodeVersion(6, 0) ? 1327 : 1387;
#endif
            using (var ssl = new SslContext(SslProtocolSide.Client, SslConnectionType.Datagram)) {
                Assert.That(ssl.BufferedReadSize, Is.EqualTo((nint)0), "BufferedReadSize");
                Assert.Null(ssl.Connection, "Connection");
                Assert.That(ssl.DatagramWriteSize, Is.EqualTo(dsize), "DatagramWriteSize");
                Assert.That(ssl.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
                Assert.That(ssl.MaxDatagramRecordSize, Is.EqualTo((nint)1400), "MaxDatagramRecordSize");
                Assert.That(ssl.MaxProtocol, Is.EqualTo(SslProtocol.Dtls_1_0), "MaxProtocol");
                Assert.That(ssl.MinProtocol, Is.EqualTo(SslProtocol.Dtls_1_0), "MinProtocol");
                Assert.That(ssl.NegotiatedCipher, Is.EqualTo(SslCipherSuite.SSL_NULL_WITH_NULL_NULL), "NegotiatedCipher");
                Assert.That(ssl.NegotiatedProtocol, Is.EqualTo(SslProtocol.Unknown), "NegotiatedProtocol");
                Assert.Null(ssl.PeerId, "PeerId");
                Assert.That(ssl.SessionState, Is.EqualTo(SslSessionState.Idle), "SessionState");

                ssl.PeerId = new byte [] { 0xff };
                Assert.That(ssl.PeerId.Length, Is.EqualTo(1), "1");
                // note: SSLSetPeerID (see Apple open source code) does not accept a null/zero-length value
                ssl.PeerId = null;
                Assert.That((int)ssl.GetLastStatus(), Is.EqualTo(errSecParam), "set_PeerId/null");

                Assert.That((int)ssl.SetDatagramHelloCookie(new byte [33]), Is.EqualTo(-50), "cookie to long");
                Assert.That(ssl.SetDatagramHelloCookie(new byte [32]), Is.EqualTo(SslStatus.Success), "tasty cookie");;
                Assert.That(ssl.SetDatagramHelloCookie(new byte [1]), Is.EqualTo(SslStatus.Success), "fat free cookie");
                Assert.That(ssl.SetDatagramHelloCookie(null), Is.EqualTo(SslStatus.Success), "no more cookies");
            }
        }
        public void GetAllCalendarIdentifiers()
        {
            RequiresIos8();

            foreach (NSCalendarType t in Enum.GetValues(typeof(NSCalendarType)))
            {
                switch (t)
                {
                case NSCalendarType.IslamicTabular:
                case NSCalendarType.IslamicUmmAlQura:
#if __MACOS__
                    if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 10))
                    {
                        continue;
                    }
#else
                    if (!TestRuntime.CheckXcodeVersion(6, 0))
                    {
                        continue;
                    }
#endif
                    break;
                }
                NSCalendar c = new NSCalendar(t);
                Assert.IsNotNull(c.Identifier, "Can't find identifier: " + t.ToString());
            }
        }
        public void Defaults()
        {
            using (var obj = new AVCaptureMetadataOutput()) {
#if XAMCORE_2_0
                Assert.AreEqual(AVMetadataObjectType.None, obj.AvailableMetadataObjectTypes, "AvailableMetadataObjectTypes");
                Assert.AreEqual(AVMetadataObjectType.None, obj.MetadataObjectTypes, "MetadataObjectTypes");

                Assert.IsNotNull(obj.WeakAvailableMetadataObjectTypes, "WeakAvailableMetadataObjectTypes");
                Assert.AreEqual(0, obj.WeakAvailableMetadataObjectTypes.Length, "WeakAvailableMetadataObjectTypes#");
                Assert.IsNotNull(obj.WeakMetadataObjectTypes, "WeakMetadataObjectTypes");
                Assert.AreEqual(0, obj.WeakMetadataObjectTypes.Length, "WeakMetadataObjectTypes#");
#else
                Assert.IsNotNull(obj.AvailableMetadataObjectTypes, "AvailableMetadataObjectTypes");
                Assert.AreEqual(0, obj.AvailableMetadataObjectTypes.Length, "AvailableMetadataObjectTypes#");
                Assert.IsNotNull(obj.MetadataObjectTypes, "MetadataObjectTypes");
                Assert.AreEqual(0, obj.MetadataObjectTypes.Length, "MetadataObjectTypes#");
#endif
                if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false))
                {
                    Assert.AreEqual(new RectangleF(0, 0, 1, 1), obj.RectOfInterest, "RectOfInterest");
                }

#if XAMCORE_2_0
                obj.WeakMetadataObjectTypes = null;
                Assert.AreEqual(AVMetadataObjectType.None, obj.MetadataObjectTypes, "MetadataObjectTypes");
                obj.MetadataObjectTypes = AVMetadataObjectType.None;
                Assert.AreEqual(AVMetadataObjectType.None, obj.MetadataObjectTypes, "MetadataObjectTypes");
#else
                obj.MetadataObjectTypes = null;
                Assert.IsNotNull(obj.MetadataObjectTypes, "MetadataObjectTypes");
                Assert.AreEqual(0, obj.MetadataObjectTypes.Length, "MetadataObjectTypes#");
#endif
                obj.SetDelegate(null, null);
            }
        }
        public void Ctor_Annotation()
        {
            using (var a = new MKPolyline())
                using (MKPinAnnotationView av = new MKPinAnnotationView(a, "reuse")) {
                    Assert.AreSame(a, av.Annotation, "Annotation");

#if !MONOMAC
                    if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0))              // Crashes with EXC_BAD_ACCESS (SIGABRT) if < iOS 7.0
                    {
                        Assert.False(av.AnimatesDrop, "AnimatesDrop");
                    }

                    if (!TestRuntime.CheckSystemVersion(PlatformName.iOS, 9, 0))
                    {
                        return;
                    }
#endif

                    Assert.That(av.PinColor, Is.EqualTo(MKPinAnnotationColor.Red), "PinColor");

                    if (TestRuntime.CheckXcodeVersion(7, 0))
                    {
                        Assert.NotNull(av.PinTintColor, "PinTintColor");
                    }
                }
        }
Beispiel #8
0
        public void NullAllowed()
        {
            using (var b = new UIButton()) {
                b.SetTitle(null, UIControlState.Normal);
                Assert.IsNull(b.Title(UIControlState.Normal), "title");

                b.SetTitleColor(null, UIControlState.Normal);
                var hasTitleColor = true;
#if __IOS__
                if (!TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 7, 0))
                {
                    hasTitleColor = false;
                }
#endif
                if (hasTitleColor)
                {
                    Assert.That(b.TitleColor(UIControlState.Normal), Is.EqualTo(UIColor.White), "titlecolor");
                }
                else
                {
                    Assert.IsNull(b.TitleColor(UIControlState.Normal), "titlecolor");
                }

                b.SetTitleShadowColor(null, UIControlState.Normal);
                Assert.IsNull(b.TitleShadowColor(UIControlState.Normal), "titleshadowcolor");
            }
        }
Beispiel #9
0
        public void Ctor_String()
        {
            // Apple deprecated `initWithCategory:` for `initWithLeaderboardIdentifier:` which  *seems* to do the
            // same thing, only with new names - but we need to be sure since 7.0 will map the .ctor(string) API
            // to the new selector
            using (var s = new GKScore("category-or-identifier")) {
#if !__TVOS__
                Assert.That(s.Category, Is.EqualTo("category-or-identifier"), "Category");
#endif
                Assert.That(s.Context, Is.EqualTo(0), "Context");
                Assert.NotNull(s.Date, "Date");
                Assert.Null(s.FormattedValue, "FormattedValue");

                // this is a new API in iOS8 (it was private before that) and returned an empty instance like:
                // "<<GKPlayer: 0x81254e60>(playerID:(null) alias:(null) name:(null) status:(null))>"
                if (TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 8, 0, throwIfOtherPlatform: false))
                {
                    Assert.Null(s.Player, "Player");
                }

                if (TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 7, 0, throwIfOtherPlatform: false))
                {
                    Assert.That(s.LeaderboardIdentifier, Is.EqualTo("category-or-identifier"), "LeaderboardIdentifier");
                }

                Assert.That(s.RetainCount, Is.EqualTo((nuint)1), "RetainCount");
            }
        }
Beispiel #10
0
        public void GetGlobalQueue_Priority()
        {
            string qdefault, qlow, qhigh;
            var    newDefaults = false;

#if __IOS__
            if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 8, 0))
            {
                newDefaults = true;
            }
#elif __WATCHOS__ || __TVOS__
            newDefaults = true;
#elif __MACOS__
            if (TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 10))
            {
                newDefaults = true;
            }
#endif
            if (newDefaults)
            {
                qdefault = "com.apple.root.default-qos";
                qlow     = "com.apple.root.utility-qos";
                qhigh    = "com.apple.root.user-initiated-qos";
            }
            else
            {
                qdefault = "com.apple.root.default-priority";
                qlow     = "com.apple.root.low-priority";
                qhigh    = "com.apple.root.high-priority";
            }
            Assert.That(DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Default).Label, Is.EqualTo(qdefault), "Default");
            Assert.That(DispatchQueue.GetGlobalQueue(DispatchQueuePriority.Low).Label, Is.EqualTo(qlow), "Low");
            Assert.That(DispatchQueue.GetGlobalQueue(DispatchQueuePriority.High).Label, Is.EqualTo(qhigh), "High");
        }
Beispiel #11
0
        public void AreaHistogram()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 8, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 10, throwIfOtherPlatform: false);

            // validate that a null NSDictionary is correct (i.e. uses filter defaults)
            using (var h = CIImage.EmptyImage.CreateByFiltering("CIAreaHistogram", null)) {
                // broken on simulator/64 bits on iOS9 beta 2 - radar 21564256 -> fixed in beta 4
                var success = true;
#if __MACOS__
                if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 11))
                {
                    success = false;
                }
#endif
                if (success)
                {
                    Assert.That(h.Extent.Height, Is.EqualTo((nfloat)1), "Height");
                }
                else
                {
                    Assert.IsNull(h, "Image");
                }
            }
        }
        public void CompareConstantEnum()
        {
            TestRuntime.RequestCameraPermission(AVMediaType.Audio, true);
            TestRuntime.RequestCameraPermission(AVMediaType.Video, true);

            Compare(AVMediaType.Audio, AVMediaTypes.Audio);
            Compare(AVMediaType.ClosedCaption, AVMediaTypes.ClosedCaption);
            Compare(AVMediaType.Metadata, AVMediaTypes.Metadata);
            Compare(AVMediaType.Muxed, AVMediaTypes.Muxed);
            Compare(AVMediaType.Subtitle, AVMediaTypes.Subtitle);
            Compare(AVMediaType.Text, AVMediaTypes.Text);
            Compare(AVMediaType.Timecode, AVMediaTypes.Timecode);
            Compare(AVMediaType.Video, AVMediaTypes.Video);

            if (TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 9, 0))
            {
                Compare(AVMediaType.MetadataObject, AVMediaTypes.MetadataObject);
            }

            // obsoleted in iOS 6, removed in iOS12
#if !__MACCATALYST__
            if (TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 12, 0))
            {
                Assert.Null(AVMediaType.TimedMetadata, "AVMediaTypeTimedMetadata");
            }
            else
            {
                Compare(AVMediaType.TimedMetadata, AVMediaTypes.TimedMetadata);
            }
#endif
        }
Beispiel #13
0
        public void EncryptTooLarge()
        {
            SecKey private_key;
            SecKey public_key;

            using (var record = new SecRecord(SecKind.Key)) {
                record.KeyType       = SecKeyType.RSA;
                record.KeySizeInBits = MinRsaKeySize;                 // it's not a performance test :)

                Assert.That(SecKey.GenerateKeyPair(record.ToDictionary(), out public_key, out private_key), Is.EqualTo(SecStatusCode.Success), "GenerateKeyPair");

                byte [] plain = new byte [MinRsaKeySize / 8];
                byte [] cipher;
                var     rv             = public_key.Encrypt(SecPadding.PKCS1, plain, out cipher);
                var     expectedStatus = SecStatusCode.Param;
#if __MACOS__
                if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 8))
                {
                    expectedStatus = SecStatusCode.Success;
                }
                else if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 12))
                {
                    expectedStatus = SecStatusCode.OutputLengthError;
                }
#endif
                Assert.That(rv, Is.EqualTo(expectedStatus), "Encrypt");

                public_key.Dispose();
                private_key.Dispose();
            }
        }
        public void Defaults()
        {
            using (QLPreviewController pc = new QLPreviewController()) {
                Assert.Null(pc.CurrentPreviewItem, "CurrentPreviewItem");
                nint index = 0;
                if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 10, 0))
                {
                    index = nint.MaxValue;
                }
                else if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 1))
                {
                    index = -1;
                }
                Assert.That(pc.CurrentPreviewItemIndex, Is.EqualTo(index), "CurrentPreviewItemIndex");

                Assert.Null(pc.Delegate, "Delegate");
                Assert.Null(pc.WeakDelegate, "WeakDelegate");

                Assert.Null(pc.DataSource, "DataSource");
                Assert.Null(pc.WeakDataSource, "WeakDataSource");

                pc.RefreshCurrentPreviewItem();
                pc.ReloadData();
            }
        }
Beispiel #15
0
        public void Atlas_MissingResource()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.TvOS, 9, 0, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 9, throwIfOtherPlatform: false);
            TestRuntime.AssertSystemVersion(PlatformName.WatchOS, 3, 0, throwIfOtherPlatform: false);

            using (var atlas = new SKTextureAtlas()) {
                // that returns a texture, calling 'MissingResource.png' (128 x 128)
                using (var texture = atlas.TextureNamed("ship")) {
                    // this completionHandler is *NOT* optional -> crash if null
                    SKTexture.PreloadTextures(new [] { texture }, CrashAvoider);

                    // this completionHandler is *NOT* optional -> crash if null
                    texture.Preload(CrashAvoider);

                    Assert.That(texture.FilteringMode, Is.EqualTo(SKTextureFilteringMode.Linear), "FilteringMode");

#if !MONOMAC
                    // FIXME: bug in iOS9 - it will randomly return 0,0 (but almost always on the first try)
                    if (!TestRuntime.CheckSystemVersion(PlatformName.iOS, 9, 0, throwIfOtherPlatform: false))
                    {
                        Assert.That(texture.Size, Is.EqualTo(new CGSize(128, 128)), "Size");
                    }
#endif

                    Assert.That(texture.TextureRect, Is.EqualTo(new CGRect(0, 0, 1, 1)), "TextureRect");
                    Assert.False(texture.UsesMipmaps, "UsesMipmaps");
                }
            }
        }
        public void TintColor()
        {
            using (UITabBar tb = new UITabBar()) {
                // TintColor is inherited in iOS7 so it won't be null by default
                if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false))
                {
                    Assert.NotNull(tb.TintColor, "1");
                }
                else
                {
                    Assert.Null(tb.TintColor, "1");
                }

                tb.TintColor = UIColor.White;
                Assert.That(tb.TintColor, Is.EqualTo(UIColor.White), "2");

                tb.TintColor = null;
                if (TestRuntime.IsTVOS)
                {
                    // we only care that setting `null` gives us back some default OS value
                    Assert.NotNull(tb.TintColor, "3");
                }
                else if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false))
                {
                    Assert.That(tb.TintColor, Is.Not.EqualTo(UIColor.White), "3");
                }
                else
                {
                    Assert.Null(tb.TintColor, "3");
                }
            }
        }
Beispiel #17
0
            public override void StartLoading()
            {
#if MONOMAC
                if (TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 10))
                {
                    if (State == 3)
                    {
                        State++;
                    }
                }
                else
                {
                    // looks like 10.9 is not calling `initWithRequest:cachedResponse:client:`
                    if (State >= 2)
                    {
                        State = 4;
                    }
                }
#else
                if (State == 3)
                {
                    State++;
                }
#endif

                string file = Path.Combine(NSBundle.MainBundle.ResourcePath, "basn3p08.png");

                using (var d = NSData.FromFile(file))
                    using (var response = new NSUrlResponse(Request.Url, "image/png", (nint)d.Length, null)) {
                        Client.ReceivedResponse(this, response, NSUrlCacheStoragePolicy.NotAllowed);
                        Client.DataLoaded(this, d);
                        Client.FinishedLoading(this);
                    }
            }
Beispiel #18
0
        public void CreateWellKnownPolicies()
        {
            TestRuntime.AssertXcodeVersion(5, 0);
            TestRuntime.AssertSystemVersion(PlatformName.MacOSX, 10, 9, throwIfOtherPlatform: false);

            CreatePolicy(SecPolicyIdentifier.AppleX509Basic);
            CreatePolicy(SecPolicyIdentifier.AppleSSL);
            CreatePolicy(SecPolicyIdentifier.AppleSMIME);
            // crash
            // CreatePolicy (SecPolicyIdentifier.AppleEAP);
            CreatePolicy(SecPolicyIdentifier.AppleIPsec);
            CreatePolicy(SecPolicyIdentifier.AppleCodeSigning);
            var oid = TestRuntime.CheckXcodeVersion(8, 0) ? "1.2.840.113635.100.1.61" : null;

            CreatePolicy(SecPolicyIdentifier.AppleIDValidation, (NSString)oid);
            // invalid handle ? not yet supported ?!?
            // CreatePolicy (SecPolicyIdentifier.AppleTimeStamping);
            oid = null;
#if __MACOS__
            if (TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 11) && !TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 12))
            {
                oid = "3";
            }
#endif
            CreatePolicy(SecPolicyIdentifier.AppleRevocation, (NSString)oid);
        }
Beispiel #19
0
        bool Skip(Type t)
        {
            switch (t.Name)
            {
            case "IKPictureTaker":             // radar://29311598
            case "AVAssetResourceLoader":
            case "AVAssetResourceLoadingRequest":
            case "AVAssetResourceLoadingContentInformationRequest":
            case "SCNRenderer":
            case "NSStream":
            case "NSSharingServicePicker":
            case "NSCache":
            case "NSToolbar":
            case "NSComboBox":
            case "NSComboBoxCell":
            case "IKScannerDeviceView":
            case "NSUserActivity":
            case "NSFontPanel":
            case "AVAudioRecorder":
            case "MKMapView":
            case "SKScene":
            case "NSSpeechRecognizer":
            case "NSClickGestureRecognizer":
            case "NSPopover":
                // These classes don't do well when you instance them without support
                return(true);

            case "SCNLayer":
            case "SCNProgram":
                if (Asserts.IsAtLeastElCapitan && IntPtr.Size == 4)
                {
                    return(true);
                }
                break;

            case "CBCentralManager":
                if (IntPtr.Size == 4 && PlatformHelper.CheckSystemVersion(10, 13))                 // Removed from 32-bit in macOS 10.13
                {
                    return(true);
                }
                break;

            case "QTMovie":
                return(TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 14, 4));                 // Broke in macOS 10.14.4.

            case "AVCaptureView":
                // Deallocating a AVCaptureView makes it trigger a permission dialog, which we don't want, so just skip this type.
                return(true);
            }

            switch (t.Namespace)
            {
            case "QTKit":
                return(TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 15));                 // QTKit is gone in 10.15.
            }

            return(false);
        }
Beispiel #20
0
        public void RoundtripRSA1024OAEP()
        {
            SecKey private_key;
            SecKey public_key;
            var    label = $"KeyTest.RoundtripRSA1024OAEP-{CFBundle.GetMain ().Identifier}-{GetType ().FullName}-{Process.GetCurrentProcess ().Id}";

            try {
                using (var record = new SecRecord(SecKind.Key)) {
                    record.KeyType       = SecKeyType.RSA;
                    record.KeySizeInBits = 1024;                     // it's not a performance test :)
                    record.Label         = label;

                    Assert.That(SecKey.GenerateKeyPair(record.ToDictionary(), out public_key, out private_key), Is.EqualTo(SecStatusCode.Success), "GenerateKeyPair");

                    byte [] plain = new byte [0];
                    byte [] cipher;
                    if (TestRuntime.CheckXcodeVersion(8, 0))
                    {
                        Assert.True(public_key.IsAlgorithmSupported(SecKeyOperationType.Encrypt, SecKeyAlgorithm.RsaEncryptionOaepSha1), "public/IsAlgorithmSupported/Encrypt");
                        // I would have expect false
#if MONOMAC
                        Assert.That(public_key.IsAlgorithmSupported(SecKeyOperationType.Decrypt, SecKeyAlgorithm.RsaEncryptionOaepSha1), Is.EqualTo(TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 13)), "public/IsAlgorithmSupported/Decrypt");
#else
                        Assert.True(public_key.IsAlgorithmSupported(SecKeyOperationType.Decrypt, SecKeyAlgorithm.RsaEncryptionOaepSha1), "public/IsAlgorithmSupported/Decrypt");
#endif
                    }
                    Assert.That(public_key.Encrypt(SecPadding.OAEP, plain, out cipher), Is.EqualTo(SecStatusCode.Success), "Encrypt");
                    public_key.Dispose();

                    byte[] result;
                    if (TestRuntime.CheckXcodeVersion(8, 0))
                    {
                        Assert.False(private_key.IsAlgorithmSupported(SecKeyOperationType.Encrypt, SecKeyAlgorithm.RsaEncryptionOaepSha1), "private/IsAlgorithmSupported/Encrypt");
                        Assert.True(private_key.IsAlgorithmSupported(SecKeyOperationType.Decrypt, SecKeyAlgorithm.RsaEncryptionOaepSha1), "private/IsAlgorithmSupported/Decrypt");
                    }
                    Assert.That(private_key.Decrypt(SecPadding.OAEP, cipher, out result), Is.EqualTo(SecStatusCode.Success), "Decrypt");
                    var expectEmpty = false;
#if __MACOS__
                    if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 12))
                    {
                        expectEmpty = true;
                    }
#endif
                    if (expectEmpty)
                    {
                        Assert.That(plain, Is.EqualTo(new byte [0]), "match (empty)");
                    }
                    else
                    {
                        Assert.That(plain, Is.EqualTo(result), "match");
                    }
                    private_key.Dispose();
                }
            } finally {
                // Clean up after us
                DeleteKeysWithLabel(label);
            }
        }
        public void GetAllSources()
        {
            TestRuntime.CheckAddressBookPermission();
            ABAddressBook ab      = new ABAddressBook();
            var           sources = ab.GetAllSources();
            int           value   = Runtime.Arch == Arch.DEVICE || TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false) ? 0 : 1;

            Assert.That(sources.Length, Is.GreaterThanOrEqualTo(value), "GetAllSources");
        }
Beispiel #22
0
        [Ignore("https://github.com/xamarin/maccore/issues/2348")]          // The native class doesn't exist
#endif

        public void InitWithTerm()
        {
            if (Runtime.Arch == Arch.DEVICE && TestRuntime.CheckSystemVersion(PlatformName.iOS, 9, 0))
            {
                Assert.Ignore("crash on iOS9 devices");
            }
            using (UIReferenceLibraryViewController rlvc = new UIReferenceLibraryViewController("Mono")) {
            }
        }
Beispiel #23
0
        public void SelectedAnnotations_BackingFields()
        {
            if (MapViewPoker.NewRefcountEnabled())
            {
                Assert.Inconclusive("backing fields are removed when newrefcount is enabled");
            }

#if !MONOMAC
            if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 7, 0))
            {
                // This test selects annotations on a map view, but according to apple's docs
                // and a lot of googling this will not necessarily work until the map view is
                // show. Since we can't relinquish control of the UI thread, we have no option
                // but ignoring this test. For now I've only seen it fail on iOS 7 DP4.
                Assert.Inconclusive("This test is not deterministic on iOS7 DP4.");
            }
#endif

            using (var a = new MKCircle())                      // MKAnnotation is abstract
#if XAMCORE_2_0
                using (var o1 = new MKPolygon())                // it must export 'coordinate' or this will fail
                    using (var o2 = new MKPolyline())
#else
                using (NSObject o1 = new MKPolygon())           // it must export 'coordinate' or this will fail
                    using (NSObject o2 = new MKPolyline())
#endif
                        using (var mv = new MapViewPoker()) {
                            Assert.Null(mv.SelectedAnnotationsBackingField, "1a");
                            Assert.Null(mv.SelectedAnnotations, "1b");      // not an empty array

                            mv.SelectAnnotation(a, false);
                            Assert.AreSame(a, mv.SelectedAnnotationsBackingField [0], "2a");
                            Assert.AreSame(a, mv.SelectedAnnotations [0], "2b");

                            // sanity
                            Assert.Null(mv.AnnotationsBackingField, "3a");
                            Assert.That(mv.Annotations, Is.Empty, "3b");

#if XAMCORE_2_0
                            mv.SelectedAnnotations = new IMKAnnotation[] { o1, o2 };
#else
                            mv.SelectedAnnotations = new NSObject[] { o1, o2 };
#endif
                            // note: when assigning the property only the first item is selected (by design)
                            // so we're not exactly backing up correctly (we still hold 'o2')
                            // OTOH we do not want to recursively [PostGet] the same property (unless handled by the generator)
                            Assert.That(mv.SelectedAnnotationsBackingField.Length, Is.EqualTo(2), "4a");
                            Assert.That(mv.SelectedAnnotations.Length, Is.EqualTo(1), "4b");

                            mv.DeselectAnnotation(o1, false);
                            // since only 'o1' was really selected, unselecting it will return null
                            Assert.Null(mv.SelectedAnnotationsBackingField, "5a");
                            Assert.Null(mv.SelectedAnnotations, "5b");      // not an empty array
                        }
        }
        public void SetUp()
        {
#if __WATCHOS__
            if (!TestRuntime.CheckSystemVersion(PlatformName.WatchOS, 3, 0))
            {
                Assert.Inconclusive("Requires watchOS 3.0+");
            }
#else
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 7, 0, throwIfOtherPlatform: false);
#endif
        }
        public void Copy()
        {
            var isMutableCopy = false;

#if __MACOS__
            if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 8))
            {
                isMutableCopy = true;
            }
#endif
            using (var k = new NSString("key"))
                using (var v = new NSString("value"))
                    using (var d = new NSMutableDictionary <NSString, NSString> (k, v)) {
                        // NSObject.Copy works because NSDictionary conforms to NSCopying
                        using (var copy1 = (NSDictionary)d.Copy()) {
                            Assert.AreNotSame(d, copy1, "1");
                            if (isMutableCopy)
                            {
                                Assert.That(copy1, Is.TypeOf <NSMutableDictionary> (), "NSDictionary-1");
                            }
                            else
                            {
                                Assert.That(copy1, Is.Not.TypeOf <NSMutableDictionary> (), "NSDictionary-1");
                            }
                            Assert.That(copy1.Count, Is.EqualTo((nuint)1), "Count-1");
                        }

                        using (var copy2 = (NSDictionary)d.Copy(null)) {
                            Assert.AreNotSame(d, copy2, "2");
                            if (isMutableCopy)
                            {
                                Assert.That(copy2, Is.TypeOf <NSMutableDictionary> (), "NSDictionary-2");
                            }
                            else
                            {
                                Assert.That(copy2, Is.Not.TypeOf <NSMutableDictionary> (), "NSDictionary-2");
                            }
                            Assert.That(copy2.Count, Is.EqualTo((nuint)1), "Count-2");
                        }

                        using (var copy3 = (NSDictionary)d.Copy(NSZone.Default)) {
                            Assert.AreNotSame(d, copy3, "3");
                            if (isMutableCopy)
                            {
                                Assert.That(copy3, Is.TypeOf <NSMutableDictionary> (), "NSDictionary-3");
                            }
                            else
                            {
                                Assert.That(copy3, Is.Not.TypeOf <NSMutableDictionary> (), "NSDictionary-3");
                            }
                            Assert.That(copy3.Count, Is.EqualTo((nuint)1), "Count-3");
                        }
                    }
        }
Beispiel #26
0
        [Ignore("https://github.com/xamarin/maccore/issues/2348")]          // The native class doesn't exist
#endif

        public void InitWithTerm()
        {
#if !__MACCATALYST__
            if (Runtime.Arch == Arch.DEVICE && TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 9, 0))
            {
                Assert.Ignore("crash on iOS9 devices");
            }
#endif
            using (UIReferenceLibraryViewController rlvc = new UIReferenceLibraryViewController("Mono")) {
            }
        }
Beispiel #27
0
 public void Ctor()
 {
     using (var l = new UICollectionViewLayout())
         // interesting ctor for the linker: a [PostSnippet] directly on the backing field is needed
         using (var c = new UICollectionViewController(l)) {
             // that's because Apple did not expose the init* argument as a property until 7.0
             if (TestRuntime.CheckSystemVersion(ApplePlatform.iOS, 7, 0, throwIfOtherPlatform: false))
             {
                 Assert.AreSame(l, c.Layout, "Layout");
             }
         }
 }
Beispiel #28
0
        public void PreparePrerollAds_New()
        {
            TestRuntime.AssertSystemVersion(PlatformName.iOS, 7, 0);

            // NSInvalidArgumentException +[MPMoviePlayerController preparePrerollAds]: unrecognized selector sent to class 0x109c46b48
            if (TestRuntime.CheckSystemVersion(PlatformName.iOS, 10, 0))
            {
                Assert.Ignore("Broken on iOS 10 beta 3");
            }

            MPMoviePlayerController.PrepareForPrerollAds();
        }
        bool CheckLibrary(string lib)
        {
#if MONOMAC
            // on macOS the file should exist on the specified path
            // for iOS the simulator paths do not match the strings
            switch (lib)
            {
            // location changed in 10.8 but it loads fine (and fixing it breaks on earlier macOS)
            case Constants.CFNetworkLibrary:
            // location changed in 10.10 but it loads fine (and fixing it breaks on earlier macOS)
            case Constants.CoreBluetoothLibrary:
            // location changed in 10.11 but it loads fine (and fixing it breaks on earlier macOS)
            case Constants.CoreImageLibrary:
                break;

            default:
                if (TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 11, 0))
                {
                    // on macOS 11.0 the frameworks binary files are not present (cache) but can be loaded
                    if (!Directory.Exists(Path.GetDirectoryName(lib)))
                    {
                        return(false);
                    }
                }
                else if (!File.Exists(lib))
                {
                    return(false);
                }
                break;
            }
#endif
            var h = IntPtr.Zero;
            try {
                h = Dlfcn.dlopen(lib, 0);
                if (h != IntPtr.Zero)
                {
                    return(true);
                }
#if MONOMAC
                // on macOS it might be wrong architecture
                // i.e. 64 bits only (thin) libraries running on 32 bits process
                if (IntPtr.Size == 4)
                {
                    return(true);
                }
#endif
            } finally {
                Dlfcn.dlclose(h);
            }
            return(false);
        }
        public void ChateauFrontenac()
        {
            using (NSMutableDictionary dict = new NSMutableDictionary()
            {
                { new NSString("Street"), new NSString("1–3 Rue Des Carrières") },
                { new NSString("SubAdministrativeArea"), new NSString("Québec") },
                { new NSString("Thoroughfare"), new NSString("Rue Des Carrières") },
                { new NSString("ZIP"), new NSString("G1R 5J5") },
                { new NSString("Name"), new NSString("1–3 Rue Des Carrières") },
                { new NSString("City"), new NSString("Quebec City") },
                { new NSString("State"), new NSString("Quebec") },
                { new NSString("SubLocality"), new NSString("Vieux-Quebec") },
                { new NSString("SubThoroughfare"), new NSString("1-3") },
                { new NSString("CountryCode"), new NSString("CA") },
            }) {
                string expected1 = "1–3 Rue Des Carrières\nQuebec City‎ Quebec‎ G1R 5J5";
                string expected2 = "1–3 Rue Des Carrières\nQuebec City Quebec G1R 5J5";                 // there's a "(char) 8206" character just after 'Quebec'
                string expected;
                string s = ABAddressFormatting.ToString(dict, false);
                if (TestRuntime.CheckXcodeVersion(9, 0))
                {
                    expected = expected2;
                }
                else
                {
                    expected = expected1;
                }
                Assert.That(s, Is.EqualTo(expected), "false");
                // country names can be translated, e.g. chinese, so we can't compare it
                s = ABAddressFormatting.ToString(dict, true);
                Assert.That(s, Does.StartWith(expected), "prefix");

                // Apple broke this again (8.0.x are hard to predict) - test will fail once it's corrected
                // iOS 8.1.2 device: working
                // iOS 8.0 (12A365) simulator (Xcode 6.0.1): working
                // iOS 8.1 (12B411) simulator (Xcode 6.1): broken
                // iOS 8.2 beta 5 (12D5480a) simulator (Xcode 6.2 beta 5): working

                // we don't check before 8.2 - where both device and simulators works again properly
                if (!TestRuntime.CheckSystemVersion(PlatformName.iOS, 8, 2))
                {
                    return;
                }

                // iOS 11.0 beta 1, 2, 3 and 4 are broken
                // and I give up (this test was not meant to track Apple breakages)
            }
        }