2024-03-12 02:16:02 +00:00
|
|
|
// Copyright Terence J. Boldt (c)2021-2024
|
2023-01-04 04:24:48 +00:00
|
|
|
// Use of this source code is governed by an MIT
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// This file provides tests for access to format a ProDOS drive image
|
|
|
|
|
2021-07-02 02:35:26 +00:00
|
|
|
package prodos
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateVolume(t *testing.T) {
|
|
|
|
var tests = []struct {
|
2024-03-11 13:05:23 +00:00
|
|
|
blocks uint16
|
2021-07-02 02:35:26 +00:00
|
|
|
wantVolumeName string
|
2024-03-11 13:05:23 +00:00
|
|
|
wantFreeBlocks uint16
|
2021-07-02 02:35:26 +00:00
|
|
|
}{
|
|
|
|
{65535, "MAX", 65513},
|
|
|
|
{65500, "ALMOST.MAX", 65478},
|
|
|
|
{280, "FLOPPY", 273},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
testname := fmt.Sprintf("%d", tt.blocks)
|
|
|
|
t.Run(testname, func(t *testing.T) {
|
2022-01-23 21:58:34 +00:00
|
|
|
file := NewMemoryFile(0x2000000)
|
2021-07-03 12:37:21 +00:00
|
|
|
|
2022-03-04 23:08:33 +00:00
|
|
|
CreateVolume(file, tt.wantVolumeName, tt.blocks)
|
2021-07-03 12:37:21 +00:00
|
|
|
|
2022-03-04 23:08:33 +00:00
|
|
|
volumeHeader, _, fileEntries, _ := ReadDirectory(file, "")
|
2021-07-02 02:35:26 +00:00
|
|
|
if volumeHeader.VolumeName != tt.wantVolumeName {
|
|
|
|
t.Errorf("got volume name %s, want %s", volumeHeader.VolumeName, tt.wantVolumeName)
|
|
|
|
}
|
|
|
|
if volumeHeader.TotalBlocks != tt.blocks {
|
|
|
|
t.Errorf("got total blocks %d, want %d", volumeHeader.TotalBlocks, tt.blocks)
|
|
|
|
}
|
|
|
|
if len(fileEntries) > 0 {
|
|
|
|
t.Errorf("got files %d, want 0", len(fileEntries))
|
|
|
|
}
|
|
|
|
|
2022-03-04 23:08:33 +00:00
|
|
|
volumeBitmap, _ := ReadVolumeBitmap(file)
|
2021-07-03 12:37:21 +00:00
|
|
|
freeBlockCount := GetFreeBlockCount(volumeBitmap, tt.blocks)
|
2021-07-02 02:35:26 +00:00
|
|
|
if freeBlockCount != tt.wantFreeBlocks {
|
|
|
|
t.Errorf("got free blocks: %d, want %d", freeBlockCount, tt.wantFreeBlocks)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|