mirror of
https://github.com/tjboldt/ProDOS-Utilities.git
synced 2024-12-28 11:32:05 +00:00
6cc7db13e1
* Add tree file read support * Update copyright year * Add tree file write support
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
// Copyright Terence J. Boldt (c)2021-2023
|
|
// 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 volum bitmap on
|
|
// a ProDOS drive image
|
|
|
|
package prodos
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestCreateVolumeBitmap(t *testing.T) {
|
|
var tests = []struct {
|
|
blocks int
|
|
want int
|
|
}{
|
|
{65536, 8192},
|
|
{65533, 8192},
|
|
{140, 512},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
testname := fmt.Sprintf("%d", tt.blocks)
|
|
t.Run(testname, func(t *testing.T) {
|
|
volumeBitMap := createVolumeBitmap(tt.blocks)
|
|
ans := len(volumeBitMap)
|
|
if ans != tt.want {
|
|
t.Errorf("got %d, want %d", ans, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCheckFreeBlockInVolumeBitmap(t *testing.T) {
|
|
var tests = []struct {
|
|
blocks int
|
|
want bool
|
|
}{
|
|
{0, false}, // boot block
|
|
{1, false}, // SOS boot block
|
|
{2, false}, // volume root
|
|
{21, false}, // end of volume bitmap
|
|
{22, true}, // beginning of free space
|
|
{8192, true}, // more free space
|
|
{65534, true}, // last free block
|
|
{65535, false}, // can't use last block because volume size is 0xFFFF, not 0x10000
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
testname := fmt.Sprintf("%d", tt.blocks)
|
|
t.Run(testname, func(t *testing.T) {
|
|
volumeBitMap := createVolumeBitmap(65535)
|
|
ans := checkFreeBlockInVolumeBitmap(volumeBitMap, tt.blocks)
|
|
if ans != tt.want {
|
|
t.Errorf("got %t, want %t", ans, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestMarkBlockInVolumeBitmap(t *testing.T) {
|
|
var tests = []struct {
|
|
blocks int
|
|
want bool
|
|
}{
|
|
{0, false}, // boot block
|
|
{1, false}, // SOS boot block
|
|
{2, false}, // volume root
|
|
{21, false}, // end of volume bitmap
|
|
{22, true}, // beginning of free space
|
|
{999, false}, // end of volume bitmap
|
|
{8192, true}, // more free space
|
|
{65534, true}, // last free block
|
|
{65535, false}, // can't use last block because volume size is 0xFFFF, not 0x10000
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
testname := fmt.Sprintf("%d", tt.blocks)
|
|
t.Run(testname, func(t *testing.T) {
|
|
volumeBitMap := createVolumeBitmap(65535)
|
|
markBlockInVolumeBitmap(volumeBitMap, 999)
|
|
ans := checkFreeBlockInVolumeBitmap(volumeBitMap, tt.blocks)
|
|
if ans != tt.want {
|
|
t.Errorf("got %t, want %t", ans, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|