ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/buf/TestStringCache.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/buf/TestStringCache.java
Status
scanned
Type
file
Name
TestStringCache.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4060 (4.0 KB)
MD5
81857e6e1a2e1e1126d275dc5e905f38
SHA1
1725dae571d7b7698b04ba711569f3e336b22f34
SHA256
dfe2c6d9525c0c594847e6eb460f22be2987bdae6d5145e49ad39409c851e228
SHA512

      
    
SHA1_git
79db10fbaedea1149eeff430021d02c73d5c07cc
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestStringCache.java | 4.0 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.util.buf; import java.nio.charset.CharacterCodingException; import java.nio.charset.CodingErrorAction; import java.nio.charset.StandardCharsets; import org.junit.Assert; import org.junit.Test; public class TestStringCache { private static final byte[] BYTES_VALID = new byte[] { 65, 66, 67, 68}; private static final byte[] BYTES_INVALID = new byte[] {65, 66, -1, 67, 68}; private static final ByteChunk INPUT_VALID = new ByteChunk(); private static final ByteChunk INPUT_INVALID = new ByteChunk(); private static final CodingErrorAction[] actions = new CodingErrorAction[] { CodingErrorAction.IGNORE, CodingErrorAction.REPLACE, CodingErrorAction.REPORT }; static { INPUT_VALID.setBytes(BYTES_VALID, 0, BYTES_VALID.length); INPUT_VALID.setCharset(StandardCharsets.UTF_8); INPUT_INVALID.setBytes(BYTES_INVALID, 0, BYTES_INVALID.length); INPUT_INVALID.setCharset(StandardCharsets.UTF_8); } @Test public void testCodingErrorLookup() { System.setProperty("tomcat.util.buf.StringCache.byte.enabled", "true"); Assert.assertTrue(StringCache.byteEnabled); StringCache sc = new StringCache(); sc.reset(); for (int i = 0; i < StringCache.trainThreshold * 2; i++) { for (CodingErrorAction malformedInputAction : actions) { try { // UTF-8 doesn't have any unmappable characters INPUT_VALID.toString(malformedInputAction, CodingErrorAction.IGNORE); INPUT_INVALID.toString(malformedInputAction, CodingErrorAction.IGNORE); } catch (CharacterCodingException e) { // Ignore } } } Assert.assertNotNull(StringCache.bcCache); // Check the valid input is cached correctly for (CodingErrorAction malformedInputAction : actions) { try { Assert.assertEquals("ABCD", INPUT_VALID.toString(malformedInputAction, CodingErrorAction.IGNORE)); } catch (CharacterCodingException e) { // Should not happen for valid input Assert.fail(); } } // Check the valid input is cached correctly try { Assert.assertEquals("ABCD", INPUT_INVALID.toString(CodingErrorAction.IGNORE, CodingErrorAction.IGNORE)); } catch (CharacterCodingException e) { // Should not happen for invalid input with IGNORE Assert.fail(); } try { Assert.assertEquals("AB\ufffdCD", INPUT_INVALID.toString(CodingErrorAction.REPLACE, CodingErrorAction.IGNORE)); } catch (CharacterCodingException e) { // Should not happen for invalid input with REPLACE Assert.fail(); } try { Assert.assertEquals("ABCD", INPUT_INVALID.toString(CodingErrorAction.REPORT, CodingErrorAction.IGNORE)); // Should throw exception Assert.fail(); } catch (CharacterCodingException e) { // Ignore } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
29.17
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9