1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/strings/utf_string_conversions.h"
8 #include "printing/printing_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h"
15 const size_t kTestLength = 8;
17 std::string Simplify(const std::string& title) {
18 return base::UTF16ToUTF8(
19 SimplifyDocumentTitleWithLength(base::UTF8ToUTF16(title), kTestLength));
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));
29 TEST(PrintingUtilsTest, SimplifyDocumentTitle) {
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"));
34 EXPECT_EQ("C:_foo_", Simplify("C:\\foo\\"));
35 EXPECT_EQ("", Simplify("\n\r\n\r\t\r"));
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"));
45 EXPECT_EQ("xyz: _.o", Format("xyz", "\\f\\oo"));
46 EXPECT_EQ("ab...j: ", Format("abcdefghij", "0123456789"));
49 } // namespace printing