| OLD | NEW |
| 1 // Copyright 2015 PDFium Authors. All rights reserved. | 1 // Copyright 2015 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/fpdftext/fpdf_text_int.h" | 5 #include "core/fpdftext/fpdf_text_int.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 // Class to help test functions in CPDF_LinkExtract class. | 9 // Class to help test functions in CPDF_LinkExtract class. |
| 10 class CPDF_TestLinkExtract : public CPDF_LinkExtract { | 10 class CPDF_TestLinkExtract : public CPDF_LinkExtract { |
| 11 private: | 11 private: |
| 12 // Add test cases as friends to access protected member functions. | 12 // Add test cases as friends to access protected member functions. |
| 13 // Access CheckMailLink. | 13 // Access CheckMailLink. |
| 14 FRIEND_TEST(fpdf_text_int, CheckMailLink); | 14 FRIEND_TEST(fpdf_text_int, CheckMailLink); |
| 15 }; | 15 }; |
| 16 | 16 |
| 17 TEST(fpdf_text_int, CheckMailLink) { | 17 TEST(fpdf_text_int, CheckMailLink) { |
| 18 CPDF_TestLinkExtract extractor; | 18 CPDF_TestLinkExtract extractor; |
| 19 // Check cases that fail to extract valid mail link. | 19 // Check cases that fail to extract valid mail link. |
| 20 const wchar_t* invalid_strs[] = { | 20 const wchar_t* invalid_strs[] = { |
| 21 L"", | 21 L"", |
| 22 L"peter.pan", // '@' is required. | 22 L"peter.pan", // '@' is required. |
| 23 L"abc@server", // Domain name needs at least one '.'. | 23 L"abc@server", // Domain name needs at least one '.'. |
| 24 L"abc.@gmail.com", // '.' can not immediately precede '@'. | 24 L"abc.@gmail.com", // '.' can not immediately precede '@'. |
| 25 L"abc@xyz&q.org", // Domain name should not contain '&'. | 25 L"abc@xyz&q.org", // Domain name should not contain '&'. |
| 26 L"abc@.xyz.org", // Domain name should not start with '.'. | 26 L"abc@.xyz.org", // Domain name should not start with '.'. |
| 27 L"fan@g..com" // Domain name should not have consecutive '.' | 27 L"fan@g..com" // Domain name should not have consecutive '.' |
| 28 }; | 28 }; |
| 29 for (int i = 0; i < FX_ArraySize(invalid_strs); ++i) { | 29 for (size_t i = 0; i < FX_ArraySize(invalid_strs); ++i) { |
| 30 CFX_WideString text_str(invalid_strs[i]); | 30 CFX_WideString text_str(invalid_strs[i]); |
| 31 EXPECT_FALSE(extractor.CheckMailLink(text_str)); | 31 EXPECT_FALSE(extractor.CheckMailLink(text_str)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Check cases that can extract valid mail link. | 34 // Check cases that can extract valid mail link. |
| 35 // An array of {input_string, expected_extracted_email_address}. | 35 // An array of {input_string, expected_extracted_email_address}. |
| 36 const wchar_t* valid_strs[][2] = { | 36 const wchar_t* valid_strs[][2] = { |
| 37 {L"peter@abc.d", L"peter@abc.d"}, | 37 {L"peter@abc.d", L"peter@abc.d"}, |
| 38 {L"red.teddy.b@abc.com", L"red.teddy.b@abc.com"}, | 38 {L"red.teddy.b@abc.com", L"red.teddy.b@abc.com"}, |
| 39 {L"abc_@gmail.com", L"abc_@gmail.com"}, // '_' is ok before '@'. | 39 {L"abc_@gmail.com", L"abc_@gmail.com"}, // '_' is ok before '@'. |
| 40 {L"dummy-hi@gmail.com", | 40 {L"dummy-hi@gmail.com", |
| 41 L"dummy-hi@gmail.com"}, // '-' is ok in user name. | 41 L"dummy-hi@gmail.com"}, // '-' is ok in user name. |
| 42 {L"a..df@gmail.com", L"df@gmail.com"}, // Stop at consecutive '.'. | 42 {L"a..df@gmail.com", L"df@gmail.com"}, // Stop at consecutive '.'. |
| 43 {L".john@yahoo.com", L"john@yahoo.com"}, // Remove heading '.'. | 43 {L".john@yahoo.com", L"john@yahoo.com"}, // Remove heading '.'. |
| 44 {L"abc@xyz.org?/", L"abc@xyz.org"}, // Trim ending invalid chars. | 44 {L"abc@xyz.org?/", L"abc@xyz.org"}, // Trim ending invalid chars. |
| 45 {L"fan{abc@xyz.org", L"abc@xyz.org"}, // Trim beginning invalid chars. | 45 {L"fan{abc@xyz.org", L"abc@xyz.org"}, // Trim beginning invalid chars. |
| 46 {L"fan@g.com..", L"fan@g.com"}, // Trim the ending periods. | 46 {L"fan@g.com..", L"fan@g.com"}, // Trim the ending periods. |
| 47 {L"CAP.cap@Gmail.Com", L"CAP.cap@Gmail.Com"}, // Keep the original case. | 47 {L"CAP.cap@Gmail.Com", L"CAP.cap@Gmail.Com"}, // Keep the original case. |
| 48 }; | 48 }; |
| 49 for (int i = 0; i < FX_ArraySize(valid_strs); ++i) { | 49 for (size_t i = 0; i < FX_ArraySize(valid_strs); ++i) { |
| 50 CFX_WideString text_str(valid_strs[i][0]); | 50 CFX_WideString text_str(valid_strs[i][0]); |
| 51 CFX_WideString expected_str(L"mailto:"); | 51 CFX_WideString expected_str(L"mailto:"); |
| 52 expected_str += valid_strs[i][1]; | 52 expected_str += valid_strs[i][1]; |
| 53 EXPECT_TRUE(extractor.CheckMailLink(text_str)); | 53 EXPECT_TRUE(extractor.CheckMailLink(text_str)); |
| 54 EXPECT_STREQ(text_str.c_str(), expected_str.c_str()); | 54 EXPECT_STREQ(text_str.c_str(), expected_str.c_str()); |
| 55 } | 55 } |
| 56 } | 56 } |
| OLD | NEW |