descriptor_test.go 905 B

1234567891011121314151617181920212223242526272829303132
  1. package descriptor_test
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/golang/protobuf/descriptor"
  6. tpb "github.com/golang/protobuf/proto/test_proto"
  7. protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
  8. )
  9. func TestMessage(t *testing.T) {
  10. var msg *protobuf.DescriptorProto
  11. fd, md := descriptor.ForMessage(msg)
  12. if pkg, want := fd.GetPackage(), "google.protobuf"; pkg != want {
  13. t.Errorf("descriptor.ForMessage(%T).GetPackage() = %q; want %q", msg, pkg, want)
  14. }
  15. if name, want := md.GetName(), "DescriptorProto"; name != want {
  16. t.Fatalf("descriptor.ForMessage(%T).GetName() = %q; want %q", msg, name, want)
  17. }
  18. }
  19. func Example_options() {
  20. var msg *tpb.MyMessageSet
  21. _, md := descriptor.ForMessage(msg)
  22. if md.GetOptions().GetMessageSetWireFormat() {
  23. fmt.Printf("%v uses option message_set_wire_format.\n", md.GetName())
  24. }
  25. // Output:
  26. // MyMessageSet uses option message_set_wire_format.
  27. }