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 (126 lines) | stat: -rw-r--r-- 4,749 bytes parent folder | download | duplicates (5)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSValue.h>
#import "GNUstepBase/GSConfig.h"

int main()
{
  NSAutoreleasePool *arp = [NSAutoreleasePool new];
  START_SET("NSXMLNode")
#if !GS_USE_LIBXML
    SKIP("library built without libxml2")
#else
  NSXMLNode *node;
  NSXMLNode *other;
  NSXMLNode *text;
  NSXMLNode *pi;
  NSXMLNode *comment;
  NSXMLNode *ns;
  NSXMLNode *attr;
  NSNumber *number;
  NSArray *instances;

  test_alloc(@"NSXMLNode");

  node = [[NSXMLNode alloc] initWithKind: NSXMLInvalidKind];
  other = [[NSXMLNode alloc] initWithKind: NSXMLElementKind];
  // We need to set the name, otherwise isEqual: wont work.
  [other setName: @"test"];
  text = [NSXMLNode textWithStringValue: @"Text node"];
  pi = [NSXMLNode processingInstructionWithName: @"PI name"
                                    stringValue: @"PI string"];
  ns = [NSXMLNode namespaceWithName: @"name space name"
                        stringValue: @"name space string"];
  comment = [NSXMLNode commentWithStringValue: @"Comment node"];
  attr = [NSXMLNode attributeWithName: @"key"
			  stringValue: @"value"];
  instances = [NSArray arrayWithObjects: node, other, text, pi, 
                       ns, comment, attr, nil];
  test_NSObject(@"NSXMLNode", instances);
  test_NSCopying(@"NSXMLNode", @"NSXMLNode", instances, NO, YES);

  PASS(NO == [other isEqual: node], "different node kinds are not equal");
  [other release];

  other = [[NSXMLNode alloc] initWithKind: NSXMLInvalidKind];
  PASS([other isEqual: node], "invalid nodes are equal");

  // Tests on invalid node
  PASS(NSXMLInvalidKind == [node kind], "invalid node kind is correct");
  PASS(0 == [node level], "invalid node level is zero");
  PASS_EQUAL([node name], nil, "invalid node name is nil");
  PASS_EQUAL([node URI], nil, "invalid node URI is nil");
  PASS_EQUAL([node objectValue], nil, "invalid node object value is nil");
  PASS_EQUAL([node stringValue], @"", "invalid node string value is empty");
  PASS_EQUAL([node children], nil, "invalid node children is nil");

  [node setName: @"name"];
  PASS_EQUAL([node name], nil,
    "setting name on invalid node gives a nil name");
  [node setURI: @"URI"];
  PASS_EQUAL([node URI], nil,
    "setting URI on invalid node gives a nil URI");
  [node setObjectValue: @"anObject"];
  PASS_EQUAL([node objectValue], @"anObject",
    "setting object value on invalid node works");
  [node setObjectValue: nil];
  PASS([node childCount] == 0, "No child after setting object value");
  // Per documentation on NSXMLNode setObjectValue/objectValue, 
  // On 10.6 this returns nil not @""
  PASS_EQUAL([node objectValue], nil,
    "setting nil object value on invalid node works");
  PASS_EQUAL([node stringValue], @"",
    "setting nil object value on invalid node gives empty string");
    
  number = [NSNumber numberWithInt: 12];
  [node setObjectValue: number];
  PASS_EQUAL([node objectValue], number,
    "setting object value on invalid node works");
  testHopeful = YES;
  PASS_EQUAL([node stringValue], @"1,2E1",
    "setting object value on invalid node sets string value");
  testHopeful = NO;
  [node setObjectValue: nil];
  
  [node setStringValue: @"aString"];
  PASS_EQUAL([node stringValue], @"aString",
    "setting string value on invalid node works");
  PASS_EQUAL([node objectValue], @"aString",
    "setting string value on invalid node sets object value");
   [node setStringValue: nil];
  PASS_EQUAL([node stringValue], @"",
    "setting nil string value on invalid node gives empty string");
  PASS_EQUAL([node objectValue], nil,
    "setting nil string value on invalid node sets object value to nil");

  [node release];
  [other release];

  // Tests on attribute node
  attr = [NSXMLNode attributeWithName: @"key"
			  stringValue: @"value"];
  PASS(NSXMLAttributeKind == [attr kind], "attr node kind is correct");
  PASS(0 == [attr level], "attr node level is zero");
  PASS_EQUAL([attr name], @"key", "name on attr node works");
  PASS_EQUAL([attr URI], nil, "attr node URI is nil");
  PASS_EQUAL([attr objectValue], @"value", "attr node object value works");
  PASS_EQUAL([attr stringValue], @"value", "string value on attr node works");
  // In libxml2 the value is on a child node, but we don't report that
  PASS_EQUAL([attr children], nil, "attr node children is nil");
  PASS([attr childCount] == 0, "No child on attr node");

  [attr setName: @"name"];
  PASS_EQUAL([attr name], @"name",
    "setting name on attr node works");
  [attr setStringValue: @"aString"];
  PASS_EQUAL([attr stringValue], @"aString",
    "setting string value on attr node works");
#endif

  END_SET("NSXMLNode")
  [arp release];
  arp = nil;

  return 0;
}