/*H********************************************************************************/ /*! \File xml.c \Description Test the XML parser. \Copyright Copyright (c) 1999-2005 Electronic Arts Inc. \Version 10/04/1999 (gschaefer) First Version */ /********************************************************************************H*/ /*** Include files ****************************************************************/ #include #include "DirtySDK/platform.h" #include "DirtySDK/dirtysock.h" #include "DirtySDK/xml/xmlparse.h" #include "DirtySDK/xml/xmlformat.h" #include "testermodules.h" #include "libsample/zlib.h" /*** Defines **********************************************************************/ /*** Type Definitions *************************************************************/ /*** Variables ********************************************************************/ // Variables static const char _CmdXml_strData1[] = "" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " "]> " "" " 123456789012345678" " 0" " Successfully Retrieved Data" " Dudeman" " Dudeman" " 0" " 1" " dudeman@ea.com" " 25" " 12" " 1970" " USA" " 1" " 0" ""; static const char _CmdXml_strData2[] = " " " " " " " " " " " " " " " " ""; static const char _CmdXml_strData3[] = #if 0 "" "1" "" "" "" "xml to entity failed, xml is invalid.unexpected element (uri:\"\", local:\"html\"). Expected elements are <{}error>" //"xml to entity failed, xml is invalid.unexpected element (uri:\"\", local:\"html\"). Expected elements are {}error" "" "" "" #elif 0 "" "" "" "" "" "" "My Default Persona" "" "" "" "" "" "" "Feature not supported yet." "" "" "" "" "" "" "" "" "" "" "" "" "" "Feature not supported yet." "" "" "" "" "" "" "" "" "" "" "" "" "Requested list not found." "" "" "" "" "" "" "" "My Default Persona" "" "" "" "" "" "" "Feature not supported yet." "" "" "" "" "" "" "" "" "" "" "" "" "" "Feature not supported yet." "" "" "" "" "" "" "" "" "" "Requested list not found." "" "" "<" "list name='block" "ed_users'/>" "" " " #endif ; /*** Private Functions ************************************************************/ /*** Public functions *************************************************************/ /*F********************************************************************************/ /*! \Function CmdXml \Description Test the Xml parser \Input *argz - environment \Input argc - standard number of arguments \Input *argv[] - standard arg list \Output standard return value \Version 10/04/1999 (gschaefer) */ /********************************************************************************F*/ int32_t CmdXml(ZContext *argz, int32_t argc, char *argv[]) { int32_t iIndex; char strData[1024]; const char *pXml; for (pXml = _CmdXml_strData3; pXml != NULL; pXml = XmlSkip(pXml)) { ZPrintf("%s\n", XmlComplete(pXml) ? "valid" : "invalid"); } XmlPrintFmt((_CmdXml_strData3, "")); // check usage if (argc < 2) { ZPrintf(" test xmlparse and xmlformat modules\n"); ZPrintf(" usage: %s testnum [1..3]\n", argv[0]); return(0); } // get the index iIndex = atoi(argv[1]); // do the tests if (iIndex == 1) { XmlContentGetString(XmlFind(_CmdXml_strData1, "get-account-info-reply.email"), strData, sizeof(strData), ""); ZPrintf("email=%s\n", strData); ZPrintf("id=%lld\n", XmlContentGetInteger64(XmlFind(_CmdXml_strData1, "get-account-info-reply.id"), -1)); ZPrintf("bdateyear=%d\n", XmlContentGetInteger(XmlFind(_CmdXml_strData1, "get-account-info-reply.bdateyear"), -1)); } if (iIndex == 2) { pXml = XmlFind(_CmdXml_strData2, "TOURNAMENT.MATCHES"); ZPrintf("hit=%s\n", pXml); ZPrintf("beginDate=%lld\n", XmlAttribGetInteger64(XmlFind(_CmdXml_strData2, "TOURNAMENT"), "beginDate", -1)); ZPrintf("id=%d\n", XmlAttribGetInteger(XmlFind(_CmdXml_strData2, "TOURNAMENT"), "id", -1)); } if (iIndex == 3) { char strBuffer[1024]; // encode some XML XmlInit(strBuffer, sizeof(strBuffer), XML_FL_WHITESPACE); XmlTagStart(strBuffer, "TestFormat1"); XmlElemAddString(strBuffer, "strText", "Some chars that should be encoded: =, <, >, &, \", \x7f"); XmlTagEnd(strBuffer); XmlTagStart(strBuffer, "TestFormat2"); XmlElemAddString(strBuffer, "strText", "Some chars that should not be encoded: \t, \r, \n"); XmlTagEnd(strBuffer); XmlFinish(strBuffer); ZPrintf("encoded xml:\n------------\n%s\n-----------\n", strBuffer); // now parse the encoded xml XmlContentGetString(XmlFind(strBuffer, "TestFormat1.strText"), strData, sizeof(strData), ""); ZPrintf("test1=%s\n", strData); XmlContentGetString(XmlFind(strBuffer, "TestFormat2.strText"), strData, sizeof(strData), ""); ZPrintf("test2=%s\n", strData); } return(0); }