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

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

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

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

namespace TestNativeElmax
{
	[TestClass]
	public ref class UnitTestSetterGetter
	{
	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;
		}
	public: 
		[TestMethod]
		void SetGetDateTime()
		{
			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();
				DateAndTime dd(2006, 7, 23, 9, 0, 23);
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetDateTime(dd);
				DateAndTime ddcheck;
				DateAndTime dd3 = elem[L"dd"].GetDateTime(ddcheck);

				Assert::AreEqual(dd.GetYear(), dd3.GetYear());
				Assert::AreEqual(dd.GetMonth(), dd3.GetMonth());
				Assert::AreEqual(dd.GetMonthDay(), dd3.GetMonthDay());
				Assert::AreEqual(dd.GetHour(), dd3.GetHour());
				Assert::AreEqual(dd.GetMinute(), dd3.GetMinute());
				Assert::AreEqual(dd.GetSecond(), dd3.GetSecond());
			}
		}
		[TestMethod]
		void SetGetDate()
		{
			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();
				Date dd(2010, 10, 1);
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetDate(dd);
				Date ddcheck;
				Date dd3 = elem[L"dd"].GetDate(ddcheck);

				Assert::AreEqual(dd.GetYear(), dd3.GetYear());
				Assert::AreEqual(dd.GetMonth(), dd3.GetMonth());
				Assert::AreEqual(dd.GetMonthDay(), dd3.GetMonthDay());
			}
		}
		[TestMethod]
		void SetGetGUID()
		{
			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();
				GUID dd;
				CoCreateGuid(&dd);
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetGUID(dd);
				GUID random1;
				CoCreateGuid(&random1);
				GUID dd3 = elem[L"dd"].GetGUID(random1);

				Assert::AreEqual(dd.Data1, dd3.Data1);
				Assert::AreEqual(dd.Data2, dd3.Data2);
				Assert::AreEqual(dd.Data3, dd3.Data3);
				Assert::AreEqual(dd.Data4[0], dd3.Data4[0]);
				Assert::AreEqual(dd.Data4[1], dd3.Data4[1]);
				Assert::AreEqual(dd.Data4[2], dd3.Data4[2]);
				Assert::AreEqual(dd.Data4[3], dd3.Data4[3]);
				Assert::AreEqual(dd.Data4[4], dd3.Data4[4]);
				Assert::AreEqual(dd.Data4[5], dd3.Data4[5]);
				Assert::AreEqual(dd.Data4[6], dd3.Data4[6]);
				Assert::AreEqual(dd.Data4[7], dd3.Data4[7]);
			}
		}
		[TestMethod]
		void SetGetGUIDNoBraces()
		{
			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();
				GUID dd;
				CoCreateGuid(&dd);
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetGUID(dd, true);
				GUID random1;
				CoCreateGuid(&random1);
				GUID dd3 = elem[L"dd"].GetGUID(random1);

				Assert::AreEqual(dd.Data1, dd3.Data1);
				Assert::AreEqual(dd.Data2, dd3.Data2);
				Assert::AreEqual(dd.Data3, dd3.Data3);
				Assert::AreEqual(dd.Data4[0], dd3.Data4[0]);
				Assert::AreEqual(dd.Data4[1], dd3.Data4[1]);
				Assert::AreEqual(dd.Data4[2], dd3.Data4[2]);
				Assert::AreEqual(dd.Data4[3], dd3.Data4[3]);
				Assert::AreEqual(dd.Data4[4], dd3.Data4[4]);
				Assert::AreEqual(dd.Data4[5], dd3.Data4[5]);
				Assert::AreEqual(dd.Data4[6], dd3.Data4[6]);
				Assert::AreEqual(dd.Data4[7], dd3.Data4[7]);
			}
		}
		[TestMethod]
		void SetGetBoolean()
		{
			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;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetBool(dd);

				bool dd2 = elem[L"dd"].GetBool(false);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetInt64()
		{
			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();
				__int64 dd = 14000000000L;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt64(dd);

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

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetInt()
		{
			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();
				int dd = 2000000000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt32(dd);

				int dd2 = elem[L"dd"].GetInt32(10);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetShort()
		{
			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();
				short dd = 32000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt16(dd);

				short dd2 = elem[L"dd"].GetInt16(10);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetChar()
		{
			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();
				char dd = 'A';
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt8(dd);

				char dd2 = elem[L"dd"].GetInt8('P');

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetUInt64()
		{
			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();
				unsigned __int64 dd = 14000000000UL;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetUInt64(dd);

				unsigned __int64 dd2 = elem[L"dd"].GetUInt64(10);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetUInt()
		{
			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();
				unsigned int dd = 4000000000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetUInt32(dd);

				unsigned int dd2 = elem[L"dd"].GetUInt32(10);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetUShort()
		{
			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();
				unsigned short dd = 65000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetUInt16(dd);

				unsigned short dd2 = elem[L"dd"].GetUInt16(10);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetUChar()
		{
			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();
				unsigned char dd = 255;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetUInt8(dd);

				unsigned char dd2 = elem[L"dd"].GetUInt8(12);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetAString()
		{
			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();
				std::string dd = "ABCD";
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetString(dd);

				std::string dd2 = elem[L"dd"].GetString("A");

				System::String^ s1 = gcnew System::String(dd.c_str());
				System::String^ s2 = gcnew System::String(dd2.c_str());

				Assert::AreEqual(s1, s2);
			}
		}
		[TestMethod]
		void SetGetWString()
		{
			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();
				std::wstring dd = L"ABCD";
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetString(dd);

				std::wstring dd2 = elem[L"dd"].GetString(L"A");

				System::String^ s1 = gcnew System::String(dd.c_str());
				System::String^ s2 = gcnew System::String(dd2.c_str());

				Assert::AreEqual(s1, s2);
			}
		}
		[TestMethod]
		void SetGetDouble()
		{
			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();
				double dd = 123.0;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetDouble(dd);

				double dd2 = elem[L"dd"].GetDouble(10.0);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetFloat()
		{
			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();
				float dd = 123.0f;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetFloat(dd);

				float dd2 = elem[L"dd"].GetFloat(10.0f);

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetDateTimeImplicit()
		{
			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();
				DateAndTime dd(2006, 7, 23, 9, 0, 23);
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;
				DateAndTime dd3 = elem[L"dd"];

				Assert::AreEqual(dd.GetYear(), dd3.GetYear());
				Assert::AreEqual(dd.GetMonth(), dd3.GetMonth());
				Assert::AreEqual(dd.GetMonthDay(), dd3.GetMonthDay());
				Assert::AreEqual(dd.GetHour(), dd3.GetHour());
				Assert::AreEqual(dd.GetMinute(), dd3.GetMinute());
				Assert::AreEqual(dd.GetSecond(), dd3.GetSecond());
			}
		}
		[TestMethod]
		void SetGetDateImplicit()
		{
			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();
				Date dd(2010, 10, 1);
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;
				Date dd3 = elem[L"dd"];

				Assert::AreEqual(dd.GetYear(), dd3.GetYear());
				Assert::AreEqual(dd.GetMonth(), dd3.GetMonth());
				Assert::AreEqual(dd.GetMonthDay(), dd3.GetMonthDay());
			}
		}
		[TestMethod]
		void SetGetGUIDImplicit()
		{
			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();
				GUID dd;
				CoCreateGuid(&dd);
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;
				GUID dd3 = elem[L"dd"];

				Assert::AreEqual(dd.Data1, dd3.Data1);
				Assert::AreEqual(dd.Data2, dd3.Data2);
				Assert::AreEqual(dd.Data3, dd3.Data3);
				Assert::AreEqual(dd.Data4[0], dd3.Data4[0]);
				Assert::AreEqual(dd.Data4[1], dd3.Data4[1]);
				Assert::AreEqual(dd.Data4[2], dd3.Data4[2]);
				Assert::AreEqual(dd.Data4[3], dd3.Data4[3]);
				Assert::AreEqual(dd.Data4[4], dd3.Data4[4]);
				Assert::AreEqual(dd.Data4[5], dd3.Data4[5]);
				Assert::AreEqual(dd.Data4[6], dd3.Data4[6]);
				Assert::AreEqual(dd.Data4[7], dd3.Data4[7]);
			}
		}
		[TestMethod]
		void SetGetInt64Implicit()
		{
			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();
				__int64 dd = 14000000000L;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				__int64 dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetIntImplicit()
		{
			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();
				int dd = 2000000000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				int dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetShortImplicit()
		{
			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();
				short dd = 32000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				short dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetCharImplicit()
		{
			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();
				char dd = 'A';
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				char dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetUInt64Implicit()
		{
			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();
				unsigned __int64 dd = 14000000000UL;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				unsigned __int64 dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetUIntImplicit()
		{
			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();
				unsigned int dd = 4000000000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				unsigned int dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetUShortImplicit()
		{
			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();
				unsigned short dd = 65000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				unsigned short dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetUCharImplicit()
		{
			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();
				unsigned char dd = 255;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				unsigned char dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetAStringImplicit()
		{
			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();
				std::string dd = "ABCD";
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				std::string dd2 = elem[L"dd"];

				System::String^ s1 = gcnew System::String(dd.c_str());
				System::String^ s2 = gcnew System::String(dd2.c_str());

				Assert::AreEqual(s1, s2);
			}
		}
		[TestMethod]
		void SetGetWStringImplicit()
		{
			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();
				std::wstring dd = L"ABCD";
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				std::wstring dd2 = elem[L"dd"];

				System::String^ s1 = gcnew System::String(dd.c_str());
				System::String^ s2 = gcnew System::String(dd2.c_str());

				Assert::AreEqual(s1, s2);
			}
		}
		[TestMethod]
		void SetGetDoubleImplicit()
		{
			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();
				double dd = 123.0;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				double dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
		[TestMethod]
		void SetGetFloatImplicit()
		{
			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();
				float dd = 123.0f;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				float dd2 = elem[L"dd"];

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				bool dd = true;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetBool(dd);

				bool dd2 = elem[L"dd"].GetBool(false);

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

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

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

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

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

				int dd2 = elem[L"dd"].GetInt32(10);

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				short dd = 32000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt16(dd);

				short dd2 = elem[L"dd"].GetInt16(10);

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				char dd = 'A';
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetInt8(dd);

				char dd2 = elem[L"dd"].GetInt8('P');

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

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

				unsigned __int64 dd2 = elem[L"dd"].GetUInt64(10);

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				unsigned int dd = 4000000000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetUInt32(dd);

				unsigned int dd2 = elem[L"dd"].GetUInt32(10);

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				unsigned short dd = 65000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetUInt16(dd);

				unsigned short dd2 = elem[L"dd"].GetUInt16(10);

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				unsigned char dd = 255;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetUInt8(dd);

				unsigned char dd2 = elem[L"dd"].GetUInt8(12);

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				std::string dd = "ABCD";
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetString(dd);

				std::string dd2 = elem[L"dd"].GetString("A");

				System::String^ s1 = gcnew System::String(dd.c_str());
				System::String^ s2 = gcnew System::String(dd2.c_str());

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				std::wstring dd = L"ABCD";
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetString(dd);

				std::wstring dd2 = elem[L"dd"].GetString(L"A");

				System::String^ s1 = gcnew System::String(dd.c_str());
				System::String^ s2 = gcnew System::String(dd2.c_str());

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				double dd = 123.0;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetDouble(dd);

				double dd2 = elem[L"dd"].GetDouble(10.0);

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				float dd = 123.0f;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"].SetFloat(dd);

				float dd2 = elem[L"dd"].GetFloat(10.0f);

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

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

				__int64 dd2 = elem[L"dd"];

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

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

				int dd2 = elem[L"dd"];

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				short dd = 32000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				short dd2 = elem[L"dd"];

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				char dd = 'A';
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				char dd2 = elem[L"dd"];

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

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

				unsigned __int64 dd2 = elem[L"dd"];

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

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

				unsigned int dd2 = elem[L"dd"];

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				unsigned short dd = 65000;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				unsigned short dd2 = elem[L"dd"];

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				unsigned char dd = 255;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				unsigned char dd2 = elem[L"dd"];

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				std::string dd = "ABCD";
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				std::string dd2 = elem[L"dd"];

				System::String^ s1 = gcnew System::String(dd.c_str());
				System::String^ s2 = gcnew System::String(dd2.c_str());

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				std::wstring dd = L"ABCD";
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				std::wstring dd2 = elem[L"dd"];

				System::String^ s1 = gcnew System::String(dd.c_str());
				System::String^ s2 = gcnew System::String(dd2.c_str());

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				double dd = 123.0;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				double dd2 = elem[L"dd"];

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

				Element elem = root[L"aa"][L"bb"][L"cc"].CreateNew();
				float dd = 123.0f;
				Assert::IsTrue(elem.Exists());
				elem[L"dd"] = dd;

				float dd2 = elem[L"dd"];

				Assert::AreEqual(dd, dd2);
			}
		}
	};
}

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)

About the Author

SV Wong
Software Developer
Singapore Singapore

Currently into areas like 3D graphics and application security. Hoping to revisit the cryptography and design pattern topics if time permits.


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