Methods Summary |
---|
public ContentValuesVerifierElem | addContentValuesVerifierElem()
if (!mInitialized) {
AndroidTestCase.fail("Not initialized");
}
if (mContentValuesVerifier == null) {
mContentValuesVerifier = new ContentValuesVerifier();
}
return mContentValuesVerifier.addElem(mAndroidTestCase);
|
public ContactEntry | addInputEntry()
if (!mInitialized) {
AndroidTestCase.fail("Not initialized");
}
if (mInputStream != null) {
AndroidTestCase.fail("setInputStream is called");
}
return mExportTestResolver.addInputContactEntry();
|
public LineVerifierElem | addLineVerifierElem()
if (!mInitialized) {
AndroidTestCase.fail("Not initialized");
}
if (mLineVerifier == null) {
mLineVerifier = new LineVerifier(mAndroidTestCase, mVCardType);
}
return mLineVerifier.addLineVerifierElem();
|
public PropertyNodesVerifierElem | addPropertyNodesVerifierElem()
final PropertyNodesVerifierElem elem = addPropertyNodesVerifierElemWithoutVersion();
final String versionString;
if (VCardConfig.isVersion21(mVCardType)) {
versionString = "2.1";
} else if (VCardConfig.isVersion30(mVCardType)) {
versionString = "3.0";
} else if (VCardConfig.isVersion40(mVCardType)) {
versionString = "4.0";
} else {
throw new RuntimeException("Unexpected vcard type during a unit test");
}
elem.addExpectedNodeWithOrder("VERSION", versionString);
return elem;
|
public PropertyNodesVerifierElem | addPropertyNodesVerifierElemWithEmptyName()
if (!mInitialized) {
AndroidTestCase.fail("Not initialized");
}
final PropertyNodesVerifierElem elem = addPropertyNodesVerifierElem();
if (VCardConfig.isVersion40(mVCardType)) {
elem.addExpectedNodeWithOrder("FN", "");
} else if (VCardConfig.isVersion30(mVCardType)) {
elem.addExpectedNodeWithOrder("N", "");
elem.addExpectedNodeWithOrder("FN", "");
} else if (mIsDoCoMo) {
elem.addExpectedNodeWithOrder("N", "");
}
return elem;
|
public PropertyNodesVerifierElem | addPropertyNodesVerifierElemWithoutVersion()
if (!mInitialized) {
AndroidTestCase.fail("Not initialized");
}
if (mPropertyNodesVerifier == null) {
mPropertyNodesVerifier = new PropertyNodesVerifier(mAndroidTestCase);
}
return mPropertyNodesVerifier.addPropertyNodesVerifierElem();
|
public void | addVCardExceptionVerifier(java.lang.String contents)
mExceptionContents = contents;
|
private java.lang.reflect.Method | getMockGetEntityIteratorMethod()
return this.getClass().getMethod("mockGetEntityIteratorMethod",
ContentResolver.class, Uri.class, String.class, String[].class, String.class);
|
public void | initForExportTest(int vcardType)
initForExportTest(vcardType, "UTF-8");
|
public void | initForExportTest(int vcardType, java.lang.String charset)
if (mInitialized) {
AndroidTestCase.fail("Already initialized");
}
mExportTestResolver = new ExportTestResolver(mAndroidTestCase);
mVCardType = vcardType;
mIsDoCoMo = VCardConfig.isDoCoMo(vcardType);
mInitialized = true;
if (TextUtils.isEmpty(charset)) {
mCharset = "UTF-8";
} else {
mCharset = charset;
}
|
public void | initForImportTest(int vcardType, int resId)
if (mInitialized) {
AndroidTestCase.fail("Already initialized");
}
mVCardType = vcardType;
mIsDoCoMo = VCardConfig.isDoCoMo(vcardType);
setInputResourceId(resId);
mInitialized = true;
|
public static android.content.EntityIterator | mockGetEntityIteratorMethod(android.content.ContentResolver resolver, android.net.Uri uri, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sortOrder)
if (ExportTestResolver.class.equals(resolver.getClass())) {
return ((ExportTestResolver)resolver).getProvider().queryEntities(
uri, selection, selectionArgs, sortOrder);
}
Log.e(LOG_TAG, "Unexpected provider given.");
return null;
|
private void | setInputResourceId(int resId)
final InputStream inputStream =
mAndroidTestCase.getContext().getResources().openRawResource(resId);
if (inputStream == null) {
AndroidTestCase.fail("Wrong resId: " + resId);
}
setInputStream(inputStream);
|
private void | setInputStream(java.io.InputStream inputStream)
if (mExportTestResolver != null) {
AndroidTestCase.fail("addInputEntry() is called.");
} else if (mInputStream != null) {
AndroidTestCase.fail("InputStream is already set");
}
mInputStream = inputStream;
|
public void | verify()
if (!mInitialized) {
TestCase.fail("Not initialized.");
}
if (mVerified) {
TestCase.fail("verify() was called twice.");
}
if (mInputStream != null) {
if (mExportTestResolver != null){
TestCase.fail("There are two input sources.");
}
verifyForImportTest();
} else if (mExportTestResolver != null){
verifyForExportTest();
} else {
TestCase.fail("No input is determined");
}
mVerified = true;
|
private void | verifyForExportTest()
final CustomMockContext context = new CustomMockContext(mExportTestResolver);
final ContentResolver resolver = context.getContentResolver();
final VCardComposer composer = new VCardComposer(context, mVCardType, mCharset);
// projection is ignored.
final Cursor cursor = resolver.query(CONTACTS_TEST_CONTENT_URI, null, null, null, null);
if (!composer.init(cursor)) {
AndroidTestCase.fail("init() failed. Reason: " + composer.getErrorReason());
}
AndroidTestCase.assertFalse(composer.isAfterLast());
try {
while (!composer.isAfterLast()) {
Method mockGetEntityIteratorMethod = null;
try {
mockGetEntityIteratorMethod = getMockGetEntityIteratorMethod();
} catch (Exception e) {
AndroidTestCase.fail("Exception thrown: " + e);
}
AndroidTestCase.assertNotNull(mockGetEntityIteratorMethod);
final String vcard = composer.createOneEntry(mockGetEntityIteratorMethod);
AndroidTestCase.assertNotNull(vcard);
if (mLineVerifier != null) {
mLineVerifier.verify(vcard);
}
verifyOneVCardForExport(vcard);
}
} finally {
composer.terminate();
}
|
private void | verifyForImportTest()
if (mLineVerifier != null) {
AndroidTestCase.fail("Not supported now.");
}
try {
verifyWithInputStream(mInputStream);
} catch (IOException e) {
AndroidTestCase.fail("IOException was thrown: " + e.getMessage());
} finally {
if (mInputStream != null) {
try {
mInputStream.close();
} catch (IOException e) {
}
}
}
|
private void | verifyOneVCardForExport(java.lang.String vcard)
if (DEBUG) Log.d(LOG_TAG, vcard);
InputStream is = null;
try {
is = new ByteArrayInputStream(vcard.getBytes(mCharset));
verifyWithInputStream(is);
} catch (IOException e) {
AndroidTestCase.fail("Unexpected IOException: " + e.getMessage());
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
AndroidTestCase.fail("Unexpected IOException: " + e.getMessage());
}
}
}
|
private void | verifyWithInputStream(java.io.InputStream is)Sets up sub-verifiers correctly and tries to parse vCard as {@link InputStream}.
Errors around InputStream must be handled outside this method.
Used both from {@link #verifyForImportTest()} and from {@link #verifyForExportTest()}.
try {
// Note: we must not specify charset toward vCard parsers. This code checks whether
// those parsers are able to encode given binary without any extra information for
// charset.
final VCardParser parser = VCardUtils.getAppropriateParser(mVCardType);
if (mContentValuesVerifier != null) {
final VCardEntryConstructor constructor = new VCardEntryConstructor(mVCardType);
constructor.addEntryHandler(mContentValuesVerifier);
parser.addInterpreter(constructor);
}
if (mPropertyNodesVerifier != null) {
parser.addInterpreter(mPropertyNodesVerifier);
}
parser.parse(is);
if (mExceptionContents != null) {
// exception contents exists, we expect an exception to occur.
AndroidTestCase.fail();
}
} catch (VCardException e) {
if (mExceptionContents != null) {
AndroidTestCase.assertTrue(e.getMessage().contains(mExceptionContents));
} else {
Log.e(LOG_TAG, "VCardException", e);
AndroidTestCase.fail("Unexpected VCardException: " + e.getMessage());
}
}
|