18d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng/* 28d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * Copyright (C) 2012 The Android Open Source Project 38d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * 48d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License"); 58d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * you may not use this file except in compliance with the License. 68d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * You may obtain a copy of the License at 78d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * 88d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * http://www.apache.org/licenses/LICENSE-2.0 98d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * 108d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * Unless required by applicable law or agreed to in writing, software 118d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS, 128d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * See the License for the specific language governing permissions and 148d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * limitations under the License 158d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng */ 168d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 178d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengpackage com.android.vcard.tests; 188d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 198d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengimport android.content.ContentValues; 208d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengimport android.provider.ContactsContract; 218d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 228d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengimport com.android.vcard.VCardBuilder; 238d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengimport com.android.vcard.VCardConfig; 248d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengimport com.google.android.collect.Lists; 258d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 268d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengimport junit.framework.TestCase; 278d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 288d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengimport java.util.ArrayList; 298d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 308d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng/** 318d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng * Unit test for VCardBuilder. 328d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng */ 338d1f50f582dc384a164a42657c35187b0226bcc3Chiao Chengpublic class VCardBuilderTest extends TestCase { 348d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 358d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng public void testVCardNameFieldFromDisplayName() { 368d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng final ArrayList<ContentValues> contentList = Lists.newArrayList(); 378d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 388d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng final ContentValues values = new ContentValues(); 398d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, "ने"); 408d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng contentList.add(values); 418d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 428d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng final VCardBuilder builder = new VCardBuilder(VCardConfig.VCARD_TYPE_DEFAULT); 438d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng builder.appendNameProperties(contentList); 448d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng final String actual = builder.toString(); 458d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 468d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng final String expectedCommon = ";CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:" + 47d98c0fe9ab6a89129c31c510ccd629a2dca148afChiao Cheng "=E0=A4=A8=E0=A5=87"; 488d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 49d98c0fe9ab6a89129c31c510ccd629a2dca148afChiao Cheng final String expectedName = "N" + expectedCommon + ";;;;"; 508d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng final String expectedFullName = "FN" + expectedCommon; 518d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 528d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng assertTrue("Actual value:\n" + actual + " expected to contain\n" + expectedName + 538d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng "\nbut does not.", actual.contains(expectedName)); 548d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng assertTrue("Actual value:\n" + actual + " expected to contain\n" + expectedFullName + 558d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng "\nbut does not.", actual.contains(expectedFullName)); 568d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng } 578d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng} 588d1f50f582dc384a164a42657c35187b0226bcc3Chiao Cheng 59