我正在编写单元测试,并试图涵盖所有代码。
我的代码中有这样的内容:
template<typename ValueType>
std::string ConvertToStringUsingBoost(ValueType const& v)
{
try
{
return boost::lexical_cast<std::string, ValueType>(v);
}
catch(boost::bad_lexical_cast const& e)
{
LOG_ERR("Fail to cast %s to string", e.source_type().name);
return std::string();
}
}
Run Code Online (Sandbox Code Playgroud)
我在阅读这些文档,但没有找到何时的任何信息boost::lexical_cast,以std::string能够抛出异常。
你能帮我吗?
如果不可能,我将删除该try-catch。如果有可能,我宁愿在单元测试中进行介绍。
与使用 protobuf 作为文本配置文件相关,我想使用 protobuf 作为配置文件。
我希望 protobuf 允许我使用具有精确结构的简单解析器。
我的配置结构如下
//my.proto
package my_config;
message MyConfigItem {
required string type = 1;
required string name = 2;
repeated string inputNames = 3 [packed=true];
repeated string outputNames = 4 [packed=true];
}
Run Code Online (Sandbox Code Playgroud)
配置文件中还有一堆不同的项目,例如
MyConfigItem {
type = "type1";
name = "name1";
inputNames = {"input1", "input2"};
}
Run Code Online (Sandbox Code Playgroud)
组织这个活动的最佳方式是什么?