2013-02-11 Sebastian Huber <sebastian.huber@embedded-brains.de>
[official-gcc.git] / libgo / go / net / dnsname_test.go
blob70df693f789a8f0fe4c91a4222166738b3ba506d
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package net
7 import (
8 "testing"
11 type testCase struct {
12 name string
13 result bool
16 var tests = []testCase{
17 // RFC2181, section 11.
18 {"_xmpp-server._tcp.google.com", true},
19 {"_xmpp-server._tcp.google.com", true},
20 {"foo.com", true},
21 {"1foo.com", true},
22 {"26.0.0.73.com", true},
23 {"fo-o.com", true},
24 {"fo1o.com", true},
25 {"foo1.com", true},
26 {"a.b..com", false},
29 func getTestCases(ch chan<- testCase) {
30 defer close(ch)
31 var char59 = ""
32 var char63 = ""
33 var char64 = ""
34 for i := 0; i < 59; i++ {
35 char59 += "a"
37 char63 = char59 + "aaaa"
38 char64 = char63 + "a"
40 for _, tc := range tests {
41 ch <- tc
44 ch <- testCase{char63 + ".com", true}
45 ch <- testCase{char64 + ".com", false}
46 // 255 char name is fine:
47 ch <- testCase{char59 + "." + char63 + "." + char63 + "." +
48 char63 + ".com",
49 true}
50 // 256 char name is bad:
51 ch <- testCase{char59 + "a." + char63 + "." + char63 + "." +
52 char63 + ".com",
53 false}
56 func TestDNSNames(t *testing.T) {
57 ch := make(chan testCase)
58 go getTestCases(ch)
59 for tc := range ch {
60 if isDomainName(tc.name) != tc.result {
61 t.Errorf("isDomainName(%v) failed: Should be %v",
62 tc.name, tc.result)