Merge change If338e940 into eclair-mr2

* changes:
  Introduce ContentValuesBuilder and make tests easier to read.
This commit is contained in:
Android (Google) Code Review
2009-11-03 18:36:29 -05:00
3 changed files with 830 additions and 786 deletions

View File

@@ -417,49 +417,46 @@ public class VCardImporterTests extends VCardTestsBase {
is.close(); is.close();
assertEquals(1, builder.vNodeList.size()); assertEquals(1, builder.vNodeList.size());
PropertyNodesVerifier verifier = new PropertyNodesVerifier(this) PropertyNodesVerifier verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("N", "Ando;Roid;", Arrays.asList("Ando", "Roid", "")); .addNodeWithOrder("N", "Ando;Roid;", Arrays.asList("Ando", "Roid", ""));
verifier.verify(builder.vNodeList.get(0)); verifier.verify(builder.vNodeList.get(0));
} }
public void testV21SimpleCase1_Type_Generic() throws IOException, VCardException { public void testV21SimpleCase1_Type_Generic() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.FAMILY_NAME, "Ando")
contentValues.put(StructuredName.FAMILY_NAME, "Ando"); .put(StructuredName.GIVEN_NAME, "Roid")
contentValues.put(StructuredName.GIVEN_NAME, "Roid"); .put(StructuredName.DISPLAY_NAME, "Roid Ando");
contentValues.put(StructuredName.DISPLAY_NAME, "Roid Ando");
verifier.verify(R.raw.v21_simple_1, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_simple_1, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
public void testV21SimpleCase1_Type_Japanese() throws IOException, VCardException { public void testV21SimpleCase1_Type_Japanese() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.FAMILY_NAME, "Ando")
contentValues.put(StructuredName.FAMILY_NAME, "Ando"); .put(StructuredName.GIVEN_NAME, "Roid")
contentValues.put(StructuredName.GIVEN_NAME, "Roid"); // If name-related strings only contains printable Ascii,
// If name-related strings only contains printable Ascii, the order is remained to be US's: // the order is remained to be US's:
// "Prefix Given Middle Family Suffix" // "Prefix Given Middle Family Suffix"
contentValues.put(StructuredName.DISPLAY_NAME, "Roid Ando"); .put(StructuredName.DISPLAY_NAME, "Roid Ando");
verifier.verify(R.raw.v21_simple_1, VCardConfig.VCARD_TYPE_V21_JAPANESE_SJIS); verifier.verify(R.raw.v21_simple_1, VCardConfig.VCARD_TYPE_V21_JAPANESE_SJIS);
} }
public void testV21SimpleCase2() throws IOException, VCardException { public void testV21SimpleCase2() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.DISPLAY_NAME, "Ando Roid");
contentValues.put(StructuredName.DISPLAY_NAME, "Ando Roid");
verifier.verify(R.raw.v21_simple_2, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_simple_2, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
public void testV21SimpleCase3() throws IOException, VCardException { public void testV21SimpleCase3() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.FAMILY_NAME, "Ando")
contentValues.put(StructuredName.FAMILY_NAME, "Ando"); .put(StructuredName.GIVEN_NAME, "Roid")
contentValues.put(StructuredName.GIVEN_NAME, "Roid"); // "FN" field should be prefered since it should contain the original order
// "FN" field should be prefered since it should contain the original order intended by // intended by the author of the file.
// the author of the file. .put(StructuredName.DISPLAY_NAME, "Ando Roid");
contentValues.put(StructuredName.DISPLAY_NAME, "Ando Roid");
verifier.verify(R.raw.v21_simple_3, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_simple_3, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
@@ -474,10 +471,10 @@ public class VCardImporterTests extends VCardTestsBase {
is.close(); is.close();
assertEquals(1, builder.vNodeList.size()); assertEquals(1, builder.vNodeList.size());
PropertyNodesVerifier verifier = new PropertyNodesVerifier(this) PropertyNodesVerifier verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("VERSION", "2.1") .addNodeWithOrder("VERSION", "2.1")
.addNodeWithOrder("N", ";A;B\\;C\\;;D;:E;\\\\;", .addNodeWithOrder("N", ";A;B\\;C\\;;D;:E;\\\\;",
Arrays.asList("", "A;B\\", "C\\;", "D", ":E", "\\\\", "")) Arrays.asList("", "A;B\\", "C\\;", "D", ":E", "\\\\", ""))
.addNodeWithOrder("FN", "A;B\\C\\;D:E\\\\"); .addNodeWithOrder("FN", "A;B\\C\\;D:E\\\\");
verifier.verify(builder.vNodeList.get(0)); verifier.verify(builder.vNodeList.get(0));
} }
@@ -486,43 +483,40 @@ public class VCardImporterTests extends VCardTestsBase {
* inserts name related data. * inserts name related data.
*/ */
public void testV21BackslashCase() throws IOException, VCardException { public void testV21BackslashCase() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); // FAMILY_NAME is empty and removed in this test...
// FAMILY_NAME is empty and removed in this test... .put(StructuredName.GIVEN_NAME, "A;B\\")
contentValues.put(StructuredName.GIVEN_NAME, "A;B\\"); .put(StructuredName.MIDDLE_NAME, "C\\;")
contentValues.put(StructuredName.MIDDLE_NAME, "C\\;"); .put(StructuredName.PREFIX, "D")
contentValues.put(StructuredName.PREFIX, "D"); .put(StructuredName.SUFFIX, ":E")
contentValues.put(StructuredName.SUFFIX, ":E"); .put(StructuredName.DISPLAY_NAME, "A;B\\C\\;D:E\\\\");
contentValues.put(StructuredName.DISPLAY_NAME, "A;B\\C\\;D:E\\\\");
verifier.verify(R.raw.v21_backslash, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_backslash, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
public void testOrgBeforTitle() throws IOException, VCardException { public void testOrgBeforTitle() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.DISPLAY_NAME, "Normal Guy");
contentValues.put(StructuredName.DISPLAY_NAME, "Normal Guy");
contentValues = verifier.createExpected(Organization.CONTENT_ITEM_TYPE); verifier.buildExpected(Organization.CONTENT_ITEM_TYPE)
contentValues.put(Organization.COMPANY, "Company"); .put(Organization.COMPANY, "Company")
contentValues.put(Organization.DEPARTMENT, "Organization Devision Room Sheet No."); .put(Organization.DEPARTMENT, "Organization Devision Room Sheet No.")
contentValues.put(Organization.TITLE, "Excellent Janitor"); .put(Organization.TITLE, "Excellent Janitor")
contentValues.put(Organization.TYPE, Organization.TYPE_WORK); .put(Organization.TYPE, Organization.TYPE_WORK);
verifier.verify(R.raw.v21_org_before_title, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_org_before_title, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
public void testTitleBeforOrg() throws IOException, VCardException { public void testTitleBeforOrg() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.DISPLAY_NAME, "Nice Guy");
contentValues.put(StructuredName.DISPLAY_NAME, "Nice Guy");
contentValues = verifier.createExpected(Organization.CONTENT_ITEM_TYPE); verifier.buildExpected(Organization.CONTENT_ITEM_TYPE)
contentValues.put(Organization.COMPANY, "Marverous"); .put(Organization.COMPANY, "Marverous")
contentValues.put(Organization.DEPARTMENT, "Perfect Great Good Bad Poor"); .put(Organization.DEPARTMENT, "Perfect Great Good Bad Poor")
contentValues.put(Organization.TITLE, "Cool Title"); .put(Organization.TITLE, "Cool Title")
contentValues.put(Organization.TYPE, Organization.TYPE_WORK); .put(Organization.TYPE, Organization.TYPE_WORK);
verifier.verify(R.raw.v21_title_before_org, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_title_before_org, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
@@ -531,49 +525,48 @@ public class VCardImporterTests extends VCardTestsBase {
* The data contain three cases: one "PREF", no "PREF" and multiple "PREF", in each type. * The data contain three cases: one "PREF", no "PREF" and multiple "PREF", in each type.
*/ */
public void testV21PrefToIsPrimary() throws IOException, VCardException { public void testV21PrefToIsPrimary() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
contentValues.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.DISPLAY_NAME, "Smith");
contentValues.put(StructuredName.DISPLAY_NAME, "Smith");
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
contentValues.put(Phone.NUMBER, "1"); .put(Phone.NUMBER, "1")
contentValues.put(Phone.TYPE, Phone.TYPE_HOME); .put(Phone.TYPE, Phone.TYPE_HOME);
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
contentValues.put(Phone.NUMBER, "2"); .put(Phone.NUMBER, "2")
contentValues.put(Phone.TYPE, Phone.TYPE_WORK); .put(Phone.TYPE, Phone.TYPE_WORK)
contentValues.put(Phone.IS_PRIMARY, 1); .put(Phone.IS_PRIMARY, 1);
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
contentValues.put(Phone.NUMBER, "3"); .put(Phone.NUMBER, "3")
contentValues.put(Phone.TYPE, Phone.TYPE_ISDN); .put(Phone.TYPE, Phone.TYPE_ISDN);
contentValues = verifier.createExpected(Email.CONTENT_ITEM_TYPE); verifier.buildExpected(Email.CONTENT_ITEM_TYPE)
contentValues.put(Email.DATA, "test@example.com"); .put(Email.DATA, "test@example.com")
contentValues.put(Email.TYPE, Email.TYPE_HOME); .put(Email.TYPE, Email.TYPE_HOME)
contentValues.put(Email.IS_PRIMARY, 1); .put(Email.IS_PRIMARY, 1);
contentValues = verifier.createExpected(Email.CONTENT_ITEM_TYPE); verifier.buildExpected(Email.CONTENT_ITEM_TYPE)
contentValues.put(Email.DATA, "test2@examination.com"); .put(Email.DATA, "test2@examination.com")
contentValues.put(Email.TYPE, Email.TYPE_MOBILE); .put(Email.TYPE, Email.TYPE_MOBILE)
contentValues.put(Email.IS_PRIMARY, 1); .put(Email.IS_PRIMARY, 1);
contentValues = verifier.createExpected(Organization.CONTENT_ITEM_TYPE); verifier.buildExpected(Organization.CONTENT_ITEM_TYPE)
contentValues.put(Organization.COMPANY, "Company"); .put(Organization.COMPANY, "Company")
contentValues.put(Organization.TITLE, "Engineer"); .put(Organization.TITLE, "Engineer")
contentValues.put(Organization.TYPE, Organization.TYPE_WORK); .put(Organization.TYPE, Organization.TYPE_WORK);
contentValues = verifier.createExpected(Organization.CONTENT_ITEM_TYPE); verifier.buildExpected(Organization.CONTENT_ITEM_TYPE)
contentValues.put(Organization.COMPANY, "Mystery"); .put(Organization.COMPANY, "Mystery")
contentValues.put(Organization.TITLE, "Blogger"); .put(Organization.TITLE, "Blogger")
contentValues.put(Organization.TYPE, Organization.TYPE_WORK); .put(Organization.TYPE, Organization.TYPE_WORK);
contentValues = verifier.createExpected(Organization.CONTENT_ITEM_TYPE); verifier.buildExpected(Organization.CONTENT_ITEM_TYPE)
contentValues.put(Organization.COMPANY, "Poetry"); .put(Organization.COMPANY, "Poetry")
contentValues.put(Organization.TITLE, "Poet"); .put(Organization.TITLE, "Poet")
contentValues.put(Organization.TYPE, Organization.TYPE_WORK); .put(Organization.TYPE, Organization.TYPE_WORK);
verifier.verify(R.raw.v21_pref_handling, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_pref_handling, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
@@ -592,50 +585,52 @@ public class VCardImporterTests extends VCardTestsBase {
ContentValues contentValuesForPhoto = new ContentValues(); ContentValues contentValuesForPhoto = new ContentValues();
contentValuesForPhoto.put("ENCODING", "BASE64"); contentValuesForPhoto.put("ENCODING", "BASE64");
PropertyNodesVerifier verifier = new PropertyNodesVerifier(this) PropertyNodesVerifier verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("VERSION", "2.1") .addNodeWithOrder("VERSION", "2.1")
.addNodeWithOrder("N", "Gump;Forrest;Hoge;Pos;Tao", .addNodeWithOrder("N", "Gump;Forrest;Hoge;Pos;Tao",
Arrays.asList("Gump", "Forrest", "Hoge", "Pos", "Tao")) Arrays.asList("Gump", "Forrest", "Hoge", "Pos", "Tao"))
.addNodeWithOrder("FN", "Joe Due") .addNodeWithOrder("FN", "Joe Due")
.addNodeWithOrder("ORG", "Gump Shrimp Co.;Sales Dept.;Manager;Fish keeper", .addNodeWithOrder("ORG", "Gump Shrimp Co.;Sales Dept.;Manager;Fish keeper",
Arrays.asList("Gump Shrimp Co.", "Sales Dept.;Manager", "Fish keeper")) Arrays.asList("Gump Shrimp Co.", "Sales Dept.;Manager", "Fish keeper"))
.addNodeWithOrder("ROLE", "Fish Cake Keeper!") .addNodeWithOrder("ROLE", "Fish Cake Keeper!")
.addNodeWithOrder("TITLE", "Shrimp Man") .addNodeWithOrder("TITLE", "Shrimp Man")
.addNodeWithOrder("X-CLASS", "PUBLIC") .addNodeWithOrder("X-CLASS", "PUBLIC")
.addNodeWithOrder("TEL", "(111) 555-1212", new TypeSet("WORK", "VOICE")) .addNodeWithOrder("TEL", "(111) 555-1212", new TypeSet("WORK", "VOICE"))
.addNodeWithOrder("TEL", "(404) 555-1212", new TypeSet("HOME", "VOICE")) .addNodeWithOrder("TEL", "(404) 555-1212", new TypeSet("HOME", "VOICE"))
.addNodeWithOrder("TEL", "0311111111", new TypeSet("CELL")) .addNodeWithOrder("TEL", "0311111111", new TypeSet("CELL"))
.addNodeWithOrder("TEL", "0322222222", new TypeSet("VIDEO")) .addNodeWithOrder("TEL", "0322222222", new TypeSet("VIDEO"))
.addNodeWithOrder("TEL", "0333333333", new TypeSet("VOICE")) .addNodeWithOrder("TEL", "0333333333", new TypeSet("VOICE"))
.addNodeWithOrder("ADR", ";;100 Waters Edge;Baytown;LA;30314;United States of America", .addNodeWithOrder("ADR",
Arrays.asList("", "", "100 Waters Edge", "Baytown", ";;100 Waters Edge;Baytown;LA;30314;United States of America",
"LA", "30314", "United States of America"), Arrays.asList("", "", "100 Waters Edge", "Baytown",
null, null, new TypeSet("WORK"), null) "LA", "30314", "United States of America"),
.addNodeWithOrder("LABEL", null, null, new TypeSet("WORK"), null)
"100 Waters Edge\r\nBaytown, LA 30314\r\nUnited States of America", .addNodeWithOrder("LABEL",
null, null, contentValuesForQP, new TypeSet("WORK"), null) "100 Waters Edge\r\nBaytown, LA 30314\r\nUnited States of America",
.addNodeWithOrder("ADR", null, null, contentValuesForQP, new TypeSet("WORK"), null)
";;42 Plantation St.;Baytown;LA;30314;United States of America", .addNodeWithOrder("ADR",
Arrays.asList("", "", "42 Plantation St.", "Baytown", ";;42 Plantation St.;Baytown;LA;30314;United States of America",
"LA", "30314", "United States of America"), null, null, Arrays.asList("", "", "42 Plantation St.", "Baytown",
new TypeSet("HOME"), null) "LA", "30314", "United States of America"), null, null,
.addNodeWithOrder("LABEL", new TypeSet("HOME"), null)
"42 Plantation St.\r\nBaytown, LA 30314\r\nUnited States of America", .addNodeWithOrder("LABEL",
null, null, contentValuesForQP, "42 Plantation St.\r\nBaytown, LA 30314\r\nUnited States of America",
new TypeSet("HOME"), null) null, null, contentValuesForQP,
.addNodeWithOrder("EMAIL", "forrestgump@walladalla.com", new TypeSet("PREF", "INTERNET")) new TypeSet("HOME"), null)
.addNodeWithOrder("EMAIL", "cell@example.com", new TypeSet("CELL")) .addNodeWithOrder("EMAIL", "forrestgump@walladalla.com",
.addNodeWithOrder("NOTE", "The following note is the example from RFC 2045.") new TypeSet("PREF", "INTERNET"))
.addNodeWithOrder("NOTE", .addNodeWithOrder("EMAIL", "cell@example.com", new TypeSet("CELL"))
"Now's the time for all folk to come to the aid of their country.", .addNodeWithOrder("NOTE", "The following note is the example from RFC 2045.")
null, null, contentValuesForQP, null, null) .addNodeWithOrder("NOTE",
.addNodeWithOrder("PHOTO", null, "Now's the time for all folk to come to the aid of their country.",
null, sPhotoByteArrayForComplicatedCase, contentValuesForPhoto, null, null, contentValuesForQP, null, null)
new TypeSet("JPEG"), null) .addNodeWithOrder("PHOTO", null,
.addNodeWithOrder("X-ATTRIBUTE", "Some String") null, sPhotoByteArrayForComplicatedCase, contentValuesForPhoto,
.addNodeWithOrder("BDAY", "19800101") new TypeSet("JPEG"), null)
.addNodeWithOrder("GEO", "35.6563854,139.6994233") .addNodeWithOrder("X-ATTRIBUTE", "Some String")
.addNodeWithOrder("URL", "http://www.example.com/") .addNodeWithOrder("BDAY", "19800101")
.addNodeWithOrder("REV", "20080424T195243Z"); .addNodeWithOrder("GEO", "35.6563854,139.6994233")
.addNodeWithOrder("URL", "http://www.example.com/")
.addNodeWithOrder("REV", "20080424T195243Z");
verifier.verify(builder.vNodeList.get(0)); verifier.verify(builder.vNodeList.get(0));
} }
@@ -644,94 +639,93 @@ public class VCardImporterTests extends VCardTestsBase {
* into ContentResolver. * into ContentResolver.
*/ */
public void testV21ComplicatedCase() throws IOException, VCardException { public void testV21ComplicatedCase() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.FAMILY_NAME, "Gump")
contentValues.put(StructuredName.FAMILY_NAME, "Gump"); .put(StructuredName.GIVEN_NAME, "Forrest")
contentValues.put(StructuredName.GIVEN_NAME, "Forrest"); .put(StructuredName.MIDDLE_NAME, "Hoge")
contentValues.put(StructuredName.MIDDLE_NAME, "Hoge"); .put(StructuredName.PREFIX, "Pos")
contentValues.put(StructuredName.PREFIX, "Pos"); .put(StructuredName.SUFFIX, "Tao")
contentValues.put(StructuredName.SUFFIX, "Tao"); .put(StructuredName.DISPLAY_NAME, "Joe Due");
contentValues.put(StructuredName.DISPLAY_NAME, "Joe Due");
contentValues = verifier.createExpected(Organization.CONTENT_ITEM_TYPE); verifier.buildExpected(Organization.CONTENT_ITEM_TYPE)
contentValues.put(Organization.TYPE, Organization.TYPE_WORK); .put(Organization.TYPE, Organization.TYPE_WORK)
contentValues.put(Organization.COMPANY, "Gump Shrimp Co."); .put(Organization.COMPANY, "Gump Shrimp Co.")
contentValues.put(Organization.DEPARTMENT, "Sales Dept.;Manager Fish keeper"); .put(Organization.DEPARTMENT, "Sales Dept.;Manager Fish keeper")
contentValues.put(Organization.TITLE, "Shrimp Man"); .put(Organization.TITLE, "Shrimp Man");
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
contentValues.put(Phone.TYPE, Phone.TYPE_WORK); .put(Phone.TYPE, Phone.TYPE_WORK)
// Phone number is expected to be formated with NAMP format in default. // Phone number is expected to be formated with NAMP format in default.
contentValues.put(Phone.NUMBER, "111-555-1212"); .put(Phone.NUMBER, "111-555-1212");
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
contentValues.put(Phone.TYPE, Phone.TYPE_HOME); .put(Phone.TYPE, Phone.TYPE_HOME)
contentValues.put(Phone.NUMBER, "404-555-1212"); .put(Phone.NUMBER, "404-555-1212");
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
contentValues.put(Phone.TYPE, Phone.TYPE_MOBILE); .put(Phone.TYPE, Phone.TYPE_MOBILE)
contentValues.put(Phone.NUMBER, "031-111-1111"); .put(Phone.NUMBER, "031-111-1111");
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
contentValues.put(Phone.TYPE, Phone.TYPE_CUSTOM); .put(Phone.TYPE, Phone.TYPE_CUSTOM)
contentValues.put(Phone.LABEL, "VIDEO"); .put(Phone.LABEL, "VIDEO")
contentValues.put(Phone.NUMBER, "032-222-2222"); .put(Phone.NUMBER, "032-222-2222");
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
contentValues.put(Phone.TYPE, Phone.TYPE_CUSTOM); .put(Phone.TYPE, Phone.TYPE_CUSTOM)
contentValues.put(Phone.LABEL, "VOICE"); .put(Phone.LABEL, "VOICE")
contentValues.put(Phone.NUMBER, "033-333-3333"); .put(Phone.NUMBER, "033-333-3333");
contentValues = verifier.createExpected(StructuredPostal.CONTENT_ITEM_TYPE); verifier.buildExpected(StructuredPostal.CONTENT_ITEM_TYPE)
contentValues.put(StructuredPostal.TYPE, StructuredPostal.TYPE_WORK); .put(StructuredPostal.TYPE, StructuredPostal.TYPE_WORK)
contentValues.put(StructuredPostal.COUNTRY, "United States of America"); .put(StructuredPostal.COUNTRY, "United States of America")
contentValues.put(StructuredPostal.POSTCODE, "30314"); .put(StructuredPostal.POSTCODE, "30314")
contentValues.put(StructuredPostal.REGION, "LA"); .put(StructuredPostal.REGION, "LA")
contentValues.put(StructuredPostal.CITY, "Baytown"); .put(StructuredPostal.CITY, "Baytown")
contentValues.put(StructuredPostal.STREET, "100 Waters Edge"); .put(StructuredPostal.STREET, "100 Waters Edge")
contentValues.put(StructuredPostal.FORMATTED_ADDRESS, .put(StructuredPostal.FORMATTED_ADDRESS,
"100 Waters Edge Baytown LA 30314 United States of America"); "100 Waters Edge Baytown LA 30314 United States of America");
contentValues = verifier.createExpected(StructuredPostal.CONTENT_ITEM_TYPE); verifier.buildExpected(StructuredPostal.CONTENT_ITEM_TYPE)
contentValues.put(StructuredPostal.TYPE, StructuredPostal.TYPE_HOME); .put(StructuredPostal.TYPE, StructuredPostal.TYPE_HOME)
contentValues.put(StructuredPostal.COUNTRY, "United States of America"); .put(StructuredPostal.COUNTRY, "United States of America")
contentValues.put(StructuredPostal.POSTCODE, "30314"); .put(StructuredPostal.POSTCODE, "30314")
contentValues.put(StructuredPostal.REGION, "LA"); .put(StructuredPostal.REGION, "LA")
contentValues.put(StructuredPostal.CITY, "Baytown"); .put(StructuredPostal.CITY, "Baytown")
contentValues.put(StructuredPostal.STREET, "42 Plantation St."); .put(StructuredPostal.STREET, "42 Plantation St.")
contentValues.put(StructuredPostal.FORMATTED_ADDRESS, .put(StructuredPostal.FORMATTED_ADDRESS,
"42 Plantation St. Baytown LA 30314 United States of America"); "42 Plantation St. Baytown LA 30314 United States of America");
contentValues = verifier.createExpected(Email.CONTENT_ITEM_TYPE); verifier.buildExpected(Email.CONTENT_ITEM_TYPE)
// "TYPE=INTERNET" -> TYPE_CUSTOM + the label "INTERNET" // "TYPE=INTERNET" -> TYPE_CUSTOM + the label "INTERNET"
contentValues.put(Email.TYPE, Email.TYPE_CUSTOM); .put(Email.TYPE, Email.TYPE_CUSTOM)
contentValues.put(Email.LABEL, "INTERNET"); .put(Email.LABEL, "INTERNET")
contentValues.put(Email.DATA, "forrestgump@walladalla.com"); .put(Email.DATA, "forrestgump@walladalla.com")
contentValues.put(Email.IS_PRIMARY, 1); .put(Email.IS_PRIMARY, 1);
contentValues = verifier.createExpected(Email.CONTENT_ITEM_TYPE); verifier.buildExpected(Email.CONTENT_ITEM_TYPE)
contentValues.put(Email.TYPE, Email.TYPE_MOBILE); .put(Email.TYPE, Email.TYPE_MOBILE)
contentValues.put(Email.DATA, "cell@example.com"); .put(Email.DATA, "cell@example.com");
contentValues = verifier.createExpected(Note.CONTENT_ITEM_TYPE); verifier.buildExpected(Note.CONTENT_ITEM_TYPE)
contentValues.put(Note.NOTE, "The following note is the example from RFC 2045."); .put(Note.NOTE, "The following note is the example from RFC 2045.");
contentValues = verifier.createExpected(Note.CONTENT_ITEM_TYPE); verifier.buildExpected(Note.CONTENT_ITEM_TYPE)
contentValues.put(Note.NOTE, .put(Note.NOTE,
"Now's the time for all folk to come to the aid of their country."); "Now's the time for all folk to come to the aid of their country.");
contentValues = verifier.createExpected(Photo.CONTENT_ITEM_TYPE); verifier.buildExpected(Photo.CONTENT_ITEM_TYPE)
// No information about its image format can be inserted. // No information about its image format can be inserted.
contentValues.put(Photo.PHOTO, sPhotoByteArrayForComplicatedCase); .put(Photo.PHOTO, sPhotoByteArrayForComplicatedCase);
contentValues = verifier.createExpected(Event.CONTENT_ITEM_TYPE); verifier.buildExpected(Event.CONTENT_ITEM_TYPE)
contentValues.put(Event.START_DATE, "19800101"); .put(Event.START_DATE, "19800101")
contentValues.put(Event.TYPE, Event.TYPE_BIRTHDAY); .put(Event.TYPE, Event.TYPE_BIRTHDAY);
contentValues = verifier.createExpected(Website.CONTENT_ITEM_TYPE); verifier.buildExpected(Website.CONTENT_ITEM_TYPE)
contentValues.put(Website.URL, "http://www.example.com/"); .put(Website.URL, "http://www.example.com/")
contentValues.put(Website.TYPE, Website.TYPE_HOMEPAGE); .put(Website.TYPE, Website.TYPE_HOMEPAGE);
verifier.verify(R.raw.v21_complicated, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_complicated, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
@@ -743,40 +737,40 @@ public class VCardImporterTests extends VCardTestsBase {
is.close(); is.close();
assertEquals(1, builder.vNodeList.size()); assertEquals(1, builder.vNodeList.size());
PropertyNodesVerifier verifier = new PropertyNodesVerifier(this) PropertyNodesVerifier verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("VERSION", "3.0") .addNodeWithOrder("VERSION", "3.0")
.addNodeWithOrder("FN", "And Roid") .addNodeWithOrder("FN", "And Roid")
.addNodeWithOrder("N", "And;Roid;;;", Arrays.asList("And", "Roid", "", "", "")) .addNodeWithOrder("N", "And;Roid;;;", Arrays.asList("And", "Roid", "", "", ""))
.addNodeWithOrder("ORG", "Open;Handset; Alliance", .addNodeWithOrder("ORG", "Open;Handset; Alliance",
Arrays.asList("Open", "Handset", " Alliance")) Arrays.asList("Open", "Handset", " Alliance"))
.addNodeWithOrder("SORT-STRING", "android") .addNodeWithOrder("SORT-STRING", "android")
.addNodeWithOrder("TEL", "0300000000", new TypeSet("PREF", "VOICE")) .addNodeWithOrder("TEL", "0300000000", new TypeSet("PREF", "VOICE"))
.addNodeWithOrder("CLASS", "PUBLIC") .addNodeWithOrder("CLASS", "PUBLIC")
.addNodeWithOrder("X-GNO", "0") .addNodeWithOrder("X-GNO", "0")
.addNodeWithOrder("X-GN", "group0") .addNodeWithOrder("X-GN", "group0")
.addNodeWithOrder("X-REDUCTION", "0") .addNodeWithOrder("X-REDUCTION", "0")
.addNodeWithOrder("REV", "20081031T065854Z"); .addNodeWithOrder("REV", "20081031T065854Z");
verifier.verify(builder.vNodeList.get(0)); verifier.verify(builder.vNodeList.get(0));
} }
public void testV30Simple() throws IOException, VCardException { public void testV30Simple() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues =
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE);
contentValues.put(StructuredName.FAMILY_NAME, "And");
contentValues.put(StructuredName.GIVEN_NAME, "Roid");
contentValues.put(StructuredName.DISPLAY_NAME, "And Roid");
contentValues.put(StructuredName.PHONETIC_GIVEN_NAME, "android");
contentValues = verifier.createExpected(Organization.CONTENT_ITEM_TYPE); verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
contentValues.put(Organization.COMPANY, "Open"); .put(StructuredName.FAMILY_NAME, "And")
contentValues.put(Organization.DEPARTMENT, "Handset Alliance"); .put(StructuredName.GIVEN_NAME, "Roid")
contentValues.put(Organization.TYPE, Organization.TYPE_WORK); .put(StructuredName.DISPLAY_NAME, "And Roid")
.put(StructuredName.PHONETIC_GIVEN_NAME, "android");
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE); verifier.buildExpected(Organization.CONTENT_ITEM_TYPE)
contentValues.put(Phone.TYPE, Phone.TYPE_CUSTOM); .put(Organization.COMPANY, "Open")
contentValues.put(Phone.LABEL, "VOICE"); .put(Organization.DEPARTMENT, "Handset Alliance")
contentValues.put(Phone.NUMBER, "030-000-0000"); .put(Organization.TYPE, Organization.TYPE_WORK);
contentValues.put(Phone.IS_PRIMARY, 1);
verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
.put(Phone.TYPE, Phone.TYPE_CUSTOM)
.put(Phone.LABEL, "VOICE")
.put(Phone.NUMBER, "030-000-0000")
.put(Phone.IS_PRIMARY, 1);
verifier.verify(R.raw.v30_simple, VCardConfig.VCARD_TYPE_V30_GENERIC_UTF8); verifier.verify(R.raw.v30_simple, VCardConfig.VCARD_TYPE_V30_GENERIC_UTF8);
} }
@@ -789,47 +783,40 @@ public class VCardImporterTests extends VCardTestsBase {
assertEquals(1, builder.vNodeList.size()); assertEquals(1, builder.vNodeList.size());
ContentValues contentValuesForShiftJis = new ContentValues(); ContentValues contentValuesForShiftJis = new ContentValues();
contentValuesForShiftJis.put("CHARSET", "SHIFT_JIS"); contentValuesForShiftJis.put("CHARSET", "SHIFT_JIS");
ContentValues contentValuesForQP = new ContentValues();
contentValuesForQP.put("ENCODING", "QUOTED-PRINTABLE");
contentValuesForQP.put("CHARSET", "SHIFT_JIS");
// Though Japanese careers append ";;;;" at the end of the value of "SOUND", // Though Japanese careers append ";;;;" at the end of the value of "SOUND",
// vCard 2.1/3.0 specification does not allow multiple values. // vCard 2.1/3.0 specification does not allow multiple values.
// Do not need to handle it as multiple values. // Do not need to handle it as multiple values.
PropertyNodesVerifier verifier = new PropertyNodesVerifier(this) PropertyNodesVerifier verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("VERSION", "2.1", null, null, null, null, null) .addNodeWithOrder("VERSION", "2.1", null, null, null, null, null)
.addNodeWithOrder("N", "\u5B89\u85E4\u30ED\u30A4\u30C9;;;;", .addNodeWithOrder("N", "\u5B89\u85E4\u30ED\u30A4\u30C9;;;;",
Arrays.asList("\u5B89\u85E4\u30ED\u30A4\u30C9", "", "", "", ""), Arrays.asList("\u5B89\u85E4\u30ED\u30A4\u30C9", "", "", "", ""),
null, contentValuesForShiftJis, null, null) null, contentValuesForShiftJis, null, null)
.addNodeWithOrder("SOUND", "\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E;;;;", .addNodeWithOrder("SOUND",
null, null, contentValuesForShiftJis, "\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E;;;;",
new TypeSet("X-IRMC-N"), null) null, null, contentValuesForShiftJis,
.addNodeWithOrder("TEL", "0300000000", null, null, null, new TypeSet("X-IRMC-N"), null)
new TypeSet("VOICE", "PREF"), null); .addNodeWithOrder("TEL", "0300000000", null, null, null,
new TypeSet("VOICE", "PREF"), null);
verifier.verify(builder.vNodeList.get(0)); verifier.verify(builder.vNodeList.get(0));
} }
private void testV21Japanese1Common(int resId, int vcardType, boolean japanese) private void testV21Japanese1Common(int resId, int vcardType, boolean japanese)
throws IOException, VCardException { throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
.put(StructuredName.FAMILY_NAME, "\u5B89\u85E4\u30ED\u30A4\u30C9")
.put(StructuredName.DISPLAY_NAME, "\u5B89\u85E4\u30ED\u30A4\u30C9")
// While vCard parser does not split "SOUND" property values,
// ContactStruct care it.
.put(StructuredName.PHONETIC_FAMILY_NAME,
"\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E");
ContentValues contentValues = verifier.buildExpected(Phone.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); // Phone number formatting is different.
contentValues.put(StructuredName.FAMILY_NAME, "\u5B89\u85E4\u30ED\u30A4\u30C9"); .put(Phone.NUMBER, (japanese ? "03-0000-0000" : "030-000-0000"))
contentValues.put(StructuredName.DISPLAY_NAME, "\u5B89\u85E4\u30ED\u30A4\u30C9"); .put(Phone.TYPE, Phone.TYPE_CUSTOM)
// While vCard parser does not split "SOUND" property values, ContactStruct care it. .put(Phone.LABEL, "VOICE")
contentValues.put(StructuredName.PHONETIC_FAMILY_NAME, .put(Phone.IS_PRIMARY, 1);
"\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E");
contentValues = verifier.createExpected(Phone.CONTENT_ITEM_TYPE);
// Phone number formatting is different.
if (japanese) {
contentValues.put(Phone.NUMBER, "03-0000-0000");
} else {
contentValues.put(Phone.NUMBER, "030-000-0000");
}
contentValues.put(Phone.TYPE, Phone.TYPE_CUSTOM);
contentValues.put(Phone.LABEL, "VOICE");
contentValues.put(Phone.IS_PRIMARY, 1);
verifier.verify(resId, vcardType); verifier.verify(resId, vcardType);
} }
@@ -870,71 +857,67 @@ public class VCardImporterTests extends VCardTestsBase {
assertEquals(1, builder.vNodeList.size()); assertEquals(1, builder.vNodeList.size());
ContentValues contentValuesForShiftJis = new ContentValues(); ContentValues contentValuesForShiftJis = new ContentValues();
contentValuesForShiftJis.put("CHARSET", "SHIFT_JIS"); contentValuesForShiftJis.put("CHARSET", "SHIFT_JIS");
ContentValues contentValuesForQP = new ContentValues(); ContentValues contentValuesForQPAndSJ = new ContentValues();
contentValuesForQP.put("ENCODING", "QUOTED-PRINTABLE"); contentValuesForQPAndSJ.put("ENCODING", "QUOTED-PRINTABLE");
contentValuesForQP.put("CHARSET", "SHIFT_JIS"); contentValuesForQPAndSJ.put("CHARSET", "SHIFT_JIS");
PropertyNodesVerifier verifier = new PropertyNodesVerifier(this) PropertyNodesVerifier verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("VERSION", "2.1") .addNodeWithOrder("VERSION", "2.1")
.addNodeWithOrder("N", "\u5B89\u85E4;\u30ED\u30A4\u30C9\u0031;;;", .addNodeWithOrder("N", "\u5B89\u85E4;\u30ED\u30A4\u30C9\u0031;;;",
Arrays.asList("\u5B89\u85E4", "\u30ED\u30A4\u30C9\u0031", Arrays.asList("\u5B89\u85E4", "\u30ED\u30A4\u30C9\u0031",
"", "", ""), "", "", ""),
null, contentValuesForShiftJis, null, null) null, contentValuesForShiftJis, null, null)
.addNodeWithOrder("FN", "\u5B89\u85E4\u0020\u30ED\u30A4\u30C9\u0020\u0031", .addNodeWithOrder("FN", "\u5B89\u85E4\u0020\u30ED\u30A4\u30C9\u0020\u0031",
null, null, contentValuesForShiftJis, null, null) null, null, contentValuesForShiftJis, null, null)
.addNodeWithOrder("SOUND", .addNodeWithOrder("SOUND",
"\uFF71\uFF9D\uFF84\uFF9E\uFF73;\uFF9B\uFF72\uFF84\uFF9E\u0031;;;", "\uFF71\uFF9D\uFF84\uFF9E\uFF73;\uFF9B\uFF72\uFF84\uFF9E\u0031;;;",
null, null, contentValuesForShiftJis, null, null, contentValuesForShiftJis,
new TypeSet("X-IRMC-N"), null) new TypeSet("X-IRMC-N"), null)
.addNodeWithOrder("ADR", .addNodeWithOrder("ADR",
";\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\u685C" + ";\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\u685C" +
"\u4E18\u753A\u0032\u0036\u002D\u0031\u30BB" + "\u4E18\u753A\u0032\u0036\u002D\u0031\u30BB" +
"\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC\u0036" + "\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC\u0036" +
"\u968E;;;;150-8512;", "\u968E;;;;150-8512;",
Arrays.asList("", Arrays.asList("",
"\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\u685C" + "\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\u685C" +
"\u4E18\u753A\u0032\u0036\u002D\u0031\u30BB" + "\u4E18\u753A\u0032\u0036\u002D\u0031\u30BB" +
"\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC" + "\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC" +
"\u0036\u968E", "", "", "", "150-8512", ""), "\u0036\u968E", "", "", "", "150-8512", ""),
null, contentValuesForQP, new TypeSet("HOME"), null) null, contentValuesForQPAndSJ, new TypeSet("HOME"), null)
.addNodeWithOrder("NOTE", "\u30E1\u30E2", null, null, contentValuesForQP, null, null); .addNodeWithOrder("NOTE", "\u30E1\u30E2", null, null,
contentValuesForQPAndSJ, null, null);
verifier.verify(builder.vNodeList.get(0)); verifier.verify(builder.vNodeList.get(0));
} }
public void testV21Japanese2_Type_Generic_Utf8() throws IOException, VCardException { public void testV21Japanese2_Type_Generic_Utf8() throws IOException, VCardException {
ContactStructVerifier verifier = new ContactStructVerifier(); ContentValuesVerifier verifier = new ContentValuesVerifier();
ContentValues contentValues = verifier.buildExpected(StructuredName.CONTENT_ITEM_TYPE)
verifier.createExpected(StructuredName.CONTENT_ITEM_TYPE); .put(StructuredName.FAMILY_NAME, "\u5B89\u85E4")
contentValues.put(StructuredName.FAMILY_NAME, "\u5B89\u85E4"); .put(StructuredName.GIVEN_NAME, "\u30ED\u30A4\u30C9\u0031")
contentValues.put(StructuredName.GIVEN_NAME, "\u30ED\u30A4\u30C9\u0031"); .put(StructuredName.DISPLAY_NAME,
contentValues.put(StructuredName.DISPLAY_NAME, "\u5B89\u85E4\u0020\u30ED\u30A4\u30C9\u0020\u0031")
"\u5B89\u85E4\u0020\u30ED\u30A4\u30C9\u0020\u0031"); // ContactStruct should correctly split "SOUND" property into several elements,
// ContactStruct should correctly split "SOUND" property into several elements, // even though VCardParser side does not care it.
// even though VCardParser side does not care it. .put(StructuredName.PHONETIC_FAMILY_NAME, "\uFF71\uFF9D\uFF84\uFF9E\uFF73")
contentValues.put(StructuredName.PHONETIC_FAMILY_NAME, .put(StructuredName.PHONETIC_GIVEN_NAME, "\uFF9B\uFF72\uFF84\uFF9E\u0031");
"\uFF71\uFF9D\uFF84\uFF9E\uFF73");
contentValues.put(StructuredName.PHONETIC_GIVEN_NAME,
"\uFF9B\uFF72\uFF84\uFF9E\u0031");
contentValues = verifier.createExpected(StructuredPostal.CONTENT_ITEM_TYPE); verifier.buildExpected(StructuredPostal.CONTENT_ITEM_TYPE)
contentValues.put(StructuredPostal.POSTCODE, "150-8512"); .put(StructuredPostal.POSTCODE, "150-8512")
contentValues.put(StructuredPostal.NEIGHBORHOOD, .put(StructuredPostal.NEIGHBORHOOD,
"\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\u685C" + "\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\u685C" +
"\u4E18\u753A\u0032\u0036\u002D\u0031\u30BB" + "\u4E18\u753A\u0032\u0036\u002D\u0031\u30BB" +
"\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC" + "\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC" +
"\u0036\u968E"); "\u0036\u968E")
contentValues.put(StructuredPostal.FORMATTED_ADDRESS, .put(StructuredPostal.FORMATTED_ADDRESS,
"\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\u685C" + "\u6771\u4EAC\u90FD\u6E0B\u8C37\u533A\u685C" +
"\u4E18\u753A\u0032\u0036\u002D\u0031\u30BB" + "\u4E18\u753A\u0032\u0036\u002D\u0031\u30BB" +
"\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC" + "\u30EB\u30EA\u30A2\u30F3\u30BF\u30EF\u30FC" +
"\u0036\u968E 150-8512"); "\u0036\u968E 150-8512")
contentValues.put(StructuredPostal.TYPE, StructuredPostal.TYPE_HOME); .put(StructuredPostal.TYPE, StructuredPostal.TYPE_HOME);
contentValues = verifier.createExpected(Note.CONTENT_ITEM_TYPE); verifier.buildExpected(Note.CONTENT_ITEM_TYPE)
contentValues.put(Note.NOTE, "\u30E1\u30E2"); .put(Note.NOTE, "\u30E1\u30E2");
verifier.verify(R.raw.v21_japanese_2, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); verifier.verify(R.raw.v21_japanese_2, VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
} }
// Following tests are old ones, though they still work fine.
public void testV21MultipleEntryCase() throws IOException, VCardException { public void testV21MultipleEntryCase() throws IOException, VCardException {
VCardParser_V21 parser = new VCardParser_V21(); VCardParser_V21 parser = new VCardParser_V21();
VNodeBuilder builder = new VNodeBuilder(); VNodeBuilder builder = new VNodeBuilder();
@@ -945,47 +928,47 @@ public class VCardImporterTests extends VCardTestsBase {
ContentValues contentValuesForShiftJis = new ContentValues(); ContentValues contentValuesForShiftJis = new ContentValues();
contentValuesForShiftJis.put("CHARSET", "SHIFT_JIS"); contentValuesForShiftJis.put("CHARSET", "SHIFT_JIS");
PropertyNodesVerifier verifier = new PropertyNodesVerifier(this) PropertyNodesVerifier verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("VERSION", "2.1") .addNodeWithOrder("VERSION", "2.1")
.addNodeWithOrder("N", "\u5B89\u85E4\u30ED\u30A4\u30C9\u0033;;;;", .addNodeWithOrder("N", "\u5B89\u85E4\u30ED\u30A4\u30C9\u0033;;;;",
Arrays.asList("\u5B89\u85E4\u30ED\u30A4\u30C9\u0033", "", "", "", ""), Arrays.asList("\u5B89\u85E4\u30ED\u30A4\u30C9\u0033", "", "", "", ""),
null, contentValuesForShiftJis, null, null) null, contentValuesForShiftJis, null, null)
.addNodeWithOrder("SOUND", .addNodeWithOrder("SOUND",
"\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E\u0033;;;;", "\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E\u0033;;;;",
null, null, contentValuesForShiftJis, null, null, contentValuesForShiftJis,
new TypeSet("X-IRMC-N"), null) new TypeSet("X-IRMC-N"), null)
.addNodeWithOrder("TEL", "9", new TypeSet("X-NEC-SECRET")) .addNodeWithOrder("TEL", "9", new TypeSet("X-NEC-SECRET"))
.addNodeWithOrder("TEL", "10", new TypeSet("X-NEC-HOTEL")) .addNodeWithOrder("TEL", "10", new TypeSet("X-NEC-HOTEL"))
.addNodeWithOrder("TEL", "11", new TypeSet("X-NEC-SCHOOL")) .addNodeWithOrder("TEL", "11", new TypeSet("X-NEC-SCHOOL"))
.addNodeWithOrder("TEL", "12", new TypeSet("FAX", "HOME")); .addNodeWithOrder("TEL", "12", new TypeSet("FAX", "HOME"));
verifier.verify(builder.vNodeList.get(0)); verifier.verify(builder.vNodeList.get(0));
verifier = new PropertyNodesVerifier(this) verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("VERSION", "2.1") .addNodeWithOrder("VERSION", "2.1")
.addNodeWithOrder("N", "\u5B89\u85E4\u30ED\u30A4\u30C9\u0034;;;;", .addNodeWithOrder("N", "\u5B89\u85E4\u30ED\u30A4\u30C9\u0034;;;;",
Arrays.asList("\u5B89\u85E4\u30ED\u30A4\u30C9\u0034", "", "", "", ""), Arrays.asList("\u5B89\u85E4\u30ED\u30A4\u30C9\u0034", "", "", "", ""),
null, contentValuesForShiftJis, null, null) null, contentValuesForShiftJis, null, null)
.addNodeWithOrder("SOUND", .addNodeWithOrder("SOUND",
"\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E\u0034;;;;", "\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E\u0034;;;;",
null, null, contentValuesForShiftJis, null, null, contentValuesForShiftJis,
new TypeSet("X-IRMC-N"), null) new TypeSet("X-IRMC-N"), null)
.addNodeWithOrder("TEL", "13", new TypeSet("MODEM")) .addNodeWithOrder("TEL", "13", new TypeSet("MODEM"))
.addNodeWithOrder("TEL", "14", new TypeSet("PAGER")) .addNodeWithOrder("TEL", "14", new TypeSet("PAGER"))
.addNodeWithOrder("TEL", "15", new TypeSet("X-NEC-FAMILY")) .addNodeWithOrder("TEL", "15", new TypeSet("X-NEC-FAMILY"))
.addNodeWithOrder("TEL", "16", new TypeSet("X-NEC-GIRL")); .addNodeWithOrder("TEL", "16", new TypeSet("X-NEC-GIRL"));
verifier.verify(builder.vNodeList.get(1)); verifier.verify(builder.vNodeList.get(1));
verifier = new PropertyNodesVerifier(this) verifier = new PropertyNodesVerifier(this)
.addNodeWithOrder("VERSION", "2.1") .addNodeWithOrder("VERSION", "2.1")
.addNodeWithOrder("N", "\u5B89\u85E4\u30ED\u30A4\u30C9\u0035;;;;", .addNodeWithOrder("N", "\u5B89\u85E4\u30ED\u30A4\u30C9\u0035;;;;",
Arrays.asList("\u5B89\u85E4\u30ED\u30A4\u30C9\u0035", "", "", "", ""), Arrays.asList("\u5B89\u85E4\u30ED\u30A4\u30C9\u0035", "", "", "", ""),
null, contentValuesForShiftJis, null, null) null, contentValuesForShiftJis, null, null)
.addNodeWithOrder("SOUND", .addNodeWithOrder("SOUND",
"\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E\u0035;;;;", "\uFF71\uFF9D\uFF84\uFF9E\uFF73\uFF9B\uFF72\uFF84\uFF9E\u0035;;;;",
null, null, contentValuesForShiftJis, null, null, contentValuesForShiftJis,
new TypeSet("X-IRMC-N"), null) new TypeSet("X-IRMC-N"), null)
.addNodeWithOrder("TEL", "17", new TypeSet("X-NEC-BOY")) .addNodeWithOrder("TEL", "17", new TypeSet("X-NEC-BOY"))
.addNodeWithOrder("TEL", "18", new TypeSet("X-NEC-FRIEND")) .addNodeWithOrder("TEL", "18", new TypeSet("X-NEC-FRIEND"))
.addNodeWithOrder("TEL", "19", new TypeSet("X-NEC-PHS")) .addNodeWithOrder("TEL", "19", new TypeSet("X-NEC-PHS"))
.addNodeWithOrder("TEL", "20", new TypeSet("X-NEC-RESTAURANT")); .addNodeWithOrder("TEL", "20", new TypeSet("X-NEC-RESTAURANT"));
verifier.verify(builder.vNodeList.get(2)); verifier.verify(builder.vNodeList.get(2));
} }
} }

View File

@@ -62,7 +62,6 @@ import android.test.mock.MockContentResolver;
import android.test.mock.MockContext; import android.test.mock.MockContext;
import android.test.mock.MockCursor; import android.test.mock.MockCursor;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import junit.framework.TestCase; import junit.framework.TestCase;
@@ -173,6 +172,64 @@ class CustomMockContext extends MockContext {
} }
} }
class ContentValuesBuilder {
private final ContentValues mContentValues;
public ContentValuesBuilder(final ContentValues contentValues) {
mContentValues = contentValues;
}
public ContentValuesBuilder put(String key, String value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder put(String key, Byte value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder put(String key, Short value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder put(String key, Integer value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder put(String key, Long value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder put(String key, Float value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder put(String key, Double value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder put(String key, Boolean value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder put(String key, byte[] value) {
mContentValues.put(key, value);
return this;
}
public ContentValuesBuilder putNull(String key) {
mContentValues.putNull(key);
return this;
}
}
/** /**
* BaseClass for vCard unit tests with utility classes. * BaseClass for vCard unit tests with utility classes.
* Please do not add each unit test here. * Please do not add each unit test here.
@@ -233,7 +290,7 @@ class CustomMockContext extends MockContext {
} }
final Collection<ContentValues> contentValuesCollection = final Collection<ContentValues> contentValuesCollection =
mMimeTypeToExpectedContentValues.get(mimeType); mMimeTypeToExpectedContentValues.get(mimeType);
contentValuesCollection.add(expectedContentValues); contentValuesCollection.add(expectedContentValues);
} }
@@ -347,19 +404,19 @@ class CustomMockContext extends MockContext {
} }
} }
public class ContactStructVerifier { public class ContentValuesVerifier {
private final ImportVerificationResolver mResolver; private final ImportVerificationResolver mResolver;
// private final String mCharset; // private final String mCharset;
public ContactStructVerifier() { public ContentValuesVerifier() {
mResolver = new ImportVerificationResolver(); mResolver = new ImportVerificationResolver();
} }
public ContentValues createExpected(String mimeType) { public ContentValuesBuilder buildExpected(String mimeType) {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
contentValues.put(Data.MIMETYPE, mimeType); contentValues.put(Data.MIMETYPE, mimeType);
mResolver.addExpectedContentValues(contentValues); mResolver.addExpectedContentValues(contentValues);
return contentValues; return new ContentValuesBuilder(contentValues);
} }
public void verify(int resId, int vCardType) public void verify(int resId, int vCardType)
@@ -399,7 +456,7 @@ class CustomMockContext extends MockContext {
addProvider(RawContacts.CONTENT_URI.getAuthority(), mProvider); addProvider(RawContacts.CONTENT_URI.getAuthority(), mProvider);
} }
public ContentValues buildData(String mimeType) { public ContentValuesBuilder buildInput(String mimeType) {
return mProvider.buildData(mimeType); return mProvider.buildData(mimeType);
} }
} }
@@ -437,11 +494,11 @@ class CustomMockContext extends MockContext {
public class ExportTestProvider extends MockContentProvider { public class ExportTestProvider extends MockContentProvider {
List<ContentValues> mContentValuesList = new ArrayList<ContentValues>(); List<ContentValues> mContentValuesList = new ArrayList<ContentValues>();
public ContentValues buildData(String mimeType) { public ContentValuesBuilder buildData(String mimeType) {
ContentValues contentValues = new ContentValues(); ContentValues contentValues = new ContentValues();
contentValues.put(Data.MIMETYPE, mimeType); contentValues.put(Data.MIMETYPE, mimeType);
mContentValuesList.add(contentValues); mContentValuesList.add(contentValues);
return contentValues; return new ContentValuesBuilder(contentValues);
} }
@Override @Override
@@ -518,48 +575,49 @@ class CustomMockContext extends MockContext {
} }
} }
public static class VCardVerificationHandler implements VCardComposer.OneEntryHandler { public class VCardVerificationHandler implements VCardComposer.OneEntryHandler {
final private TestCase mTestCase; final private TestCase mTestCase;
final private List<PropertyNodesVerifier> mPropertyNodesVerifierList; final private List<PropertyNodesVerifier> mPropertyNodesVerifierList;
final private boolean mIsV30; final private boolean mIsV30;
// To allow duplication, use list instead of set. // To allow duplication, use list instead of set.
// TODO: support multiple vCard entries. // TODO: support multiple vCard entries.
final private List<String> mExpectedLineList; final private List<String> mExpectedLineList;
final private ContactStructVerifier mContactStructVerifier; final private List<ContentValuesVerifier> mContentValuesVerifierList;
final private int mVCardType; final private int mVCardType;
int mCount; int mCount;
public VCardVerificationHandler(final TestCase testCase, final int version) { public VCardVerificationHandler(final TestCase testCase, final int version) {
this(testCase, null, version);
}
public VCardVerificationHandler(final TestCase testCase,
ContactStructVerifier contactStructVerifier, final int version) {
mTestCase = testCase; mTestCase = testCase;
mPropertyNodesVerifierList = new ArrayList<PropertyNodesVerifier>(); mPropertyNodesVerifierList = new ArrayList<PropertyNodesVerifier>();
mIsV30 = (version == V30); mIsV30 = (version == V30);
mExpectedLineList = new ArrayList<String>(); mExpectedLineList = new ArrayList<String>();
mContactStructVerifier = contactStructVerifier; mContentValuesVerifierList = new ArrayList<ContentValuesVerifier>();
mVCardType = (version == V30 ? VCardConfig.VCARD_TYPE_V30_GENERIC_UTF8 mVCardType = (version == V30 ? VCardConfig.VCARD_TYPE_V30_GENERIC_UTF8
: VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8); : VCardConfig.VCARD_TYPE_V21_GENERIC_UTF8);
mCount = 1; mCount = 1;
} }
public PropertyNodesVerifier addNewVerifier() { public PropertyNodesVerifier addPropertyNodesVerifier() {
PropertyNodesVerifier verifier = new PropertyNodesVerifier(mTestCase); PropertyNodesVerifier verifier = new PropertyNodesVerifier(mTestCase);
mPropertyNodesVerifierList.add(verifier); mPropertyNodesVerifierList.add(verifier);
verifier.addNodeWithOrder("VERSION", mIsV30 ? "3.0" : "2.1"); verifier.addNodeWithOrder("VERSION", mIsV30 ? "3.0" : "2.1");
return verifier; return verifier;
} }
public PropertyNodesVerifier addNewVerifierWithEmptyName() { public PropertyNodesVerifier addPropertyVerifierWithEmptyName() {
PropertyNodesVerifier verifier = addNewVerifier(); PropertyNodesVerifier verifier = addPropertyNodesVerifier();
if (mIsV30) { if (mIsV30) {
verifier.addNodeWithOrder("N", "").addNodeWithOrder("FN", ""); verifier.addNodeWithOrder("N", "").addNodeWithOrder("FN", "");
} }
return verifier; return verifier;
} }
public ContentValuesVerifier addContentValuesVerifier() {
ContentValuesVerifier verifier = new ContentValuesVerifier();
mContentValuesVerifierList.add(verifier);
return verifier;
}
public VCardVerificationHandler addExpectedLine(String line) { public VCardVerificationHandler addExpectedLine(String line) {
mExpectedLineList.add(line); mExpectedLineList.add(line);
return this; return this;
@@ -610,7 +668,7 @@ class CustomMockContext extends MockContext {
+ mCount + " of the entries (No.1 is the first entry))"); + mCount + " of the entries (No.1 is the first entry))");
} }
PropertyNodesVerifier propertyNodesVerifier = PropertyNodesVerifier propertyNodesVerifier =
mPropertyNodesVerifierList.get(0); mPropertyNodesVerifierList.get(0);
mPropertyNodesVerifierList.remove(0); mPropertyNodesVerifierList.remove(0);
VCardParser parser = (mIsV30 ? new VCardParser_V30(true) : new VCardParser_V21()); VCardParser parser = (mIsV30 ? new VCardParser_V30(true) : new VCardParser_V21());
VNodeBuilder builder = new VNodeBuilder(); VNodeBuilder builder = new VNodeBuilder();
@@ -621,10 +679,11 @@ class CustomMockContext extends MockContext {
is.close(); is.close();
mTestCase.assertEquals(1, builder.vNodeList.size()); mTestCase.assertEquals(1, builder.vNodeList.size());
propertyNodesVerifier.verify(builder.vNodeList.get(0)); propertyNodesVerifier.verify(builder.vNodeList.get(0));
if (mContactStructVerifier != null) { if (!mContentValuesVerifierList.isEmpty()) {
Log.d("@@@", vcard); ContentValuesVerifier contentValuesVerifier =
mContentValuesVerifierList.get(0);
is = new ByteArrayInputStream(vcard.getBytes("UTF-8")); is = new ByteArrayInputStream(vcard.getBytes("UTF-8"));
mContactStructVerifier.verify(is, mVCardType); contentValuesVerifier.verify(is, mVCardType);
is.close(); is.close();
} }
} catch (IOException e) { } catch (IOException e) {