Start adding LOC tests

This commit is contained in:
Miek Gieben 2012-04-30 21:42:58 +02:00
parent 57f5a215d1
commit d85d8f9fe9
4 changed files with 69 additions and 25 deletions

View File

@ -228,7 +228,6 @@ func TestParseDirectiveMisc(t *testing.T) {
}
}
// Another one hear, geared to NSECx
func TestParseNSEC(t *testing.T) {
nsectests := map[string]string{
"nl. IN NSEC3PARAM 1 0 5 30923C44C6CBBB8F": "nl.\t3600\tIN\tNSEC3PARAM\t1 0 5 30923C44C6CBBB8F",
@ -252,6 +251,16 @@ func TestParseNSEC(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")
if e != nil {
t.Log("Failed to parse LOC RR: " + e.Error())
t.Fatal()
} else {
t.Logf("RR is OK: `%s'\n", l1.String())
}
}
func TestQuotes(t *testing.T) {
tests := map[string]string{
`t.example.com. IN TXT "a bc"`: "t.example.com.\t3600\tIN\tTXT\t\"a bc\"",

View File

@ -889,7 +889,7 @@ func (rr *RR_NSEC3) String() string {
s += strconv.Itoa(int(rr.Hash)) +
" " + strconv.Itoa(int(rr.Flags)) +
" " + strconv.Itoa(int(rr.Iterations)) +
" " + strings.ToUpper(rr.Salt) +
" " + saltString(rr.Salt) +
" " + rr.NextDomain
for i := 0; i < len(rr.TypeBitMap); i++ {
if _, ok := Rr_str[rr.TypeBitMap[i]]; ok {
@ -924,7 +924,7 @@ func (rr *RR_NSEC3PARAM) String() string {
s += strconv.Itoa(int(rr.Hash)) +
" " + strconv.Itoa(int(rr.Flags)) +
" " + strconv.Itoa(int(rr.Iterations)) +
" " + strings.ToUpper(rr.Salt)
" " + saltString(rr.Salt)
return s
}

View File

@ -775,6 +775,28 @@ func appendOrigin(name, origin string) string {
return name + "." + origin
}
// LOC record helper function
func locCheckNorth(token string, latitude uint32) (uint32, bool) {
switch token {
case "n", "N":
return _LOC_EQUATOR + latitude, true
case "s", "S":
return _LOC_EQUATOR - latitude, true
}
return latitude, false
}
// LOC record helper function
func locCheckEast(token string, longitude uint32) (uint32, bool) {
switch token {
case "e", "E":
return _LOC_EQUATOR + longitude, true
case "w", "W":
return _LOC_EQUATOR - longitude, true
}
return longitude, false
}
func slurpRemainder(c chan lex, f string) *ParseError {
l := <-c
switch l.value {

View File

@ -511,33 +511,46 @@ Altitude:
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad LOC Altitude", l}
} else {
rr.Altitude = uint32(i * 100.0 + 10000000.0) // +0.5 in ldns?
rr.Altitude = uint32(i*100.0 + 10000000.0) // +0.5 in ldns?
}
// And now optionally the other values
l = <-c
count := 0
for l.value != _NEWLINE && l.value != _EOF {
switch l.value {
case _STRING:
switch count {
case 0: // Size
if e, m, ok := stringToCm(l.token); !ok {
return nil, &ParseError{f, "bad LOC Size", l}
} else {
rr.Size = (e & 0x0f) | (m << 4 & 0xf0)
}
case 1: // HorizPre
if e, m, ok := stringToCm(l.token); !ok {
return nil, &ParseError{f, "bad LOC HorizPre", l}
} else {
rr.HorizPre = (e & 0x0f) | (m << 4 & 0xf0)
}
case 2: // VertPre
if e, m, ok := stringToCm(l.token); !ok {
return nil, &ParseError{f, "bad LOC VertPre", l}
} else {
rr.VertPre = (e & 0x0f) | (m << 4 & 0xf0)
}
}
count++
case _BLANK:
// Ok
default:
return nil, &ParseError{f, "bad LOC Size, HorizPre or VertPre", l}
}
l = <-c
}
return rr, nil
}
func locCheckNorth(token string, latitude uint32) (uint32, bool) {
switch token {
case "n", "N":
return _LOC_EQUATOR + latitude, true
case "s", "S":
return _LOC_EQUATOR - latitude, true
}
return latitude, false
}
func locCheckEast(token string, longitude uint32) (uint32, bool) {
switch token {
case "e", "E":
return _LOC_EQUATOR + longitude, true
case "w", "W":
return _LOC_EQUATOR - longitude, true
}
return longitude, false
}
func setHIP(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RR_HIP)
rr.Hdr = h