23#include "../../dynamic_protobuf_manager.h"
26#include <google/protobuf/descriptor.pb.h>
27#include <google/protobuf/text_format.h>
29#include "dccl/logger.h"
33int main(
int argc,
char* argv[])
36 const char* lib_path =
nullptr;
37 for (
int i = 1; i < argc; ++i)
39 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
51 std::cerr <<
"Usage: " << argv[0] <<
" [-v] /path/to/libtest_dyn_protobuf" << std::endl;
55 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
57 void* dl_handle = dlopen(lib_path, RTLD_LAZY);
61 std::cerr <<
"Failed to open libtest_dyn_protobuf" SHARED_LIBRARY_SUFFIX
62 <<
", error: " << dlerror() << std::endl;
66 std::shared_ptr<google::protobuf::SimpleDescriptorDatabase> simple_database(
67 new google::protobuf::SimpleDescriptorDatabase);
72 std::shared_ptr<google::protobuf::Message> adyn_msg =
75 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << adyn_msg->GetDescriptor()->DebugString() << std::endl;
78 std::shared_ptr<google::protobuf::Message> bdyn_msg =
81 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << bdyn_msg->GetDescriptor()->DebugString() << std::endl;
86 std::shared_ptr<google::protobuf::Message> cdyn_msg =
89 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << cdyn_msg->GetDescriptor()->DebugString() << std::endl;
92 catch (std::exception& e)
98 google::protobuf::FileDescriptorProto d_proto;
99 std::string d_proto_str =
"name: \"goby/test/util/dynamic_protobuf/test_d.proto\" "
100 "message_type { name: \"D\" field { name: \"d1\" "
101 "number: 1 label: LABEL_REQUIRED type: TYPE_DOUBLE } } ";
103 google::protobuf::TextFormat::ParseFromString(d_proto_str, &d_proto);
106 std::shared_ptr<google::protobuf::Message> ddyn_msg =
109 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << ddyn_msg->GetDescriptor()->DebugString() << std::endl;
112 google::protobuf::FileDescriptorProto e_proto;
113 std::string e_proto_str =
"name: \"goby/test/util/dynamic_protobuf/test_e.proto\" "
114 "message_type { name: \"E\" field { name: \"e1\" "
115 "number: 1 label: LABEL_REQUIRED type: TYPE_DOUBLE } } ";
117 google::protobuf::TextFormat::ParseFromString(e_proto_str, &e_proto);
119 simple_database->Add(e_proto);
121 std::shared_ptr<google::protobuf::Message> edyn_msg =
123 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << edyn_msg->GetDescriptor()->DebugString() << std::endl;
125 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"all tests passed" << std::endl;
128 dccl::DynamicProtobufManager::protobuf_shutdown();
static GoogleProtobufMessagePointer new_protobuf_message(const std::string &protobuf_type_name, bool user_pool_first=false)
Create a new (empty) Google Protobuf message of a given type by name.
static const google::protobuf::FileDescriptor * add_protobuf_file(const google::protobuf::FileDescriptorProto &proto)
Add a protobuf file defined in a google::protobuf::FileDescriptorProto.
static void add_database(std::shared_ptr< google::protobuf::DescriptorDatabase > database)
Add a Google Protobuf DescriptorDatabase to the set of databases searched for Message Descriptors.
bool is(logger::Verbosity verbosity, logger::Group group=logger::GENERAL)
Indicates the verbosity of the Logger until the next std::flush or std::endl. The boolean return is u...
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
Dynamic Compact Control Language namespace.