blob: 4a0442760d760bdfb4efcc625e6aa24c5b966086 [file] [log] [blame]
[email protected]ec91bfa2013-11-09 17:24:271// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]09083eb2012-09-20 05:58:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avi126e93c2015-12-21 21:48:165#include <stddef.h>
6
[email protected]906265872013-06-07 22:40:457#include "base/strings/utf_string_conversions.h"
[email protected]ec91bfa2013-11-09 17:24:278#include "printing/printing_utils.h"
[email protected]09083eb2012-09-20 05:58:439#include "testing/gtest/include/gtest/gtest.h"
10
11namespace printing {
12
vitalybuka27e401c2015-07-07 18:21:1613namespace {
14
15const size_t kTestLength = 8;
16
17std::string Simplify(const std::string& title) {
18 return base::UTF16ToUTF8(
19 SimplifyDocumentTitleWithLength(base::UTF8ToUTF16(title), kTestLength));
[email protected]09083eb2012-09-20 05:58:4320}
21
vitalybuka27e401c2015-07-07 18:21:1622std::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]ec91bfa2013-11-09 17:24:2729TEST(PrintingUtilsTest, SimplifyDocumentTitle) {
vitalybuka27e401c2015-07-07 18:21:1630 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"));
thestig3ccfd1f2016-02-03 21:46:3134 EXPECT_EQ("C:_foo_", Simplify("C:\\foo\\"));
vitalybuka27e401c2015-07-07 18:21:1635 EXPECT_EQ("", Simplify("\n\r\n\r\t\r"));
36}
37
38TEST(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"));
thestig3ccfd1f2016-02-03 21:46:3145 EXPECT_EQ("xyz: _.o", Format("xyz", "\\f\\oo"));
vitalybuka27e401c2015-07-07 18:21:1646 EXPECT_EQ("ab...j: ", Format("abcdefghij", "0123456789"));
[email protected]09083eb2012-09-20 05:58:4347}
48
49} // namespace printing