File: basic.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 (67 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download | duplicates (2)
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
57
58
59
60
61
62
63
64
65
66
67
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSSortDescriptor.h>

int main()
{
  NSAutoreleasePool   *arp = [NSAutoreleasePool new];
  NSArray		*array;
  NSSortDescriptor	*s1;
  NSSortDescriptor	*s2;
  NSSortDescriptor	*s3;
  NSSortDescriptor	*s4;
  NSDictionary		*d1;
  NSDictionary		*d2;
  NSDictionary		*d3;
  NSDictionary		*d4;
  NSArray		*a1;
  NSArray		*a2;
  NSArray		*a3;

  s1 = [NSSortDescriptor sortDescriptorWithKey: @"name" ascending: YES];
  PASS(s1 != nil, "can create a sort descriptor");
   
  array = [NSArray arrayWithObject: s1];
  test_NSObject(@"NSSortDescriptor", array);
  test_NSCoding(array);
  test_keyed_NSCoding(array);
  test_NSCopying(@"NSSortDescriptor", @"NSSortDescriptor", array, NO, NO);

  s2 = [NSSortDescriptor sortDescriptorWithKey: @"name" ascending: YES];
  s3 = [NSSortDescriptor sortDescriptorWithKey: @"other" ascending: YES];
  s4 = [NSSortDescriptor sortDescriptorWithKey: @"other" ascending: NO];
  PASS([s1 hash] == [s2 hash], "hash for similar descriptors is the same");
  PASS([s1 isEqual: s2], "similar descriptors are equal");
  PASS(![s1 isEqual: s3], "different keyed descriptors are not equal");
  PASS(![s3 isEqual: s4], "different ordered descriptors are not equal");

  d1 = [NSDictionary dictionaryWithObjectsAndKeys:
    @"1", @"name",
    @"1", @"other",
    nil];
  d2 = [NSDictionary dictionaryWithObjectsAndKeys:
    @"1", @"name",
    @"2", @"other",
    nil];
  d3 = [NSDictionary dictionaryWithObjectsAndKeys:
    @"2", @"name",
    @"1", @"other",
    nil];
  d4 = [NSDictionary dictionaryWithObjectsAndKeys:
    @"2", @"name",
    @"2", @"other",
    nil];
  PASS([s3 compareObject: d3 toObject: d4] == NSOrderedAscending,
    "basic comparison works for ascending descriptor");
  PASS([s4 compareObject: d3 toObject: d4] == NSOrderedDescending,
    "basic comparison works for descending descriptor");

  array = [NSArray arrayWithObjects: s3, s1, nil];
  a1 = [NSArray arrayWithObjects: d1, d2, d3, d4, nil];
  a2 = [NSArray arrayWithObjects: d1, d3, d2, d4, nil];
  a3 = [a1 sortedArrayUsingDescriptors: array];
  PASS([a2 isEqual: a3], "simple multilevel sort works");
  
  [arp release]; arp = nil;
  return 0;
}