ContentEquals.java revision 0
/*
* Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4242309 4982981
* @summary Test equals and contentEquals in String
*/
// Yes, I used cut and paste for this test. Yes more code
// sharing could have been accomplished.
public class ContentEquals {
private static final int ITERATIONS = 1000;
private static final int STR_LEN = 20;
testString();
}
// Test a StringBuffer, which uses the old method from 1.4
public static void testStringBuffer() throws Exception {
for (int i=0; i<ITERATIONS; i++) {
for(int x=0; x<length; x++) {
}
throw new RuntimeException("ContentsEqual failure");
}
}
// Test StringBuilder as a CharSequence using new method in 1.5
public static void testStringBuilder() throws Exception {
for (int i=0; i<ITERATIONS; i++) {
for(int x=0; x<length; x++) {
}
throw new RuntimeException("ContentsEqual failure");
}
}
// Test a String as a CharSequence. This takes a different codepath in
// the new method in 1.5
public static void testString() throws Exception {
for (int i=0; i<ITERATIONS; i++) {
for(int x=0; x<length; x++) {
}
throw new RuntimeException("ContentsEqual failure");
}
}
// Test a CharSequence that is not an AbstractStringBuilder,
// this takes a different codepath in the new method in 1.5
public static void testCharSequence() throws Exception {
for (int i=0; i<ITERATIONS; i++) {
for(int x=0; x<length; x++) {
}
throw new RuntimeException("ContentsEqual failure");
}
}
}