Skip to content

Commit

Permalink
Fix config's logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MizukiSonoko authored and l4l committed Jul 23, 2017
1 parent 3b17e12 commit f80ed3c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions irohad/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ namespace common {
}

int ConfigLoader::getIntOrElse(const std::string& key, int def){
if(doc[key.c_str()].IsInt()){
if(doc.IsObject() && doc.HasMember(key.c_str()) && doc[key.c_str()].IsInt()){
return doc[key.c_str()].GetInt();
}else{
return def;
};
}

std::string ConfigLoader::getStringOrElse(const std::string& key, std::string def){
if(doc[key.c_str()].IsString()){
if(doc.IsObject() && doc.HasMember(key.c_str()) && doc[key.c_str()].IsString()){
return doc[key.c_str()].GetString();
}else{
return def;
};
}

bool ConfigLoader::getBoolOrElse(const std::string& key, bool def){
if(doc[key.c_str()].IsBool()){
if(doc.IsObject() && doc.HasMember(key.c_str()) && doc[key.c_str()].IsBool()){
return doc[key.c_str()].GetBool();
}else{
return def;
Expand Down
12 changes: 12 additions & 0 deletions test/module/irohad/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

add_executable(config_loader_test
config_loader_test.cpp
)
target_link_libraries(config_loader_test
config
gtest
)
add_test(
NAME config_loader_test
COMMAND $<TARGET_FILE:config_loader_test>
)

0 comments on commit f80ed3c

Please sign in to comment.