* Tests/base/NSXMLElement/attributes.m: Test for changed

exception.
* Tests/base/NSXMLNode/basic.m: More tests.
* Source/NSXMLNode.m: Rewrite object value handling.
* Source/NSXMLElement.m (-objectValue): Return @"" when the
value is nil.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34881 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2012-03-05 22:48:18 +00:00
parent 6461dd4aac
commit 9f1c97406d
5 changed files with 90 additions and 28 deletions

View file

@ -1,3 +1,12 @@
2012-03-05 Fred Kiefer <FredKiefer@gmx.de>
* Tests/base/NSXMLElement/attributes.m: Test for changed
exception.
* Tests/base/NSXMLNode/basic.m: More tests.
* Source/NSXMLNode.m: Rewrite object value handling.
* Source/NSXMLElement.m (-objectValue): Return @"" when the value
is nil.
2012-03-05 Eric Wasylishen <ewasylishen@gmail.com>
* Source/NSString.m (-rangeOfString:options:range:locale:):

View file

@ -61,11 +61,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
{
if (NSXMLElementKind == kind)
{
if ((self = [super initWithKind: kind options: theOptions]))
{
internal->objectValue = @"";
}
return self;
return [super initWithKind: kind options: theOptions];
}
else
{
@ -123,6 +119,15 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
return result;
}
- (id) objectValue
{
if (internal->objectValue == nil)
{
return @"";
}
return internal->objectValue;
}
- (NSArray*) elementsForName: (NSString*)name
{
NSMutableArray *results = [NSMutableArray arrayWithCapacity: 10];

View file

@ -840,7 +840,7 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
- (id) copyWithZone: (NSZone*)zone
{
id c = [[self class] allocWithZone: zone];
NSXMLNode *c = [[self class] allocWithZone: zone];
xmlNodePtr newNode = xmlCopyNode([self _node], 2); // make a deep copy
clearPrivatePointers(newNode);
@ -858,7 +858,7 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
{
return [NSString stringWithFormat:@"<%@ %@ %d>%@\n",
NSStringFromClass([self class]),
[self name], [self kind], [self stringValue]];
[self name], [self kind], [self XMLString]];
}
- (void) dealloc
@ -1166,12 +1166,6 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
- (id) objectValue
{
// FIXME: Most likely this is wrong, but currently needed for an NSXMLElement test
if ((NSXMLInvalidKind != internal->kind) &&
(internal->objectValue == nil))
{
return @"";
}
return internal->objectValue;
}
@ -1215,14 +1209,27 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
}
*/
result = StringFromXMLStringPtr(content);
xmlFree(content);
if (NULL != content)
{
result = StringFromXMLStringPtr(content);
xmlFree(content);
}
else
{
result = @"";
}
return result;
}
- (void) setObjectValue: (id)value
{
NSString *stringValue;
// FIXME: Use correct formatter here
stringValue = [value description];
[self setStringValue: stringValue];
ASSIGN(internal->objectValue, value);
}
@ -1245,11 +1252,6 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
{
xmlNodePtr node = MY_NODE;
if (nil == string)
{
// string value may not be nil
string = @"";
}
if (resolve == NO)
{
xmlNodeSetContent(node, XMLSTRING(string));
@ -1257,11 +1259,12 @@ execute_xpath(NSXMLNode *xmlNode, NSString *xpath_exp, NSString *nmspaces)
else
{
// need to actually resolve entities...
// is this the right functionality??
xmlChar *newstr = xmlEncodeSpecialChars(node->doc, XMLSTRING(string));
// is this the right functionality?? xmlEncodeSpecialChars()
xmlChar *newstr = xmlEncodeEntitiesReentrant(node->doc, XMLSTRING(string));
xmlNodeSetContent(node, newstr);
xmlMemFree(newstr);
}
ASSIGN(internal->objectValue, string);
}
- (void) setURI: (NSString*)URI

View file

@ -35,7 +35,7 @@ int main()
"may not overwrite pre-existing attributes");
PASS_EXCEPTION([root2 addAttribute: attr1],
NSInvalidArgumentException,
NSInternalInconsistencyException,
"cannot add attributes to multiple parents");

View file

@ -1,28 +1,34 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSXMLNode.h>
#import <Foundation/NSValue.h>
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSXMLNode *node;
NSXMLNode *other;
NSXMLNode *attr;
NSXMLNode *attr;
NSNumber *number;
node = [[NSXMLNode alloc] initWithKind: NSXMLInvalidKind];
other = [[NSXMLNode alloc] initWithKind: NSXMLElementKind];
// We need to set the name, otherwise isEqual: wont work.
[other setName: @"test"];
attr = [NSXMLNode attributeWithName: @"key"
stringValue: @"value"];
test_alloc(@"NSXMLNode");
test_NSObject(@"NSXMLNode", [NSArray arrayWithObjects: node, other, nil]);
test_NSCopying(@"NSXMLNode", @"NSXMLNode", [NSArray arrayWithObjects: node, other, nil], NO, YES);
test_NSObject(@"NSXMLNode", [NSArray arrayWithObjects: node, other, attr, nil]);
test_NSCopying(@"NSXMLNode", @"NSXMLNode", [NSArray arrayWithObjects: node, other, attr, nil], NO, YES);
PASS(NO == [other isEqual: node], "different node kinds are not equal");
[other release];
other = [[NSXMLNode alloc] initWithKind: NSXMLInvalidKind];
PASS([other isEqual: node], "empty nodes are equal");
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");
@ -41,20 +47,59 @@ int main()
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");
[node setStringValue: nil];
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
//PASS_EQUAL([attr children], nil, "attr node children is nil");
[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");
// In libxml2 the value is on a child node
//PASS([attr childCount] == 0, "No child on attr node");
// Equality tests.
node = [[NSXMLNode alloc] initWithKind: NSXMLElementKind];
other = [[NSXMLNode alloc] initWithKind: NSXMLElementKind];