MSXML2::IXMLDOMNodePtr AccessDatabase::Save(AppSecInc::Xml::XmlDocument& xmldoc, MSXML2::IXMLDOMNodePtr parent) const { MSXML2::IXMLDOMNodePtr root = xmldoc.AppendChild(L"AccessDatabase", parent); xmldoc.AppendChild(L"DBQ", root)->text = _bstr_t(_dbq.c_str()); xmldoc.AppendChild(L"ConnectionString", root)->text = _bstr_t(AppSecInc::Crypt::DPAPIImpl::Protect(_connection_string).c_str()); return root; }
void XmlDocumentUnitTests::testSetAttribute() { AppSecInc::Xml::XmlDocument xml; xml.Create(); xml.AppendChild(L"xml"); { xml.SetAttribute(L"name", L"value", xml.SelectNode(L"/xml")); std::wstring data = xml.GetXml(); AppSecInc::StringUtils::lrtrim(data, L"\r\n"); std::wcout << std::endl << data; CPPUNIT_ASSERT(data == L"<xml name=\"value\"/>"); } }
void XmlDocumentUnitTests::testAppendChild() { AppSecInc::Xml::XmlDocument xml; xml.Create(); xml.AppendChild(L"xml"); { std::wstring data = xml.GetXml(); AppSecInc::StringUtils::lrtrim(data, L"\r\n"); std::wcout << std::endl << data; CPPUNIT_ASSERT(! data.empty()); CPPUNIT_ASSERT(data == L"<xml/>"); } { xml.AppendChild(L"node", xml.SelectNode(L"/xml")); std::wstring data = xml.GetXml(); AppSecInc::StringUtils::lrtrim(data, L"\r\n"); std::wcout << std::endl << data; CPPUNIT_ASSERT(! data.empty()); CPPUNIT_ASSERT(data == L"<xml><node/></xml>"); } }
void AccessDatabaseUnitTests::testLoadSave() { AccessDatabase database1; database1.SetDBQ(L"test"); AppSecInc::Xml::XmlDocument doc; doc.Create(); MSXML2::IXMLDOMNodePtr root = doc.AppendChild(L"Databases"); MSXML2::IXMLDOMNodePtr database_root = database1.Save(doc, root); std::wcout << std::endl << doc.GetXml(); AccessDatabase database2; database2.Load(doc, database_root); CPPUNIT_ASSERT(database2.GetDBQ() == database1.GetDBQ()); }