2025-06-11 16:01:49 +02:00
|
|
|
package fmp
|
|
|
|
|
2025-06-14 15:30:42 +02:00
|
|
|
import (
|
|
|
|
"slices"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func slicesHaveSameElements[Type comparable](a, b []Type) bool {
|
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, av := range a {
|
|
|
|
found := slices.Contains(b, av)
|
|
|
|
if !found {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2025-06-11 16:01:49 +02:00
|
|
|
|
|
|
|
func TestOpenFile(t *testing.T) {
|
|
|
|
f, err := OpenFile("../files/Untitled.fmp12")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2025-06-11 16:19:31 +02:00
|
|
|
if f.FileSize != 393216 {
|
|
|
|
t.Errorf("expected file size to be 393216, got %d", f.FileSize)
|
|
|
|
}
|
2025-06-13 12:09:39 +02:00
|
|
|
if f.numSectors != 95 {
|
|
|
|
t.Errorf("expected number of sectors to be 95, got %d", f.numSectors)
|
2025-06-11 16:19:31 +02:00
|
|
|
}
|
2025-06-11 21:52:52 +02:00
|
|
|
if f.CreatorName != "Pro 12.0" {
|
|
|
|
t.Errorf("expected application name to be 'Pro 12.0', got '%s'", f.CreatorName)
|
2025-06-11 16:01:49 +02:00
|
|
|
}
|
|
|
|
if f.VersionDate.Format("2006-01-02") != "2025-01-11" {
|
|
|
|
t.Errorf("expected version date to be '2025-01-11', got '%s'", f.VersionDate.Format("2006-01-02"))
|
|
|
|
}
|
2025-06-12 10:53:31 +02:00
|
|
|
f.ToDebugFile("../private/output")
|
2025-06-11 16:01:49 +02:00
|
|
|
}
|
2025-06-12 11:44:57 +02:00
|
|
|
|
|
|
|
func TestTables(t *testing.T) {
|
|
|
|
f, err := OpenFile("../files/Untitled.fmp12")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
tables := f.Tables()
|
|
|
|
|
2025-06-14 15:30:42 +02:00
|
|
|
expectedNames := []string{"Untitled", "WayDomains", "WayProcesses"}
|
|
|
|
tableNames := []string{}
|
|
|
|
for _, table := range tables {
|
|
|
|
tableNames = append(tableNames, table.Name)
|
2025-06-14 15:19:36 +02:00
|
|
|
}
|
|
|
|
|
2025-06-14 15:30:42 +02:00
|
|
|
if !slicesHaveSameElements(tableNames, expectedNames) {
|
|
|
|
t.Errorf("tables do not match")
|
2025-06-12 11:44:57 +02:00
|
|
|
}
|
|
|
|
}
|