From e605ab5ed9381c1606e20d4acde8702f0472ba63 Mon Sep 17 00:00:00 2001 From: Todd White Date: Wed, 22 Jul 2026 15:11:40 -0400 Subject: [PATCH] Fix: CFXMLNode returns its type code and compares nodes by value --- Source/CFXMLNode.c | 6 ++-- Tests/CFXMLNode/TestInfo | 0 Tests/CFXMLNode/equal.m | 35 +++++++++++++++++++++++ Tests/CFXMLNode/typecode.m | 58 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 Tests/CFXMLNode/TestInfo create mode 100644 Tests/CFXMLNode/equal.m create mode 100644 Tests/CFXMLNode/typecode.m diff --git a/Source/CFXMLNode.c b/Source/CFXMLNode.c index 39a3513..4263c05 100644 --- a/Source/CFXMLNode.c +++ b/Source/CFXMLNode.c @@ -213,10 +213,10 @@ CFXMLNodeEqual (CFTypeRef cf1, CFTypeRef cf2) } } default: - break; + return true; } } - + return false; } @@ -446,7 +446,7 @@ CFXMLNodeGetString (CFXMLNodeRef node) CFXMLNodeTypeCode CFXMLNodeGetTypeCode (CFXMLNodeRef node) { - return ((CFRuntimeBase*)node)->_flags.info; + return node->_type; } CFIndex diff --git a/Tests/CFXMLNode/TestInfo b/Tests/CFXMLNode/TestInfo new file mode 100644 index 0000000..e69de29 diff --git a/Tests/CFXMLNode/equal.m b/Tests/CFXMLNode/equal.m new file mode 100644 index 0000000..69e8e75 --- /dev/null +++ b/Tests/CFXMLNode/equal.m @@ -0,0 +1,35 @@ +#include +#include + +#include "../CFTesting.h" + +int main (void) +{ + CFXMLNodeRef t1; + CFXMLNodeRef t2; + CFXMLNodeRef t3; + CFXMLNodeRef c1; + CFXMLNodeRef c2; + + t1 = CFXMLNodeCreate (NULL, kCFXMLNodeTypeText, CFSTR ("hello"), NULL, 1); + t2 = CFXMLNodeCreateCopy (NULL, t1); + PASS_CF(CFEqual (t1, t2), "Two identical text nodes are equal."); + + t3 = CFXMLNodeCreate (NULL, kCFXMLNodeTypeText, CFSTR ("world"), NULL, 1); + PASS_CF(!CFEqual (t1, t3), "Text nodes with different strings are not equal."); + + c1 = CFXMLNodeCreate (NULL, kCFXMLNodeTypeComment, CFSTR ("note"), NULL, 1); + c2 = CFXMLNodeCreateCopy (NULL, c1); + PASS_CF(CFEqual (c1, c2), "Two identical comment nodes are equal."); + + PASS_CF(!CFEqual (t1, c1), + "A text node and a comment node are not equal."); + + CFRelease (t1); + CFRelease (t2); + CFRelease (t3); + CFRelease (c1); + CFRelease (c2); + + return 0; +} diff --git a/Tests/CFXMLNode/typecode.m b/Tests/CFXMLNode/typecode.m new file mode 100644 index 0000000..a6d98cf --- /dev/null +++ b/Tests/CFXMLNode/typecode.m @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +#include "../CFTesting.h" + +int main (void) +{ + CFXMLNodeRef text; + CFXMLNodeRef comment; + CFXMLNodeRef elem; + CFXMLNodeRef pi; + CFXMLNodeRef copy; + CFDictionaryRef attrs; + CFArrayRef order; + CFXMLElementInfo einfo; + CFXMLProcessingInstructionInfo piinfo; + + text = CFXMLNodeCreate (NULL, kCFXMLNodeTypeText, CFSTR ("t"), NULL, 1); + PASS_CF(CFXMLNodeGetTypeCode (text) == kCFXMLNodeTypeText, + "A text node reports the text type code."); + + comment = CFXMLNodeCreate (NULL, kCFXMLNodeTypeComment, CFSTR ("c"), NULL, 1); + PASS_CF(CFXMLNodeGetTypeCode (comment) == kCFXMLNodeTypeComment, + "A comment node reports the comment type code."); + + attrs = CFDictionaryCreate (NULL, NULL, NULL, 0, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + order = CFArrayCreate (NULL, NULL, 0, &kCFTypeArrayCallBacks); + einfo.attributes = attrs; + einfo.attributeOrder = order; + einfo.isEmpty = true; + elem = CFXMLNodeCreate (NULL, kCFXMLNodeTypeElement, CFSTR ("e"), &einfo, 1); + PASS_CF(CFXMLNodeGetTypeCode (elem) == kCFXMLNodeTypeElement, + "An element node reports the element type code."); + + piinfo.dataString = CFSTR ("d"); + pi = CFXMLNodeCreate (NULL, kCFXMLNodeTypeProcessingInstruction, + CFSTR ("p"), &piinfo, 1); + PASS_CF(CFXMLNodeGetTypeCode (pi) == kCFXMLNodeTypeProcessingInstruction, + "A processing instruction reports the processing instruction type code."); + + copy = CFXMLNodeCreateCopy (NULL, text); + PASS_CF(CFXMLNodeGetTypeCode (copy) == kCFXMLNodeTypeText, + "A copied node preserves its type code."); + + CFRelease (text); + CFRelease (comment); + CFRelease (elem); + CFRelease (attrs); + CFRelease (order); + CFRelease (pi); + CFRelease (copy); + + return 0; +}