author | vlivanov |
Wed, 02 Mar 2016 15:42:03 +0300 | |
changeset 36349 | 6cc8e6f596b2 |
parent 26039 | a6d9e5b030b1 |
permissions | -rw-r--r-- |
14674
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
21964
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
14674
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
4 |
* |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
8 |
* |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
13 |
* accompanied this code). |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
14 |
* |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
18 |
* |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
21 |
* questions. |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
22 |
*/ |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
23 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
24 |
/* |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
25 |
* @test 4235519 |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
26 |
* @author Eric Wang <yiming.wang@oracle.com> |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
27 |
* @summary tests java.util.Base64 |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
28 |
*/ |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
29 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
30 |
import java.io.BufferedReader; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
31 |
import java.io.FileReader; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
32 |
import java.nio.ByteBuffer; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
33 |
import java.nio.charset.Charset; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
34 |
import java.nio.charset.StandardCharsets; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
35 |
import java.nio.file.Files; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
36 |
import java.nio.file.Paths; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
37 |
import java.util.Base64; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
38 |
import java.util.Base64.Decoder; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
39 |
import java.util.Base64.Encoder; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
40 |
import java.util.Objects; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
41 |
import java.util.Random; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
42 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
43 |
public class TestBase64Golden { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
44 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
45 |
public static void main(String[] args) throws Exception { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
46 |
test0(Base64Type.BASIC, Base64.getEncoder(), Base64.getDecoder(), |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
47 |
"plain.txt", "baseEncode.txt"); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
48 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
49 |
test0(Base64Type.URLSAFE, Base64.getUrlEncoder(), Base64.getUrlDecoder(), |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
50 |
"plain.txt", "urlEncode.txt"); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
51 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
52 |
test0(Base64Type.MIME, Base64.getMimeEncoder(), Base64.getMimeDecoder(), |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
53 |
"plain.txt", "mimeEncode.txt"); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
54 |
test1(); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
55 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
56 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
57 |
public static void test0(Base64Type type, Encoder encoder, Decoder decoder, |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
58 |
String srcFile, String encodedFile) throws Exception { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
59 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
60 |
String[] srcLns = Files.readAllLines(Paths.get(SRCDIR, srcFile), DEF_CHARSET) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
61 |
.toArray(new String[0]); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
62 |
String[] encodedLns = Files.readAllLines(Paths.get(SRCDIR, encodedFile), |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
63 |
DEF_CHARSET) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
64 |
.toArray(new String[0]); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
65 |
int lns = 0; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
66 |
for (String srcStr : srcLns) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
67 |
String encodedStr = null; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
68 |
if (type != Base64Type.MIME) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
69 |
encodedStr = encodedLns[lns++]; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
70 |
} else { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
71 |
while (lns < encodedLns.length) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
72 |
String s = encodedLns[lns++]; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
73 |
if (s.length() == 0) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
74 |
break; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
75 |
if (encodedStr != null) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
76 |
encodedStr += DEFAULT_CRLF + s; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
77 |
} else { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
78 |
encodedStr = s; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
79 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
80 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
81 |
if (encodedStr == null && srcStr.length() == 0) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
82 |
encodedStr = ""; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
83 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
84 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
85 |
System.out.printf("%n src[%d]: %s%n", srcStr.length(), srcStr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
86 |
System.out.printf("encoded[%d]: %s%n", encodedStr.length(), encodedStr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
87 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
88 |
byte[] srcArr = srcStr.getBytes(DEF_CHARSET); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
89 |
byte[] encodedArr = encodedStr.getBytes(DEF_CHARSET); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
90 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
91 |
ByteBuffer srcBuf = ByteBuffer.wrap(srcArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
92 |
ByteBuffer encodedBuf = ByteBuffer.wrap(encodedArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
93 |
byte[] resArr = new byte[encodedArr.length]; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
94 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
95 |
// test int encode(byte[], byte[]) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
96 |
int len = encoder.encode(srcArr, resArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
97 |
assertEqual(len, encodedArr.length); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
98 |
assertEqual(resArr, encodedArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
99 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
100 |
// test byte[] encode(byte[]) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
101 |
resArr = encoder.encode(srcArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
102 |
assertEqual(resArr, encodedArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
103 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
104 |
// test ByteBuffer encode(ByteBuffer) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
105 |
int limit = srcBuf.limit(); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
106 |
ByteBuffer resBuf = encoder.encode(srcBuf); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
107 |
assertEqual(srcBuf.position(), limit); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
108 |
assertEqual(srcBuf.limit(), limit); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
109 |
assertEqual(resBuf, encodedBuf); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
110 |
srcBuf.rewind(); // reset for next test |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
111 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
112 |
// test String encodeToString(byte[]) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
113 |
String resEncodeStr = encoder.encodeToString(srcArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
114 |
assertEqual(resEncodeStr, encodedStr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
115 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
116 |
// test int decode(byte[], byte[]) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
117 |
resArr = new byte[srcArr.length]; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
118 |
len = decoder.decode(encodedArr, resArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
119 |
assertEqual(len, srcArr.length); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
120 |
assertEqual(resArr, srcArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
121 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
122 |
// test byte[] decode(byte[]) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
123 |
resArr = decoder.decode(encodedArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
124 |
assertEqual(resArr, srcArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
125 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
126 |
// test ByteBuffer decode(ByteBuffer) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
127 |
limit = encodedBuf.limit(); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
128 |
resBuf = decoder.decode(encodedBuf); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
129 |
assertEqual(encodedBuf.position(), limit); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
130 |
assertEqual(encodedBuf.limit(), limit); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
131 |
assertEqual(resBuf, srcBuf); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
132 |
encodedBuf.rewind(); // reset for next test |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
133 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
134 |
// test byte[] decode(String) |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
135 |
resArr = decoder.decode(encodedStr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
136 |
assertEqual(resArr, srcArr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
137 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
138 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
139 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
140 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
141 |
private static void test1() throws Exception { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
142 |
byte[] src = new byte[] { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
143 |
46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
144 |
40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
145 |
-80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 }; |
21363
82e139fdd879
8025003: Base64 should be less strict with padding
sherman
parents:
14674
diff
changeset
|
146 |
Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e }); |
14674
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
147 |
byte[] encoded = encoder.encode(src); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
148 |
Decoder decoder = Base64.getMimeDecoder(); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
149 |
byte[] decoded = decoder.decode(encoded); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
150 |
if (!Objects.deepEquals(src, decoded)) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
151 |
throw new RuntimeException(); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
152 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
153 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
154 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
155 |
// helper |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
156 |
enum Base64Type { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
157 |
BASIC, URLSAFE, MIME |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
158 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
159 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
160 |
private static final String SRCDIR = System.getProperty("test.src", "."); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
161 |
private static final Charset DEF_CHARSET = StandardCharsets.US_ASCII; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
162 |
private static final String DEF_EXCEPTION_MSG = |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
163 |
"Assertion failed! The result is not same as expected"; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
164 |
private static final String DEFAULT_CRLF = "\r\n"; |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
165 |
|
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
166 |
private static void assertEqual(Object result, Object expect) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
167 |
if (!Objects.deepEquals(result, expect)) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
168 |
String resultStr = result.toString(); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
169 |
String expectStr = expect.toString(); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
170 |
if (result instanceof byte[]) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
171 |
resultStr = new String((byte[]) result, DEF_CHARSET); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
172 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
173 |
if (expect instanceof byte[]) { |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
174 |
expectStr = new String((byte[]) expect, DEF_CHARSET); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
175 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
176 |
throw new RuntimeException(DEF_EXCEPTION_MSG + |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
177 |
" result: " + resultStr + " expected: " + expectStr); |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
178 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
179 |
} |
be67058c3dc7
8004088: hg push for bug#4235519 failed to push all files
sherman
parents:
diff
changeset
|
180 |
} |