public void CreateMax()
        {
            TestRuntime.AssertXcodeVersion(7, 3);

            var first = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericRgb(),
                Intent    = CGColorRenderingIntent.Default,
                Transform = CGColorConverterTransformType.ApplySpace
            };
            var second = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericGray(),
                Intent    = CGColorRenderingIntent.Perceptual,
                Transform = CGColorConverterTransformType.FromSpace
            };
            var third = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericXyz(),
                Intent    = CGColorRenderingIntent.Saturation,
                Transform = CGColorConverterTransformType.ToSpace
            };

            using (var converter = new CGColorConverter(null, first, first, first)) {
                Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
            }
        }
        public void CreateDual()
        {
            TestRuntime.AssertXcodeVersion(7, 3);

            var triple = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericRgb(),
                Intent    = CGColorRenderingIntent.Default,
                Transform = CGColorConverterTransformType.ApplySpace
            };

            using (var converter = new CGColorConverter(null, triple, triple)) {
                Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
            }
        }
Example #3
0
        public void CreateDual()
        {
            if (!TestRuntime.CheckSystemAndSDKVersion(9, 3))
            {
                Assert.Ignore("requires iOS 9.3+");
            }

            var triple = new CGColorConverterTriple()
            {
                Space     = CGColorSpace.CreateGenericRgb(),
                Intent    = CGColorRenderingIntent.Default,
                Transform = CGColorConverterTransformType.ApplySpace
            };

            using (var converter = new CGColorConverter(null, triple, triple)) {
                Assert.That(converter.Handle, Is.Not.EqualTo(IntPtr.Zero), "Handle");
            }
        }
