libstdc++: Fix testsuite for remote testing (and sim)
[official-gcc.git] / libgo / go / net / dnsname_test.go
blob28b7c680feb16a27fa7ce3fd6d310c5cb80bc84b
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 //go:build !js
7 package net
9 import (
10 "strings"
11 "testing"
14 type dnsNameTest struct {
15 name string
16 result bool
19 var dnsNameTests = []dnsNameTest{
20 // RFC 2181, section 11.
21 {"_xmpp-server._tcp.google.com", true},
22 {"foo.com", true},
23 {"1foo.com", true},
24 {"26.0.0.73.com", true},
25 {"10-0-0-1", true},
26 {"fo-o.com", true},
27 {"fo1o.com", true},
28 {"foo1.com", true},
29 {"a.b..com", false},
30 {"a.b-.com", false},
31 {"a.b.com-", false},
32 {"a.b..", false},
33 {"b.com.", true},
36 func emitDNSNameTest(ch chan<- dnsNameTest) {
37 defer close(ch)
38 var char63 = ""
39 for i := 0; i < 63; i++ {
40 char63 += "a"
42 char64 := char63 + "a"
43 longDomain := strings.Repeat(char63+".", 5) + "example"
45 for _, tc := range dnsNameTests {
46 ch <- tc
49 ch <- dnsNameTest{char63 + ".com", true}
50 ch <- dnsNameTest{char64 + ".com", false}
52 // Remember: wire format is two octets longer than presentation
53 // (length octets for the first and [root] last labels).
54 // 253 is fine:
55 ch <- dnsNameTest{longDomain[len(longDomain)-253:], true}
56 // A terminal dot doesn't contribute to length:
57 ch <- dnsNameTest{longDomain[len(longDomain)-253:] + ".", true}
58 // 254 is bad:
59 ch <- dnsNameTest{longDomain[len(longDomain)-254:], false}
62 func TestDNSName(t *testing.T) {
63 ch := make(chan dnsNameTest)
64 go emitDNSNameTest(ch)
65 for tc := range ch {
66 if isDomainName(tc.name) != tc.result {
67 t.Errorf("isDomainName(%q) = %v; want %v", tc.name, !tc.result, tc.result)
72 func BenchmarkDNSName(b *testing.B) {
73 testHookUninstaller.Do(uninstallTestHooks)
75 benchmarks := append(dnsNameTests, []dnsNameTest{
76 {strings.Repeat("a", 63), true},
77 {strings.Repeat("a", 64), false},
78 }...)
79 for n := 0; n < b.N; n++ {
80 for _, tc := range benchmarks {
81 if isDomainName(tc.name) != tc.result {
82 b.Errorf("isDomainName(%q) = %v; want %v", tc.name, !tc.result, tc.result)