From: Nicola Pero Date: Mon, 17 Dec 2001 17:27:08 +0000 (+0000) Subject: New test for loading unclaimed categories in Objective-C X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=18c8746d1360487f7a1335e8b475313ca34d78bf;p=gcc.git New test for loading unclaimed categories in Objective-C From-SVN: r48111 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 43bcac065a3..4f87ba605ee 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +Mon Dec 17 16:54:56 2001 Nicola Pero + + * objc.dg/special/: New directory. + * objc.dg/special/special.exp: New file. + * objc.dg/special/unclaimed-category-1.h: New file. + * objc.dg/special/unclaimed-category-1a.m: New file. + * objc.dg/special/unclaimed-category-1.m: New file. + 2001-12-17 Andreas Jaeger * gcc.c-torture/compile/20011217-2.c: New test. diff --git a/gcc/testsuite/objc.dg/special/special.exp b/gcc/testsuite/objc.dg/special/special.exp new file mode 100644 index 00000000000..09552a72ad6 --- /dev/null +++ b/gcc/testsuite/objc.dg/special/special.exp @@ -0,0 +1,46 @@ +# GCC Objective-C testsuite that uses the `dg.exp' driver. +# Copyright (C) 1997, 2001 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Load support procs. +load_lib objc-dg.exp + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS "" +} + +# Initialize `dg'. +dg-init + +# +# unclaimed-category-1 test +# +# This test is special because we must compile two different modules, +# unclaimed-category-1a.m and unclaimed-category-1.m, then link +# together, then run the resulting executable. +set lines [objc_target_compile "$srcdir/$subdir/unclaimed-category-1a.m" "unclaimed-category-1a.o" object ""] +if ![string match "" $lines] then { + fail "unclaimed-category-1a.o" +} else { + dg-runtest "$srcdir/$subdir/unclaimed-category-1.m" "unclaimed-category-1a.o" "" + file delete unclaimed-category-1a.o +} + +# All done. +dg-finish + diff --git a/gcc/testsuite/objc.dg/special/unclaimed-category-1.h b/gcc/testsuite/objc.dg/special/unclaimed-category-1.h new file mode 100644 index 00000000000..6c73d28fd17 --- /dev/null +++ b/gcc/testsuite/objc.dg/special/unclaimed-category-1.h @@ -0,0 +1,27 @@ +/* Contributed by Nicola Pero - Fri Dec 14 08:36:00 GMT 2001 */ +#include +#include + +/* Test loading unclaimed categories - categories of a class defined + separately from the class itself. */ + +@interface TestClass +{ + id isa; +} +- (int)D; +@end + +@interface TestClass (A) +- (int)A; +@end + +@interface TestClass (B) +- (int)B; +@end + +@interface TestClass (C) +- (int)C; +@end + + diff --git a/gcc/testsuite/objc.dg/special/unclaimed-category-1.m b/gcc/testsuite/objc.dg/special/unclaimed-category-1.m new file mode 100644 index 00000000000..f9cbfc8d1d1 --- /dev/null +++ b/gcc/testsuite/objc.dg/special/unclaimed-category-1.m @@ -0,0 +1,65 @@ +/* Contributed by Nicola Pero - Fri Dec 14 08:36:00 GMT 2001 */ +/* { dg-do run } */ +#include +#include + +/* Test loading unclaimed categories - categories of a class defined + separately from the class itself. */ + + +/* unclaimed-category-1.m contains only the class definition but not + the categories. unclaimed-category-1a.m contains only the + categories of the class, but not the class itself. We want to + check that the runtime can load the class from one module (file) + and the categories from another module (file). */ + +#include "unclaimed-category-1.h" + +@implementation TestClass +- (int)D +{ + return 4; +} +@end + + +int main (void) +{ + TestClass *test; + Class testClass; + + testClass = objc_get_class ("TestClass"); + if (testClass == Nil) + { + abort (); + } + + test = (TestClass *)(class_create_instance (testClass)); + if (test == nil) + { + abort (); + } + + if ([test A] != 1) + { + abort (); + } + + if ([test B] != 2) + { + abort (); + } + + if ([test C] != 3) + { + abort (); + } + + + if ([test D] != 4) + { + abort (); + } + + return 0; +} diff --git a/gcc/testsuite/objc.dg/special/unclaimed-category-1a.m b/gcc/testsuite/objc.dg/special/unclaimed-category-1a.m new file mode 100644 index 00000000000..6bcd1b4c53c --- /dev/null +++ b/gcc/testsuite/objc.dg/special/unclaimed-category-1a.m @@ -0,0 +1,31 @@ +/* Contributed by Nicola Pero - Fri Dec 14 08:36:00 GMT 2001 */ +#include +#include + +/* Test loading unclaimed categories - categories of a class defined + separately from the class itself. */ + +#include "unclaimed-category-1.h" + +@implementation TestClass (A) +- (int)A +{ + return 1; +} +@end + +@implementation TestClass (B) +- (int)B +{ + return 2; +} +@end + +@implementation TestClass (C) +- (int)C +{ + return 3; +} +@end + +