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 volum bitmap on
|
|
|
|
// a ProDOS drive image
|
|
|
|
|
2021-06-09 12:23:18 +00:00
|
|
|
package prodos
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateVolumeBitmap(t *testing.T) {
|
|
|
|
var tests = []struct {
|
2024-03-11 13:05:23 +00:00
|
|
|
blocks uint16
|
|
|
|
want uint16
|
2021-06-09 12:23:18 +00:00
|
|
|
}{
|
2024-03-11 13:05:23 +00:00
|
|
|
{65535, 8192},
|
2021-06-09 12:23:18 +00:00
|
|
|
{65533, 8192},
|
|
|
|
{140, 512},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
testname := fmt.Sprintf("%d", tt.blocks)
|
|
|
|
t.Run(testname, func(t *testing.T) {
|
2021-06-29 02:26:20 +00:00
|
|
|
volumeBitMap := createVolumeBitmap(tt.blocks)
|
2024-03-11 13:05:23 +00:00
|
|
|
ans := uint16(len(volumeBitMap))
|
2021-06-09 12:23:18 +00:00
|
|
|
if ans != tt.want {
|
|
|
|
t.Errorf("got %d, want %d", ans, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-06-26 01:15:20 +00:00
|
|
|
|
|
|
|
func TestCheckFreeBlockInVolumeBitmap(t *testing.T) {
|
|
|
|
var tests = []struct {
|
2024-03-11 13:05:23 +00:00
|
|
|
blocks uint16
|
2021-06-26 01:15:20 +00:00
|
|
|
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) {
|
2021-06-29 02:26:20 +00:00
|
|
|
volumeBitMap := createVolumeBitmap(65535)
|
|
|
|
ans := checkFreeBlockInVolumeBitmap(volumeBitMap, tt.blocks)
|
2021-06-26 01:15:20 +00:00
|
|
|
if ans != tt.want {
|
|
|
|
t.Errorf("got %t, want %t", ans, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-03-06 10:29:33 +00:00
|
|
|
|
|
|
|
func TestMarkBlockInVolumeBitmap(t *testing.T) {
|
|
|
|
var tests = []struct {
|
2024-03-11 13:05:23 +00:00
|
|
|
blocks uint16
|
2022-03-06 10:29:33 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|