Annotation of objc/Test/ProtocolTest.m, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * "Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.0 (the 'License').  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License."
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: #import <objc/Object.h>
        !            26: #import <appkit/screens.h>
        !            27: #import <appkit/graphics.h>
        !            28: #import <appkit/color.h>
        !            29: #import <objc/objc-class.h>
        !            30: #import <mach/mach_types.h>
        !            31: #import <netinfo/ni.h>
        !            32: #import <mach-o/ldsyms.h>
        !            33: #import <objc/Protocol.h>
        !            34: 
        !            35: @protocol kitmethods
        !            36: 
        !            37: - beginPageSetupRect:(const NXRect *)aRect placement:(const NXPoint *)location;
        !            38: - placePrintRect:(const NXRect *)aRect offset:(NXPoint *)location;
        !            39: - moveTopLeftTo:(NXCoord)x :(NXCoord)y;
        !            40: - setBackgroundColor:(NXColor)color;
        !            41: - copyPSCodeInside:(const NXRect *)rect to:(NXStream *)stream;
        !            42: - windowResized:(NXEvent *)theEvent;
        !            43: 
        !            44: @end
        !            45: 
        !            46: @protocol testMethodQualifiers <kitmethods>
        !            47: 
        !            48: - in:(in int *)meaningless out:(out unsigned int *)y;
        !            49: - inout:(inout int *)weeb bycopy:(bycopy id)x;
        !            50: - structReference:(const NXRect *)s :(const NXRect **)y;
        !            51: - structValue:(NXPoint)s;
        !            52: - (oneway)asyncronousMessage;
        !            53: + someClassMethod;
        !            54: 
        !            55: @end
        !            56: 
        !            57: @protocol GetValues
        !            58: - (int)intValue;
        !            59: - (float)floatValue;
        !            60: - (double)doubleValue;
        !            61: - (const char *)stringValue;
        !            62: @end
        !            63: 
        !            64: @protocol SetValues
        !            65: - setIntValue:(int)anInt;
        !            66: - setFloatValue:(float)aFloat;
        !            67: - setDoubleValue:(double)aDouble;
        !            68: - setStringValue:(const char *)aString;
        !            69: @end
        !            70: 
        !            71: @protocol Values <SetValues, GetValues>
        !            72: @end
        !            73: 
        !            74: @interface Example1 : Object <SetValues, GetValues>
        !            75: @end
        !            76: 
        !            77: @implementation Example1
        !            78: @end
        !            79: 
        !            80: static void test_conformsTo()
        !            81: {
        !            82:        Object <SetValues, GetValues> *ex = [Example1 new];
        !            83:        
        !            84:        /* test protocol lookup */
        !            85:        
        !            86:        Protocol *pobj2 = [Protocol getProtocol:"kitmethods"], 
        !            87:                 *pobj3 = [Protocol getProtocol:"testMethodQualifiers"];
        !            88: 
        !            89:        /* test protocol conformance for objects */
        !            90:        
        !            91:        if ([ex conformsTo:[Protocol getProtocol:"SetValues"]])
        !            92:          printf("ex DOES conform to SetValues\n");
        !            93:        if (![ex conformsTo:[Protocol getProtocol:"Values"]])
        !            94:          printf("ex DOES NOT conform to Values\n");
        !            95:          
        !            96:        if ([ex conformsToGivenName:"SetValues"])
        !            97:          printf("ex DOES conform to SetValues\n");
        !            98:        if (![ex conformsToGivenName:"Values"])
        !            99:          printf("ex DOES NOT conform to Values\n");
        !           100: 
        !           101:        /* test protocol conformance for classes */
        !           102:        
        !           103:        if ([[Example1 class] conformsTo:[Protocol getProtocol:"SetValues"]])
        !           104:          printf("Example1 DOES conform to SetValues\n");
        !           105:        if (![[Example1 class] conformsTo:[Protocol getProtocol:"Values"]])
        !           106:          printf("Example1 DOES NOT conform to Values\n");
        !           107: 
        !           108:        /* test protocol conformance for protocols */
        !           109:          
        !           110:        if (![pobj2 conformsTo:pobj3])
        !           111:          printf("kitmethods DO NOT conform to testMethodQualifiers\n");
        !           112:        if (![pobj2 conformsToGivenName:[pobj3 protocolName]])
        !           113:          printf("kitmethods DO NOT conform to testMethodQualifiers\n");
        !           114:          
        !           115:        if ([pobj3 conformsTo:pobj2])
        !           116:          printf("testMethodQualifiers DO conform to kitmethods\n");
        !           117:        if ([pobj3 conformsToGivenName:[pobj2 protocolName]])
        !           118:          printf("testMethodQualifiers DO conform to kitmethods\n");
        !           119: }
        !           120: 
        !           121: static void test_methodDescFor()
        !           122: {
        !           123:        Protocol *valuesProtocol = [Protocol getProtocol:"Values"];
        !           124:        struct objc_method_desc *m;
        !           125:                
        !           126:        m = [valuesProtocol instanceMethodDescFor:@selector(setIntValue:)];
        !           127:        if (m)
        !           128:          printf("name = %s types = %s\n",sel_getName(m->name),m->types);
        !           129:          
        !           130:        m = [valuesProtocol instanceMethodDescFor:@selector(intValue)];
        !           131:        if (m)
        !           132:          printf("name = %s types = %s\n",sel_getName(m->name),m->types);
        !           133: }
        !           134: 
        !           135: main()
        !           136: {
        !           137:        test_conformsTo();
        !           138:        test_methodDescFor();
        !           139: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.