github.com/annchain/OG@v0.0.9/og/protocol/dagmessage/message_content_gen_test.go (about)

     1  package dagmessage
     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 TestMarshalUnmarshalMessageContentTx(t *testing.T) {
    13  	v := MessageContentTx{}
    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 BenchmarkMarshalMsgMessageContentTx(b *testing.B) {
    36  	v := MessageContentTx{}
    37  	b.ReportAllocs()
    38  	b.ResetTimer()
    39  	for i := 0; i < b.N; i++ {
    40  		v.MarshalMsg(nil)
    41  	}
    42  }
    43  
    44  func BenchmarkAppendMsgMessageContentTx(b *testing.B) {
    45  	v := MessageContentTx{}
    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 BenchmarkUnmarshalMessageContentTx(b *testing.B) {
    57  	v := MessageContentTx{}
    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 TestEncodeDecodeMessageContentTx(t *testing.T) {
    71  	v := MessageContentTx{}
    72  	var buf bytes.Buffer
    73  	msgp.Encode(&buf, &v)
    74  
    75  	m := v.Msgsize()
    76  	if buf.Len() > m {
    77  		t.Log("WARNING: TestEncodeDecodeMessageContentTx Msgsize() is inaccurate")
    78  	}
    79  
    80  	vn := MessageContentTx{}
    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 BenchmarkEncodeMessageContentTx(b *testing.B) {
    95  	v := MessageContentTx{}
    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 BenchmarkDecodeMessageContentTx(b *testing.B) {
   109  	v := MessageContentTx{}
   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  }
   124  
   125  func TestMarshalUnmarshalMessageContentSequencer(t *testing.T) {
   126  	v := MessageContentSequencer{}
   127  	bts, err := v.MarshalMsg(nil)
   128  	if err != nil {
   129  		t.Fatal(err)
   130  	}
   131  	left, err := v.UnmarshalMsg(bts)
   132  	if err != nil {
   133  		t.Fatal(err)
   134  	}
   135  	if len(left) > 0 {
   136  		t.Errorf("%d bytes left over after UnmarshalMsg(): %q", len(left), left)
   137  	}
   138  
   139  	left, err = msgp.Skip(bts)
   140  	if err != nil {
   141  		t.Fatal(err)
   142  	}
   143  	if len(left) > 0 {
   144  		t.Errorf("%d bytes left over after Skip(): %q", len(left), left)
   145  	}
   146  }
   147  
   148  func BenchmarkMarshalMsgMessageContentSequencer(b *testing.B) {
   149  	v := MessageContentSequencer{}
   150  	b.ReportAllocs()
   151  	b.ResetTimer()
   152  	for i := 0; i < b.N; i++ {
   153  		v.MarshalMsg(nil)
   154  	}
   155  }
   156  
   157  func BenchmarkAppendMsgMessageContentSequencer(b *testing.B) {
   158  	v := MessageContentSequencer{}
   159  	bts := make([]byte, 0, v.Msgsize())
   160  	bts, _ = v.MarshalMsg(bts[0:0])
   161  	b.SetBytes(int64(len(bts)))
   162  	b.ReportAllocs()
   163  	b.ResetTimer()
   164  	for i := 0; i < b.N; i++ {
   165  		bts, _ = v.MarshalMsg(bts[0:0])
   166  	}
   167  }
   168  
   169  func BenchmarkUnmarshalMessageContentSequencer(b *testing.B) {
   170  	v := MessageContentSequencer{}
   171  	bts, _ := v.MarshalMsg(nil)
   172  	b.ReportAllocs()
   173  	b.SetBytes(int64(len(bts)))
   174  	b.ResetTimer()
   175  	for i := 0; i < b.N; i++ {
   176  		_, err := v.UnmarshalMsg(bts)
   177  		if err != nil {
   178  			b.Fatal(err)
   179  		}
   180  	}
   181  }
   182  
   183  func TestEncodeDecodeMessageContentSequencer(t *testing.T) {
   184  	v := MessageContentSequencer{}
   185  	var buf bytes.Buffer
   186  	msgp.Encode(&buf, &v)
   187  
   188  	m := v.Msgsize()
   189  	if buf.Len() > m {
   190  		t.Log("WARNING: TestEncodeDecodeMessageContentSequencer Msgsize() is inaccurate")
   191  	}
   192  
   193  	vn := MessageContentSequencer{}
   194  	err := msgp.Decode(&buf, &vn)
   195  	if err != nil {
   196  		t.Error(err)
   197  	}
   198  
   199  	buf.Reset()
   200  	msgp.Encode(&buf, &v)
   201  	err = msgp.NewReader(&buf).Skip()
   202  	if err != nil {
   203  		t.Error(err)
   204  	}
   205  }
   206  
   207  func BenchmarkEncodeMessageContentSequencer(b *testing.B) {
   208  	v := MessageContentSequencer{}
   209  	var buf bytes.Buffer
   210  	msgp.Encode(&buf, &v)
   211  	b.SetBytes(int64(buf.Len()))
   212  	en := msgp.NewWriter(msgp.Nowhere)
   213  	b.ReportAllocs()
   214  	b.ResetTimer()
   215  	for i := 0; i < b.N; i++ {
   216  		v.EncodeMsg(en)
   217  	}
   218  	en.Flush()
   219  }
   220  
   221  func BenchmarkDecodeMessageContentSequencer(b *testing.B) {
   222  	v := MessageContentSequencer{}
   223  	var buf bytes.Buffer
   224  	msgp.Encode(&buf, &v)
   225  	b.SetBytes(int64(buf.Len()))
   226  	rd := msgp.NewEndlessReader(buf.Bytes(), b)
   227  	dc := msgp.NewReader(rd)
   228  	b.ReportAllocs()
   229  	b.ResetTimer()
   230  	for i := 0; i < b.N; i++ {
   231  		err := v.DecodeMsg(dc)
   232  		if err != nil {
   233  			b.Fatal(err)
   234  		}
   235  	}
   236  }