diff --git a/src/gui/core/preferences.cc b/src/gui/core/preferences.cc index 57d56159..0e47bcec 100644 --- a/src/gui/core/preferences.cc +++ b/src/gui/core/preferences.cc @@ -150,11 +150,11 @@ double Preferences::getDouble(const std::string§ion,const std::string&key,do return def; } -std::string Preferences::getString(const std::string§ion,const std::string&key,const char*def){ +std::string Preferences::getString(const std::string§ion,const std::string&key,const std::string&def){ auto sec=mPrefs.find(section); if(sec==mPrefs.end())return def; auto kv=sec->second.find(key); - if(kv==sec->second.end())return std::string(def); + if(kv==sec->second.end())return def; return kv->second; } diff --git a/src/gui/core/preferences.h b/src/gui/core/preferences.h index 06dc9485..30af5f4b 100644 --- a/src/gui/core/preferences.h +++ b/src/gui/core/preferences.h @@ -23,7 +23,7 @@ public: int getInt(const std::string§ion,const std::string&key,int def=0); float getFloat(const std::string§ion,const std::string&key,float def=.0); double getDouble(const std::string§ion,const std::string&key,double def=.0); - std::string getString(const std::string§ion,const std::string&key,const char*); + std::string getString(const std::string§ion,const std::string&key,const std::string&def=""); void setValue(const std::string§ion,const std::string&key,bool v); void setValue(const std::string§ion,const std::string&key,int v); diff --git a/tests/gui/preference_tests.cc b/tests/gui/preference_tests.cc index ba299664..d463cb47 100755 --- a/tests/gui/preference_tests.cc +++ b/tests/gui/preference_tests.cc @@ -15,7 +15,6 @@ public : virtual void TearDown(){ } }; - TEST_F(PREFERENCES,setbool){ Preferences pref; pref.setValue("Video","width",false); @@ -51,13 +50,15 @@ TEST_F(PREFERENCES,setdouble){ ASSERT_DOUBLE_EQ(1800.123,pref.getDouble("Video","width",0.f)); pref.save("testdouble.pref"); } + TEST_F(PREFERENCES,setstring){ Preferences pref; pref.setValue("Video","url","url1"); pref.setValue("Video","url","url2"); - EXPECT_STREQ("url2",pref.getString("Video","url","")); + EXPECT_STREQ("url2",pref.getString("Video","url","").c_str()); pref.save("teststr.pref"); } + TEST_F(PREFERENCES,strings){ Preferences pref,pld; std::string server("videoserver"); @@ -72,8 +73,8 @@ TEST_F(PREFERENCES,strings){ pld.load("server.pref"); ASSERT_EQ(1234,pref.getInt(server,port,0)); - EXPECT_STREQ("192.168.1.150",pref.getString(server,ip,"")); + EXPECT_STREQ("192.168.1.150",pref.getString(server,ip).c_str()); ASSERT_EQ(1234,pref.getInt("server2",port,0)); - EXPECT_STREQ("192.168.1.150",pref.getString("server2",ip,"")); + EXPECT_STREQ("192.168.1.150",pref.getString("server2",ip).c_str()); }