fix preference_tests.cc's compile issues

This commit is contained in:
houzh 2023-03-13 10:48:12 +00:00
parent 4e0d8b2c72
commit 8eb5adad42
3 changed files with 8 additions and 7 deletions

View File

@ -150,11 +150,11 @@ double Preferences::getDouble(const std::string&section,const std::string&key,do
return def;
}
std::string Preferences::getString(const std::string&section,const std::string&key,const char*def){
std::string Preferences::getString(const std::string&section,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;
}

View File

@ -23,7 +23,7 @@ public:
int getInt(const std::string&section,const std::string&key,int def=0);
float getFloat(const std::string&section,const std::string&key,float def=.0);
double getDouble(const std::string&section,const std::string&key,double def=.0);
std::string getString(const std::string&section,const std::string&key,const char*);
std::string getString(const std::string&section,const std::string&key,const std::string&def="");
void setValue(const std::string&section,const std::string&key,bool v);
void setValue(const std::string&section,const std::string&key,int v);

View File

@ -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());
}