package udp import ( "bytes" "testing" ) // What we send has to be what we can read back: Logger32 and the rest decode // this with the same rules our own parser uses, so a round trip through // ParseWSJT is the honest check. // // The case behind it: OpsLog reported "sent 1153 bytes to 127.0.0.1:2250" and // Logger32 showed nothing. Both were true — its UDP sockets speak the WSJT-X // protocol and discard a bare ADIF record without a word. func TestWSJTLoggedADIFRoundTrips(t *testing.T) { const rec = "VK9XX20mFT820260814174433" pkt := BuildWSJTLoggedADIF("OpsLog", rec) ev, ok, err := ParseWSJT(pkt) if err != nil { t.Fatalf("ParseWSJT: %v", err) } if !ok { t.Fatal("our own parser did not recognise the datagram we build") } if ev.LoggedADIF != rec { t.Errorf("ADIF = %q, want %q", ev.LoggedADIF, rec) } if ev.ProgramID != "OpsLog" { t.Errorf("id = %q, want OpsLog — a receiver uses it to tell instances apart", ev.ProgramID) } } // The header is fixed and other programs match on it byte for byte. func TestWSJTLoggedADIFHeader(t *testing.T) { pkt := BuildWSJTLoggedADIF("OpsLog", "") want := []byte{ 0xad, 0xbc, 0xcb, 0xda, // magic 0x00, 0x00, 0x00, 0x02, // schema 2 0x00, 0x00, 0x00, 0x0c, // type 12 — Logged ADIF 0x00, 0x00, 0x00, 0x06, // len("OpsLog") 'O', 'p', 's', 'L', 'o', 'g', 0x00, 0x00, 0x00, 0x05, // len("") '<', 'E', 'O', 'R', '>', } if !bytes.Equal(pkt, want) { t.Errorf("packet = % X\nwant % X", pkt, want) } }