diskii/prodos/prodos_test.go
2021-07-10 21:09:57 -04:00

93 lines
2.2 KiB
Go

package prodos
import (
"crypto/rand"
"strings"
"testing"
"github.com/kr/pretty"
"github.com/zellyn/diskii/disk"
)
func randomBlock() disk.Block {
var b1 disk.Block
rand.Read(b1[:])
return b1
}
// TestVolumeDirectoryKeyBlockMarshalRoundtrip checks a simple roundtrip of VDKB data.
func TestVolumeDirectoryKeyBlockMarshalRoundtrip(t *testing.T) {
b1 := randomBlock()
vdkb := &VolumeDirectoryKeyBlock{}
vdkb.FromBlock(b1)
b2, err := vdkb.ToBlock()
if err != nil {
t.Fatal(err)
}
if b1 != b2 {
t.Fatalf("Blocks differ: %s", strings.Join(pretty.Diff(b1[:], b2[:]), "; "))
}
vdkb2 := &VolumeDirectoryKeyBlock{}
vdkb2.FromBlock(b2)
if *vdkb != *vdkb2 {
t.Errorf("Structs differ: %v != %v", vdkb, vdkb2)
}
}
// TestVolumeDirectoryBlockMarshalRoundtrip checks a simple roundtrip of VDB data.
func TestVolumeDirectoryBlockMarshalRoundtrip(t *testing.T) {
b1 := randomBlock()
vdb := &VolumeDirectoryBlock{}
vdb.FromBlock(b1)
b2, err := vdb.ToBlock()
if err != nil {
t.Fatal(err)
}
if b1 != b2 {
t.Fatalf("Blocks differ: %s", strings.Join(pretty.Diff(b1[:], b2[:]), "; "))
}
vdb2 := &VolumeDirectoryBlock{}
vdb2.FromBlock(b2)
if *vdb != *vdb2 {
t.Errorf("Structs differ: %v != %v", vdb, vdb2)
}
}
// TestSubdirectoryKeyBlockMarshalRoundtrip checks a simple roundtrip of SKB data.
func TestSubdirectoryKeyBlockMarshalRoundtrip(t *testing.T) {
b1 := randomBlock()
skb := &SubdirectoryKeyBlock{}
skb.FromBlock(b1)
b2, err := skb.ToBlock()
if err != nil {
t.Fatal(err)
}
if b1 != b2 {
t.Fatalf("Blocks differ: %s", strings.Join(pretty.Diff(b1[:], b2[:]), "; "))
}
skb2 := &SubdirectoryKeyBlock{}
skb2.FromBlock(b2)
if *skb != *skb2 {
t.Errorf("Structs differ: %v != %v", skb, skb2)
}
}
// TestSubdirectoryBlockMarshalRoundtrip checks a simple roundtrip of SB data.
func TestSubdirectoryBlockMarshalRoundtrip(t *testing.T) {
b1 := randomBlock()
sb := &SubdirectoryBlock{}
sb.FromBlock(b1)
b2, err := sb.ToBlock()
if err != nil {
t.Fatal(err)
}
if b1 != b2 {
t.Fatalf("Blocks differ: %s", strings.Join(pretty.Diff(b1[:], b2[:]), "; "))
}
sb2 := &SubdirectoryBlock{}
sb2.FromBlock(b2)
if *sb != *sb2 {
t.Errorf("Structs differ: %v != %v", sb, sb2)
}
}