github.com/annchain/OG@v0.0.9/common/address_gen_test.go (about)

     1  package common
     2  
     3  // Code generated by github.com/tinylib/msgp DO NOT EDIT.
     4  
     5  import (
     6  	"bytes"
     7  	"testing"
     8  
     9  	"github.com/tinylib/msgp/msgp"
    10  )
    11  
    12  func TestMarshalUnmarshalAddress(t *testing.T) {
    13  	v := Address{}
    14  	bts, err := v.MarshalMsg(nil)
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  	left, err := v.UnmarshalMsg(bts)
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  	if len(left) > 0 {
    23  		t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left)
    24  	}
    25  
    26  	left, err = msgp.Skip(bts)
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  	if len(left) > 0 {
    31  		t.Errorf("%d bytes left over after Skip(): %q", len(left), left)
    32  	}
    33  }
    34  
    35  func BenchmarkMarshalMsgAddress(b *testing.B) {
    36  	v := Address{}
    37  	b.ReportAllocs()
    38  	b.ResetTimer()
    39  	for i := 0; i < b.N; i++ {
    40  		v.MarshalMsg(nil)
    41  	}
    42  }
    43  
    44  func BenchmarkAppendMsgAddress(b *testing.B) {
    45  	v := Address{}
    46  	bts := make([]byte, 0, v.Msgsize())
    47  	bts, _ = v.MarshalMsg(bts[0:0])
    48  	b.SetBytes(int64(len(bts)))
    49  	b.ReportAllocs()
    50  	b.ResetTimer()
    51  	for i := 0; i < b.N; i++ {
    52  		bts, _ = v.MarshalMsg(bts[0:0])
    53  	}
    54  }
    55  
    56  func BenchmarkUnmarshalAddress(b *testing.B) {
    57  	v := Address{}
    58  	bts, _ := v.MarshalMsg(nil)
    59  	b.ReportAllocs()
    60  	b.SetBytes(int64(len(bts)))
    61  	b.ResetTimer()
    62  	for i := 0; i < b.N; i++ {
    63  		_, err := v.UnmarshalMsg(bts)
    64  		if err != nil {
    65  			b.Fatal(err)
    66  		}
    67  	}
    68  }
    69  
    70  func TestEncodeDecodeAddress(t *testing.T) {
    71  	v := Address{}
    72  	var buf bytes.Buffer
    73  	msgp.Encode(&buf, &v)
    74  
    75  	m := v.Msgsize()
    76  	if buf.Len() > m {
    77  		t.Logf("WARNING: Msgsize() for %v is inaccurate", v)
    78  	}
    79  
    80  	vn := Address{}
    81  	err := msgp.Decode(&buf, &vn)
    82  	if err != nil {
    83  		t.Error(err)
    84  	}
    85  
    86  	buf.Reset()
    87  	msgp.Encode(&buf, &v)
    88  	err = msgp.NewReader(&buf).Skip()
    89  	if err != nil {
    90  		t.Error(err)
    91  	}
    92  }
    93  
    94  func BenchmarkEncodeAddress(b *testing.B) {
    95  	v := Address{}
    96  	var buf bytes.Buffer
    97  	msgp.Encode(&buf, &v)
    98  	b.SetBytes(int64(buf.Len()))
    99  	en := msgp.NewWriter(msgp.Nowhere)
   100  	b.ReportAllocs()
   101  	b.ResetTimer()
   102  	for i := 0; i < b.N; i++ {
   103  		v.EncodeMsg(en)
   104  	}
   105  	en.Flush()
   106  }
   107  
   108  func BenchmarkDecodeAddress(b *testing.B) {
   109  	v := Address{}
   110  	var buf bytes.Buffer
   111  	msgp.Encode(&buf, &v)
   112  	b.SetBytes(int64(buf.Len()))
   113  	rd := msgp.NewEndlessReader(buf.Bytes(), b)
   114  	dc := msgp.NewReader(rd)
   115  	b.ReportAllocs()
   116  	b.ResetTimer()
   117  	for i := 0; i < b.N; i++ {
   118  		err := v.DecodeMsg(dc)
   119  		if err != nil {
   120  			b.Fatal(err)
   121  		}
   122  	}
   123  }