23#include "../../dynamic_protobuf_manager.h"
26#include <google/protobuf/descriptor.pb.h>
27#include <google/protobuf/text_format.h>
32int main(
int argc,
char* argv[])
36 std::cerr <<
"Usage: " << argv[0] <<
" /path/to/libtest_dyn_protobuf" << std::endl;
40 void* dl_handle = dlopen(argv[1], RTLD_LAZY);
44 std::cerr <<
"Failed to open libtest_dyn_protobuf" SHARED_LIBRARY_SUFFIX
45 <<
", error: " << dlerror() << std::endl;
49 std::shared_ptr<google::protobuf::SimpleDescriptorDatabase> simple_database(
50 new google::protobuf::SimpleDescriptorDatabase);
55 std::shared_ptr<google::protobuf::Message> adyn_msg =
58 std::cout << adyn_msg->GetDescriptor()->DebugString() << std::endl;
61 std::shared_ptr<google::protobuf::Message> bdyn_msg =
64 std::cout << bdyn_msg->GetDescriptor()->DebugString() << std::endl;
69 std::shared_ptr<google::protobuf::Message> cdyn_msg =
72 std::cout << cdyn_msg->GetDescriptor()->DebugString() << std::endl;
75 catch (std::exception& e)
81 google::protobuf::FileDescriptorProto d_proto;
82 std::string d_proto_str =
"name: \"goby/test/util/dynamic_protobuf/test_d.proto\" "
83 "message_type { name: \"D\" field { name: \"d1\" "
84 "number: 1 label: LABEL_REQUIRED type: TYPE_DOUBLE } } ";
86 google::protobuf::TextFormat::ParseFromString(d_proto_str, &d_proto);
89 std::shared_ptr<google::protobuf::Message> ddyn_msg =
92 std::cout << ddyn_msg->GetDescriptor()->DebugString() << std::endl;
95 google::protobuf::FileDescriptorProto e_proto;
96 std::string e_proto_str =
"name: \"goby/test/util/dynamic_protobuf/test_e.proto\" "
97 "message_type { name: \"E\" field { name: \"e1\" "
98 "number: 1 label: LABEL_REQUIRED type: TYPE_DOUBLE } } ";
100 google::protobuf::TextFormat::ParseFromString(e_proto_str, &e_proto);
102 simple_database->Add(e_proto);
104 std::shared_ptr<google::protobuf::Message> edyn_msg =
106 std::cout << edyn_msg->GetDescriptor()->DebugString() << std::endl;
108 std::cout <<
"all tests passed" << std::endl;
111 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.