protocol/aprs: refactored
This commit is contained in:
120
protocol/aprs/status_test.go
Normal file
120
protocol/aprs/status_test.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package aprs
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseStatusReport(t *testing.T) {
|
||||
tests := []struct {
|
||||
Name string
|
||||
Raw Raw
|
||||
Want *Status
|
||||
}{
|
||||
{
|
||||
"without timestamp",
|
||||
">Net Control Center",
|
||||
&Status{
|
||||
Text: "Net Control Center",
|
||||
},
|
||||
},
|
||||
{
|
||||
"with timestamp",
|
||||
">092345zNet Control Center",
|
||||
&Status{
|
||||
Text: "Net Control Center",
|
||||
},
|
||||
},
|
||||
{
|
||||
"with beam heading and erp",
|
||||
">Test^B7",
|
||||
&Status{
|
||||
Text: "Test",
|
||||
BeamHeading: 110,
|
||||
ERP: 490,
|
||||
},
|
||||
},
|
||||
{
|
||||
"with maidenhead locator",
|
||||
">IO91SX/G",
|
||||
&Status{
|
||||
Latitude: 51.958333,
|
||||
Longitude: -0.5,
|
||||
Symbol: "/G",
|
||||
},
|
||||
},
|
||||
{
|
||||
"with short maidenhead locator",
|
||||
">IO91/G",
|
||||
&Status{
|
||||
Latitude: 51,
|
||||
Longitude: -2,
|
||||
Symbol: "/G",
|
||||
},
|
||||
},
|
||||
{
|
||||
"with maidenhead locator and comment",
|
||||
">IO91SX/- My house",
|
||||
&Status{
|
||||
Latitude: 51.958333,
|
||||
Longitude: -0.5,
|
||||
Symbol: "/-",
|
||||
Text: "My house",
|
||||
},
|
||||
},
|
||||
{
|
||||
"with maidenhead locator and beam heading",
|
||||
">IO91SX/- ^B7",
|
||||
&Status{
|
||||
Latitude: 51.958333,
|
||||
Longitude: -0.5,
|
||||
Symbol: "/-",
|
||||
BeamHeading: 110,
|
||||
ERP: 490,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var decoder statusReportDecoder
|
||||
for _, test := range tests {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
frame := Frame{Raw: test.Raw}
|
||||
if !decoder.CanDecode(frame) {
|
||||
t.Fatalf("%T can't decode %q", decoder, test.Raw)
|
||||
}
|
||||
|
||||
v, err := decoder.Decode(frame)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testCompareStatusReport(t, test.Want, v)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func testCompareStatusReport(t *testing.T, want *Status, value any) {
|
||||
t.Helper()
|
||||
|
||||
test, ok := value.(*Status)
|
||||
if !ok {
|
||||
t.Fatalf("expected data to be a %T, got %T", want, value)
|
||||
return
|
||||
}
|
||||
|
||||
if !testAlmostEqual(test.Latitude, want.Latitude) {
|
||||
t.Errorf("expected latitude %f, got %f", want.Latitude, test.Latitude)
|
||||
}
|
||||
if !testAlmostEqual(test.Longitude, want.Longitude) {
|
||||
t.Errorf("expected longitude %f, got %f", want.Longitude, test.Longitude)
|
||||
}
|
||||
if test.BeamHeading != want.BeamHeading {
|
||||
t.Errorf("expected beam heading %d, got %d", want.BeamHeading, test.BeamHeading)
|
||||
}
|
||||
if test.ERP != want.ERP {
|
||||
t.Errorf("expected ERP %dW, got %dW", want.ERP, test.ERP)
|
||||
}
|
||||
if test.Symbol != want.Symbol {
|
||||
t.Errorf("expected symbol %q, got %q", want.Symbol, test.Symbol)
|
||||
}
|
||||
if test.Text != want.Text {
|
||||
t.Errorf("expected text %q, got %q", want.Text, test.Text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user