Example #4
0
        protected INativeObject GetINativeInstance(Type t)
        {
            var ctor = t.GetConstructor(Type.EmptyTypes);

            if ((ctor != null) && !ctor.IsAbstract)
            {
                return(ctor.Invoke(null) as INativeObject);
            }

            if (!NativeObjectInterfaceType.IsAssignableFrom(t))
            {
                throw new ArgumentException("t");
            }
            switch (t.Name)
            {
            case "CFAllocator":
                return(CFAllocator.SystemDefault);

            case "CFBundle":
                var bundles = CFBundle.GetAll();
                if (bundles.Length > 0)
                {
                    return(bundles [0]);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
                }

            case "CFNotificationCenter":
                return(CFNotificationCenter.Darwin);

            case "CFReadStream":
            case "CFStream":
                CFReadStream  readStream;
                CFWriteStream writeStream;
                CFStream.CreatePairWithSocketToHost("www.google.com", 80, out readStream, out writeStream);
                return(readStream);

            case "CFWriteStream":
                CFStream.CreatePairWithSocketToHost("www.google.com", 80, out readStream, out writeStream);
                return(writeStream);

            case "CFUrl":
                return(CFUrl.FromFile("/etc"));

            case "AudioFile":
                var path = Path.GetFullPath("1.caf");
                var af   = AudioFile.Open(CFUrl.FromFile(path), AudioFilePermission.Read, AudioFileType.CAF);
                return(af);

            case "CFHTTPMessage":
                return(CFHTTPMessage.CreateEmpty(false));

            case "CGBitmapContext":
                byte[] data = new byte [400];
                using (CGColorSpace space = CGColorSpace.CreateDeviceRGB()) {
                    return(new CGBitmapContext(data, 10, 10, 8, 40, space, CGBitmapFlags.PremultipliedLast));
                }

            case "CGContextPDF":
                var filename = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + "/t.pdf";
                using (var url = new NSUrl(filename))
                    return(new CGContextPDF(url));

            case "CGColorConverter":
                var cvt = new CGColorConverterTriple()
                {
                    Space     = CGColorSpace.CreateGenericRgb(),
                    Intent    = CGColorRenderingIntent.Default,
                    Transform = CGColorConverterTransformType.ApplySpace
                };
                return(new CGColorConverter(null, cvt, cvt, cvt));

            case "CGDataConsumer":
                using (NSMutableData destData = new NSMutableData()) {
                    return(new CGDataConsumer(destData));
                }

            case "CGDataProvider":
                filename = "xamarin1.png";
                return(new CGDataProvider(filename));

            case "CGFont":
                return(CGFont.CreateWithFontName("Courier New"));

            case "CGPattern":
                return(new CGPattern(
                           new RectangleF(0, 0, 16, 16),
                           CGAffineTransform.MakeIdentity(),
                           16, 16,
                           CGPatternTiling.NoDistortion,
                           true,
                           (cgc) => {}));

            case "CMBufferQueue":
                return(CMBufferQueue.CreateUnsorted(2));

            case "CTFont":
                CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes()
                {
                    FamilyName = "Courier",
                    StyleName  = "Bold",
                    Size       = 16.0f
                };
                using (var fd = new CTFontDescriptor(fda))
                    return(new CTFont(fd, 10, CTFontOptions.Default));

            case "CTFontCollection":
                return(new CTFontCollection(new CTFontCollectionOptions()));

            case "CTFontDescriptor":
                fda = new CTFontDescriptorAttributes();
                return(new CTFontDescriptor(fda));

            case "CTTextTab":
                return(new CTTextTab(CTTextAlignment.Left, 2));

            case "CTTypesetter":
                return(new CTTypesetter(new NSAttributedString("Hello, world",
                                                               new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("Arial", 24)
                })));

            case "CTFrame":
                var framesetter = new CTFramesetter(new NSAttributedString("Hello, world",
                                                                           new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("Arial", 24)
                }));
                var bPath = UIBezierPath.FromRect(new RectangleF(0, 0, 3, 3));
                return(framesetter.GetFrame(new NSRange(0, 0), bPath.CGPath, null));

            case "CTFramesetter":
                return(new CTFramesetter(new NSAttributedString("Hello, world",
                                                                new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("Arial", 24)
                })));

            case "CTGlyphInfo":
                return(new CTGlyphInfo("Zapfino", new CTFont("Arial", 24), "Foo"));

            case "CTLine":
                return(new CTLine(new NSAttributedString("Hello, world",
                                                         new CTStringAttributes()
                {
                    ForegroundColorFromContext = true,
                    Font = new CTFont("Arial", 24)
                })));

            case "CGImageDestination":
                var storage = new NSMutableData();
                return(CGImageDestination.Create(new CGDataConsumer(storage), "public.png", 1));

            case "CGImageMetadataTag":
                using (NSString name = new NSString("tagName"))
                    using (var value = new NSString("value"))
                        return(new CGImageMetadataTag(CGImageMetadataTagNamespaces.Exif, CGImageMetadataTagPrefixes.Exif, name, CGImageMetadataType.Default, value));

            case "CGImageSource":
                filename = "xamarin1.png";
                return(CGImageSource.FromUrl(NSUrl.FromFilename(filename)));

            case "SecPolicy":
                return(SecPolicy.CreateSslPolicy(false, null));

            case "SecIdentity":
                using (var options = NSDictionary.FromObjectAndKey(new NSString("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var            result = SecImportExport.ImportPkcs12(farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(string.Format("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    }
                    return(new SecIdentity(array [0].LowlevelObjectForKey(SecImportExport.Identity.Handle)));
                }

            case "SecTrust":
                X509Certificate x = new X509Certificate(mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy(true, "mail.google.com"))
                    return(new SecTrust(x, policy));

            case "SslContext":
                return(new SslContext(SslProtocolSide.Client, SslConnectionType.Stream));

            case "UIFontFeature":
                return(new UIFontFeature(CTFontFeatureNumberSpacing.Selector.ProportionalNumbers));

            case "NetworkReachability":
                return(new NetworkReachability(IPAddress.Loopback, null));

#if !__TVOS__
            case "VTCompressionSession":
            case "VTSession":
                return(VTCompressionSession.Create(1024, 768, CMVideoCodecType.H264, (sourceFrame, status, flags, buffer) => { }, null, (CVPixelBufferAttributes)null));

            case "VTFrameSilo":
                return(VTFrameSilo.Create());

            case "VTMultiPassStorage":
                return(VTMultiPassStorage.Create());
#endif
            case "CFString":
                return(new CFString("test"));

            case "DispatchQueue":
                return(new DispatchQueue("com.example.subsystem.taskXYZ"));

            case "DispatchGroup":
                return(DispatchGroup.Create());

            case "CGColorSpace":
                return(CGColorSpace.CreateAcesCGLinear());

            case "CGGradient":
                CGColor[] cArray = { UIColor.Black.CGColor, UIColor.Clear.CGColor, UIColor.Blue.CGColor };
                return(new CGGradient(null, cArray));

            case "CGImage":
                filename = "xamarin1.png";
                using (var dp = new CGDataProvider(filename))
                    return(CGImage.FromPNG(dp, null, false, CGColorRenderingIntent.Default));

            case "CGColor":
                return(UIColor.Black.CGColor);

            case "CMClock":
                CMClockError ce;
                CMClock      clock = CMClock.CreateAudioClock(out ce);
                if (ce == CMClockError.None)
                {
                    return(clock);
                }
                throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));

            case "CMTimebase":
                clock = CMClock.CreateAudioClock(out ce);
                if (ce == CMClockError.None)
                {
                    return(new CMTimebase(clock));
                }
                throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));

            case "CVPixelBufferPool":
                return(new CVPixelBufferPool(
                           new CVPixelBufferPoolSettings(),
                           new CVPixelBufferAttributes(CVPixelFormatType.CV24RGB, 100, 50)
                           ));

            case "SecCertificate":
                using (var cdata = NSData.FromArray(mail_google_com))
                    return(new SecCertificate(cdata));

            case "SecKey":
                SecKey private_key;
                SecKey public_key;
                using (var record = new SecRecord(SecKind.Key)) {
                    record.KeyType       = SecKeyType.RSA;
                    record.KeySizeInBits = 512;                     // it's not a performance test :)
                    SecKey.GenerateKeyPair(record.ToDictionary(), out public_key, out private_key);
                    return(private_key);
                }

            case "SecAccessControl":
                return(new SecAccessControl(SecAccessible.WhenPasscodeSetThisDeviceOnly));

            default:
                throw new InvalidOperationException(string.Format("Could not create the new instance for type {0}.", t.Name));
            }
        }
        protected INativeObject GetINativeInstance(Type t)
        {
            var ctor = t.GetConstructor (Type.EmptyTypes);
            if ((ctor != null) && !ctor.IsAbstract)
                return ctor.Invoke (null) as INativeObject;

            if (!NativeObjectInterfaceType.IsAssignableFrom (t))
                throw new ArgumentException ("t");
            switch (t.Name) {
            case "CFAllocator":
                return CFAllocator.SystemDefault;
            case "CFBundle":
                var bundles = CFBundle.GetAll ();
                if (bundles.Length > 0)
                    return bundles [0];
                else
                    throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0}.", t.Name));
            case "CFNotificationCenter":
                return CFNotificationCenter.Darwin;
            case "CFReadStream":
            case "CFStream":
                CFReadStream readStream;
                CFWriteStream writeStream;
                CFStream.CreatePairWithSocketToHost ("www.google.com", 80, out readStream, out writeStream);
                return readStream;
            case "CFWriteStream":
                CFStream.CreatePairWithSocketToHost ("www.google.com", 80, out readStream, out writeStream);
                return writeStream;
            case "CFUrl":
                return CFUrl.FromFile ("/etc");
            case "AudioFile":
                var path = Path.GetFullPath ("1.caf");
                var af = AudioFile.Open (CFUrl.FromFile (path), AudioFilePermission.Read, AudioFileType.CAF);
                return af;
            case "CFHTTPMessage":
                return CFHTTPMessage.CreateEmpty (false);
            case "CGBitmapContext":
                byte[] data = new byte [400];
                using (CGColorSpace space = CGColorSpace.CreateDeviceRGB ()) {
                    return new CGBitmapContext (data, 10, 10, 8, 40, space, CGBitmapFlags.PremultipliedLast);
                }
            case "CGContextPDF":
                var filename = Environment.GetFolderPath (Environment.SpecialFolder.CommonDocuments) + "/t.pdf";
                using (var url = new NSUrl (filename))
                    return new CGContextPDF (url);
            case "CGColorConverter":
                var cvt = new CGColorConverterTriple () {
                    Space = CGColorSpace.CreateGenericRgb (),
                    Intent = CGColorRenderingIntent.Default,
                    Transform = CGColorConverterTransformType.ApplySpace
                };
                return new CGColorConverter (null, cvt, cvt, cvt);
            case "CGDataConsumer":
                using (NSMutableData destData = new NSMutableData ()) {
                    return new CGDataConsumer (destData);
                }
            case "CGDataProvider":
                filename = "xamarin1.png";
                return new CGDataProvider (filename);
            case "CGFont":
                return CGFont.CreateWithFontName ("Courier New");
            case "CGPattern":
                return new CGPattern (
                    new RectangleF (0, 0, 16, 16),
                    CGAffineTransform.MakeIdentity (),
                    16, 16,
                    CGPatternTiling.NoDistortion,
                    true,
                    (cgc) => {});
            case "CMBufferQueue":
                return CMBufferQueue.CreateUnsorted (2);
            case "CTFont":
                CTFontDescriptorAttributes fda = new CTFontDescriptorAttributes () {
                    FamilyName = "Courier",
                    StyleName = "Bold",
                    Size = 16.0f
                };
                using (var fd = new CTFontDescriptor (fda))
                    return new CTFont (fd, 10, CTFontOptions.Default);
            case "CTFontCollection":
                return new CTFontCollection (new CTFontCollectionOptions ());
            case "CTFontDescriptor":
                fda = new CTFontDescriptorAttributes ();
                return new CTFontDescriptor (fda);
            case "CTTextTab":
                return new CTTextTab (CTTextAlignment.Left, 2);
            case "CTTypesetter":
                return new CTTypesetter (new NSAttributedString ("Hello, world",
                    new CTStringAttributes () {
                        ForegroundColorFromContext =  true,
                        Font = new CTFont ("Arial", 24)
                    }));
            case "CTFrame":
                var framesetter = new CTFramesetter (new NSAttributedString ("Hello, world",
                    new CTStringAttributes () {
                        ForegroundColorFromContext =  true,
                        Font = new CTFont ("Arial", 24)
                    }));
                var bPath = UIBezierPath.FromRect (new RectangleF (0, 0, 3, 3));
                return framesetter.GetFrame (new NSRange (0, 0), bPath.CGPath, null);
            case "CTFramesetter":
                return new CTFramesetter (new NSAttributedString ("Hello, world",
                    new CTStringAttributes () {
                        ForegroundColorFromContext =  true,
                        Font = new CTFont ("Arial", 24)
                    }));
            case "CTGlyphInfo":
                return new CTGlyphInfo ("Zapfino", new CTFont ("Arial", 24), "Foo");
            case "CTLine":
                return new CTLine (new NSAttributedString ("Hello, world",
                    new CTStringAttributes () {
                        ForegroundColorFromContext =  true,
                        Font = new CTFont ("Arial", 24)
                    }));
            case "CGImageDestination":
                var storage = new NSMutableData ();
                return CGImageDestination.Create (new CGDataConsumer (storage), "public.png", 1);
            case "CGImageMetadataTag":
                using (NSString name = new NSString ("tagName"))
                using (var value = new NSString ("value"))
                    return new CGImageMetadataTag (CGImageMetadataTagNamespaces.Exif, CGImageMetadataTagPrefixes.Exif, name, CGImageMetadataType.Default, value);
            case "CGImageSource":
                filename = "xamarin1.png";
                return CGImageSource.FromUrl (NSUrl.FromFilename (filename));
            case "SecPolicy":
                return SecPolicy.CreateSslPolicy (false, null);
            case "SecIdentity":
                using (var options = NSDictionary.FromObjectAndKey (new NSString ("farscape"), SecImportExport.Passphrase)) {
                    NSDictionary[] array;
                    var result = SecImportExport.ImportPkcs12 (farscape_pfx, options, out array);
                    if (result != SecStatusCode.Success)
                        throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0} due to {1}.", t.Name, result));
                    return new SecIdentity (array [0].LowlevelObjectForKey (SecImportExport.Identity.Handle));
                }
            case "SecTrust":
                X509Certificate x = new X509Certificate (mail_google_com);
                using (var policy = SecPolicy.CreateSslPolicy (true, "mail.google.com"))
                    return new SecTrust (x, policy);
            case "SslContext":
                return new SslContext (SslProtocolSide.Client, SslConnectionType.Stream);
            case "UIFontFeature":
                return new UIFontFeature (CTFontFeatureNumberSpacing.Selector.ProportionalNumbers);
            case "NetworkReachability":
                return new NetworkReachability (IPAddress.Loopback, null);
            #if !__TVOS__
            case "VTCompressionSession":
            case "VTSession":
                return VTCompressionSession.Create (1024, 768, CMVideoCodecType.H264, (sourceFrame, status, flags, buffer) => { }, null, (CVPixelBufferAttributes) null);
            case "VTFrameSilo":
                return VTFrameSilo.Create ();
            case "VTMultiPassStorage":
                return VTMultiPassStorage.Create ();
            #endif
            case "CFString":
                return new CFString ("test");
            case "DispatchQueue":
                return new DispatchQueue ("com.example.subsystem.taskXYZ");
            case "DispatchGroup":
                return DispatchGroup.Create ();
            case "CGColorSpace":
                return CGColorSpace.CreateAcesCGLinear ();
            case "CGGradient":
                CGColor[] cArray = { UIColor.Black.CGColor, UIColor.Clear.CGColor, UIColor.Blue.CGColor };
                return new CGGradient (null, cArray);
            case "CGImage":
                filename = "xamarin1.png";
                using (var dp = new CGDataProvider (filename))
                    return CGImage.FromPNG (dp, null, false, CGColorRenderingIntent.Default);
            case "CGColor":
                return UIColor.Black.CGColor;
            case "CMClock":
                CMClockError ce;
                CMClock clock = CMClock.CreateAudioClock (out ce);
                if (ce == CMClockError.None)
                    return clock;
                throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0}.", t.Name));
            case "CMTimebase":
                clock = CMClock.CreateAudioClock (out ce);
                if (ce == CMClockError.None) {
                    return new CMTimebase (clock);
                }
                throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0}.", t.Name));
            case "CVPixelBufferPool":
                return new CVPixelBufferPool (
                    new CVPixelBufferPoolSettings (),
                    new CVPixelBufferAttributes (CVPixelFormatType.CV24RGB, 100, 50)
                );
            case "SecCertificate":
                using (var cdata = NSData.FromArray (mail_google_com))
                    return new SecCertificate (cdata);
            case "SecKey":
                SecKey private_key;
                SecKey public_key;
                using (var record = new SecRecord (SecKind.Key)) {
                    record.KeyType = SecKeyType.RSA;
                    record.KeySizeInBits = 512; // it's not a performance test :)
                    SecKey.GenerateKeyPair (record.ToDictionary (), out public_key, out private_key);
                    return private_key;
                }
            case "SecAccessControl":
                return new SecAccessControl (SecAccessible.WhenPasscodeSetThisDeviceOnly);
            default:
                throw new InvalidOperationException (string.Format ("Could not create the new instance for type {0}.", t.Name));
            }
        }