File: test1.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 (43 lines) | stat: -rw-r--r-- 1,454 bytes parent folder | download | duplicates (8)
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
#import <Foundation/Foundation.h>
#import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSPropertyList.h>
#include <Testing.h>
int main()
{
  NSAutoreleasePool	*pool = [[NSAutoreleasePool alloc] init];
  NSMutableData		*m = [NSMutableData dataWithCapacity: 1024];
  NSPropertyListFormat  aFormat;
  NSString		*aString;
  id			pl;
  NSKeyedArchiver	*a;
  NSKeyedUnarchiver	*u;
  NSMutableIndexSet	*original;
  NSIndexSet		*decoded;

  a = [[NSKeyedArchiver alloc] initForWritingWithMutableData: m];
  [a setOutputFormat: NSPropertyListXMLFormat_v1_0];

  original = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(2,3)];
  [original addIndex: 7];
  [original addIndex: 557];
  [original addIndex: 947];
  [a encodeObject: original forKey: @"outer1"];
  [a finishEncoding];
  
  pl = [NSPropertyListSerialization propertyListFromData: m
                                        mutabilityOption: 0
                                                  format: &aFormat
                                        errorDescription: &aString];
  pl = [(NSDictionary*)[[(NSDictionary*)pl objectForKey: @"$objects"]
    objectAtIndex: 2] objectForKey: @"NS.data"];
  // FIXME ... maybe check encoded data format

  [a release];

  u = [[NSKeyedUnarchiver alloc] initForReadingWithData: m];
  decoded = [u decodeObjectForKey: @"outer1"];
  PASS([decoded isEqual: original], "decoded value equals encoded");
  [u release];
  [pool release];
  return 0;
}