OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [obj-c++.dg/] [torture/] [strings/] [const-cfstring-1.mm] - Blame information for rev 703

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 703 jeremybenn
/* Test the -fconstant-cfstrings option for constructing
2
   compile-time immutable CFStrings, and their interoperation
3
   with both Cocoa and CoreFoundation.  This will only work
4
   on MacOS X 10.1.2 and later.  */
5
/* Developed by Ziemowit Laski .  */
6
 
7
/* So far, CFString is darwin-only.  */
8
/* { dg-do run { target *-*-darwin* } } */
9
/* { dg-skip-if "NeXT only" { *-*-* } { "-fgnu-runtime" } { "" } } */
10
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
11
/* { dg-options "-mconstant-cfstrings -framework Cocoa" } */
12
/* Darwin10's linker emits a warning that the constant strings are incompatible with writable ones.
13
   well, we don't implement writable ones at this juncture.  */
14
/* { dg-options "-mconstant-cfstrings -framework Cocoa -Wl,-w" { target *-*-darwin[123]* } } */
15
 
16
#import 
17
#import 
18
#include 
19
 
20
void printOut(NSString *str) {
21
  NSLog(@"The value of str is: %@", str);
22
}
23
 
24
CFStringRef s0a = CFSTR("Compile-time string literal");
25
CFStringRef s0b = CFSTR("Compile-time string literal");
26
 
27
void checkNSRange(NSRange r) {
28
  if (r.location != 6 || r.length != 5) {
29
    printOut(@"Range check failed");
30
    abort();
31
  }
32
}
33
 
34
void checkCFRange(CFRange r) {
35
  if (r.location != 6 || r.length != 5) {
36
    printOut(@"Range check failed");
37
    abort();
38
  }
39
}
40
 
41
int main(void) {
42
  const NSString *s1 = @"Compile-time string literal";
43
  CFStringRef s2 = CFSTR("Compile-time string literal");
44
 
45
  checkNSRange([@"Hello World" rangeOfString:@"World"]);
46
  checkNSRange([(id)CFSTR("Hello World") rangeOfString:@"World"]);
47
  checkNSRange([@"Hello World" rangeOfString:(id)CFSTR("World")]);
48
  checkNSRange([(id)CFSTR("Hello World") rangeOfString:(id)CFSTR("World")]);
49
 
50
  checkCFRange(CFStringFind((CFStringRef)@"Hello World", (CFStringRef)@"World", 0));
51
  checkCFRange(CFStringFind(CFSTR("Hello World"), (CFStringRef)@"World", 0));
52
  checkCFRange(CFStringFind((CFStringRef)@"Hello World", CFSTR("World"), 0));
53
  checkCFRange(CFStringFind(CFSTR("Hello World"), CFSTR("World"), 0));
54
 
55
  /* Check for string uniquing.  */
56
  if (s0a != s0b || s0a != s2 || s1 != (id)s2) {
57
    NSLog(@"String uniquing failed");
58
    abort ();
59
  }
60
 
61
  return 0;
62
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.