Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

Linq-To-XML Style of Node Creation for C++

, 7 Jun 2012
Linq-To-XML Node Creation for Native C++
elmax-84498.zip
BuildProcessTemplates
Elmax.vsmdi
ElmaxNet
Properties
Elmax
Elmax.vcxproj.user
StringUtils
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
TryoutNet
Properties
Settings.settings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
elmax-ver083.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver084.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver085.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver086.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver087.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
Elmax-ver089.zip
Elmax-ver089
Elmax.vsmdi
Elmax
Elmax.vcxproj.user
StringUtils
ElmaxNet
Properties
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
TryoutNet
Properties
Settings.settings
ElmaxSrcVer082.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
#include "stdafx.h"
#include <algorithm>

using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace	Microsoft::VisualStudio::TestTools::UnitTesting;

namespace TestNativeElmax
{
	[TestClass]
	public ref class UnitTestMisc
	{

	private:
		HRESULT CreateAndInitDom(MSXML2::IXMLDOMDocumentPtr& pDoc)
		{
			HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
			if (SUCCEEDED(hr))
			{
				// these methods should not fail so don't inspect result
				pDoc->async = VARIANT_FALSE;
				pDoc->validateOnParse = VARIANT_FALSE;
				pDoc->resolveExternals = VARIANT_FALSE;
				MSXML2::IXMLDOMProcessingInstructionPtr pi = pDoc->createProcessingInstruction(L"xml", L" version='1.0' encoding='UTF-8'");
				pDoc->appendChild(pi);
			}
			Assert::IsTrue(SUCCEEDED(hr));
			return hr;
		}
		bool SaveXml(MSXML2::IXMLDOMDocumentPtr& pDoc, const std::wstring& strFilename)
		{
			TCHAR szPath[MAX_PATH];

			if(SUCCEEDED(SHGetFolderPath(NULL, 
				CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, 
				NULL, 
				0, 
				szPath))) 
			{
				PathAppend(szPath, strFilename.c_str());
			}

			variant_t varFile(szPath);
			return SUCCEEDED(pDoc->save(varFile));
		}
		bool CreateAndLoadXmlString(MSXML2::IXMLDOMDocumentPtr& pDoc, const std::wstring& strXml)
		{
			HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30));
			VARIANT_BOOL bLoad = VARIANT_FALSE;
			if (SUCCEEDED(hr))
			{
				bstr_t bstrXml(strXml.c_str());
				bLoad = pDoc->loadXML(bstrXml);
				Assert::IsTrue(bLoad==VARIANT_TRUE);
			}
			return bLoad == VARIANT_TRUE;
		}
		bool DeleteFile(const std::wstring& strFilename)
		{
			TCHAR szPath[MAX_PATH];

			if(SUCCEEDED(SHGetFolderPath(NULL, 
				CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, 
				NULL, 
				0, 
				szPath))) 
			{
				PathAppend(szPath, strFilename.c_str());
			}
			else
				return false;

			return ::DeleteFile(szPath)==TRUE;
		}
	public: 
		[TestMethod]
		void TestFileContents()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				// Create file
				TCHAR szPath[MAX_PATH];
				std::wstring filename1 = L"filecontents_xyz.dat";

				if(SUCCEEDED(SHGetFolderPath(NULL, 
					CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, 
					NULL, 
					0, 
					szPath))) 
				{
					PathAppend(szPath, filename1.c_str());
				}

				FILE* fp = NULL;
				_wfopen_s(&fp, szPath, L"w");

				Assert::AreNotEqual(0, (intptr_t)(fp));

				std::string strData = "";
				strData += (char)(254);
				strData += (char)(230);
				strData += (char)(85);
				strData += (char)(30);
				strData += (char)(28);
				strData += "Hello";

				fwrite(strData.c_str(), 1, strData.length(), fp);

				fclose(fp);
				fp = NULL;

				Element elem1 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem1.SetFileContents(szPath, true, true);

				::DeleteFile(szPath);

				std::wstring filename;
				int length=0;
				char* p = elem1.GetFileContents(filename, length);

				System::String^ s1 = gcnew System::String(filename1.c_str());
				System::String^ s2 = gcnew System::String(filename.c_str());
				Assert::AreEqual(s1, s2);
				
				Assert::AreNotEqual((intptr_t)(0), (intptr_t)(p));
				Assert::AreNotEqual((int)(0), (int)length);

				for(size_t i=0; i<strData.length(); ++i)
					Assert::AreEqual(strData.at(i), p[i]);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa"][L"bb"][L"cc"];

				filename = L"";
				length = 0;
				p = elem2.GetFileContents(filename, length);

				s2 = gcnew System::String(filename.c_str());
				Assert::AreEqual(s1, s2);

				Assert::AreNotEqual((intptr_t)(0), (intptr_t)(p));
				Assert::AreNotEqual((int)(0), (int)length);

				for(size_t i=0; i<strData.length(); ++i)
					Assert::AreEqual(strData.at(i), p[i]);
			}
		}
		[TestMethod]
		void TestDateAndTime()
		{
			using namespace Elmax;
			DateAndTime date(2007, 1, 1, 14, 23, 00);
			System::String^ s1 = gcnew System::String(date.GetString().c_str());
			System::String^ s2 = L"2007-01-01 14:23:00";

			Assert::AreEqual(s1, s2);

			date.SetDateTime(2007, 12, 15, 2, 25, 59);
			s1 = gcnew System::String(date.GetString().c_str());
			s2 = L"2007-12-15 02:25:59";

			Assert::AreEqual(s1, s2);

			date.SetString(L"2008-08-21 12:00:00");
			Assert::AreEqual((short)(2008), date.GetYear());
			Assert::AreEqual((short)(8), date.GetMonth());
			Assert::AreEqual((short)(21), date.GetMonthDay());
			Assert::AreEqual((short)(12), date.GetHour());
			Assert::AreEqual((short)(0), date.GetMinute());
			Assert::AreEqual((short)(0), date.GetSecond());
		}
		[TestMethod]
		void TestDate()
		{
			using namespace Elmax;
			Date date(2007, 1, 1);
			System::String^ s1 = gcnew System::String(date.GetString().c_str());
			System::String^ s2 = L"2007-01-01";

			Assert::AreEqual(s1, s2);

			date.SetDate(2007, 12, 15);
			s1 = gcnew System::String(date.GetString().c_str());
			s2 = L"2007-12-15";

			Assert::AreEqual(s1, s2);

			date.SetString(L"2008-08-21");
			Assert::AreEqual(date.GetYear(), (short)(2008));
			Assert::AreEqual(date.GetMonth(), (short)(8));
			Assert::AreEqual(date.GetMonthDay(), (short)(21));
		}
		[TestMethod]
		void Base64()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				using namespace std;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa"][L"bb"][L"cc"].CreateNew();

				string strNormal = "";
				for(unsigned char i=1; i<255; ++i)
					strNormal += (char)(i);

				random_shuffle(strNormal.begin(), strNormal.end());
				elem1 = Element::ConvToBase64(strNormal.c_str(), strNormal.length());

				wstring strBase64 = elem1.GetString(L"ABC");

				int len = 0;

				Element::ConvFromBase64(strBase64, NULL, len);

				char* p1 = new char[len+1];
				memset(p1, 0, len+1);

				Element::ConvFromBase64(strBase64, p1, len);

				string strNormal1 = p1;

				delete [] p1;
				p1 = NULL;

				System::String^ s1 = gcnew System::String(strNormal.c_str());
				System::String^ s2 = gcnew System::String(strNormal1.c_str());

				Assert::AreEqual(s1, s2);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa"][L"bb"][L"cc"];

				wstring strBase64_2 = elem2.GetString(L"ABC");

				int len2 = 0;

				Element::ConvFromBase64(strBase64_2, NULL, len2);

				char* p2 = new char[len2+1];
				memset(p2, 0, len2+1);

				Element::ConvFromBase64(strBase64_2, p2, len2);

				string strNormal2 = p2;
				delete [] p2;
				p2 = NULL;

				s1 = gcnew System::String(strNormal.c_str());
				s2 = gcnew System::String(strNormal2.c_str());

				Assert::AreEqual(s1, s2);
			}
		}
		[TestMethod]
		void QueryChildrenNum1()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa"][L"bb"][L"qq"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem3.SetInt32(33);
				Element elem4 = root[L"aa"][L"bb"][L"qq"].CreateNew();
				elem4.SetInt32(44);
				Element elem5 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem5.SetInt32(55);

				Element::available_child_t acmap = root[L"aa"][L"bb"].QueryChildrenNum();

				Assert::AreEqual(acmap[L"cc"], (unsigned int)(3));
				Assert::AreEqual(acmap[L"qq"], (unsigned int)(2));

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::available_child_t acmap2 = root2[L"aa"][L"bb"].QueryChildrenNum();

				Assert::AreEqual(acmap2[L"cc"], (unsigned int)(3));
				Assert::AreEqual(acmap2[L"qq"], (unsigned int)(2));
			}
		}
		[TestMethod]
		void QueryChildrenNum2()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|qq"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);
				Element elem4 = root[L"aa|bb|qq"].CreateNew();
				elem4.SetInt32(44);
				Element elem5 = root[L"aa|bb|cc"].CreateNew();
				elem5.SetInt32(55);

				Element::available_child_t acmap = root[L"aa"][L"bb"].QueryChildrenNum();

				Assert::AreEqual(acmap[L"cc"], (unsigned int)(3));
				Assert::AreEqual(acmap[L"qq"], (unsigned int)(2));

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::available_child_t acmap2 = root2[L"aa"][L"bb"].QueryChildrenNum();

				Assert::AreEqual(acmap2[L"cc"], (unsigned int)(3));
				Assert::AreEqual(acmap2[L"qq"], (unsigned int)(2));
			}
		}
		[TestMethod]
		void AsCollection1()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);

				Element::collection_t vec = root[L"aa"][L"bb"][L"cc"].AsCollection();

				Assert::AreNotEqual(vec.size(), 0U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).GetInt32(10), (int)(11*(i+1)));
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::collection_t vec2 = root2[L"aa"][L"bb"][L"cc"].AsCollection();

				Assert::AreNotEqual(vec2.size(), 0U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).GetInt32(10), (int)(11*(i+1)));
				}
			}
		}
		[TestMethod]
		void AsCollection2()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem3.SetInt32(33);

				Element::collection_t vec = root[L"aa"][L"bb"][L"cc"].AsCollection();

				Assert::AreNotEqual(vec.size(), 0U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).GetInt32(10), (int)(11*(i+1)));
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::collection_t vec2 = root2[L"aa"][L"bb"][L"cc"].AsCollection();

				Assert::AreNotEqual(vec2.size(), 0U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).GetInt32(10), (int)(11*(i+1)));
				}
			}
		}
		[TestMethod]
		void AsCollectionPred()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);

				Pred pred;
				Element::collection_t vec = root[L"aa"][L"bb"][L"cc"].AsCollection(pred);

				Assert::AreEqual(vec.size(), 2U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).GetInt32(10), (int)(11*(i+1)));
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::collection_t vec2 = root2[L"aa"][L"bb"][L"cc"].AsCollection(pred);

				Assert::AreEqual(vec2.size(), 2U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).GetInt32(10), (int)(11*(i+1)));
				}
			}
		}
		[TestMethod]
		void GetCollection1()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);

				Element::collection_t vec = root[L"aa"][L"bb"].GetCollection(L"cc");

				Assert::AreNotEqual(vec.size(), 0U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).GetInt32(10), (int)(11*(i+1)));
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::collection_t vec2 = root2[L"aa"][L"bb"].GetCollection(L"cc");

				Assert::AreNotEqual(vec2.size(), 0U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).GetInt32(10), (int)(11*(i+1)));
				}
			}
		}
		[TestMethod]
		void GetCollection2()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa"][L"bb"][L"cc"].CreateNew();
				elem3.SetInt32(33);

				Element::collection_t vec = root[L"aa"][L"bb"].GetCollection(L"cc");

				Assert::AreNotEqual(vec.size(), 0U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).GetInt32(10), (int)(11*(i+1)));
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::collection_t vec2 = root2[L"aa"][L"bb"].GetCollection(L"cc");

				Assert::AreNotEqual(vec2.size(), 0U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).GetInt32(10), (int)(11*(i+1)));
				}
			}
		}
		[TestMethod]
		void GetCollectionPred()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);

				Pred pred;
				Element::collection_t vec = root[L"aa"][L"bb"].GetCollection(L"cc",  pred);

				Assert::AreEqual(vec.size(), 2U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).GetInt32(10), (int)(11*(i+1)));
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::collection_t vec2 = root2[L"aa"][L"bb"].GetCollection(L"cc",  pred);

				Assert::AreEqual(vec2.size(), 2U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).GetInt32(10), (int)(11*(i+1)));
				}
			}
		}
		[TestMethod]
		void AddDeleteNode()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa|bb|cc"].Create();
				int dd = 2000000000;
				elem[L"dd"].SetInt32(dd);
				int dd2 = elem[L"dd"].GetInt32(10);
				Assert::AreEqual(dd, dd2);

				Element elemDelete = elem[L"dd"];
				Assert::IsTrue(elemDelete.Exists());
				elem.RemoveNode(elemDelete);
				
				dd2 = elem[L"dd"].GetInt32(10);
				Assert::AreEqual(10, dd2);

				elem.AddNode(elemDelete);

				dd2 = elem[L"dd"].GetInt32(10);
				Assert::AreEqual(dd, dd2);

				elem.RemoveNode(elemDelete);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa|bb|cc"];
				Assert::IsTrue(elem2.Exists());

				dd2 = elem2[L"dd"].GetInt32(10);
				Assert::AreEqual(10, dd2);
			}
		}
		[TestMethod]
		void RemoveNode()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa|bb|cc"].Create();
				int dd = 2000000000;
				elem[L"dd"].SetInt32(dd);
				int dd2 = elem[L"dd"].GetInt32(10);
				Assert::AreEqual(dd, dd2);

				elem[L"dd"].RemoveNode();
				dd2 = elem[L"dd"].GetInt32(10);
				Assert::AreEqual(10, dd2);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa|bb|cc"];
				Assert::IsTrue(elem2.Exists());

				dd2 = elem2[L"dd"].GetInt32(10);
				Assert::AreEqual(10, dd2);
			}
		}
		[TestMethod]
		void TestNamespaceUri1()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa|bb|yahoo:cc"].Create(L"http://www.example.com");
				int dd = 2000000000;
				Assert::IsTrue(elem.Exists());
				elem.Attribute(L"attr").Create(L"http://www.example.com");
				elem.Attribute(L"attr").SetInt32(dd);
				elem[L"dd"].Create(L"http://www.example.com");
				elem[L"dd"].SetInt32(dd);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa|bb|yahoo:cc"];
				Assert::IsTrue(elem2.Exists());

				int dd2 = elem2[L"dd"].GetInt32(10);
				Assert::AreEqual(dd, dd2);
				
				dd2 = elem2.Attribute(L"attr").GetInt32(10);
				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void TestDelimiter1()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa|bb|cc"].CreateNew();
				__int64 dd = 14000000000L;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt64(dd);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa|bb|cc"];
				Assert::IsTrue(elem2.Exists());

				__int64 dd2 = elem2[L"dd"].GetInt64(10);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void TestDelimiter2()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa\\bb\\cc"].CreateNew();
				__int64 dd = 14000000000L;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt64(dd);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa\\bb\\cc"];
				Assert::IsTrue(elem2.Exists());

				__int64 dd2 = elem2[L"dd"].GetInt64(10);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void TestDelimiter3()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa/bb/cc"].CreateNew();
				__int64 dd = 14000000000L;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt64(dd);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa/bb/cc"];
				Assert::IsTrue(elem2.Exists());

				__int64 dd2 = elem2[L"dd"].GetInt64(10);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void TestSelectSingleNode()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa/bb/cc"].CreateNew();
				int dd = 100;
				Assert::IsTrue(elem.Exists());
				elem.SetInt32(dd);

				Element elem2 = root[L"aa/bb/dd"].CreateNew();
				dd = 120;
				Assert::IsTrue(elem2.Exists());
				elem2.SetInt32(dd);

				Element singleNode = root.SelectSingleNode(L"//dd");

				Assert::AreEqual(120, singleNode.GetInt32(0));

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element singleNode2 = root2.SelectSingleNode(L"//dd");

				Assert::AreEqual(120, singleNode2.GetInt32(0));
			}
		}
		[TestMethod]
		void TestSelectNodes()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa/bb/cc"].CreateNew();
				int dd = 100;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt32(dd);

				Element elem2 = root[L"aa/bb/cc"].CreateNew();
				dd = 120;
				Assert::IsTrue(elem2.Exists());
				elem2[L"dd"].SetInt32(dd);

				Element elem3 = root[L"aa/bb/cc"].CreateNew();
				dd = 50;
				Assert::IsTrue(elem3.Exists());
				elem3[L"dd"].SetInt32(dd);

				std::vector<Element> nodes = root.SelectNodes(L"//cc[dd>50]");

				Assert::AreEqual((size_t)(2), nodes.size());
				Assert::AreEqual(100, nodes[0].GetInt32(0));
				Assert::AreEqual(120, nodes[1].GetInt32(0));

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				std::vector<Element> nodes2 = root2.SelectNodes(L"//cc[dd>50]");

				Assert::AreEqual((size_t)(2), nodes2.size());
				Assert::AreEqual(100, nodes2[0].GetInt32(0));
				Assert::AreEqual(120, nodes2[1].GetInt32(0));
			}
		}
		[TestMethod]
		void GetAttributes()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				bool dd = true;
				int dd2 = 123;
				Assert::IsTrue(elem.Exists());
				elem.Attribute(L"Attr1").SetBool(dd);
				elem.Attribute(L"Attr2").SetInt32(dd2);
				elem.Attribute(L"Attr3").SetString(L"Hello");

				std::vector<Elmax::Attribute> attrs = elem.GetAttributes();
				Assert::AreEqual(gcnew System::String(L"Attr1"), gcnew System::String(attrs[0].GetName().c_str()));
				Assert::AreEqual(gcnew System::String(L"Attr2"), gcnew System::String(attrs[1].GetName().c_str()));
				Assert::AreEqual(gcnew System::String(L"Attr3"), gcnew System::String(attrs[2].GetName().c_str()));

				Assert::AreEqual(dd, attrs[0].GetBool(false));
				Assert::AreEqual(dd2, attrs[1].GetInt32(0));
				Assert::AreEqual( gcnew System::String(L"Hello"), gcnew System::String(attrs[2].GetString(L"").c_str()) );

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element elem2 = root2[L"aa"][L"bb"][L"cc"];
				Assert::IsTrue(elem2.Exists());

				std::vector<Elmax::Attribute> attrs2 = elem2.GetAttributes();
				Assert::AreEqual(gcnew System::String(L"Attr1"), gcnew System::String(attrs2[0].GetName().c_str()));
				Assert::AreEqual(gcnew System::String(L"Attr2"), gcnew System::String(attrs2[1].GetName().c_str()));
				Assert::AreEqual(gcnew System::String(L"Attr3"), gcnew System::String(attrs2[2].GetName().c_str()));

				Assert::AreEqual(dd, attrs2[0].GetBool(false));
				Assert::AreEqual(dd2, attrs2[1].GetInt32(0));
				Assert::AreEqual( gcnew System::String(L"Hello"), gcnew System::String(attrs2[2].GetString(L"").c_str()) );
			}
		}
		[TestMethod]
		void TestDocSelectSingleNode()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa/bb/cc"].CreateNew();
				int dd = 100;
				Assert::IsTrue(elem.Exists());
				elem.SetInt32(dd);

				Element elem2 = root[L"aa/bb/dd"].CreateNew();
				dd = 120;
				Assert::IsTrue(elem2.Exists());
				elem2.SetInt32(dd);

				Document elmaxDoc(pDoc);

				Element singleNode = elmaxDoc.SelectSingleNode(L"//dd");

				Assert::AreEqual(120, singleNode.GetInt32(0));

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Document elmaxDoc2(pDoc2);
				Element singleNode2 = elmaxDoc2.SelectSingleNode(L"//dd");

				Assert::AreEqual(120, singleNode2.GetInt32(0));
			}
		}
		[TestMethod]
		void TestDocSelectNodes()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa/bb/cc"].CreateNew();
				int dd = 100;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt32(dd);

				Element elem2 = root[L"aa/bb/cc"].CreateNew();
				dd = 120;
				Assert::IsTrue(elem2.Exists());
				elem2[L"dd"].SetInt32(dd);

				Element elem3 = root[L"aa/bb/cc"].CreateNew();
				dd = 50;
				Assert::IsTrue(elem3.Exists());
				elem3[L"dd"].SetInt32(dd);

				Document elmaxDoc(pDoc);
				std::vector<Element> nodes = elmaxDoc.SelectNodes(L"//cc[dd>50]");

				Assert::AreEqual((size_t)(2), nodes.size());
				Assert::AreEqual(100, nodes[0].GetInt32(0));
				Assert::AreEqual(120, nodes[1].GetInt32(0));

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Document elmaxDoc2(pDoc2);

				std::vector<Element> nodes2 = elmaxDoc2.SelectNodes(L"//cc[dd>50]");

				Assert::AreEqual((size_t)(2), nodes2.size());
				Assert::AreEqual(100, nodes2[0].GetInt32(0));
				Assert::AreEqual(120, nodes2[1].GetInt32(0));
			}
		}
		[TestMethod]
		void TestDocGetElementsByTagName()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem = root[L"aa/bb/cc"].CreateNew();
				int dd = 100;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt32(dd);

				Element elem2 = root[L"aa/bb/cc"].CreateNew();
				dd = 120;
				Assert::IsTrue(elem2.Exists());
				elem2[L"dd"].SetInt32(dd);

				Element elem3 = root[L"aa/bb/cc"].CreateNew();
				dd = 50;
				Assert::IsTrue(elem3.Exists());
				elem3[L"dd"].SetInt32(dd);

				Document elmaxDoc(pDoc);
				std::vector<Element> nodes = elmaxDoc.GetElementsByTagName(L"dd");

				Assert::AreEqual((size_t)(3), nodes.size());
				Assert::AreEqual(100, nodes[0].GetInt32(0));
				Assert::AreEqual(120, nodes[1].GetInt32(0));
				Assert::AreEqual(50, nodes[2].GetInt32(0));

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Document elmaxDoc2(pDoc2);

				std::vector<Element> nodes2 = elmaxDoc2.GetElementsByTagName(L"dd");

				Assert::AreEqual((size_t)(3), nodes2.size());
				Assert::AreEqual(100, nodes2[0].GetInt32(0));
				Assert::AreEqual(120, nodes2[1].GetInt32(0));
				Assert::AreEqual(50, nodes2[2].GetInt32(0));
			}
		}
		[TestMethod]
		void EmptyAsCollection()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa"].CreateNew();
				elem1.SetInt32(11);

				bool bExceptionThrown = false;
				try
				{
					Element::collection_t vec = root[L"aa"][L"bb"].AsCollection();

					Assert::AreEqual((size_t)(0), vec.size());
				}
				catch (std::exception e)
				{
					bExceptionThrown = true;
				}
				Assert::IsTrue(bExceptionThrown);
				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				bExceptionThrown = false;
				try
				{
					Element::collection_t vec2 = root2[L"aa"][L"bb"].AsCollection();

					Assert::AreEqual((size_t)(0), vec2.size());
				}
				catch (std::exception e)
				{
					bExceptionThrown = true;
				}
			}
		}
		[TestMethod]
		void EmptyGetCollection()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb"].CreateNew();
				elem1.SetInt32(11);

				Element::collection_t vec = root[L"aa"][L"bb"].GetCollection(L"cc");

				Assert::AreEqual((size_t)(0), vec.size());

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::collection_t vec2 = root2[L"aa"][L"bb"].GetCollection(L"cc");

				Assert::AreEqual((size_t)(0), vec2.size());
			}
		}
		[TestMethod]
		void EmptyQueryChildrenNum()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				root[L"aa"].CreateNew();

				Element::available_child_t acmap = root[L"aa"].QueryChildrenNum();

				Assert::AreEqual((size_t)(0), acmap.size());

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				Element::available_child_t acmap2 = root2[L"aa"].QueryChildrenNum();

				Assert::AreEqual((size_t)(0), acmap2.size());
			}
		}
		[TestMethod]
		void InvalidElementGetCollection()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa"].CreateNew();
				elem1.SetInt32(11);

				bool bExceptionThrown = false;
				try
				{
					Element::collection_t vec = root[L"aa"][L"bb"].GetCollection(L"cc");

					Assert::AreEqual((size_t)(0), vec.size());
				}
				catch (std::exception e)
				{
					bExceptionThrown = true;
				}
				Assert::IsTrue(bExceptionThrown);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				bExceptionThrown = false;
				try
				{
					Element::collection_t vec2 = root2[L"aa"][L"bb"].GetCollection(L"cc");

					Assert::AreEqual((size_t)(0), vec2.size());
				}
				catch (std::exception e)
				{
					bExceptionThrown = true;
				}
				Assert::IsTrue(bExceptionThrown);
			}
		}
		[TestMethod]
		void InvalidElementQueryChildrenNum()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				root[L"aa"].CreateNew();

				bool bExceptionThrown = false;
				try
				{
					Element::available_child_t acmap = root[L"aa|bb"].QueryChildrenNum();

					Assert::AreEqual((size_t)(0), acmap.size());
				}
				catch (std::exception e)
				{
					bExceptionThrown = true;
				}
				Assert::IsTrue(bExceptionThrown);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				bExceptionThrown = false;
				try
				{
					Element::available_child_t acmap2 = root2[L"aa|bb"].QueryChildrenNum();

					Assert::AreEqual((size_t)(0), acmap2.size());
				}
				catch (std::exception e)
				{
					bExceptionThrown = true;
				}
				Assert::IsTrue(bExceptionThrown);
			}
		}
		[TestMethod]
		void HyperElementJoinOneToOne()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);

				Element elem4 = root[L"dd|ee"].CreateNew();
				elem4.Attribute(L"SomeValue").SetInt32(11);
				Element elem5 = root[L"dd|ee"].CreateNew();
				elem5.Attribute(L"SomeValue").SetInt32(22);
				Element elem6 = root[L"dd|ee"].CreateNew();
				elem6.Attribute(L"SomeValue").SetInt32(33);

				std::vector< std::pair<Elmax::Element, Elmax::Element> > vec =
				HyperElement::JoinOneToOne(elem1.AsCollection(), L"", elem4.AsCollection(), L"SomeValue", false);

				Assert::AreEqual(vec.size(), 3U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).first.GetInt32(10), vec.at(i).second.Attribute(L"SomeValue").GetInt32(11));
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				std::vector< std::pair<Elmax::Element, Elmax::Element> > vec2 =
					HyperElement::JoinOneToOne(root2[L"aa|bb|cc"].AsCollection(), L"", 
					root2[L"dd|ee"].AsCollection(), L"SomeValue", false);

				Assert::AreEqual(vec2.size(), 3U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).first.GetInt32(10), vec2.at(i).second.Attribute(L"SomeValue").GetInt32(11));
				}
			}
		}
		[TestMethod]
		void HyperElementJoinOneToMany()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);

				Element elem4 = root[L"dd|ee"].CreateNew();
				elem4.Attribute(L"SomeValue").SetInt32(11);
				Element elem5 = root[L"dd|ee"].CreateNew();
				elem5.Attribute(L"SomeValue").SetInt32(22);
				Element elem6 = root[L"dd|ee"].CreateNew();
				elem6.Attribute(L"SomeValue").SetInt32(33);
				Element elem7 = root[L"dd|ee"].CreateNew();
				elem7.Attribute(L"SomeValue").SetInt32(11);
				Element elem8 = root[L"dd|ee"].CreateNew();
				elem8.Attribute(L"SomeValue").SetInt32(22);
				Element elem9 = root[L"dd|ee"].CreateNew();
				elem9.Attribute(L"SomeValue").SetInt32(33);
				Element elem10 = root[L"dd|ee"].CreateNew();
				elem10.Attribute(L"SomeValue").SetInt32(11);
				Element elem11 = root[L"dd|ee"].CreateNew();
				elem11.Attribute(L"SomeValue").SetInt32(22);
				Element elem12 = root[L"dd|ee"].CreateNew();
				elem12.Attribute(L"SomeValue").SetInt32(33);

				std::vector< std::pair<Elmax::Element, std::vector<Elmax::Element> > > vec =
					HyperElement::JoinOneToMany(elem1.AsCollection(), L"", elem4.AsCollection(), L"SomeValue", false);

				Assert::AreEqual(vec.size(), 3U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).second.size(), 3U);
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				std::vector< std::pair<Elmax::Element, std::vector<Elmax::Element> > > vec2 =
					HyperElement::JoinOneToMany(root2[L"aa|bb|cc"].AsCollection(), L"", 
					root2[L"dd|ee"].AsCollection(), L"SomeValue", false);

				Assert::AreEqual(vec2.size(), 3U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).second.size(), 3U);
				}
			}
		}
		[TestMethod]
		void HyperElementJoinOneToOnePred()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);

				Element elem4 = root[L"dd|ee"].CreateNew();
				elem4.Attribute(L"SomeValue").SetInt32(11);
				Element elem5 = root[L"dd|ee"].CreateNew();
				elem5.Attribute(L"SomeValue").SetInt32(22);
				Element elem6 = root[L"dd|ee"].CreateNew();
				elem6.Attribute(L"SomeValue").SetInt32(33);

				DoubleElementPred pred;
				std::vector< std::pair<Elmax::Element, Elmax::Element> > vec =
					HyperElement::JoinOneToOne(elem1.AsCollection(), elem4.AsCollection(), pred);

				Assert::AreEqual(vec.size(), 3U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).first.GetInt32(10), vec.at(i).second.Attribute(L"SomeValue").GetInt32(11));
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				std::vector< std::pair<Elmax::Element, Elmax::Element> > vec2 =
					HyperElement::JoinOneToOne(root2[L"aa|bb|cc"].AsCollection(), 
					root2[L"dd|ee"].AsCollection(), pred);

				Assert::AreEqual(vec2.size(), 3U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).first.GetInt32(10), vec2.at(i).second.Attribute(L"SomeValue").GetInt32(11));
				}
			}
		}
		[TestMethod]
		void HyperElementJoinOneToManyPred()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb|cc"].CreateNew();
				elem1.SetInt32(11);
				Element elem2 = root[L"aa|bb|cc"].CreateNew();
				elem2.SetInt32(22);
				Element elem3 = root[L"aa|bb|cc"].CreateNew();
				elem3.SetInt32(33);

				Element elem4 = root[L"dd|ee"].CreateNew();
				elem4.Attribute(L"SomeValue").SetInt32(11);
				Element elem5 = root[L"dd|ee"].CreateNew();
				elem5.Attribute(L"SomeValue").SetInt32(22);
				Element elem6 = root[L"dd|ee"].CreateNew();
				elem6.Attribute(L"SomeValue").SetInt32(33);
				Element elem7 = root[L"dd|ee"].CreateNew();
				elem7.Attribute(L"SomeValue").SetInt32(11);
				Element elem8 = root[L"dd|ee"].CreateNew();
				elem8.Attribute(L"SomeValue").SetInt32(22);
				Element elem9 = root[L"dd|ee"].CreateNew();
				elem9.Attribute(L"SomeValue").SetInt32(33);
				Element elem10 = root[L"dd|ee"].CreateNew();
				elem10.Attribute(L"SomeValue").SetInt32(11);
				Element elem11 = root[L"dd|ee"].CreateNew();
				elem11.Attribute(L"SomeValue").SetInt32(22);
				Element elem12 = root[L"dd|ee"].CreateNew();
				elem12.Attribute(L"SomeValue").SetInt32(33);

				DoubleElementPred pred;
				std::vector< std::pair<Elmax::Element, std::vector<Elmax::Element> > > vec =
					HyperElement::JoinOneToMany(elem1.AsCollection(), elem4.AsCollection(), pred);

				Assert::AreEqual(vec.size(), 3U);
				for(size_t i=0;i<vec.size(); ++i)
				{
					Assert::AreEqual(vec.at(i).second.size(), 3U);
				}

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				std::vector< std::pair<Elmax::Element, std::vector<Elmax::Element> > > vec2 =
					HyperElement::JoinOneToMany(root2[L"aa|bb|cc"].AsCollection(), 
					root2[L"dd|ee"].AsCollection(), pred);

				Assert::AreEqual(vec2.size(), 3U);
				for(size_t i=0;i<vec2.size(); ++i)
				{
					Assert::AreEqual(vec2.at(i).second.size(), 3U);
				}
			}
		}
		[TestMethod]
		void DoubleRoot()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|aa"].CreateNew();
				elem1.SetInt32(11);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				int x = root2[L"aa"][L"aa"].GetInt32(0);

				Assert::AreEqual(x, 11);

				x = root2[L"aa"].GetInt32(0);

				Assert::AreEqual(x, 11);
			}
		}
		[TestMethod]
		void DoubleRoot2()
		{
			MSXML2::IXMLDOMDocumentPtr pDoc;
			HRESULT hr = CreateAndInitDom(pDoc);
			if (SUCCEEDED(hr))
			{
				using namespace Elmax;
				Element root;
				root.SetConverter(NORMAL_CONV);
				root.SetDomDoc(pDoc);

				Element elem1 = root[L"aa|bb"].CreateNew();
				elem1.SetInt32(11);

				MSXML2::IXMLDOMDocumentPtr pDoc2;
				BSTR xml;
				pDoc->get_xml(&xml);
				std::wstring strXML = (LPCWSTR)(xml);
				SysFreeString(xml);
				Assert::IsTrue(CreateAndLoadXmlString(pDoc2, strXML));

				// root2 does not have any tag name associated with it.
				Element root2;
				root2.SetConverter(NORMAL_CONV);
				root2.SetDomDoc(pDoc2);

				// root2 has tag name "aa" associated with it.
				int x = root2[L"aa"][L"bb"].GetInt32(0);

				Assert::AreEqual(x, 11);

				// Since root2 is associated with tag name "aa",
				// we need not reference "aa" to get "bb".
				x = root2[L"bb"].GetInt32(0);

				Assert::AreEqual(x, 11);
			}
		}

	};
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Shao Voon Wong
Software Developer
Singapore Singapore
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.140905.1 | Last Updated 7 Jun 2012
Article Copyright 2011 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid