FileDocCategorySizeDatePackage
Support_Format.javaAPI DocAndroid 1.5 API5513Wed May 06 22:41:06 BST 2009tests.support

Support_Format

public class Support_Format extends TestCase

Fields Summary
protected String
text
Constructors Summary
public Support_Format(String p1)

        super(p1);
    
Methods Summary
protected static booleancompare(java.util.Vector vector1, java.util.Vector vector2)
compares two vectors regardless of the order of their elements

        return vector1.size() == vector2.size() && vector1.containsAll(vector2);
    
protected static java.util.VectorfindFields(java.text.AttributedCharacterIterator iterator)
finds attributes with regards to char index in this AttributedCharacterIterator, and puts them in a vector

param
iterator
return
a vector, each entry in this vector are of type FieldContainer , which stores start and end indexes and an attribute this range has

        Vector<FieldContainer> result = new Vector<FieldContainer>();
        while (iterator.getIndex() != iterator.getEndIndex()) {
            int start = iterator.getRunStart();
            int end = iterator.getRunLimit();

            Iterator<Attribute> it = iterator.getAttributes().keySet().iterator();
            while (it.hasNext()) {
                AttributedCharacterIterator.Attribute attribute = it.next();
                Object value = iterator.getAttribute(attribute);
                result.add(new FieldContainer(start, end, attribute, value));
                // System.out.println(start + " " + end + ": " + attribute + ",
                // " + value );
                // System.out.println("v.add(new FieldContainer(" + start +"," +
                // end +"," + attribute+ "," + value+ "));");
            }
            iterator.setIndex(end);
        }
        return result;
    
protected voidt_Format(int count, java.lang.Object object, java.text.Format format, java.util.Vector expectedResults)

        // System.out.println(format.format(object));
        Vector<FieldContainer> results = findFields(format.formatToCharacterIterator(object));
        assertTrue("Test " + count
                + ": Format returned incorrect CharacterIterator for "
                + format.format(object), compare(results, expectedResults));
    
protected voidt_FormatWithField(int count, java.text.Format format, java.lang.Object object, java.lang.String text, java.text.Format$Field field, int begin, int end)

        StringBuffer buffer = new StringBuffer();
        FieldPosition pos = new FieldPosition(field);
        format.format(object, buffer, pos);

        // System.out.println(buffer);
        // System.out.println(pos);

        if (text == null) {
            assertEquals("Test " + count + ": incorrect formatted text",
                    this.text, buffer.toString());
        } else {
            assertEquals("Test " + count + ": incorrect formatted text", text,
                    buffer.toString());
        }

        assertEquals("Test " + count + ": incorrect begin index for field "
                + field, begin, pos.getBeginIndex());
        assertEquals("Test " + count + ": incorrect end index for field"
                + field, end, pos.getEndIndex());