From: <sar...@us...> - 2008-11-22 00:36:02
|
Revision: 8434 http://sbml.svn.sourceforge.net/sbml/?rev=8434&view=rev Author: sarahkeating Date: 2008-11-22 00:36:00 +0000 (Sat, 22 Nov 2008) Log Message: ----------- changed return of add functions and added tests Modified Paths: -------------- branches/libsbml-new-api-3.3/src/xml/XMLToken.cpp branches/libsbml-new-api-3.3/src/xml/XMLToken.h branches/libsbml-new-api-3.3/src/xml/test/TestXMLToken_newSetters.c Modified: branches/libsbml-new-api-3.3/src/xml/XMLToken.cpp =================================================================== --- branches/libsbml-new-api-3.3/src/xml/XMLToken.cpp 2008-11-22 00:06:50 UTC (rev 8433) +++ branches/libsbml-new-api-3.3/src/xml/XMLToken.cpp 2008-11-22 00:36:00 UTC (rev 8434) @@ -303,13 +303,21 @@ * other variants of this method near where this one appears in the * documentation. */ -void +int XMLToken::addAttr ( const std::string& name , const std::string& value , const std::string& namespaceURI , const std::string& prefix ) { - if (mIsStart) mAttributes.add(name, value, namespaceURI, prefix); + if (mIsStart) + { + mAttributes.add(name, value, namespaceURI, prefix); + return LIBSBML_OPERATION_SUCCESS; + } + else + { + return LIBSBML_INVALID_XML_OPERATION; + } } @@ -324,10 +332,18 @@ * @param triple an XMLTriple, the XML triple of the attribute. * @param value a string, the value of the attribute. */ -void +int XMLToken::addAttr ( const XMLTriple& triple, const std::string& value) { - if (mIsStart) mAttributes.add(triple, value); + if (mIsStart) + { + mAttributes.add(triple, value); + return LIBSBML_OPERATION_SUCCESS; + } + else + { + return LIBSBML_INVALID_XML_OPERATION; + } } @@ -1376,10 +1392,10 @@ * */ LIBLAX_EXTERN -void +int XMLToken_addAttr ( XMLToken_t *token, const char* name, const char* value ) { - token->addAttr(name, value, "", ""); + return token->addAttr(name, value, "", ""); } @@ -1399,13 +1415,13 @@ * */ LIBLAX_EXTERN -void +int XMLToken_addAttrWithNS ( XMLToken_t *token, const char* name , const char* value , const char* namespaceURI , const char* prefix ) { - token->addAttr(name, value, namespaceURI, prefix); + return token->addAttr(name, value, namespaceURI, prefix); } @@ -1423,10 +1439,10 @@ * @param value a string, the value of the attribute. */ LIBLAX_EXTERN -void +int XMLToken_addAttrWithTriple (XMLToken_t *token, const XMLTriple_t *triple, const char* value) { - token->addAttr(*triple, value); + return token->addAttr(*triple, value); } Modified: branches/libsbml-new-api-3.3/src/xml/XMLToken.h =================================================================== --- branches/libsbml-new-api-3.3/src/xml/XMLToken.h 2008-11-22 00:06:50 UTC (rev 8433) +++ branches/libsbml-new-api-3.3/src/xml/XMLToken.h 2008-11-22 00:36:00 UTC (rev 8434) @@ -232,7 +232,7 @@ * other variants of this method near where this one appears in the * documentation. */ - void addAttr ( const std::string& name + int addAttr ( const std::string& name , const std::string& value , const std::string& namespaceURI = "" , const std::string& prefix = ""); @@ -248,7 +248,7 @@ * @param triple an XMLTriple, the XML triple of the attribute. * @param value a string, the value of the attribute. */ - void addAttr ( const XMLTriple& triple, const std::string& value); + int addAttr ( const XMLTriple& triple, const std::string& value); /** @@ -1023,12 +1023,12 @@ LIBLAX_EXTERN -void +int XMLToken_addAttr ( XMLToken_t *token, const char* name, const char* value ); LIBLAX_EXTERN -void +int XMLToken_addAttrWithNS ( XMLToken_t *token, const char* name , const char* value , const char* namespaceURI @@ -1036,7 +1036,7 @@ LIBLAX_EXTERN -void +int XMLToken_addAttrWithTriple (XMLToken_t *token, const XMLTriple_t *triple, const char* value); Modified: branches/libsbml-new-api-3.3/src/xml/test/TestXMLToken_newSetters.c =================================================================== --- branches/libsbml-new-api-3.3/src/xml/test/TestXMLToken_newSetters.c 2008-11-22 00:06:50 UTC (rev 8433) +++ branches/libsbml-new-api-3.3/src/xml/test/TestXMLToken_newSetters.c 2008-11-22 00:36:00 UTC (rev 8434) @@ -87,6 +87,98 @@ END_TEST +START_TEST(test_XMLToken_newSetters_addAttributes1) +{ + /*-- setup --*/ + + XMLTriple_t* triple = XMLTriple_createWith("test","",""); + XMLAttributes_t* attr = XMLAttributes_create(); + XMLToken_t* token = XMLToken_createWithTripleAttr(triple, attr); + + XMLTriple_t* xt2 = XMLTriple_createWith("name3", + "http://name3.org/", "p3"); + /*-- test of adding attributes --*/ + + int i = XMLToken_addAttr(token, "name1", "val1"); + + fail_unless( i == 0 ); + fail_unless( XMLToken_getAttributesLength(token) == 1 ); + fail_unless( XMLToken_isAttributesEmpty(token) == 0 ); + + fail_unless( strcmp(XMLToken_getAttrName (token, 0), "name1") == 0 ); + fail_unless( strcmp(XMLToken_getAttrValue (token, 0), "val1" ) == 0 ); + + i = XMLToken_addAttrWithNS(token, "name2", "val2", + "http://name1.org/", "p1"); + + fail_unless( i == 0 ); + fail_unless( XMLToken_getAttributesLength(token) == 2 ); + fail_unless( XMLToken_isAttributesEmpty(token) == 0 ); + + fail_unless( strcmp(XMLToken_getAttrName (token, 1), "name2") == 0 ); + fail_unless( strcmp(XMLToken_getAttrValue (token, 1), "val2" ) == 0 ); + fail_unless( strcmp(XMLToken_getAttrURI (token, 1), "http://name1.org/") == 0 ); + fail_unless( strcmp(XMLToken_getAttrPrefix(token, 1), "p1" ) == 0 ); + + i = XMLToken_addAttrWithTriple(token, xt2, "val2"); + + fail_unless( i == 0 ); + fail_unless( XMLToken_getAttributesLength(token) == 3 ); + fail_unless( XMLToken_isAttributesEmpty(token) == 0 ); + fail_unless( strcmp(XMLToken_getAttrName (token, 2), "name3") == 0 ); + fail_unless( strcmp(XMLToken_getAttrValue (token, 2), "val2" ) == 0 ); + fail_unless( strcmp(XMLToken_getAttrURI (token, 2), "http://name3.org/") == 0 ); + fail_unless( strcmp(XMLToken_getAttrPrefix(token, 2), "p3" ) == 0 ); + + /*-- teardown --*/ + + XMLTriple_free(xt2); + XMLTriple_free(triple); + XMLAttributes_free(attr); + XMLToken_free(token); +} +END_TEST + + +START_TEST(test_XMLToken_newSetters_addAttributes2) +{ + /*-- setup --*/ + + XMLTriple_t* triple = XMLTriple_createWith("test","",""); + XMLToken_t* token = XMLToken_createWithTriple(triple); + + XMLTriple_t* xt2 = XMLTriple_createWith("name3", + "http://name3.org/", "p3"); + /*-- test of adding attributes --*/ + + int i = XMLToken_addAttr(token, "name1", "val1"); + + fail_unless( i == -13 ); + fail_unless( XMLToken_getAttributesLength(token) == 0 ); + fail_unless( XMLToken_isAttributesEmpty(token) == 1 ); + + i = XMLToken_addAttrWithNS(token, "name2", "val2", + "http://name1.org/", "p1"); + + fail_unless( i == -13 ); + fail_unless( XMLToken_getAttributesLength(token) == 0 ); + fail_unless( XMLToken_isAttributesEmpty(token) == 1 ); + + i = XMLToken_addAttrWithTriple(token, xt2, "val2"); + + fail_unless( i == -13 ); + fail_unless( XMLToken_getAttributesLength(token) == 0 ); + fail_unless( XMLToken_isAttributesEmpty(token) == 1 ); + + /*-- teardown --*/ + + XMLTriple_free(xt2); + XMLTriple_free(triple); + XMLToken_free(token); +} +END_TEST + + START_TEST(test_XMLToken_newSetters_setNamespaces1) { /*-- setup --*/ @@ -294,6 +386,8 @@ tcase_add_test( tcase, test_XMLToken_newSetters_setAttributes1); tcase_add_test( tcase, test_XMLToken_newSetters_setAttributes2); + tcase_add_test( tcase, test_XMLToken_newSetters_addAttributes1); + tcase_add_test( tcase, test_XMLToken_newSetters_addAttributes2); tcase_add_test( tcase, test_XMLToken_newSetters_setNamespaces1); tcase_add_test( tcase, test_XMLToken_newSetters_setNamespaces2); tcase_add_test( tcase, test_XMLToken_newSetters_addNamespaces1); @@ -301,6 +395,7 @@ tcase_add_test( tcase, test_XMLToken_newSetters_setTriple1); tcase_add_test( tcase, test_XMLToken_newSetters_setTriple2); tcase_add_test( tcase, test_XMLToken_newSetters_setEnd); + tcase_add_test( tcase, test_XMLToken_newSetters_setEOF); suite_add_tcase(suite, tcase); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |