summaryrefslogtreecommitdiff
path: root/core/src/fxcrt
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-03 14:34:32 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-03 14:34:32 -0500
commitc9e76c09b9e7901823ac52a3705da235bd2abe24 (patch)
treecf9af9e6cc40e05cdbcf3ee7271ccc684e805f20 /core/src/fxcrt
parenta6400478803ed338e61980cea239b74c5a59b9c0 (diff)
downloadpdfium-c9e76c09b9e7901823ac52a3705da235bd2abe24.tar.xz
Add format width and precision tests.
This CL adds tests for the numeric conversion done when calculating the format percision and width fields. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1411973005 .
Diffstat (limited to 'core/src/fxcrt')
-rw-r--r--core/src/fxcrt/fx_basic_bstring_unittest.cpp76
-rw-r--r--core/src/fxcrt/fx_basic_wstring_unittest.cpp76
2 files changed, 152 insertions, 0 deletions
diff --git a/core/src/fxcrt/fx_basic_bstring_unittest.cpp b/core/src/fxcrt/fx_basic_bstring_unittest.cpp
index 3779397891..d8d880f8b1 100644
--- a/core/src/fxcrt/fx_basic_bstring_unittest.cpp
+++ b/core/src/fxcrt/fx_basic_bstring_unittest.cpp
@@ -603,3 +603,79 @@ TEST(fxcrt, ByteStringCOperatorNE) {
EXPECT_TRUE(c_string2 != byte_string_c);
EXPECT_TRUE(c_string3 != byte_string_c);
}
+
+TEST(fxcrt, ByteStringFormatWidth) {
+ {
+ CFX_ByteString str;
+ str.Format("%5d", 1);
+ EXPECT_EQ(" 1", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%d", 1);
+ EXPECT_EQ("1", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%*d", 5, 1);
+ EXPECT_EQ(" 1", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%-1d", 1);
+ EXPECT_EQ("1", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%0d", 1);
+ EXPECT_EQ("1", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%1048576d", 1);
+ EXPECT_EQ("Bad width", str);
+ }
+}
+
+TEST(fxcrt, ByteStringFormatPrecision) {
+ {
+ CFX_ByteString str;
+ str.Format("%.2f", 1.12345);
+ EXPECT_EQ("1.12", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%.*f", 3, 1.12345);
+ EXPECT_EQ("1.123", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%f", 1.12345);
+ EXPECT_EQ("1.123450", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%-1f", 1.12345);
+ EXPECT_EQ("1.123450", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%0f", 1.12345);
+ EXPECT_EQ("1.123450", str);
+ }
+
+ {
+ CFX_ByteString str;
+ str.Format("%.1048576f", 1.2);
+ EXPECT_EQ("Bad precision", str);
+ }
+}
diff --git a/core/src/fxcrt/fx_basic_wstring_unittest.cpp b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
index b75a6fbd39..5141cdd61f 100644
--- a/core/src/fxcrt/fx_basic_wstring_unittest.cpp
+++ b/core/src/fxcrt/fx_basic_wstring_unittest.cpp
@@ -440,3 +440,79 @@ TEST(fxcrt, WideStringCOperatorNE) {
EXPECT_TRUE(c_string2 != wide_string_c);
EXPECT_TRUE(c_string3 != wide_string_c);
}
+
+TEST(fxcrt, WideStringFormatWidth) {
+ {
+ CFX_WideString str;
+ str.Format(L"%5d", 1);
+ EXPECT_EQ(L" 1", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%d", 1);
+ EXPECT_EQ(L"1", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%*d", 5, 1);
+ EXPECT_EQ(L" 1", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%-1d", 1);
+ EXPECT_EQ(L"1", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%0d", 1);
+ EXPECT_EQ(L"1", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%1048576d", 1);
+ EXPECT_EQ(L"Bad width", str);
+ }
+}
+
+TEST(fxcrt, WideStringFormatPrecision) {
+ {
+ CFX_WideString str;
+ str.Format(L"%.2f", 1.12345);
+ EXPECT_EQ(L"1.12", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%.*f", 3, 1.12345);
+ EXPECT_EQ(L"1.123", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%f", 1.12345);
+ EXPECT_EQ(L"1.123450", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%-1f", 1.12345);
+ EXPECT_EQ(L"1.123450", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%0f", 1.12345);
+ EXPECT_EQ(L"1.123450", str);
+ }
+
+ {
+ CFX_WideString str;
+ str.Format(L"%.1048576f", 1.2);
+ EXPECT_EQ(L"Bad precision", str);
+ }
+}