• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

test/TestConfigSettings.cpp

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
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