22 #include "goby/util/dynamic_protobuf_manager.h" 25 #include <google/protobuf/descriptor.pb.h> 26 #include <google/protobuf/text_format.h> 29 #include "test_a.pb.h" 35 void* dl_handle = dlopen(
"libtest_dyn_protobuf" SHARED_LIBRARY_SUFFIX, RTLD_LAZY);
39 std::cerr <<
"Failed to open libtest_dyn_protobuf" SHARED_LIBRARY_SUFFIX << std::endl;
43 boost::shared_ptr<google::protobuf::SimpleDescriptorDatabase> simple_database(
44 new google::protobuf::SimpleDescriptorDatabase);
45 goby::util::DynamicProtobufManager::add_database(simple_database);
49 boost::shared_ptr<google::protobuf::Message> adyn_msg =
50 goby::util::DynamicProtobufManager::new_protobuf_message(
"A");
52 std::cout << adyn_msg->GetDescriptor()->DebugString() << std::endl;
55 boost::shared_ptr<google::protobuf::Message> bdyn_msg =
56 goby::util::DynamicProtobufManager::new_protobuf_message(
"B");
58 std::cout << bdyn_msg->GetDescriptor()->DebugString() << std::endl;
63 boost::shared_ptr<google::protobuf::Message> cdyn_msg =
64 goby::util::DynamicProtobufManager::new_protobuf_message(
"C");
68 catch (std::exception& e)
74 google::protobuf::FileDescriptorProto d_proto;
75 std::string d_proto_str =
"name: \"goby/test/util/dynamic_protobuf/test_d.proto\" " 76 "message_type { name: \"D\" field { name: \"d1\" " 77 "number: 1 label: LABEL_REQUIRED type: TYPE_DOUBLE } } ";
79 google::protobuf::TextFormat::ParseFromString(d_proto_str, &d_proto);
80 goby::util::DynamicProtobufManager::add_protobuf_file(d_proto);
82 boost::shared_ptr<google::protobuf::Message> ddyn_msg =
83 goby::util::DynamicProtobufManager::new_protobuf_message(
"D");
85 std::cout << ddyn_msg->GetDescriptor()->DebugString() << std::endl;
88 google::protobuf::FileDescriptorProto e_proto;
89 std::string e_proto_str =
"name: \"goby/test/util/dynamic_protobuf/test_e.proto\" " 90 "message_type { name: \"E\" field { name: \"e1\" " 91 "number: 1 label: LABEL_REQUIRED type: TYPE_DOUBLE } } ";
93 google::protobuf::TextFormat::ParseFromString(e_proto_str, &e_proto);
95 simple_database->Add(e_proto);
97 boost::shared_ptr<google::protobuf::Message> edyn_msg =
98 goby::util::DynamicProtobufManager::new_protobuf_message(
"E");
99 std::cout << edyn_msg->GetDescriptor()->DebugString() << std::endl;
101 std::cout <<
"all tests passed" << std::endl;
104 goby::util::DynamicProtobufManager::protobuf_shutdown();