Bug 975792 - Follow-up: blindly copy CursorDumper into Robocop tests. r=me

This commit is contained in:
Richard Newman 2014-02-24 16:52:13 -08:00
parent 36c969ac7a
commit 478ecfde11

View File

@ -13,7 +13,6 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.Random;
import org.mozilla.gecko.background.db.CursorDumper;
import org.mozilla.gecko.db.BrowserContract;
/*
@ -1869,4 +1868,76 @@ public class testBrowserProvider extends ContentProviderTest {
c.close();
}
}
/**
* Pilfered from Android Background Services code.
*/
public static class CursorDumper {
protected static String fixedWidth(int width, String s) {
if (s == null) {
return spaces(width);
}
int length = s.length();
if (width == length) {
return s;
}
if (width > length) {
return s + spaces(width - length);
}
return s.substring(0, width);
}
protected static String spaces(int i) {
return " ".substring(0, i);
}
protected static String dashes(int i) {
return "-------------------------------------".substring(0, i);
}
public static void dumpCursor(Cursor cursor) {
dumpCursor(cursor, 18, "records");
}
protected static void dumpCursor(Cursor cursor, int columnWidth,
String tags) {
int originalPosition = cursor.getPosition();
try {
String[] columnNames = cursor.getColumnNames();
int columnCount = cursor.getColumnCount();
for (int i = 0; i < columnCount; ++i) {
System.out.print(fixedWidth(columnWidth, columnNames[i]) +
" | ");
}
System.out.println("(" + cursor.getCount() + " " + tags + ")");
for (int i = 0; i < columnCount; ++i) {
System.out.print(dashes(columnWidth) + " | ");
}
System.out.println("");
if (!cursor.moveToFirst()) {
System.out.println("EMPTY");
return;
}
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
for (int i = 0; i < columnCount; ++i) {
System.out.print(fixedWidth(columnWidth,
cursor.getString(i)) +
" | ");
}
System.out.println("");
cursor.moveToNext();
}
for (int i = 0; i < columnCount - 1; ++i) {
System.out.print(dashes(columnWidth + 3));
}
System.out.print(dashes(columnWidth + 3 - 1));
System.out.println("");
} finally {
cursor.moveToPosition(originalPosition);
}
}
}
}