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:
rfm 2012-01-07 13:08:03 +00:00
parent ccc4e39fc5
commit fd96ccd439
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> 2012-01-06 17:57-EST Gregory John Casamento <greg.casamento@gmail.com>
* Source/NSXMLElement.m: Removing assertion that * Source/NSXMLElement.m: Removing assertion that

View file

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

View file

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

View file

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

View file

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