本文整理汇总了Golang中code/google/com/p/goprotobuf/proto.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestClone
func TestClone(t *testing.T) {
m := proto.Clone(cloneTestMessage).(*pb.MyMessage)
if !proto.Equal(m, cloneTestMessage) {
t.Errorf("Clone(%v) = %v", cloneTestMessage, m)
}
// Verify it was a deep copy.
*m.Inner.Port++
if proto.Equal(m, cloneTestMessage) {
t.Error("Mutating clone changed the original")
}
// Byte fields and repeated fields should be copied.
if &m.Pet[0] == &cloneTestMessage.Pet[0] {
t.Error("Pet: repeated field not copied")
}
if &m.Others[0] == &cloneTestMessage.Others[0] {
t.Error("Others: repeated field not copied")
}
if &m.Others[0].Value[0] == &cloneTestMessage.Others[0].Value[0] {
t.Error("Others[0].Value: bytes field not copied")
}
if &m.RepBytes[0] == &cloneTestMessage.RepBytes[0] {
t.Error("RepBytes: repeated field not copied")
}
if &m.RepBytes[0][0] == &cloneTestMessage.RepBytes[0][0] {
t.Error("RepBytes[0]: bytes field not copied")
}
}
开发者ID:carriercomm,项目名称:lavabot,代码行数:28,代码来源:clone_test.go
示例2: TestClone
func TestClone(t *testing.T) {
m := proto.Clone(cloneTestMessage).(*pb.MyMessage)
if !proto.Equal(m, cloneTestMessage) {
t.Errorf("Clone(%v) = %v", cloneTestMessage, m)
}
// Verify it was a deep copy.
*m.Inner.Port++
if proto.Equal(m, cloneTestMessage) {
t.Error("Mutating clone changed the original")
}
}
开发者ID:kulasama,项目名称:goprotobuf,代码行数:12,代码来源:clone_test.go
示例3: TestLogging
func TestLogging(t *testing.T) {
l, err := NewLogFile("logging.log")
if err != nil {
t.Error(err)
return
}
defer os.Remove("logging.log")
for _, val := range testValues {
err = l.Put(val)
if err != nil {
t.Fatal(err)
}
}
err = l.Close()
if err != nil {
t.Fatal(err)
}
f, err := os.Open("logging.log")
if err != nil {
t.Fatal(err)
}
walker, err := NewReaderWalker(f)
if err != nil {
t.Error(err)
return
}
i := 0
for {
entries, err := walker.Next()
if err == io.EOF {
err = f.Close()
if err != nil {
t.Fatal(err)
}
break
} else if err != nil {
t.Error(err)
return
}
if len(entries) != 1 {
t.Error("> 1 entry in log tx")
return
}
val, ok := entries[0].(proto.Message)
if !ok {
t.Fatal("val does not implement proto.Message")
}
if !proto.Equal(val, testValues[i]) {
t.Error("proto message mismatch")
}
i += 1
}
}
开发者ID:carriercomm,项目名称:grumble,代码行数:58,代码来源:freezer_test.go
示例4: TestMerge
func TestMerge(t *testing.T) {
for _, m := range mergeTests {
got := proto.Clone(m.dst)
proto.Merge(got, m.src)
if !proto.Equal(got, m.want) {
t.Errorf("Merge(%v, %v)\n got %v\nwant %v\n", m.dst, m.src, got, m.want)
}
}
}
开发者ID:kulasama,项目名称:goprotobuf,代码行数:9,代码来源:clone_test.go
示例5: fakeRunQuery
func fakeRunQuery(in *pb.Query, out *pb.QueryResult) error {
expectedIn := &pb.Query{
App: proto.String("dev~fake-app"),
Kind: proto.String("Gopher"),
Compile: proto.Bool(true),
}
if !proto.Equal(in, expectedIn) {
return fmt.Errorf("unsupported argument: got %v want %v", in, expectedIn)
}
*out = pb.QueryResult{
Result: []*pb.EntityProto{
{
Key: &pb.Reference{
App: proto.String("s~test-app"),
Path: path1,
},
EntityGroup: path1,
Property: []*pb.Property{
{
Meaning: pb.Property_TEXT.Enum(),
Name: proto.String("Name"),
Value: &pb.PropertyValue{
StringValue: proto.String("George"),
},
},
{
Name: proto.String("Height"),
Value: &pb.PropertyValue{
Int64Value: proto.Int64(32),
},
},
},
},
{
Key: &pb.Reference{
App: proto.String("s~test-app"),
Path: path2,
},
EntityGroup: path1, // ancestor is George
Property: []*pb.Property{
{
Meaning: pb.Property_TEXT.Enum(),
Name: proto.String("Name"),
Value: &pb.PropertyValue{
StringValue: proto.String("Rufus"),
},
},
// No height for Rufus.
},
},
},
MoreResults: proto.Bool(false),
}
return nil
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:55,代码来源:query_test.go
示例6: TestMessageConstruction
func TestMessageConstruction(t *testing.T) {
var got *pb.MailMessage
c := aetesting.FakeSingleContext(t, "mail", "Send", func(in *pb.MailMessage, out *basepb.VoidProto) error {
got = in
return nil
})
msg := &Message{
Sender: "[email protected]",
To: []string{"[email protected]"},
Body: "Hey, lunch time?",
Attachments: []Attachment{
// Regression test for a prod bug. The address of a range variable was used when
// constructing the outgoing proto, so multiple attachments used the same name.
{
Name: "att1.txt",
Data: []byte("data1"),
ContentID: "<att1>",
},
{
Name: "att2.txt",
Data: []byte("data2"),
},
},
}
if err := Send(c, msg); err != nil {
t.Fatalf("Send: %v", err)
}
want := &pb.MailMessage{
Sender: proto.String("[email protected]"),
To: []string{"[email protected]"},
Subject: proto.String(""),
TextBody: proto.String("Hey, lunch time?"),
Attachment: []*pb.MailAttachment{
{
FileName: proto.String("att1.txt"),
Data: []byte("data1"),
ContentID: proto.String("<att1>"),
},
{
FileName: proto.String("att2.txt"),
Data: []byte("data2"),
},
},
}
if !proto.Equal(got, want) {
t.Errorf("Bad proto for %+v\n got %v\nwant %v", msg, got, want)
}
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:49,代码来源:mail_test.go
示例7: TestPut
func TestPut(t *testing.T) {
index, err := Open("Doc")
if err != nil {
t.Fatalf("err from Open: %v", err)
}
c := aetesting.FakeSingleContext(t, "search", "IndexDocument", func(in *pb.IndexDocumentRequest, out *pb.IndexDocumentResponse) error {
expectedIn := &pb.IndexDocumentRequest{
Params: &pb.IndexDocumentParams{
Document: []*pb.Document{
{Field: protoFields},
// Omit OrderId since we'll check it explicitly.
},
IndexSpec: &pb.IndexSpec{
Name: proto.String("Doc"),
},
},
}
if len(in.Params.GetDocument()) < 1 {
return fmt.Errorf("expected at least one Document, got %v", in)
}
got, want := in.Params.Document[0].GetOrderId(), int32(time.Since(orderIDEpoch).Seconds())
if d := got - want; -5 > d || d > 5 {
return fmt.Errorf("got OrderId %d, want near %d", got, want)
}
in.Params.Document[0].OrderId = nil
if !proto.Equal(in, expectedIn) {
return fmt.Errorf("unsupported argument:\ngot %v\nwant %v", in, expectedIn)
}
*out = pb.IndexDocumentResponse{
Status: []*pb.RequestStatus{
{Code: pb.SearchServiceError_OK.Enum()},
},
DocId: []string{
"doc_id",
},
}
return nil
})
id, err := index.Put(c, "", &searchDoc)
if err != nil {
t.Fatal(err)
}
if want := "doc_id"; id != want {
t.Errorf("Got doc ID %q, want %q", id, want)
}
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:48,代码来源:search_test.go
示例8: TestStringEscaping
func TestStringEscaping(t *testing.T) {
testCases := []struct {
in *pb.Strings
out string
}{
{
// Test data from C++ test (TextFormatTest.StringEscape).
// Single divergence: we don't escape apostrophes.
&pb.Strings{StringField: proto.String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces")},
"string_field: \"\\\"A string with ' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"\n",
},
{
// Test data from the same C++ test.
&pb.Strings{StringField: proto.String("\350\260\267\346\255\214")},
"string_field: \"\\350\\260\\267\\346\\255\\214\"\n",
},
{
// Some UTF-8.
&pb.Strings{StringField: proto.String("\x00\x01\xff\x81")},
`string_field: "\000\001\377\201"` + "\n",
},
}
for i, tc := range testCases {
var buf bytes.Buffer
if err := proto.MarshalText(&buf, tc.in); err != nil {
t.Errorf("proto.MarsalText: %v", err)
continue
}
s := buf.String()
if s != tc.out {
t.Errorf("#%d: Got:\n%s\nExpected:\n%s\n", i, s, tc.out)
continue
}
// Check round-trip.
pb := new(pb.Strings)
if err := proto.UnmarshalText(s, pb); err != nil {
t.Errorf("#%d: UnmarshalText: %v", i, err)
continue
}
if !proto.Equal(pb, tc.in) {
t.Errorf("#%d: Round-trip failed:\nstart: %v\n end: %v", i, tc.in, pb)
}
}
}
开发者ID:adjust,项目名称:goprotobuf,代码行数:46,代码来源:text_test.go
示例9: TestLogging
func TestLogging(t *testing.T) {
l, err := NewLogFile("logging.log")
if err != nil {
t.Error(err)
return
}
defer l.Close()
defer os.Remove("logging.log")
for _, val := range testValues {
err = l.Put(val)
if err != nil {
t.Error(err)
return
}
}
walker, err := NewFileWalker("logging.log")
if err != nil {
t.Error(err)
return
}
i := 0
for {
entries, err := walker.Next()
if err == io.EOF {
break
} else if err != nil {
t.Error(err)
return
}
if len(entries) != 1 {
t.Error("> 1 entry in log tx")
return
}
val := entries[0]
if !proto.Equal(val, testValues[i]) {
t.Error("proto message mismatch")
}
i += 1
}
}
开发者ID:Kissaki,项目名称:grumble,代码行数:43,代码来源:freezer_test.go
示例10: TestPut
func TestPut(t *testing.T) {
index, err := Open("Doc")
if err != nil {
t.Fatalf("err from Open: %v", err)
}
c := aetesting.FakeSingleContext(t, "search", "IndexDocument", func(in *pb.IndexDocumentRequest, out *pb.IndexDocumentResponse) error {
expectedIn := &pb.IndexDocumentRequest{
Params: &pb.IndexDocumentParams{
Document: []*pb.Document{
{Field: protoFields, OrderId: proto.Int32(42)},
},
IndexSpec: &pb.IndexSpec{
Name: proto.String("Doc"),
},
},
}
if !proto.Equal(in, expectedIn) {
return fmt.Errorf("unsupported argument:\ngot %v\nwant %v", in, expectedIn)
}
*out = pb.IndexDocumentResponse{
Status: []*pb.RequestStatus{
{Code: pb.SearchServiceError_OK.Enum()},
},
DocId: []string{
"doc_id",
},
}
return nil
})
id, err := index.Put(c, "", &FieldListWithMeta{
Meta: searchMeta,
Fields: searchFields,
})
if err != nil {
t.Fatal(err)
}
if want := "doc_id"; id != want {
t.Errorf("Got doc ID %q, want %q", id, want)
}
}
开发者ID:qwo,项目名称:abelana-gcp,代码行数:42,代码来源:search_test.go
示例11: TestLoginURL
func TestLoginURL(t *testing.T) {
expectedQuery := &pb.CreateLoginURLRequest{
DestinationUrl: proto.String("/destination"),
}
const expectedDest = "/redir/dest"
c := aetesting.FakeSingleContext(t, "user", "CreateLoginURL", func(req *pb.CreateLoginURLRequest, res *pb.CreateLoginURLResponse) error {
if !proto.Equal(req, expectedQuery) {
return fmt.Errorf("got %v, want %v", req, expectedQuery)
}
res.LoginUrl = proto.String(expectedDest)
return nil
})
url, err := LoginURL(c, "/destination")
if err != nil {
t.Fatalf("LoginURL failed: %v", err)
}
if url != expectedDest {
t.Errorf("got %v, want %v", url, expectedDest)
}
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:21,代码来源:user_test.go
示例12: TestCloneNil
func TestCloneNil(t *testing.T) {
var m *pb.MyMessage
if c := proto.Clone(m); !proto.Equal(m, c) {
t.Errorf("Clone(%v) = %v", m, c)
}
}
开发者ID:kulasama,项目名称:goprotobuf,代码行数:6,代码来源:clone_test.go
示例13: checkProtosEqual
func checkProtosEqual(t *testing.T, expectedTrace *Trace, trace *Trace) {
if !proto.Equal(expectedTrace, trace) {
t.Fatalf("Protocol buffers not equal:\nExpected: %s\nActual: %s", expectedTrace, trace)
}
}
开发者ID:sburnett,项目名称:bismark-passive-server-go,代码行数:5,代码来源:trace_test.go
示例14: Call
func (c *stubContext) Call(service, method string, in, out proto.Message, _ *internal.CallOptions) error {
c.nCall++
if service != "datastore_v3" || method != "RunQuery" {
return fmt.Errorf("stubContext: unsupported service %q or method %q", service, method)
}
expectedIn := &pb.Query{
App: proto.String("s~test-app"),
Kind: proto.String("Gopher"),
Compile: proto.Bool(true),
}
if !proto.Equal(in, expectedIn) {
return fmt.Errorf("stubContext: unsupported in argument: got %v want %v", in, expectedIn)
}
x, ok := out.(*pb.QueryResult)
if !ok {
return fmt.Errorf("stubContext: unsupported out argument type: got %T want %T", out, x)
}
*x = pb.QueryResult{
Result: []*pb.EntityProto{
&pb.EntityProto{
Key: &pb.Reference{
App: proto.String("s~test-app"),
Path: path1,
},
EntityGroup: path1,
Property: []*pb.Property{
&pb.Property{
Meaning: pb.Property_TEXT.Enum(),
Name: proto.String("Name"),
Value: &pb.PropertyValue{
StringValue: proto.String("George"),
},
},
&pb.Property{
Name: proto.String("Height"),
Value: &pb.PropertyValue{
Int64Value: proto.Int64(32),
},
},
},
},
&pb.EntityProto{
Key: &pb.Reference{
App: proto.String("s~test-app"),
Path: path2,
},
EntityGroup: path1, // ancestor is George
Property: []*pb.Property{
&pb.Property{
Meaning: pb.Property_TEXT.Enum(),
Name: proto.String("Name"),
Value: &pb.PropertyValue{
StringValue: proto.String("Rufus"),
},
},
// No height for Rufus.
},
},
},
MoreResults: proto.Bool(false),
}
return nil
}
开发者ID:proppy,项目名称:appengine,代码行数:63,代码来源:query_test.go
注:本文中的code/google/com/p/goprotobuf/proto.Equal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论