github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/exp/cksum/cksum_test.go (about) 1 // Copyright 2018 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "testing" 9 10 "github.com/u-root/u-root/pkg/testutil" 11 ) 12 13 func TestCksum(t *testing.T) { 14 var testMatrix = []struct { 15 data []byte 16 cksum uint32 17 }{ 18 {[]byte("abcdef\n"), 3512391007}, 19 {[]byte("pqra\n"), 1063566492}, 20 {[]byte("abcdef\nafdsfsfgdglfdgkdlvcmdfposvpomfvmlcvdfk;lgkd'f;k;lvcvcv\n" + 21 "afdsfsfgdglfdgkdlvcmdfposvpomfvmlcvdfk;lgkd'f;k;lvcvcv\nafdsfsfg" + 22 "dglfdgkdlvcmdfposvpomfvmlcvdfk;lgkd'f;k;lvcvcv\nafdsfsfgdglfdgkd" + 23 "lvcmdfposvpomfvmlcvdfk;lgkd'f;k;lvcvcv\nsdddsfsfsdfsdfsdasaarwre" + 24 "mazadsfssfsfsfsafsadfsfdsadfsafsafsfsafdsfsdfsfdsdf"), 689622513}, 25 } 26 27 for _, testData := range testMatrix { 28 if testData.cksum != calculateCksum(testData.data) { 29 t.Errorf("Cksum verification failed. (Expected: %d, Received: %d)", testData.cksum, calculateCksum(testData.data)) 30 } 31 } 32 } 33 34 func TestMain(m *testing.M) { 35 testutil.Run(m, main) 36 }