예제 #1
0
파일: reader_test.go 프로젝트: tormoder/fit
func TestDecodeHeaderAndFileID(t *testing.T) {
	wantHeader := fit.Header{
		Size:            0xe,
		ProtocolVersion: 0x10,
		ProfileVersion:  0x457,
		DataSize:        0x1dbdf,
		DataType:        [4]uint8{0x2e, 0x46, 0x49, 0x54},
		CRC:             0x1ec4,
	}
	tc := time.Unix(1439652761, 0)
	tc = tc.UTC()
	wantFileId := fit.FileIdMsg{
		Type:         0x4,
		Manufacturer: 0x1,
		Product:      0x7af,
		SerialNumber: 0xe762d9cf,
		Number:       0xffff,
		TimeCreated:  tc,
		ProductName:  "",
	}

	gotHeader, gotFileId, err := fit.DecodeHeaderAndFileID(bytes.NewReader(activitySmallData))
	if err != nil {
		t.Errorf("%q: DecodeHeaderAndFileId failed: %v", activitySmall, err)
	}
	if gotHeader != wantHeader {
		t.Errorf("%q:\ngot header:\n%#v\nwant header:\n%#v", activitySmall, gotHeader, wantHeader)
	}
	if gotFileId != wantFileId {
		t.Errorf("%q:\ngot FileIdMsg:\n%v\nwant FileIdMsg:\n%v", activitySmall, gotFileId, wantFileId)
	}
}
예제 #2
0
파일: reader_test.go 프로젝트: tormoder/fit
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")
	}
}