From patchwork Fri Oct 15 23:00:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 68007 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 1CAC1B70E6 for ; Sat, 16 Oct 2010 10:00:53 +1100 (EST) Received: (qmail 24129 invoked by alias); 15 Oct 2010 23:00:52 -0000 Received: (qmail 24120 invoked by uid 22791); 15 Oct 2010 23:00:51 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, SARE_SUB_ENC_UTF8, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 Oct 2010 23:00:46 +0000 Received: from eggs.gnu.org ([140.186.70.92]:33132) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P6tGW-0005eu-A6 for gcc-patches@gnu.org; Fri, 15 Oct 2010 19:00:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P6tGV-0002we-4i for gcc-patches@gnu.org; Fri, 15 Oct 2010 19:00:44 -0400 Received: from smtp151.iad.emailsrvr.com ([207.97.245.151]:49176) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P6tGV-0002wY-1B for gcc-patches@gnu.org; Fri, 15 Oct 2010 19:00:43 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp45.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 5D1CC905D2 for ; Fri, 15 Oct 2010 19:00:42 -0400 (EDT) X-Orig-To: gcc-patches@gnu.org Received: from dynamic9.wm-web.iad.mlsrvr.com (dynamic9.wm-web.iad1a.rsapps.net [192.168.2.216]) by smtp45.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 46F73902FE for ; Fri, 15 Oct 2010 19:00:42 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic9.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 38BA0320088 for ; Fri, 15 Oct 2010 19:00:42 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sat, 16 Oct 2010 01:00:42 +0200 (CEST) Date: Sat, 16 Oct 2010 01:00:42 +0200 (CEST) Subject: =?UTF-8?Q?libobjc=20-=20more=20modern=20Objective-C=20API=20(8)?= From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1287183642.2311965@192.168.2.228> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This adds a testcase for all the new object_xxx API functions. Committed to trunk. Thanks In gcc/testsuite/: 2010-10-15 Nicola Pero * objc.dg/gnu-api-2-object.m: New. Index: ChangeLog =================================================================== --- ChangeLog (revision 165528) +++ ChangeLog (working copy) @@ -1,5 +1,9 @@ 2010-10-15 Nicola Pero + * objc.dg/gnu-api-2-object.m: New. + +2010-10-15 Nicola Pero + * objc.dg/gnu-api-2-method.m: New. 2010-10-15 Jason Merrill Index: objc.dg/gnu-api-2-object.m =================================================================== --- objc.dg/gnu-api-2-object.m (revision 0) +++ objc.dg/gnu-api-2-object.m (revision 0) @@ -0,0 +1,161 @@ +/* Test the Modern GNU Objective-C Runtime API. + + This is test 'object', covering all functions starting with 'object'. */ + +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ + +/* To get the modern GNU Objective-C Runtime API, you include + objc/runtime.h. */ +#include +#include +#include +#include + +@interface MyRootClass +{ Class isa; } ++ alloc; +- init; +@end + +@implementation MyRootClass ++ alloc { return class_createInstance (self, 0); } +- init { return self; } +@end + +@protocol MyProtocol +- (id) variable; +@end + +@protocol MySecondProtocol +- (id) setVariable: (id)value; +@end + +@interface MySubClass : MyRootClass +{ id variable_ivar; } +- (void) setVariable: (id)value; +- (id) variable; +@end + +@implementation MySubClass +- (void) setVariable: (id)value { variable_ivar = value; } +- (id) variable { return variable_ivar; } +@end + +@interface MySubSubClass : MySubClass +- (id) test; +@end + +@implementation MySubSubClass +- (id) test { return self; } +@end + + + +int main(int argc, void **args) +{ + /* Functions are tested in alphabetical order. */ + + printf ("Testing object_copy () ...\n"); + { + MySubClass *object_a = [[MySubClass alloc] init]; + MySubClass *object_b = object_copy (object_a, 0); + + [object_b setVariable: object_a]; + if ([object_b variable] != object_a) + abort (); + } + + printf ("Testing object_dispose () ...\n"); + { + MySubClass *object = [[MySubClass alloc] init]; + + object_dispose (object); + } + + printf ("Testing object_getClass () ...\n"); + { + MyRootClass *o = [[MySubClass alloc] init]; + + if (object_getClass (o) != objc_getClass ("MySubClass")) + abort (); + } + + printf ("Testing object_getClassName () ...\n"); + { + MyRootClass *o = [[MyRootClass alloc] init]; + + if (strcmp (object_getClassName (o), "MyRootClass") != 0) + abort (); + } + + printf ("Testing object_getIndexedIvars () ...\n"); + { + if (object_getIndexedIvars ([[MyRootClass alloc] init]) == NULL) + abort (); + } + + printf ("Testing object_getInstanceVariable () ...\n"); + { + MySubClass *o = [[MySubClass alloc] init]; + id value; + + [o setVariable: o]; + + if (object_getInstanceVariable (o, "variable_ivar", (void **)&value) == NULL) + abort (); + + if (value != o) + abort (); + } + + printf ("Testing object_getIvar () ...\n"); + { + MySubClass *o = [[MySubClass alloc] init]; + Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"), "variable_ivar"); + + [o setVariable: o]; + + if (object_getIvar (o, ivar) != o) + abort (); + } + + printf ("Testing object_setClass () ...\n"); + { + MySubClass *o = [[MySubClass alloc] init]; + + object_setClass (o, objc_getClass ("MySubSubClass")); + + if ([(MySubSubClass *)o test] != o) + abort (); + } + + printf ("Testing object_setInstanceVariable () ...\n"); + { + MySubClass *o = [[MySubClass alloc] init]; + + [o setVariable: nil]; + + if (object_setInstanceVariable (o, "variable_ivar", (void *)o) == NULL) + abort (); + + if ([o variable] != o) + abort (); + } + + printf ("Testing object_setIvar () ...\n"); + { + MySubClass *o = [[MySubClass alloc] init]; + MySubClass *value = [[MySubClass alloc] init]; + Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"), "variable_ivar"); + + [o setVariable: o]; + + object_setIvar (o, ivar, value); + + if ([o variable] != value) + abort (); + } + + return 0; +}