00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <spl/Debug.h>
00018
00019 #ifdef DEBUG
00020 #include <spl/configuration/ConfigurationSettings.h>
00021 #include <spl/Log.h>
00022 #include <spl/xml/XmlElement.h>
00023
00024 static const char *_xmlConfigTestStr = "<?xml version=\"1.0\"?>\n<configuration><appSettings><add key=\"KEY1\" value=\"VALUE1\" /></appSettings></configuration>";
00025
00026 static void _TestConfigSettings1()
00027 {
00028 ConfigurationSettings *cs = new ConfigurationSettings();
00029
00030 XmlDocumentPtr doc = XmlDocument::ParseXml(_xmlConfigTestStr);
00031 cs->Load(doc);
00032
00033 DEBUG_CLEAR_MEM_CHECK_POINTS();
00034 DEBUG_NOTE_MEM(cs);
00035 cs->CheckMem();
00036 doc.CheckMem();
00037 DEBUG_DUMP_MEM_LEAKS();
00038 UNIT_ASSERT_MEM_NOTED("ConfigurationSettings 1.0");
00039
00040 UNIT_ASSERT("Lookup", *cs->Value("appSettings", "KEY1") == "VALUE1");
00041
00042 delete cs;
00043 doc.ValidateMem();
00044
00045 DEBUG_CLEAR_MEM_CHECK_POINTS();
00046 doc.CheckMem();
00047 DEBUG_DUMP_MEM_LEAKS();
00048 UNIT_ASSERT_MEM_NOTED("ConfigurationSettings 1.2");
00049 Log::SWriteOkFail( "ConfigurationSettings 1" );
00050 }
00051
00052 static void _TestConfigSettingsToString()
00053 {
00054 ConfigurationSettings cs;
00055
00056 XmlDocumentPtr doc = XmlDocument::ParseXml(_xmlConfigTestStr);
00057 cs.Load(doc);
00058
00059 StringPtr xml(cs.ToXmlString());
00060
00061 doc = XmlDocument::ParseXml(xml);
00062 XmlNodePtr as(doc->SelectSingleNode("//appSettings"));
00063 UNIT_ASSERT("appSettings node", as.IsNotNull());
00064 UNIT_ASSERT("appSettings node", as->FirstChild()->ToElement()->Name().Equals("add"));
00065
00066 Log::SWriteOkFail( "ConfigurationSettings ToXmlString" );
00067 }
00068
00069 void _TestConfigSettings()
00070 {
00071 _TestConfigSettings1();
00072 DEBUG_CLEAR_MEM_CHECK_POINTS();
00073 DEBUG_DUMP_MEM_LEAKS();
00074
00075 _TestConfigSettingsToString();
00076 DEBUG_CLEAR_MEM_CHECK_POINTS();
00077 DEBUG_DUMP_MEM_LEAKS();
00078 }
00079
00080 #endif