Example #1
0
func TestDecodeHeader(t *testing.T) {
	wantHeader := fit.Header{
		Size:            0xe,
		ProtocolVersion: 0x10,
		ProfileVersion:  0x457,
		DataSize:        0x1dbdf,
		DataType:        [4]uint8{0x2e, 0x46, 0x49, 0x54},
		CRC:             0x1ec4,
	}
	gotHeader, err := fit.DecodeHeader(bytes.NewReader(activitySmallData))
	if err != nil {
		t.Errorf("%q: DecodeHeader failed: %v", activitySmall, err)
	}
	if gotHeader != wantHeader {
		t.Errorf("got header:\n%#v\nwant header: %#v", gotHeader, wantHeader)
	}
}
Example #2
0
func benchmarkDecode(b *testing.B, filename string, bench string) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		b.Fatal(err)
	}
	b.ReportAllocs()
	b.SetBytes(int64(len(data)))
	switch bench {
	case "Full":
		b.ResetTimer()
		for i := 0; i < b.N; i++ {
			_, err := fit.Decode(bytes.NewReader(data))
			if err != nil {
				b.Fatal(err)
			}
		}
	case "Header":
		b.ResetTimer()
		for i := 0; i < b.N; i++ {
			_, err := fit.DecodeHeader(bytes.NewReader(data))
			if err != nil {
				b.Fatal(err)
			}
		}
	case "HeaderAndFileID":
		b.ResetTimer()
		for i := 0; i < b.N; i++ {
			_, _, err := fit.DecodeHeaderAndFileID(bytes.NewReader(data))
			if err != nil {
				b.Fatal(err)
			}
		}
	default:
		panic("benchmarkDecode: unknown benchmark")
	}
}