[email protected] | ec91bfa | 2013-11-09 17:24:27 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 09083eb | 2012-09-20 05:58:43 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | 126e93c | 2015-12-21 21:48:16 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | |
[email protected] | 90626587 | 2013-06-07 22:40:45 | [diff] [blame] | 7 | #include "base/strings/utf_string_conversions.h" |
[email protected] | ec91bfa | 2013-11-09 17:24:27 | [diff] [blame] | 8 | #include "printing/printing_utils.h" |
[email protected] | 09083eb | 2012-09-20 05:58:43 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
| 10 | |
| 11 | namespace printing { |
| 12 | |
vitalybuka | 27e401c | 2015-07-07 18:21:16 | [diff] [blame] | 13 | namespace { |
| 14 | |
| 15 | const size_t kTestLength = 8; |
| 16 | |
| 17 | std::string Simplify(const std::string& title) { |
| 18 | return base::UTF16ToUTF8( |
| 19 | SimplifyDocumentTitleWithLength(base::UTF8ToUTF16(title), kTestLength)); |
[email protected] | 09083eb | 2012-09-20 05:58:43 | [diff] [blame] | 20 | } |
| 21 | |
vitalybuka | 27e401c | 2015-07-07 18:21:16 | [diff] [blame] | 22 | std::string Format(const std::string& owner, const std::string& title) { |
| 23 | return base::UTF16ToUTF8(FormatDocumentTitleWithOwnerAndLength( |
| 24 | base::UTF8ToUTF16(owner), base::UTF8ToUTF16(title), kTestLength)); |
| 25 | } |
| 26 | |
| 27 | } // namespace |
| 28 | |
[email protected] | ec91bfa | 2013-11-09 17:24:27 | [diff] [blame] | 29 | TEST(PrintingUtilsTest, SimplifyDocumentTitle) { |
vitalybuka | 27e401c | 2015-07-07 18:21:16 | [diff] [blame] | 30 | EXPECT_EQ("", Simplify("")); |
| 31 | EXPECT_EQ("abcdefgh", Simplify("abcdefgh")); |
| 32 | EXPECT_EQ("abc...ij", Simplify("abcdefghij")); |
| 33 | EXPECT_EQ("Controls", Simplify("C\ron\nt\15rols")); |
thestig | 3ccfd1f | 2016-02-03 21:46:31 | [diff] [blame] | 34 | EXPECT_EQ("C:_foo_", Simplify("C:\\foo\\")); |
vitalybuka | 27e401c | 2015-07-07 18:21:16 | [diff] [blame] | 35 | EXPECT_EQ("", Simplify("\n\r\n\r\t\r")); |
| 36 | } |
| 37 | |
| 38 | TEST(PrintingUtilsTest, FormatDocumentTitleWithOwner) { |
| 39 | EXPECT_EQ(": ", Format("", "")); |
| 40 | EXPECT_EQ("abc: ", Format("abc", "")); |
| 41 | EXPECT_EQ(": 123", Format("", "123")); |
| 42 | EXPECT_EQ("abc: 123", Format("abc", "123")); |
| 43 | EXPECT_EQ("abc: 0.9", Format("abc", "0123456789")); |
| 44 | EXPECT_EQ("ab...j: ", Format("abcdefghij", "123")); |
thestig | 3ccfd1f | 2016-02-03 21:46:31 | [diff] [blame] | 45 | EXPECT_EQ("xyz: _.o", Format("xyz", "\\f\\oo")); |
vitalybuka | 27e401c | 2015-07-07 18:21:16 | [diff] [blame] | 46 | EXPECT_EQ("ab...j: ", Format("abcdefghij", "0123456789")); |
[email protected] | 09083eb | 2012-09-20 05:58:43 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | } // namespace printing |