/**
 * END USER LICENSE AGREEMENT (“EULA”)
 *
 * READ THIS AGREEMENT CAREFULLY (date: 9/13/2011):
 * http://www.akiban.com/licensing/20110913
 *
 * BY INSTALLING OR USING ALL OR ANY PORTION OF THE SOFTWARE, YOU ARE ACCEPTING
 * ALL OF THE TERMS AND CONDITIONS OF THIS AGREEMENT. YOU AGREE THAT THIS
 * AGREEMENT IS ENFORCEABLE LIKE ANY WRITTEN AGREEMENT SIGNED BY YOU.
 *
 * IF YOU HAVE PAID A LICENSE FEE FOR USE OF THE SOFTWARE AND DO NOT AGREE TO
 * THESE TERMS, YOU MAY RETURN THE SOFTWARE FOR A FULL REFUND PROVIDED YOU (A) DO
 * NOT USE THE SOFTWARE AND (B) RETURN THE SOFTWARE WITHIN THIRTY (30) DAYS OF
 * YOUR INITIAL PURCHASE.
 *
 * IF YOU WISH TO USE THE SOFTWARE AS AN EMPLOYEE, CONTRACTOR, OR AGENT OF A
 * CORPORATION, PARTNERSHIP OR SIMILAR ENTITY, THEN YOU MUST BE AUTHORIZED TO SIGN
 * FOR AND BIND THE ENTITY IN ORDER TO ACCEPT THE TERMS OF THIS AGREEMENT. THE
 * LICENSES GRANTED UNDER THIS AGREEMENT ARE EXPRESSLY CONDITIONED UPON ACCEPTANCE
 * BY SUCH AUTHORIZED PERSONNEL.
 *
 * IF YOU HAVE ENTERED INTO A SEPARATE WRITTEN LICENSE AGREEMENT WITH AKIBAN FOR
 * USE OF THE SOFTWARE, THE TERMS AND CONDITIONS OF SUCH OTHER AGREEMENT SHALL
 * PREVAIL OVER ANY CONFLICTING TERMS OR CONDITIONS IN THIS AGREEMENT.
 */

package com.akiban.server.rowdata;

import com.akiban.ais.model.AkibanInformationSchema;
import com.akiban.ais.model.aisb2.AISBBasedBuilder;
import com.akiban.server.encoding.EncodingException;
import com.google.common.base.Strings;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

public final class RowDataTest {
    @Test
    public void reallocateOnBind() throws ClassNotFoundException {
        AkibanInformationSchema ais = AISBBasedBuilder.create()
                .userTable("myschema", "mytable")
                .colLong("id", false)
                .colLong("int_0", true)
                .colLong("int_1", true)
                .colLong("int_2", true)
                .colLong("int_3", true)
                .colLong("int_4", true)
                .colString("bigstring", 500)
                .colString("smallstring", 2)
                .ais();

        List<?> values = Arrays.asList(
                1L, // id
                null, null, null, null, null, // int_x's
                Strings.repeat("a", 476), // bigstring
                "hi" // smallstring
        );
        Object[] valuesArray = values.toArray(new Object[values.size()]);
        RowData rowData = new RowData(new byte[500]);

        RowDefCache rdc = new SchemaFactory().rowDefCache(ais);
        RowDef rowDef = rdc.getRowDef("myschema", "mytable");
        assertNotNull("RowDef", rowDef);

        try {
            rowData.createRow(rowDef, valuesArray, false);
            fail("expected ArrayIndexOutOfBoundsException");
        } catch (ArrayIndexOutOfBoundsException e) {
            boolean foundInBind = false;
            for (StackTraceElement frame : e.getStackTrace()) {
                Class<?> frameClass = Class.forName(frame.getClassName());
                if (RowDataTarget.class.isAssignableFrom(frameClass) && "bind".equals(frame.getMethodName())) {
                    foundInBind = true;
                    break;
                }
            }
            assertTrue("stack trace didn't include RowDataTarget.bind", foundInBind);
        }
    }
}

@@ -1529,24 +1529,69 @@
 util.List;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import stati
@@ -3484,10 +3484,1362 @@
 %7D%0A    %7D%0A
+%0A    @Test%0A    public void unsignedWidth() throws ClassNotFoundException %7B%0A        AkibanInformationSchema ais = AISBBasedBuilder.create()%0A                .userTable(%22myschema%22, %22mytable2%22)%0A                .colLong(%22id%22, false)%0A                .colString(%22smallstring%22, 129)%0A                .colString(%22bigstring%22, 32769)%0A                .ais();%0A%0A        RowDefCache rdc = new SchemaFactory().rowDefCache(ais);%0A        RowDef rowDef = rdc.getRowDef(%22myschema%22, %22mytable2%22);%0A        assertNotNull(%22RowDef%22, rowDef);%0A%0A        for (int pass = 1; pass %3C= 2; pass++) %7B%0A            List%3C?%3E values = Arrays.asList((long)pass,%0A                                           (pass == 1) ? Strings.repeat(%22x%22, 128) : null,%0A                                           (pass == 2) ? Strings.repeat(%22z%22, 32768) : null);%0A            Object%5B%5D valuesArray = values.toArray(new Object%5Bvalues.size()%5D);%0A            RowData rowData = new RowData(new byte%5B500%5D);%0A%0A            rowData.createRow(rowDef, valuesArray, true);%0A            assertEquals(String.format(%22mytable2(%25d,%25s,%25s,)%22,%0A                                       valuesArray%5B0%5D,%0A                                       (valuesArray%5B1%5D != null) ? valuesArray%5B1%5D : %22%22,%0A                                       (valuesArray%5B2%5D != null) ? valuesArray%5B2%5D : %22%22),%0A                         rowData.toString());%0A        %7D%0A    %7D%0A%0A
 %7D%0A

Add a unit test for that.