summaryrefslogtreecommitdiffstats
path: root/net/dns/dns_config_service_win_unittest.cc
blob: 6397c32035c9474676d81f0482e42e2488cfdb44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/dns/dns_config_service_win.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace net {

namespace {

TEST(DnsConfigServiceWinTest, ParseDomain) {
  const struct TestCase {
    const wchar_t* input;
    const char* output[4];  // NULL-terminated, empty if expected false
  } cases[] = {
    { L"chromium.org", { "chromium.org", NULL } },
    { L"chromium.org,org", { "chromium.org", "org", NULL } },
    // Empty suffixes terminate the list
    { L"crbug.com,com,,org", { "crbug.com", "com", NULL } },
    // IDN are converted to punycode
    { L"\u017c\xf3\u0142ta.pi\u0119\u015b\u0107.pl,pl",
        { "xn--ta-4ja03asj.xn--pi-wla5e0q.pl", "pl", NULL } },
    // Empty search list is invalid
    { L"", { NULL } },
    { L",,", { NULL } },
    { NULL, { NULL } },
  };

  std::vector<std::string> actual_output, expected_output;
  for (const TestCase* t = cases; t->input; ++t) {
    actual_output.clear();
    actual_output.push_back("UNSET");
    expected_output.clear();
    for (const char* const* output = t->output; *output; ++output) {
      expected_output.push_back(*output);
    }
    bool result = ParseSearchList(t->input, &actual_output);
    if (!expected_output.empty()) {
      EXPECT_TRUE(result);
      EXPECT_EQ(expected_output, actual_output);
    } else {
      EXPECT_FALSE(result) << "Unexpected parse success on " << t->input;
      expected_output.push_back("UNSET");
      EXPECT_EQ(expected_output, actual_output);
    }
  }
}

}  // namespace

}  // namespace net