updated convertToRegFormat name to begin with lowercase and added test

This commit is contained in:
Aleksandar Fabijanic 2012-05-18 03:27:52 +00:00
parent f5bb43f9d3
commit e5e3a57baf
3 changed files with 11 additions and 6 deletions

View File

@ -76,10 +76,11 @@ protected:
void enumerate(const std::string& key, Keys& range) const;
void removeRaw(const std::string& key);
std::string ConvertToRegFormat(const std::string& key, std::string& keyName) const;
/// takes a key in the format of A.B.C and converts it to
std::string convertToRegFormat(const std::string& key, std::string& keyName) const;
/// Takes a key in the format of A.B.C and converts it to
/// registry format A\B\C, the last entry is the keyName, the rest is returned as path
friend class WinConfigurationTest;
private:
std::string _rootPath;
REGSAM _extraSam;

View File

@ -65,7 +65,7 @@ WinRegistryConfiguration::~WinRegistryConfiguration()
bool WinRegistryConfiguration::getRaw(const std::string& key, std::string& value) const
{
std::string keyName;
std::string fullPath = _rootPath + ConvertToRegFormat(key, keyName);
std::string fullPath = _rootPath + convertToRegFormat(key, keyName);
WinRegistryKey aKey(fullPath, true, _extraSam);
bool exists = aKey.exists(keyName);
if (exists)
@ -94,7 +94,7 @@ bool WinRegistryConfiguration::getRaw(const std::string& key, std::string& value
void WinRegistryConfiguration::setRaw(const std::string& key, const std::string& value)
{
std::string keyName;
std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
std::string fullPath = _rootPath + convertToRegFormat(key, keyName);
WinRegistryKey aKey(fullPath, false, _extraSam);
aKey.setString(keyName, value);
}
@ -115,7 +115,7 @@ void WinRegistryConfiguration::enumerate(const std::string& key, Keys& range) co
else
{
std::string keyName;
std::string fullPath = _rootPath+ConvertToRegFormat(key, keyName);
std::string fullPath = _rootPath + convertToRegFormat(key, keyName);
WinRegistryKey aKey(fullPath, true, _extraSam);
aKey.values(range);
aKey.subKeys(range);
@ -129,7 +129,7 @@ void WinRegistryConfiguration::removeRaw(const std::string& key)
}
std::string WinRegistryConfiguration::ConvertToRegFormat(const std::string& key, std::string& value) const
std::string WinRegistryConfiguration::convertToRegFormat(const std::string& key, std::string& value) const
{
std::size_t pos = key.rfind('.');
if (pos == std::string::npos)

View File

@ -74,6 +74,10 @@ void WinConfigurationTest::testConfiguration()
pView->setString("sub.foo", "bar");
assert (pView->getString("sub.foo", "default") == "bar");
std::string value;
assert (pReg->convertToRegFormat("A.B.C", value) == "A\\B");
assert (value == "C");
}