aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/obj-c++.dg/strings
diff options
context:
space:
mode:
Diffstat (limited to 'gcc-4.9/gcc/testsuite/obj-c++.dg/strings')
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm27
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm26
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-1.mm25
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-12.mm34
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-2.mm8
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-5.mm28
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-6.mm28
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings-1.mm32
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings-2.mm66
-rw-r--r--gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings.exp45
10 files changed, 319 insertions, 0 deletions
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm
new file mode 100644
index 000000000..b4fc9e6ed
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-cfstring-2.mm
@@ -0,0 +1,27 @@
+/* Test the -Wnonportable-cfstrings option, which should give
+ warnings if non-ASCII characters are embedded in constant
+ CFStrings. This will only work on MacOS X 10.2 and later. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-ftrack-macro-expansion=0 -mconstant-cfstrings -Wnonportable-cfstrings" } */
+
+#import <Foundation/NSString.h>
+#import <CoreFoundation/CFString.h>
+
+#ifndef __CONSTANT_CFSTRINGS__
+#error The -fconstant-cfstrings option is not functioning properly
+#endif
+
+void foo(void) {
+ NSString *s1 = @"Compile-time string literal";
+ CFStringRef s2 = CFSTR("Compile-time string literal");
+ NSString *s3 = @"Non-ASCII literal - \222"; /* { dg-warning "non-ASCII character in CFString literal" } */
+ CFStringRef s4 = CFSTR("\222 - Non-ASCII literal"); /* { dg-warning "non-ASCII character in CFString literal" } */
+ CFStringRef s5 = CFSTR("Non-ASCII (\222) literal"); /* { dg-warning "non-ASCII character in CFString literal" } */
+ NSString *s6 = @"\0Embedded NUL"; /* { dg-warning "embedded NUL in CFString literal" } */
+ CFStringRef s7 = CFSTR("Embedded \0NUL"); /* { dg-warning "embedded NUL in CFString literal" } */
+ CFStringRef s8 = CFSTR("Embedded NUL\0"); /* { dg-warning "embedded NUL in CFString literal" } */
+}
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm
new file mode 100644
index 000000000..98bb7c5bd
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-cfstring-5.mm
@@ -0,0 +1,26 @@
+/* Test if constant CFStrings may be passed back as ObjC strings. */
+/* Author: Ziemowit Laski */
+
+/* So far, CFString is darwin-only. */
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+#include <Foundation/NSObject.h>
+
+@interface Foo: NSObject {
+ char *cString;
+ unsigned int len;
+}
++ (Foo *)description;
+@end
+
+@interface Bar: NSObject
++ (Foo *) getString: (int) which;
+@end
+
+@implementation Bar
++ (Foo *) getString: (int) which {
+ return which? [Foo description]: @"Hello";
+}
+@end
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-1.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-1.mm
new file mode 100644
index 000000000..754c99bf1
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-1.mm
@@ -0,0 +1,25 @@
+/* Test errors for constant strings. */
+/* { dg-do compile } */
+/* { dg-options "-mno-constant-cfstrings" { target *-*-darwin* } } */
+
+#ifdef __cplusplus
+extern void baz(...);
+#endif
+
+void foo()
+{
+ baz(@"hiya"); /* { dg-error "annot find interface declaration" } */
+}
+
+@interface NXConstantString
+{
+ void *isa;
+ char *str;
+ int len;
+}
+@end
+
+void bar()
+{
+ baz(@"howdah");
+}
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-12.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-12.mm
new file mode 100644
index 000000000..d0dfb668e
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-12.mm
@@ -0,0 +1,34 @@
+/* Test if ObjC types play nice in conditional expressions. */
+/* Author: Ziemowit Laski */
+
+/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=Foo" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=Foo" { target *-*-darwin* } } */
+
+#ifdef __NEXT_RUNTIME__
+#include <Foundation/NSObject.h>
+#define OBJECT NSObject
+#else
+#include <objc/Object.h>
+#define OBJECT Object
+#endif
+#include "../../objc-obj-c++-shared/objc-test-suite-types.h"
+
+@interface Foo: OBJECT {
+ char *cString;
+ unsigned int len;
+}
++ (id)description;
+@end
+
+@interface Bar: OBJECT
++ (Foo *) getString: (int) which;
+@end
+
+TNS_STRING_REF_T _FooClassReference; /* Only used by NeXT. */
+
+@implementation Bar
++ (Foo *) getString: (int) which {
+ return which? [Foo description]: @"Hello";
+}
+@end
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-2.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-2.mm
new file mode 100644
index 000000000..e9e2fc93d
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-2.mm
@@ -0,0 +1,8 @@
+/* Test the -fconstant-string-class flag error. */
+/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=" { target *-*-darwin* } } */
+
+{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 }
+
+void foo () {}
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-5.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-5.mm
new file mode 100644
index 000000000..8c12a0c11
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-5.mm
@@ -0,0 +1,28 @@
+/* Positive test case for constant string layout. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=MyConstantString" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */
+
+@interface MyBase {
+ const char *p;
+}
+@end
+
+@interface MyConstantString: MyBase {
+ union equiv_u {
+ void *u;
+ unsigned char *c;
+ } _contents;
+ unsigned int _count;
+}
+@end
+
+/* The NeXT runtime initializes the 'isa' pointer of string constants at
+ compile time. */
+#ifdef __NEXT_RUNTIME__
+extern void *_MyConstantStringClassReference;
+#endif
+
+MyConstantString *str = @"Hello";
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-6.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-6.mm
new file mode 100644
index 000000000..69954d9f4
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/const-str-6.mm
@@ -0,0 +1,28 @@
+/* Negative test case for constant string layout. */
+/* Contributed by Ziemowit Laski <zlaski@apple.com>. */
+
+/* { dg-do compile } */
+/* { dg-options "-fconstant-string-class=MyConstantString" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyConstantString" { target *-*-darwin* } } */
+
+@interface MyBase {
+ char p;
+}
+@end
+
+@interface MyConstantString: MyBase {
+ union equiv_u {
+ void *u;
+ unsigned char *c;
+ } _contents;
+ char _count;
+}
+@end
+
+/* The NeXT runtime initializes the 'isa' pointer of string constants at
+ compile time. */
+#ifdef __NEXT_RUNTIME__
+extern void *_MyConstantStringClassReference;
+#endif
+
+MyConstantString *str = @"Hello"; /* { dg-error "interface .MyConstantString. does not have valid constant string layout" } */
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings-1.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings-1.mm
new file mode 100644
index 000000000..408392fd5
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings-1.mm
@@ -0,0 +1,32 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
+/* { dg-do compile } */
+
+#include "../../objc-obj-c++-shared/runtime.h"
+#ifndef __NEXT_RUNTIME__
+#include <objc/NXConstStr.h>
+#endif
+
+/* The following are correct. */
+id test_valid1 = @"test";
+id test_valid2 = @"te" @"st";
+id test_valid3 = @"te" @"s" @"t";
+id test_valid4 = @ "t" @ "e" @ "s" @ "t";
+
+/* The following are accepted too; you can concat an ObjC string to a
+ C string, the result being an ObjC string. */
+id test_valid5 = @"te" "st";
+id test_valid6 = @"te" "s" @"t";
+id test_valid7 = @"te" @"s" "t";
+
+/* The following are not correct. */
+id test_invalid1 = @@"test"; /* { dg-error "stray .@. in program" } */
+const char *test_invalid2 = "test"@; /* { dg-error "stray .@. in program" } */
+const char *test_invalid3 = "test"@@; /* { dg-error "stray .@. in program" } */
+const char *test_invalid4 = "te" @"st"; /* { dg-error "expected" } */
+id test_invalid5 = @"te" @@"st"; /* { dg-error "repeated .@. before Objective-C string" } */
+id test_invalid6 = @@"te" @"st"; /* { dg-error "stray .@. in program" } */
+id test_invalid7 = @"te" @"s" @@"t"; /* { dg-error "repeated .@. before Objective-C string" } */
+id test_invalid8 = @"te" @@"s" @"t"; /* { dg-error "repeated .@. before Objective-C string" } */
+id test_invalid9 = @"te" @"s" @"t" @; /* { dg-error "stray .@. in program" } */
+id test_invalidA = @"te" @ st; /* { dg-error "stray .@. in program" } */
+ /* { dg-error "expected" "" { target *-*-* } 31 } */
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings-2.mm b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings-2.mm
new file mode 100644
index 000000000..403cf7d3b
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings-2.mm
@@ -0,0 +1,66 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
+
+/* { dg-do run } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+/* { dg-options "-fconstant-string-class=MyTestString" } */
+/* { dg-options "-mno-constant-cfstrings -fconstant-string-class=MyTestString" { target *-*-darwin* } } */
+
+#include "../../objc-obj-c++-shared/objc-test-suite-types.h"
+
+#include <stdlib.h> /* For abort() */
+
+@interface MyTestString
+{
+ void *dummy_class_ptr;
+ char *string;
+ unsigned int len;
+}
++ initialize;
+/* All strings should contain the C string 'test'. Call -check to
+ test that this is true. */
+- (void) check;
+@end
+
+@implementation MyTestString
++ initialize {return self;}
+- (void) check
+{
+ if (len != 4 || string[0] != 't' || string[1] != 'e'
+ || string[2] != 's' || string[3] != 't' || string[4] != '\0')
+ abort ();
+}
+@end
+
+TNS_STRING_REF_T _MyTestStringClassReference; /* Only used by NeXT. */
+
+int main (void)
+{
+ MyTestString *test_valid1 = @"test";
+ MyTestString *test_valid2 = @"te" @"st";
+ MyTestString *test_valid3 = @"te" @"s" @"t";
+ MyTestString *test_valid4 = @ "t" @ "e" @ "s" @ "t";
+ MyTestString *test_valid5 = @ "t" "e" "s" "t";
+ MyTestString *test_valid6 = @ "t" "e" "s" @ "t";
+
+ [test_valid1 check];
+ [test_valid2 check];
+ [test_valid3 check];
+ [test_valid4 check];
+ [test_valid5 check];
+ [test_valid6 check];
+
+ return 0;
+}
+
+#ifdef __NEXT_RUNTIME__
+#include <string.h>
+/* The MyTestString metaclass will need to be initialized before we can
+ send messages to strings. */
+
+void testsuite_mytest_string_init (void) __attribute__((constructor));
+void testsuite_mytest_string_init (void) {
+ memcpy (&_MyTestStringClassReference,
+ objc_getClass ("MyTestString"),
+ sizeof (_MyTestStringClassReference));
+}
+#endif \ No newline at end of file
diff --git a/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings.exp b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings.exp
new file mode 100644
index 000000000..96e2c69ac
--- /dev/null
+++ b/gcc-4.9/gcc/testsuite/obj-c++.dg/strings/strings.exp
@@ -0,0 +1,45 @@
+# String tests that only need to run at default optimization.
+
+# Copyright (C) 2010-2014 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC 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 3, or (at your option)
+# any later version.
+#
+# GCC 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 GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Load support procs.
+load_lib obj-c++-dg.exp
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_OBJCXXFLAGS
+if ![info exists DEFAULT_OBJCXXFLAGS] then {
+ set DEFAULT_OBJCXXFLAGS " -ansi -pedantic-errors -Wno-long-long"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Gather a list of all tests.
+set tests [lsort [glob -nocomplain $srcdir/$subdir/*.mm]]
+
+# Main loop.
+dg-runtest $tests "-fgnu-runtime" $DEFAULT_OBJCXXFLAGS
+
+# darwin targets can also run code with the NeXT runtime.
+if [istarget "*-*-darwin*" ] {
+ dg-runtest $tests "-fnext-runtime" $DEFAULT_OBJCXXFLAGS
+}
+
+# All done.
+dg-finish