Make sure code passes testsuite

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34456 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2012-01-07 13:08:03 +00:00
parent 6e979028e7
commit 1c23e5145d
5 changed files with 87 additions and 33 deletions

View file

@ -1,3 +1,17 @@
2012-01-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSXMLDocument.m:
* Source/NSXMLPrivate.h:
* Source/NSXMLNode.m:
* Source/NSXMLElement.m:
Replace missing assertion (needed for OSX compatibility) also fix
several other issues in node hierarchy handling ... all rather
academic since greg's going to rewrite, but these fixes do mean
the current code passes the testsuite. It's a bad idea to leave
the code and testsuite in an inconsistent state, and the testsuite
represents accumulated information about OSX, so we want our code
to pass all tests rather than removing tests.
2012-01-06 17:57-EST Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSXMLElement.m: Removing assertion that

View file

@ -57,6 +57,10 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
{
if (GS_EXISTS_INTERNAL)
{
while (internal->childCount > 0)
{
[self removeChildAtIndex: internal->childCount - 1];
}
[internal->encoding release];
[internal->version release];
[internal->docType release];
@ -218,15 +222,18 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
- (void) setRootElement: (NSXMLNode*)root
{
NSArray *children;
if (nil != root)
{
NSArray *children;
NSAssert(internal->rootElement == nil, NSGenericException);
/* this method replaces *all* children with the specified element.
*/
children = [[NSArray alloc] initWithObjects: &root count: 1];
[self setChildren: children];
[children release];
internal->rootElement = (NSXMLElement*)root;
NSAssert(internal->rootElement == nil, NSGenericException);
/* this method replaces *all* children with the specified element.
*/
children = [[NSArray alloc] initWithObjects: &root count: 1];
[self setChildren: children];
[children release];
internal->rootElement = (NSXMLElement*)root;
}
}
- (void) setStandalone: (BOOL)standalone
@ -427,10 +434,23 @@ GS_PRIVATE_INTERNAL(NSXMLDocument)
- (id) copyWithZone: (NSZone *)zone
{
NSXMLDocument *c = (NSXMLDocument*)[super copyWithZone: zone];
NSXMLElement *r = [self rootElement];
NSEnumerator *en;
id obj;
[c setStandalone: internal->standalone];
[c setChildren: internal->children];
GSIVar(c, rootElement) = internal->rootElement;
en = [internal->children objectEnumerator];
while ((obj = [en nextObject]) != nil)
{
NSXMLNode *child = [obj copyWithZone: zone];
if ([child isEqual: r])
{
GSIVar(c, rootElement) = (NSXMLElement*)child;
}
[c addChild: child];
[child release];
}
[c setDTD: internal->docType];
[c setMIMEType: internal->MIMEType];
return c;

View file

@ -35,6 +35,10 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
{
if (GS_EXISTS_INTERNAL && _internal != nil)
{
while (internal->childCount > 0)
{
[self removeChildAtIndex: internal->childCount - 1];
}
[internal->attributes release];
[internal->namespaces release];
}
@ -220,7 +224,8 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
NSAssert(nil != child, NSInvalidArgumentException);
NSAssert(index <= internal->childCount, NSInvalidArgumentException);
kind = [child kind];
NSAssert(nil == [child parent], NSInternalInconsistencyException);
kind = [child kind];
// FIXME ... should we check for valid kinds rather than invalid ones?
NSAssert(NSXMLAttributeKind != kind, NSInvalidArgumentException);
NSAssert(NSXMLDTDKind != kind, NSInvalidArgumentException);
@ -254,19 +259,22 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
- (void) removeChildAtIndex: (NSUInteger)index
{
NSXMLNode *child = [internal->children objectAtIndex: index];
NSXMLNode *child;
if (nil != child)
if (index >= internal->childCount)
{
GSIVar(child, parent) = nil;
[internal->children removeObjectAtIndex: index];
if (0 == --internal->childCount)
{
/* The -children method must return nil if there are no children,
* so we destroy the container.
*/
DESTROY(internal->children);
}
[NSException raise: NSRangeException
format: @"index to large"];
}
child = [internal->children objectAtIndex: index];
GSIVar(child, parent) = nil;
[internal->children removeObjectAtIndex: index];
if (0 == --internal->childCount)
{
/* The -children method must return nil if there are no children,
* so we destroy the container.
*/
DESTROY(internal->children);
}
}
@ -346,22 +354,35 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
- (id) copyWithZone: (NSZone *)zone
{
NSXMLElement *c = (NSXMLElement*)[super copyWithZone: zone];
NSEnumerator *en = [internal->namespaces objectEnumerator];
id obj = nil;
NSEnumerator *en;
id obj;
en = [internal->namespaces objectEnumerator];
while ((obj = [en nextObject]) != nil)
{
[c addNamespace: [obj copyWithZone: zone]];
NSXMLNode *ns = [obj copyWithZone: zone];
[c addNamespace: ns];
[ns release];
}
en = [internal->attributes objectEnumerator];
while ((obj = [en nextObject]) != nil)
{
NSXMLNode *attr = [obj copyWithZone: zone];
[c addAttribute: attr];
[attr release];
}
[c setChildren: [self children]];
en = [internal->children objectEnumerator];
while ((obj = [en nextObject]) != nil)
{
NSXMLNode *child = [obj copyWithZone: zone];
[c addChild: child];
[child release];
}
return c;
}

View file

@ -227,11 +227,7 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
- (void) detach
{
if (internal->parent != nil)
{
[(NSXMLElement*)internal->parent removeChildAtIndex: internal->index];
internal->parent = nil;
}
[(NSXMLElement*)internal->parent removeChildAtIndex: [self index]];
}
- (NSUInteger) hash
@ -241,7 +237,11 @@ GS_PRIVATE_INTERNAL(NSXMLNode)
- (NSUInteger) index
{
return internal->index;
if (nil == internal->parent)
{
return 0;
}
return [GSIVar(internal->parent, children) indexOfObjectIdenticalTo: self];
}
- (id) init

View file

@ -52,7 +52,6 @@
void *handle; \
NSUInteger kind; \
NSXMLNode *parent; \
NSUInteger index; \
id objectValue; \
NSString *stringValue; \
NSString *name; \