64 CPDF_TestLinkExtract extractor;
67 const wchar_t*
const kInvalidCases[] = {
76 L"http//[example.com",
77 L"http//[00:00:00:00:00:00",
81 for (
const wchar_t* input : kInvalidCases) {
82 auto maybe_link = extractor.CheckWebLink(input);
83 EXPECT_FALSE(maybe_link.has_value()) << input;
89 const wchar_t*
const input_string;
90 const wchar_t*
const url_extracted;
91 const size_t start_offset;
94 const ValidCase kValidCases[] = {
95 {L"http://www.example.com", L"http://www.example.com", 0,
97 {L"http://www.example.com:88", L"http://www.example.com:88", 0,
99 {L"http://test@www.example.com", L"http://test@www.example.com", 0,
101 {L"http://test:test@example.com", L"http://test:test@example.com", 0,
103 {L"http://example", L"http://example", 0,
105 {L"http////www.server", L"http://www.server", 8,
107 {L"http:/www.abc.com", L"http://www.abc.com", 6,
109 {L"www.a.b.c", L"http://www.a.b.c", 0, 9},
110 {L"https://a.us", L"https://a.us", 0, 12},
111 {L"https://www.t.us", L"https://www.t.us", 0, 16},
112 {L"www.example-test.com", L"http://www.example-test.com", 0,
114 {L"www.example.com,", L"http://www.example.com", 0,
116 {L"www.example.com;(", L"http://www.example.com", 0,
118 {L"test:www.abc.com", L"http://www.abc.com", 5,
120 {L"(http://www.abc.com)", L"http://www.abc.com", 1,
122 {L"0(http://www.abc.com)0", L"http://www.abc.com", 2,
124 {L"0(www.abc.com)0", L"http://www.abc.com", 2,
126 {L"http://www.abc.com)0", L"http://www.abc.com)0", 0,
128 {L"{(<http://www.abc.com>)}", L"http://www.abc.com", 3,
130 {L"[http://www.abc.com/z(1)]", L"http://www.abc.com/z(1)", 1,
132 {L"(http://www.abc.com/z(1))", L"http://www.abc.com/z(1)", 1,
134 {L"\"http://www.abc.com\"", L"http://www.abc.com", 1,
136 {L"www.g.com..", L"http://www.g.com..", 0, 11},
139 {L"http://192.168.0.1", L"http://192.168.0.1", 0, 18},
140 {L"http://192.168.0.1:80", L"http://192.168.0.1:80", 0,
142 {L"http://[aa::00:bb::00:cc:00]", L"http://[aa::00:bb::00:cc:00]", 0,
144 {L"http://[aa::00:bb::00:cc:00]:12", L"http://[aa::00:bb::00:cc:00]:12",
146 {L"http://[aa]:12", L"http://[aa]:12", 0,
148 {L"http://[aa]:12abc", L"http://[aa]:12", 0,
150 {L"http://[aa]:", L"http://[aa]", 0, 11},
153 {L"www.abc.com/#%%^&&*(", L"http://www.abc.com/#%%^&&*(", 0, 20},
154 {L"www.a.com/#a=@?q=rr&r=y", L"http://www.a.com/#a=@?q=rr&r=y", 0, 23},
155 {L"http://a.com/1/2/3/4\5\6", L"http://a.com/1/2/3/4\5\6", 0, 22},
156 {L"http://www.example.com/foo;bar", L"http://www.example.com/foo;bar", 0,
160 {L"http://ex[am]ple", L"http://ex[am]ple", 0, 16},
161 {L"http://:example.com", L"http://:example.com", 0, 19},
162 {L"http://((())/path?", L"http://((())/path?", 0, 18},
163 {L"http:////abc.server", L"http:////abc.server", 0, 19},
166 {L"www.测试.net", L"http://www.测试.net", 0, 10},
167 {L"www.测试。net。", L"http://www.测试。net。", 0, 11},
168 {L"www.测试.net;", L"http://www.测试.net;", 0, 11},
170 for (
const auto& it : kValidCases) {
171 auto maybe_link = extractor.CheckWebLink(it.input_string);
172 ASSERT_TRUE(maybe_link.has_value()) << it.input_string;
173 EXPECT_STREQ(it.url_extracted, maybe_link.value().m_strUrl.c_str());
174 EXPECT_EQ(it.start_offset, maybe_link.value().m_Start) << it.input_string;
175 EXPECT_EQ(it.count, maybe_link.value().m_Count) << it.input_string;