FileDocCategorySizeDatePackage
GDataParseTest.javaAPI DocAndroid 1.5 API5765Wed May 06 22:42:02 BST 2009com.android.unit_tests

GDataParseTest

public class GDataParseTest extends android.test.AndroidTestCase implements android.test.PerformanceTestCase
Tests timing on parsing various formats of GData.

Fields Summary
Constructors Summary
Methods Summary
private static voiddumpXml(org.xmlpull.v1.XmlPullParser parser)

        int eventType = parser.nextTag();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            switch (eventType) {
                case XmlPullParser.START_TAG:
                    parser.getName();
                    // System.out.print("<" + parser.getName());
                    int nattrs = parser.getAttributeCount();
                    for (int i = 0; i < nattrs; ++i) {
                        parser.getAttributeName(i);
                        parser.getAttributeValue(i);
                        // System.out.print(" " + parser.getAttributeName(i) + "=\""
                        //        + parser.getAttributeValue(i) + "\"");
                    }
                    // System.out.print(">");
                    break;
                case XmlPullParser.END_TAG:
                    parser.getName();
                    // System.out.print("</" + parser.getName() + ">");
                    break;
                case XmlPullParser.TEXT:
                    parser.getText();
                    // System.out.print(parser.getText());
                    break;
                default:
                    // do nothing
            }
            eventType = parser.next();
        }
    
private byte[]getBytesForResource(int resid)

        // all resources are written into a zip file, so the InputStream we
        // get for a resource is on top of zipped
        // data.  in order to compare performance of parsing unzipped vs.
        // zipped content, we first read the data into an in-memory buffer.
        InputStream zipIs = null;
        try {
            zipIs = mContext.getResources().openRawResource(resid);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte buf[] = new byte[1024];
            int bytesRead = zipIs.read(buf);
            while (bytesRead > 0) {
                baos.write(buf, 0, bytesRead);
                bytesRead = zipIs.read(buf);
            }
            return baos.toByteArray();
        } finally {
            if (zipIs != null) {
                zipIs.close();
            }
        }
    
public booleanisPerformanceOnly()

        return true;
    
private static voidparseXml(java.io.InputStream is)

        XmlPullParser xmlParser = Xml.newPullParser();
        XmlGDataParser parser = new XmlGDataParser(is, xmlParser);
        Feed feed = parser.init();
        Entry entry = null;
        while (parser.hasMoreData()) {
            entry = parser.readNextEntry(entry);
        }
    
private static voidparseXml(org.xmlpull.v1.XmlPullParser xmlP)

        XmlGDataParser parser = new XmlGDataParser(null /* in */, xmlP);
        Feed feed = parser.init();
        Entry entry = null;
        while (parser.hasMoreData()) {
            entry = parser.readNextEntry(entry);
        }
    
public intstartPerformance(PerformanceTestCase.Intermediates intermediates)

        return 0;
    
public voidtestBinaryXml()

        XmlResourceParser parser = mContext.getResources().getXml(R.xml.calendar);
        parseXml(parser);
        parser.close();
    
public voidtestJson()

        String jsonString = new String(getBytesForResource(R.raw.calendarjs), "UTF-8");
        JSONTokener tokens = new JSONTokener(jsonString);
        assertNotNull(new JSONObject(tokens));
    
public voidtestXml()

        InputStream is = new ByteArrayInputStream(getBytesForResource(R.raw.calendarxml));
        try {
            is.reset();
            parseXml(is);
        } finally {
            is.close();
        }
    
public voidtestXmlGzip()

        InputStream gzIs = new GZIPInputStream(
                new ByteArrayInputStream(getBytesForResource(R.raw.calendarxmlgz)));
        try {
            parseXml(gzIs);
        } finally {
            gzIs.close();
        }