Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: fpdfsdk/src/javascript/public_methods_embeddertest.cpp

Issue 1539113002: Cleanup CJS_PublicMethods (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/javascript/PublicMethods.cpp ('k') | fpdfsdk/src/javascript/util.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <cmath> 5 #include <cmath>
6 6
7 #include "core/include/fxcrt/fx_string.h" 7 #include "core/include/fxcrt/fx_string.h"
8 #include "fpdfsdk/src/javascript/PublicMethods.h" 8 #include "fpdfsdk/src/javascript/PublicMethods.h"
9 #include "testing/js_embedder_test.h" 9 #include "testing/js_embedder_test.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace { 12 namespace {
13 13
14 double RoundDownDate(double date) { 14 double RoundDownDate(double date) {
15 return date - fmod(date, 86400000); 15 return date - fmod(date, 86400000);
16 } 16 }
17 17
18 } // namespace 18 } // namespace
19 19
20 class PublicMethodsEmbedderTest : public JSEmbedderTest {}; 20 class PublicMethodsEmbedderTest : public JSEmbedderTest {};
21 21
22 TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) { 22 TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
23 v8::Isolate::Scope isolate_scope(isolate()); 23 v8::Isolate::Scope isolate_scope(isolate());
24 v8::HandleScope handle_scope(isolate()); 24 v8::HandleScope handle_scope(isolate());
25 v8::Context::Scope context_scope(GetV8Context()); 25 v8::Context::Scope context_scope(GetV8Context());
26 FX_BOOL bWrongFormat; 26 bool bWrongFormat;
27 double date; 27 double date;
28 28
29 // 1968 29 // 1968
30 bWrongFormat = false; 30 bWrongFormat = false;
31 date = CJS_PublicMethods::MakeRegularDate(L"06/25/1968", L"mm/dd/yyyy", 31 date = CJS_PublicMethods::MakeRegularDate(L"06/25/1968", L"mm/dd/yyyy",
32 bWrongFormat); 32 &bWrongFormat);
33 date = RoundDownDate(date); 33 date = RoundDownDate(date);
34 EXPECT_DOUBLE_EQ(-47865600000, date); 34 EXPECT_DOUBLE_EQ(-47865600000, date);
35 EXPECT_FALSE(bWrongFormat); 35 EXPECT_FALSE(bWrongFormat);
36 36
37 // 1968 37 // 1968
38 bWrongFormat = false; 38 bWrongFormat = false;
39 date = CJS_PublicMethods::MakeRegularDate(L"25061968", L"ddmmyyyy", 39 date = CJS_PublicMethods::MakeRegularDate(L"25061968", L"ddmmyyyy",
40 bWrongFormat); 40 &bWrongFormat);
41 date = RoundDownDate(date); 41 date = RoundDownDate(date);
42 EXPECT_DOUBLE_EQ(-47865600000, date); 42 EXPECT_DOUBLE_EQ(-47865600000, date);
43 EXPECT_FALSE(bWrongFormat); 43 EXPECT_FALSE(bWrongFormat);
44 44
45 // 1968 45 // 1968
46 bWrongFormat = false; 46 bWrongFormat = false;
47 date = CJS_PublicMethods::MakeRegularDate(L"19680625", L"yyyymmdd", 47 date = CJS_PublicMethods::MakeRegularDate(L"19680625", L"yyyymmdd",
48 bWrongFormat); 48 &bWrongFormat);
49 date = RoundDownDate(date); 49 date = RoundDownDate(date);
50 EXPECT_DOUBLE_EQ(-47865600000, date); 50 EXPECT_DOUBLE_EQ(-47865600000, date);
51 EXPECT_FALSE(bWrongFormat); 51 EXPECT_FALSE(bWrongFormat);
52 52
53 // 1985 53 // 1985
54 bWrongFormat = false; 54 bWrongFormat = false;
55 date = CJS_PublicMethods::MakeRegularDate(L"31121985", L"ddmmyyyy", 55 date = CJS_PublicMethods::MakeRegularDate(L"31121985", L"ddmmyyyy",
56 bWrongFormat); 56 &bWrongFormat);
57 date = RoundDownDate(date); 57 date = RoundDownDate(date);
58 EXPECT_DOUBLE_EQ(504835200000.0, date); 58 EXPECT_DOUBLE_EQ(504835200000.0, date);
59 EXPECT_FALSE(bWrongFormat); 59 EXPECT_FALSE(bWrongFormat);
60 60
61 // 2085, the other '85. 61 // 2085, the other '85.
62 bWrongFormat = false; 62 bWrongFormat = false;
63 date = CJS_PublicMethods::MakeRegularDate(L"311285", L"ddmmyy", bWrongFormat); 63 date =
64 CJS_PublicMethods::MakeRegularDate(L"311285", L"ddmmyy", &bWrongFormat);
64 date = RoundDownDate(date); 65 date = RoundDownDate(date);
65 EXPECT_DOUBLE_EQ(3660595200000.0, date); 66 EXPECT_DOUBLE_EQ(3660595200000.0, date);
66 EXPECT_FALSE(bWrongFormat); 67 EXPECT_FALSE(bWrongFormat);
67 68
68 // 1995 69 // 1995
69 bWrongFormat = false; 70 bWrongFormat = false;
70 date = CJS_PublicMethods::MakeRegularDate(L"01021995", L"ddmmyyyy", 71 date = CJS_PublicMethods::MakeRegularDate(L"01021995", L"ddmmyyyy",
71 bWrongFormat); 72 &bWrongFormat);
72 date = RoundDownDate(date); 73 date = RoundDownDate(date);
73 EXPECT_DOUBLE_EQ(791596800000.0, date); 74 EXPECT_DOUBLE_EQ(791596800000.0, date);
74 EXPECT_FALSE(bWrongFormat); 75 EXPECT_FALSE(bWrongFormat);
75 76
76 // 2095, the other '95. 77 // 2095, the other '95.
77 bWrongFormat = false; 78 bWrongFormat = false;
78 date = CJS_PublicMethods::MakeRegularDate(L"010295", L"ddmmyy", bWrongFormat); 79 date =
80 CJS_PublicMethods::MakeRegularDate(L"010295", L"ddmmyy", &bWrongFormat);
79 date = RoundDownDate(date); 81 date = RoundDownDate(date);
80 EXPECT_DOUBLE_EQ(3947356800000.0, date); 82 EXPECT_DOUBLE_EQ(3947356800000.0, date);
81 EXPECT_FALSE(bWrongFormat); 83 EXPECT_FALSE(bWrongFormat);
82 84
83 // 2005 85 // 2005
84 bWrongFormat = false; 86 bWrongFormat = false;
85 date = CJS_PublicMethods::MakeRegularDate(L"01022005", L"ddmmyyyy", 87 date = CJS_PublicMethods::MakeRegularDate(L"01022005", L"ddmmyyyy",
86 bWrongFormat); 88 &bWrongFormat);
87 date = RoundDownDate(date); 89 date = RoundDownDate(date);
88 EXPECT_DOUBLE_EQ(1107216000000.0, date); 90 EXPECT_DOUBLE_EQ(1107216000000.0, date);
89 EXPECT_FALSE(bWrongFormat); 91 EXPECT_FALSE(bWrongFormat);
90 92
91 // 2005 93 // 2005
92 bWrongFormat = false; 94 bWrongFormat = false;
93 date = CJS_PublicMethods::MakeRegularDate(L"010205", L"ddmmyy", bWrongFormat); 95 date =
96 CJS_PublicMethods::MakeRegularDate(L"010205", L"ddmmyy", &bWrongFormat);
94 date = RoundDownDate(date); 97 date = RoundDownDate(date);
95 EXPECT_DOUBLE_EQ(1107216000000.0, date); 98 EXPECT_DOUBLE_EQ(1107216000000.0, date);
96 EXPECT_FALSE(bWrongFormat); 99 EXPECT_FALSE(bWrongFormat);
97 } 100 }
98 101
99 TEST_F(PublicMethodsEmbedderTest, MakeFormatDate) { 102 TEST_F(PublicMethodsEmbedderTest, MakeFormatDate) {
100 v8::Isolate::Scope isolate_scope(isolate()); 103 v8::Isolate::Scope isolate_scope(isolate());
101 v8::HandleScope handle_scope(isolate()); 104 v8::HandleScope handle_scope(isolate());
102 v8::Context::Scope context_scope(GetV8Context()); 105 v8::Context::Scope context_scope(GetV8Context());
103 CFX_WideString formatted_date; 106 CFX_WideString formatted_date;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 EXPECT_STREQ(L"208531", formatted_date); 153 EXPECT_STREQ(L"208531", formatted_date);
151 154
152 // 2095-02-01 155 // 2095-02-01
153 formatted_date = 156 formatted_date =
154 CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"ddmmyy"); 157 CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"ddmmyy");
155 EXPECT_STREQ(L"010295", formatted_date); 158 EXPECT_STREQ(L"010295", formatted_date);
156 formatted_date = 159 formatted_date =
157 CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"mmddyyyy"); 160 CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"mmddyyyy");
158 EXPECT_STREQ(L"02012095", formatted_date); 161 EXPECT_STREQ(L"02012095", formatted_date);
159 } 162 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/javascript/PublicMethods.cpp ('k') | fpdfsdk/src/javascript/util.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698