8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6952330
27 * @summary Test StringBuffer/StringBuilder capacity handling.
28 */
29
30 import java.util.Random;
31
32 public class Capacity {
33 void test(String[] args) throws Throwable {
34 Random rnd = new Random();
35 int[] sizes = { 0, 1, rnd.nextInt(10), rnd.nextInt(1000) };
36 for (int size : sizes) {
37 equal(16, new StringBuffer().capacity());
38 equal(16, new StringBuilder().capacity());
39 StringBuffer buff = new StringBuffer(size);
40 StringBuilder bild = new StringBuilder(size);
41 equal(size, buff.capacity());
42 equal(size, bild.capacity());
43 buff.ensureCapacity(size);
44 bild.ensureCapacity(size);
45 equal(size, buff.capacity());
46 equal(size, bild.capacity());
47 buff.ensureCapacity(size+1);
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 6952330
27 * @summary Test StringBuffer/StringBuilder capacity handling.
28 * @key randomness
29 */
30
31 import java.util.Random;
32
33 public class Capacity {
34 void test(String[] args) throws Throwable {
35 Random rnd = new Random();
36 int[] sizes = { 0, 1, rnd.nextInt(10), rnd.nextInt(1000) };
37 for (int size : sizes) {
38 equal(16, new StringBuffer().capacity());
39 equal(16, new StringBuilder().capacity());
40 StringBuffer buff = new StringBuffer(size);
41 StringBuilder bild = new StringBuilder(size);
42 equal(size, buff.capacity());
43 equal(size, bild.capacity());
44 buff.ensureCapacity(size);
45 bild.ensureCapacity(size);
46 equal(size, buff.capacity());
47 equal(size, bild.capacity());
48 buff.ensureCapacity(size+1);
|