github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/xdr/refl_test.go (about)

     1  // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
     2  // All rights reserved. Use of this source code is governed by an MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build refl
     6  
     7  package xdr_test
     8  
     9  import (
    10  	"bytes"
    11  	"testing"
    12  
    13  	refl "github.com/davecgh/go-xdr/xdr"
    14  )
    15  
    16  func TestCompareMarshals(t *testing.T) {
    17  	e0 := s.MarshalXDR()
    18  	e1, err := refl.Marshal(s)
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  	if bytes.Compare(e0, e1) != 0 {
    23  		t.Fatalf("Encoding mismatch;\n\t%x (this)\n\t%x (refl)", e0, e1)
    24  	}
    25  }
    26  
    27  func BenchmarkReflMarshal(b *testing.B) {
    28  	var err error
    29  	for i := 0; i < b.N; i++ {
    30  		res, err = refl.Marshal(s)
    31  		if err != nil {
    32  			b.Fatal(err)
    33  		}
    34  	}
    35  }
    36  
    37  func BenchmarkReflUnmarshal(b *testing.B) {
    38  	var t XDRBenchStruct
    39  	for i := 0; i < b.N; i++ {
    40  		_, err := refl.Unmarshal(e, &t)
    41  		if err != nil {
    42  			b.Fatal(err)
    43  		}
    44  	}
    45  }