bool mime_body::save_body(pipe_manager& out, const char* src /* = NULL */, int len /* = 0 */) { // 是否需要从 HTML 数据中提取出纯文本数据 xml* pXml; if (m_htmlFirst == false && m_ctype == MIME_CTYPE_TEXT && m_stype == MIME_STYPE_HTML) { pXml = NEW xml1(); out.push_front(pXml); } else pXml = NULL; // 当需要进行字符集转换时查找字符集转换器 charset_conv* conv; if (m_toCharset[0] != 0) { conv = charset_conv::create(m_charset, m_toCharset); if (conv) out.push_front(conv); } else conv = NULL; bool ret = save(out, src, len); // 调用 mime_node::save if (pXml) delete pXml; if (conv) delete conv; return (ret); }
/***********************************************************************//** * @brief Test XML constructors **************************************************************************/ void TestGXml::test_GXml_construct(void) { // Test void constructor test_try("Test void constructor"); try { GXml xml; test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test load constructor test_try("Test load constructor"); try { GXml xml(m_xml_file); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test copy constructor test_try("Test copy constructor"); try { GXml xml1(m_xml_file); GXml xml2 = xml1; test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test XML file creation test_try("Test XML file creation"); try { GXml xml; xml.append(GXmlComment("This is a comment.")); xml.append(GXmlElement("source_library")); GXmlElement* lib = xml.element("source_library", 0); lib->append(GXmlElement("source name=\"LMC\" type=\"DiffuseSource\"")); GXmlNode* src = lib->element("source", 0); src->append(GXmlElement("spectrum type=\"PLSuperExpCutoff\"")); GXmlNode* spec = src->element("spectrum", 0); spec->append(GXmlElement("parameter free=\"1\" max=\"1000\" min=\"1e-07\"" " name=\"Prefactor\" scale=\"1e-07\"" " value=\"0.02754520844\"")); spec->append(GXmlElement("parameter free=\"1\" max=\"5\" min=\"-5\"" " name=\"Index1\" scale=\"1\" value=\"-2.0458781\"")); GXmlElement* par = spec->element("parameter", 0); par->attribute("value", "1.01"); par->attribute("error", "3.145"); par = spec->element("parameter", 1); par->attribute("value", "-2.100"); par->attribute("error", "9.876"); src->append(GXmlElement("spatialModel file=\"LMC.fits\" type=\"SpatialMap\"")); GXmlNode* spat = src->element("spatialModel", 0); spat->append(GXmlElement("parameter free=\"0\" max=\"1000\" min=\"0.001\"" " name=\"Prefactor\" scale=\"1\" value=\"1\"")); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Return return; }