This commit is contained in:
Miek Gieben 2012-04-30 21:57:42 +02:00
parent d85d8f9fe9
commit 2ea2204a8b
2 changed files with 24 additions and 12 deletions

View File

@ -252,12 +252,23 @@ func TestParseNSEC(t *testing.T) {
} }
func TestParseLOC(t *testing.T) { func TestParseLOC(t *testing.T) {
l1, e := NewRR("SW1A2AA.find.me.uk. 604797 IN LOC 51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m") lt := map[string]string{
if e != nil { "SW1A2AA.find.me.uk. LOC 51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m":
t.Log("Failed to parse LOC RR: " + e.Error()) "SW1A2AA.find.me.uk.\t3600\tIN\tLOC\t51 30 12.748 N 00 07 39.611 W 0.00m 0.00m 0.00m 0.00m",
t.Fatal() }
} else { for i, o := range lt {
t.Logf("RR is OK: `%s'\n", l1.String()) rr, e := NewRR(i)
if e != nil {
t.Log("Failed to parse RR: " + e.Error())
t.Fail()
continue
}
if rr.String() != o {
t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
t.Fail()
} else {
t.Logf("RR is OK: `%s'", rr.String())
}
} }
} }

View File

@ -449,10 +449,10 @@ func setLOC(h RR_Header, c chan lex, f string) (RR, *ParseError) {
if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok { if rr.Latitude, ok = locCheckNorth(l.token, rr.Latitude); ok {
goto East goto East
} }
if i, e := strconv.Atoi(l.token); e != nil { if i, e := strconv.ParseFloat(l.token, 32); e != nil {
return nil, &ParseError{f, "bad LOC Latitude seconds", l} return nil, &ParseError{f, "bad LOC Latitude seconds", l}
} else { } else {
rr.Latitude += 1000 * 60 * 60 * uint32(i) rr.Latitude += uint32(1000 * 60 * 60 * i)
} }
<-c // _BLANK <-c // _BLANK
// Either number, 'N' or 'S' // Either number, 'N' or 'S'
@ -465,6 +465,7 @@ func setLOC(h RR_Header, c chan lex, f string) (RR, *ParseError) {
East: East:
// East // East
<-c // _BLANK
l = <-c l = <-c
if i, e := strconv.Atoi(l.token); e != nil { if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad LOC Longitude", l} return nil, &ParseError{f, "bad LOC Longitude", l}
@ -488,10 +489,10 @@ East:
if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok { if rr.Longitude, ok = locCheckEast(l.token, rr.Longitude); ok {
goto Altitude goto Altitude
} }
if i, e := strconv.Atoi(l.token); e != nil { if i, e := strconv.ParseFloat(l.token, 32); e != nil {
return nil, &ParseError{f, "bad LOC Longitude seconds", l} return nil, &ParseError{f, "bad LOC Longitude seconds", l}
} else { } else {
rr.Longitude += 1000 * 60 * 60 * uint32(i) rr.Longitude += uint32(1000 * 60 * 60 * i)
} }
<-c // _BLANK <-c // _BLANK
// Either number, 'E' or 'W' // Either number, 'E' or 'W'
@ -508,10 +509,10 @@ Altitude:
if l.token[len(l.token)-1] == 'M' || l.token[len(l.token)-1] == 'm' { if l.token[len(l.token)-1] == 'M' || l.token[len(l.token)-1] == 'm' {
l.token = l.token[0 : len(l.token)-1] l.token = l.token[0 : len(l.token)-1]
} }
if i, e := strconv.Atoi(l.token); e != nil { if i, e := strconv.ParseFloat(l.token, 32); e != nil {
return nil, &ParseError{f, "bad LOC Altitude", l} return nil, &ParseError{f, "bad LOC Altitude", l}
} else { } else {
rr.Altitude = uint32(i*100.0 + 10000000.0) // +0.5 in ldns? rr.Altitude = uint32(i*100.0 + 10000000.0 + 0.5)
} }
// And now optionally the other values // And now optionally the other values