Index: src/libchengine/ConfigNodeContainer.cpp =================================================================== diff -u -N -r0d5b67ee96b435d63f7bf075dc8e28603793b187 -r782902eb6d63ccceb0c1f3808403a23b8372d66f --- src/libchengine/ConfigNodeContainer.cpp (.../ConfigNodeContainer.cpp) (revision 0d5b67ee96b435d63f7bf075dc8e28603793b187) +++ src/libchengine/ConfigNodeContainer.cpp (.../ConfigNodeContainer.cpp) (revision 782902eb6d63ccceb0c1f3808403a23b8372d66f) @@ -285,7 +285,6 @@ { bool bFound = false; TString strReplace(pszNode); - strReplace += _T("["); boost::shared_lock<boost::shared_mutex> lock(m_lock); @@ -300,13 +299,23 @@ TString strName = iter->m_strNodeName.Get(); strName.MidSelf(strReplace.GetLength()); - size_t stPos = strName.Find(_T("]")); - if (stPos == std::numeric_limits<size_t>::max()) - throw TCoreException(eErr_InvalidData, L"] character not found", LOCATION); - if (strName.GetAt(stPos + 1) != _T('.')) - throw TCoreException(eErr_InvalidData, L". character not found", LOCATION); - size_t stNodeIndex = boost::lexical_cast<size_t>(strName.Left(stPos)); + size_t stNodeIndex = 0; + if (strName.StartsWith(L"[")) + { + size_t stPos = strName.Find(_T("]")); + if (stPos == std::numeric_limits<size_t>::max()) + throw TCoreException(eErr_InvalidData, L"] character not found", LOCATION); + if (strName.GetAt(stPos + 1) != _T('.')) + throw TCoreException(eErr_InvalidData, L". character not found", LOCATION); + + stNodeIndex = boost::lexical_cast<size_t>(strName.Mid(1, stPos - 1)); + + strName.Delete(0, stPos + 2); // skip "]." at the beginning + } + else + strName.Delete(0, 1); // skip "." at the beginning + if (stNodeIndex != stLastIndex) { tNewContainers.push_back(ConfigNodeContainer()); @@ -315,7 +324,6 @@ stLastIndex = stNodeIndex; } - strName.Delete(0, stPos + 2); // skip "]." at the beginning if (!pCurrentContainer) throw TCoreException(eErr_InvalidPointer, L"pCurrentContainer", LOCATION); Index: src/libchengine/Tests/TestsTConfig.cpp =================================================================== diff -u -N -r07f5ed57f11f0b908313f692fc4830401f0db552 -r782902eb6d63ccceb0c1f3808403a23b8372d66f --- src/libchengine/Tests/TestsTConfig.cpp (.../TestsTConfig.cpp) (revision 07f5ed57f11f0b908313f692fc4830401f0db552) +++ src/libchengine/Tests/TestsTConfig.cpp (.../TestsTConfig.cpp) (revision 782902eb6d63ccceb0c1f3808403a23b8372d66f) @@ -116,6 +116,12 @@ <Name>SecondName</Name>\ </Object>\ </CompositeObjects>\ + <SingleObject>\ + <Object>\ + <Path><WINDOWS>\\FirstPath</Path>\ + <Name>FirstName</Name>\ + </Object>\ + </SingleObject>\ </Core>\ </CHConfig>"; @@ -583,11 +589,8 @@ m_cfg.WriteToString(wstrWithDeletion); EXPECT_EQ(TString(_T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\ -<CHConfig><Core><AutosaveInterval>30000</AutosaveInterval>\ -<CompositeObjects><Object><Name>FirstName</Name><Path><WINDOWS>\\FirstPath</Path></Object><Object><Name>SecondName</Name><Path><WINDOWS>\\SecondPath</Path></Object></CompositeObjects>\ -<Notifications><PathList><Path>c:\\Windows\\System32</Path><Path>d:\\Movies</Path><Path>x:\\Music</Path><Path>s:\\projects\\ch-rw</Path></PathList>\ -<Sounds><Enable>true</Enable><ErrorSoundPath><WINDOWS>\\media\\chord.wav</ErrorSoundPath>\ -<FinishedSoundPath><WINDOWS>\\\x597D\x8FD0\\ding.wav</FinishedSoundPath></Sounds></Notifications></Core></CHConfig>")), wstrWithDeletion); +<CHConfig><Core><AutosaveInterval>30000</AutosaveInterval><CompositeObjects><Object><Name>FirstName</Name><Path><WINDOWS>\\FirstPath</Path></Object><Object><Name>SecondName</Name><Path><WINDOWS>\\SecondPath</Path></Object></CompositeObjects><Notifications><PathList><Path>c:\\Windows\\System32</Path><Path>d:\\Movies</Path><Path>x:\\Music</Path><Path>s:\\projects\\ch-rw</Path></PathList><Sounds><Enable>true</Enable><ErrorSoundPath><WINDOWS>\\media\\chord.wav</ErrorSoundPath><FinishedSoundPath><WINDOWS>\\\x597D\x8FD0\\ding.wav</FinishedSoundPath></Sounds></Notifications><SingleObject><Object><Name>FirstName</Name><Path><WINDOWS>\\FirstPath</Path></Object></SingleObject></Core></CHConfig>")), + wstrWithDeletion); } /////////////////////////////////////////////////////////////////////////// @@ -599,8 +602,8 @@ m_cfg.WriteToString(wstrWithDeletion); EXPECT_EQ(TString(_T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\ -<CHConfig><Core><AutosaveInterval>30000</AutosaveInterval><CompositeObjects><Object><Name>FirstName</Name><Path><WINDOWS>\\FirstPath</Path></Object>\ -<Object><Name>SecondName</Name><Path><WINDOWS>\\SecondPath</Path></Object></CompositeObjects></Core></CHConfig>")), wstrWithDeletion); +<CHConfig><Core><AutosaveInterval>30000</AutosaveInterval><CompositeObjects><Object><Name>FirstName</Name><Path><WINDOWS>\\FirstPath</Path></Object><Object><Name>SecondName</Name><Path><WINDOWS>\\SecondPath</Path></Object></CompositeObjects><SingleObject><Object><Name>FirstName</Name><Path><WINDOWS>\\FirstPath</Path></Object></SingleObject></Core></CHConfig>")), + wstrWithDeletion); } /////////////////////////////////////////////////////////////////////////// @@ -628,6 +631,18 @@ EXPECT_EQ(TString(_T("<WINDOWS>\\SecondPath")), cfgSubArray.GetAt(1).GetString(_T("Path"))); } +TEST_F(InitializedConfigFixture, ExtractMultipleConfigsWithSingleNode) +{ + TConfigArray cfgSubArray; + + m_cfg.ExtractMultiSubConfigs(_T("CHConfig.Core.SingleObject.Object"), cfgSubArray); + + EXPECT_EQ(1UL, cfgSubArray.GetCount()); + + EXPECT_EQ(TString(_T("FirstName")), cfgSubArray.GetAt(0).GetString(_T("Name"))); + EXPECT_EQ(TString(_T("<WINDOWS>\\FirstPath")), cfgSubArray.GetAt(0).GetString(_T("Path"))); +} + TEST(TConfigTests, PutSubConfig) { TConfig mainCfg;