OSDN Git Service

tests for Darwin CFStrings
authoriains <iains@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 23 Oct 2010 19:40:26 +0000 (19:40 +0000)
committeriains <iains@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 23 Oct 2010 19:40:26 +0000 (19:40 +0000)
gcc/testsuite:

Based on the CFString implementation in FSF apple/trunk branch.

* gcc.dg/darwin-cfstring-1.c: New.
* gcc.dg/darwin-cfstring-2.c: New.
* gcc.dg/torture/darwin-cfstring-3.c: New.
* g++.dg/other/darwin-cfstring1.C: New.
* g++.dg/torture/darwin-cfstring-3.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165889 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/darwin-cfstring1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/darwin-cfstring-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/darwin-cfstring-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c [new file with mode: 0644]

index 137f965..cfebd35 100644 (file)
@@ -1,3 +1,13 @@
+2010-10-23  Iain Sandoe  <iains@gcc.gnu.org>
+
+       Based on the CFString implementation in FSF apple/trunk branch.
+
+       * gcc.dg/darwin-cfstring-1.c: New.
+       * gcc.dg/darwin-cfstring-2.c: New.
+       * gcc.dg/torture/darwin-cfstring-3.c: New.
+       * g++.dg/other/darwin-cfstring1.C: New.
+       * g++.dg/torture/darwin-cfstring-3.C: New.
+
 2010-10-23  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        * objc.dg/demangle-1.m: New test.
diff --git a/gcc/testsuite/g++.dg/other/darwin-cfstring1.C b/gcc/testsuite/g++.dg/other/darwin-cfstring1.C
new file mode 100644 (file)
index 0000000..b30ba9b
--- /dev/null
@@ -0,0 +1,25 @@
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" fails gracefully when handed a non-constant
+   argument.  This will only work on MacOS X 10.1.2 and later.  */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+#include <CoreFoundation/CFString.h>
+
+#ifdef __CONSTANT_CFSTRINGS__
+#undef CFSTR
+#define CFSTR(STR)  ((CFStringRef) __builtin___CFStringMakeConstantString (STR))
+#endif
+
+extern int cond;
+extern const char *func(void);
+
+int main(void) {
+  CFStringRef s1 = CFSTR("Str1");
+  CFStringRef s2 = CFSTR(cond? "Str2": "Str3"); /* { dg-error "CFString literal expression is not a string constant" } */
+  CFStringRef s3 = CFSTR(func());  /* { dg-error "CFString literal expression is not a string constant" } */
+
+  return 0;
+}
diff --git a/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C b/gcc/testsuite/g++.dg/torture/darwin-cfstring-3.C
new file mode 100644 (file)
index 0000000..2d755ec
--- /dev/null
@@ -0,0 +1,30 @@
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" generates compile-time objects with the correct layout. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+typedef const struct __CFString *CFStringRef;
+
+#ifdef __CONSTANT_CFSTRINGS__
+#define CFSTR(STR)  ((CFStringRef) __builtin___CFStringMakeConstantString (STR))
+#else
+#error __CONSTANT_CFSTRINGS__ not defined
+#endif
+
+extern int cond;
+extern const char *func(void);
+
+CFStringRef s0 = CFSTR("Hello" "there");
+
+void foo(void) {
+  const CFStringRef s1 = CFSTR("Str1");
+
+  s0 = s1;
+}
+
+/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+4\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+10\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t4\n" { target { *-*-darwin* && {  lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t10\n" { target { *-*-darwin* && {  lp64 } } } } } */
diff --git a/gcc/testsuite/gcc.dg/darwin-cfstring-1.c b/gcc/testsuite/gcc.dg/darwin-cfstring-1.c
new file mode 100644 (file)
index 0000000..b9565e7
--- /dev/null
@@ -0,0 +1,28 @@
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" fails gracefully when handed a non-constant
+   argument.  This will only work on MacOS X 10.1.2 and later.  */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+typedef const struct __CFString *CFStringRef;
+
+#ifdef __CONSTANT_CFSTRINGS__
+#define CFSTR(STR)  ((CFStringRef) __builtin___CFStringMakeConstantString (STR))
+#else
+#error __CONSTANT_CFSTRINGS__ not defined
+#endif
+
+extern int cond;
+extern const char *func(void);
+
+const CFStringRef s0 = CFSTR("Hello" "there");
+
+int main(void) {
+  CFStringRef s1 = CFSTR("Str1");
+  CFStringRef s2 = CFSTR(cond? "Str2": "Str3"); /* { dg-error "CFString literal expression is not a string constant" } */
+  CFStringRef s3 = CFSTR(func());  /* { dg-error "CFString literal expression is not a string constant" } */
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/darwin-cfstring-2.c b/gcc/testsuite/gcc.dg/darwin-cfstring-2.c
new file mode 100644 (file)
index 0000000..1c724b2
--- /dev/null
@@ -0,0 +1,12 @@
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" fails gracefully when used without the
+   -mconstant-cfstrings flag.  */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mno-constant-cfstrings" } */
+
+typedef const struct __CFString *CFStringRef;
+
+const CFStringRef S = ((CFStringRef)__builtin___CFStringMakeConstantString("Testing"));
+/* { dg-error "built-in" "built-in function .* requires .* flag" { target *-*-* } 11 } */
diff --git a/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c b/gcc/testsuite/gcc.dg/torture/darwin-cfstring-3.c
new file mode 100644 (file)
index 0000000..2d755ec
--- /dev/null
@@ -0,0 +1,30 @@
+/* Test whether the __builtin__CFStringMakeConstantString 
+   "function" generates compile-time objects with the correct layout. */
+/* Developed by Ziemowit Laski <zlaski@apple.com>.  */
+
+/* { dg-do compile { target *-*-darwin* } } */
+/* { dg-options "-mconstant-cfstrings" } */
+
+typedef const struct __CFString *CFStringRef;
+
+#ifdef __CONSTANT_CFSTRINGS__
+#define CFSTR(STR)  ((CFStringRef) __builtin___CFStringMakeConstantString (STR))
+#else
+#error __CONSTANT_CFSTRINGS__ not defined
+#endif
+
+extern int cond;
+extern const char *func(void);
+
+CFStringRef s0 = CFSTR("Hello" "there");
+
+void foo(void) {
+  const CFStringRef s1 = CFSTR("Str1");
+
+  s0 = s1;
+}
+
+/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+4\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler "\\.long\[ \\t\]+___CFConstantStringClassReference\n\[ \\t\]*\\.long\[ \\t\]+1992\n\[ \\t\]*\\.long\[ \\t\]+LC.*\n\[ \\t\]*\\.long\[ \\t\]+10\n" { target { *-*-darwin* && { ! lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t4\n" { target { *-*-darwin* && {  lp64 } } } } } */
+/* { dg-final { scan-assembler ".quad\t___CFConstantStringClassReference\n\t.long\t1992\n\t.space 4\n\t.quad\t.*\n\t.quad\t10\n" { target { *-*-darwin* && {  lp64 } } } } } */