mirror of
https://github.com/tjboldt/ProDOS-Utilities.git
synced 2024-12-27 20:29:18 +00:00
Move and add tests
This commit is contained in:
parent
46cfc454c5
commit
4fa573260c
@ -2,7 +2,7 @@
|
||||
// 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
|
||||
// This file provides tests for access to volume bitmap on
|
||||
// a ProDOS drive image
|
||||
|
||||
package prodos
|
||||
@ -89,3 +89,26 @@ func TestMarkBlockInVolumeBitmap(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateVolumeBitmap(t *testing.T) {
|
||||
blockList := []uint16{10, 11, 12, 100, 120}
|
||||
|
||||
virtualDisk := NewMemoryFile(0x2000000)
|
||||
CreateVolume(virtualDisk, "VIRTUAL.DISK", 0xFFFE)
|
||||
updateVolumeBitmap(virtualDisk, blockList)
|
||||
|
||||
for _, tt := range blockList {
|
||||
testname := fmt.Sprintf("%d", tt)
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
|
||||
volumeBitmap, err := ReadVolumeBitmap(virtualDisk)
|
||||
if err != nil {
|
||||
t.Error("got error, want nil")
|
||||
}
|
||||
free := checkFreeBlockInVolumeBitmap(volumeBitmap, tt)
|
||||
if free {
|
||||
t.Errorf("got true, want false")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// This file provides access to read, write, delete
|
||||
// fand parse directories on a ProDOS drive image
|
||||
// and parse directories on a ProDOS drive image
|
||||
|
||||
package prodos
|
||||
|
||||
@ -117,7 +117,7 @@ func ReadDirectory(reader io.ReaderAt, path string) (VolumeHeader, DirectoryHead
|
||||
// on a ProDOS image
|
||||
func CreateDirectory(readerWriter ReaderWriterAt, path string) error {
|
||||
if len(path) == 0 {
|
||||
return errors.New("cannot create directory with path")
|
||||
return errors.New("cannot create directory without path")
|
||||
}
|
||||
|
||||
// add volume name if not full path
|
||||
|
79
prodos/directory_test.go
Normal file
79
prodos/directory_test.go
Normal file
@ -0,0 +1,79 @@
|
||||
// Copyright Terence J. Boldt (c)2024
|
||||
// Use of this source code is governed by an MIT
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// This file provides tests for directories on
|
||||
// a ProDOS drive image
|
||||
|
||||
package prodos
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateDirectoryWithoutPathFails(t *testing.T) {
|
||||
t.Run("TestCreateDirectoryWithoutPathFails", func(t *testing.T) {
|
||||
file := NewMemoryFile(0x2000000)
|
||||
|
||||
CreateVolume(file, "test.volume", 1024)
|
||||
|
||||
err := CreateDirectory(file, "")
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("got nil, want non-nil")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateDuplicateDirectoryFails(t *testing.T) {
|
||||
t.Run("TestCreateDuplicateDirectoryFails", func(t *testing.T) {
|
||||
file := NewMemoryFile(0x2000000)
|
||||
|
||||
CreateVolume(file, "test.volume", 1024)
|
||||
|
||||
err := CreateDirectory(file, "duplicate")
|
||||
if err != nil {
|
||||
t.Errorf("failed to create directory: %s", err)
|
||||
}
|
||||
|
||||
err = CreateDirectory(file, "duplicate")
|
||||
|
||||
if err == nil {
|
||||
t.Error("got nil, want non-nil")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCreateAndReadDirectory(t *testing.T) {
|
||||
var tests = []struct {
|
||||
testName string
|
||||
createPath string
|
||||
readPath string
|
||||
expectedCount int
|
||||
}{
|
||||
{"checkRoot", "", "/test", 0},
|
||||
{"checkCreateInRoot", "one", "/test", 1},
|
||||
{"checkRootCreateInSub", "/test/one/two", "/test", 1},
|
||||
{"checkSub", "", "/test/one", 1},
|
||||
}
|
||||
|
||||
file := NewMemoryFile(0x2000000)
|
||||
CreateVolume(file, "test", 1024)
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.testName, func(t *testing.T) {
|
||||
if len(tt.createPath) > 0 {
|
||||
CreateDirectory(file, tt.createPath)
|
||||
}
|
||||
_, _, fileEntries, err := ReadDirectory(file, tt.readPath)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("got error %s", err)
|
||||
}
|
||||
got := len(fileEntries)
|
||||
if got != int(tt.expectedCount) {
|
||||
t.Errorf("got %d, want %d", got, tt.expectedCount)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -39,26 +39,3 @@ func TestCreateBlocklist(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateVolumeBitmap(t *testing.T) {
|
||||
blockList := []uint16{10, 11, 12, 100, 120}
|
||||
|
||||
virtualDisk := NewMemoryFile(0x2000000)
|
||||
CreateVolume(virtualDisk, "VIRTUAL.DISK", 0xFFFE)
|
||||
updateVolumeBitmap(virtualDisk, blockList)
|
||||
|
||||
for _, tt := range blockList {
|
||||
testname := fmt.Sprintf("%d", tt)
|
||||
t.Run(testname, func(t *testing.T) {
|
||||
|
||||
volumeBitmap, err := ReadVolumeBitmap(virtualDisk)
|
||||
if err != nil {
|
||||
t.Error("got error, want nil")
|
||||
}
|
||||
free := checkFreeBlockInVolumeBitmap(volumeBitmap, tt)
|
||||
if free {
|
||||
t.Errorf("got true, want false")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user