File: test07.m

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (56 lines) | stat: -rw-r--r-- 2,083 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>

int main()
{
  NSAutoreleasePool	*arp = [NSAutoreleasePool new];
  unichar		u = 0x00a3;	// Pound sign
  NSString		*s;
  double 		d;

  PASS([@"12" intValue] == 12, "simple intValue works");
  PASS([@"-12" intValue] == -12, "negative intValue works");
  PASS([@"+12" intValue] == 12, "positive intValue works");
  PASS([@"1.6" intValue] == 1, "intValue ignores trailing data");
  PASS([@"                                12" intValue] == 12,
    "intValue with leading space works");

  d = [@"1.2" doubleValue];
  PASS(d > 1.199999 && d < 1.200001, "simple doubleValue works");
  PASS([@"1.9" doubleValue] == 90 / 100.0 + 1.0, "precise doubleValue works");
  d = [@"-1.2" doubleValue];
  PASS(d < -1.199999 && d > -1.200001, "negative doubleValue works");
  d = [@"+1.2" doubleValue];
  PASS(d > 1.199999 && d < 1.200001, "positive doubleValue works");
  d = [@"+1.2 x" doubleValue];
  PASS(d > 1.199999 && d < 1.200001, "doubleValue ignores trailing data");
  d = [@"                                1.2" doubleValue];
  PASS(d > 1.199999 && d < 1.200001, "doubleValue with leading space works");

  s = @"50.6468746467461646";
  sscanf([s UTF8String], "%lg", &d);
  PASS(EQ([s doubleValue], d), "50.6468746467461646 -doubleValue OK");

  s = @"50.64687464674616461";
  sscanf([s UTF8String], "%lg", &d);
  PASS(EQ([s doubleValue], d), "50.64687464674616461 -doubleValue OK");

  s = @"0.646874646746164616898211";
  sscanf([s UTF8String], "%lg", &d);
  PASS(EQ([s doubleValue], d), "0.646874646746164616898211 -doubleValue OK");

  s = @"502.646874646746164";
  sscanf([s UTF8String], "%lg", &d);
  PASS(EQ([s doubleValue], d), "502.646874646746164 -doubleValue OK");

  s = @"502.6468746467461646";
  sscanf([s UTF8String], "%lg", &d);
  PASS(EQ([s doubleValue], d), "502.6468746467461646 -doubleValue OK");

  s = [NSString stringWithCharacters: &u length: 1];
  PASS_EQUAL(s, @"£", "UTF-8 string literal matches 16bit unicode string");

  [arp release]; arp = nil;
  return 0;
}