23 #include "../../dynamic_protobuf_manager.h"
26 #include <google/protobuf/descriptor.pb.h>
27 #include <google/protobuf/text_format.h>
30 #include "test_a.pb.h"
32 int 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 =
74 catch (std::exception& e)
80 google::protobuf::FileDescriptorProto d_proto;
81 std::string d_proto_str =
"name: \"goby/test/util/dynamic_protobuf/test_d.proto\" "
82 "message_type { name: \"D\" field { name: \"d1\" "
83 "number: 1 label: LABEL_REQUIRED type: TYPE_DOUBLE } } ";
85 google::protobuf::TextFormat::ParseFromString(d_proto_str, &d_proto);
88 std::shared_ptr<google::protobuf::Message> ddyn_msg =
91 std::cout << ddyn_msg->GetDescriptor()->DebugString() << std::endl;
94 google::protobuf::FileDescriptorProto e_proto;
95 std::string e_proto_str =
"name: \"goby/test/util/dynamic_protobuf/test_e.proto\" "
96 "message_type { name: \"E\" field { name: \"e1\" "
97 "number: 1 label: LABEL_REQUIRED type: TYPE_DOUBLE } } ";
99 google::protobuf::TextFormat::ParseFromString(e_proto_str, &e_proto);
101 simple_database->Add(e_proto);
103 std::shared_ptr<google::protobuf::Message> edyn_msg =
105 std::cout << edyn_msg->GetDescriptor()->DebugString() << std::endl;
107 std::cout <<
"all tests passed" << std::endl;
110 dccl::DynamicProtobufManager::protobuf_shutdown();