// // Test the generated API selectors against typos or non-existing cases // // Authors: // Sebastien Pouliot // // Copyright 2012-2013 Xamarin Inc. All rights reserved. // using System; using System.Reflection; using NUnit.Framework; #if XAMCORE_2_0 using Foundation; using ObjCRuntime; #elif MONOMAC using MonoMac.Foundation; using MonoMac.ObjCRuntime; #else using MonoTouch.Foundation; using MonoTouch.ObjCRuntime; #endif namespace TouchUnit.Bindings { public abstract class CoreSelectorTest : ApiSelectorTest { protected override bool CheckResponse (bool value, Type actualType, MethodBase method, ref string name) { if (value) return true; var declaredType = method.DeclaringType; switch (name) { // optional stuff defined in NSObject (but not implemented by every subclasses) case "encodeWithCoder:": case "objectDidEndEditing:": case "commitEditing": case "commitEditingWithDelegate:didCommitSelector:contextInfo:": if (declaredType.Name == "NSObject") return true; break; // internal stuff that must be used case "_setCFClientFlags:callback:context:": case "_scheduleInCFRunLoop:forMode:": case "_unscheduleFromCFRunLoop:forMode:": // init* works (see monotouchtest.app) but does not respond when queried case "initWithFileAtPath:": case "initWithData:": case "initWithURL:": if (declaredType.Name == "NSInputStream") return true; break; // init* works (see monotouchtest.app) but does not respond when queried case "initToMemory": case "initToFileAtPath:append:": if (declaredType.Name == "NSOutputStream") return true; break; // init* works (see monotouchtest.app) but does not respond when queried case "initWithFileDescriptor:": case "initWithFileDescriptor:closeOnDealloc:": if (declaredType.Name == "NSFileHandle") return true; break; case "initWithString:": case "initWithString:attributes:": case "initWithAttributedString:": if (declaredType.Name == "NSAttributedString" || declaredType.Name == "NSMutableAttributedString") return true; break; } return base.CheckResponse (value, actualType, method, ref name); } protected override bool Skip (Type type) { switch (type.Name) { case "MTLRenderPassAttachmentDescriptor": // This is an abstract(-ish...) type, iOS allows creating an instance of it, but the instance doesn't respond to most of the selector in the headers. return true; } return base.Skip (type); } protected override IntPtr GetClassForType (Type type) { switch (type.Namespace) { case "MonoTouch.Metal": case "MonoMac.Metal": case "Metal": switch (type.Name) { case "MTLArgument": case "MTLArrayType": case "MTLCompileOptions": case "MTLComputePipelineDescriptor": case "MTLComputePipelineReflection": case "MTLDepthStencilDescriptor": case "MTLRenderPassAttachmentDescriptor": case "MTLRenderPassColorAttachmentDescriptor": case "MTLRenderPassDepthAttachmentDescriptor": case "MTLRenderPassDescriptor": case "MTLRenderPassStencilAttachmentDescriptor": case "MTLRenderPipelineColorAttachmentDescriptor": case "MTLRenderPipelineDescriptor": case "MTLRenderPipelineReflection": case "MTLSamplerDescriptor": case "MTLStencilDescriptor": case "MTLStructMember": case "MTLStructType": case "MTLTextureDescriptor": case "MTLVertexAttribute": case "MTLVertexAttributeDescriptor": case "MTLVertexBufferLayoutDescriptor": case "MTLVertexDescriptor": var ctor = type.GetConstructor (Type.EmptyTypes); using (var obj = ctor.Invoke (null) as NSObject) { return IntPtr_objc_msgSend (obj.Handle, Selector.GetHandle ("class")); } } break; } return base.GetClassForType (type); } } }