~ubuntu-branches/ubuntu/karmic/gnustep-base/karmic

« back to all changes in this revision

Viewing changes to Testing/nsarchiver.m

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
#include <Foundation/NSValue.h>
11
11
#include <Foundation/NSDate.h>
12
12
 
 
13
@interface      ClassOne : NSObject
 
14
@end
 
15
@implementation ClassOne
 
16
- (void) encodeWithCoder: (NSCoder*)aCoder
 
17
{
 
18
}
 
19
- (id) initWithCoder: (NSCoder*)aCoder
 
20
{
 
21
  return self;
 
22
}
 
23
@end
 
24
@interface      ClassTwo : NSObject
 
25
@end
 
26
@implementation ClassTwo
 
27
- (void) encodeWithCoder: (NSCoder*)aCoder
 
28
{
 
29
}
 
30
- (id) initWithCoder: (NSCoder*)aCoder
 
31
{
 
32
  return self;
 
33
}
 
34
@end
 
35
 
 
36
typedef struct { char a; double b; char c;} tstruct;
13
37
int main()
14
38
{
 
39
  id obj;
15
40
  id set;
16
41
  id arp;
17
42
  id arc;
18
43
  id una;
19
44
  id xxx;
20
45
  id apl;
21
 
  
 
46
  tstruct       ss;
 
47
  tstruct       tt;
 
48
 
22
49
  [NSAutoreleasePool enableDoubleReleaseCheck:YES];
23
 
  
 
50
 
24
51
  arp = [[NSAutoreleasePool alloc] init];
25
52
 
26
53
  /* Create a Set of int's */
37
64
  {
38
65
    id o, e = [set objectEnumerator];
39
66
    while ((o = [e nextObject]))
40
 
      printf("%s\n", [[o description] cString]);    
 
67
      printf("%s\n", [[o description] cString]);
41
68
  }
42
69
 
43
70
  apl = [[NSAutoreleasePool alloc] init];
 
71
  ss.a = 'A';
 
72
  ss.b = 1.234;
 
73
  ss.c = 'Z';
 
74
  arc = [[NSArchiver new] autorelease];
 
75
  [arc encodeValueOfObjCType: @encode(tstruct) at: &ss];
 
76
  una = [[[NSUnarchiver alloc] initForReadingWithData: [arc archiverData]] autorelease];
 
77
  [una decodeValueOfObjCType: @encode(tstruct) at: &tt];
 
78
  [apl release];
 
79
  if (ss.a != tt.a) printf("Encoded '%c' in 'a' but got '%c'\n", ss.a, tt.a);
 
80
  if (ss.b != tt.b) printf("Encoded '%f' in 'a' but got '%f'\n", ss.b, tt.b);
 
81
  if (ss.c != tt.c) printf("Encoded '%c' in 'a' but got '%c'\n", ss.c, tt.c);
 
82
 
 
83
  apl = [[NSAutoreleasePool alloc] init];
44
84
  arc = [[NSArchiver new] autorelease];
45
85
printf("%u\n", [arc retainCount]);
46
86
  [arc retain];
79
119
  {
80
120
    id o, e = [set objectEnumerator];
81
121
    while ((o = [e nextObject]))
82
 
      printf("%s\n", [[o description] cString]);    
 
122
      printf("%s\n", [[o description] cString]);
83
123
  }
84
124
 
 
125
  obj = [ClassOne new];
 
126
  [NSArchiver archiveRootObject: obj toFile: @"./nsarchiver.dat"];
 
127
  RELEASE(obj);
 
128
  [NSUnarchiver decodeClassName: @"ClassOne" asClassName: @"ClassTwo"];
 
129
  obj = [NSUnarchiver unarchiveObjectWithFile: @"./nsarchiver.dat"];
 
130
  if ([obj isKindOfClass: [ClassTwo class]] == NO)
 
131
    NSLog(@"ERROR: ClassOne decoded as %@", NSStringFromClass([obj class]));
 
132
 
85
133
#if 0
86
134
/*
87
135
 *      Benchmark use of very lightwight archiving - a single
126
174
 
127
175
  /* Do the autorelease. */
128
176
  [arp release];
129
 
  
 
177
 
130
178
  exit(0);
131
179
}
132
180
 
134
182
/* An old, unused test. */
135
183
#else
136
184
 
137
 
#include <base/all.h>
 
185
#include <GNUstepBase/all.h>
138
186
#include <Foundation/NSArchiver.h>
139
187
#include <Foundation/NSAutoreleasePool.h>
140
188