Daisuke Miyakawa | 673c1d1 | 2009-11-20 11:06:39 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Daisuke Miyakawa | 69831d9 | 2010-09-02 10:39:00 -0700 | [diff] [blame] | 16 | package android.pim.vcard.test_utils; |
Daisuke Miyakawa | 673c1d1 | 2009-11-20 11:06:39 +0900 | [diff] [blame] | 17 | |
| 18 | import android.content.Context; |
| 19 | import android.pim.vcard.VCardComposer; |
Daisuke Miyakawa | 69831d9 | 2010-09-02 10:39:00 -0700 | [diff] [blame] | 20 | import android.test.AndroidTestCase; |
Daisuke Miyakawa | 673c1d1 | 2009-11-20 11:06:39 +0900 | [diff] [blame] | 21 | |
| 22 | import junit.framework.TestCase; |
| 23 | |
| 24 | import java.util.ArrayList; |
| 25 | |
Daisuke Miyakawa | 69831d9 | 2010-09-02 10:39:00 -0700 | [diff] [blame] | 26 | public class LineVerifier implements VCardComposer.OneEntryHandler { |
| 27 | private final AndroidTestCase mAndroidTestCase; |
Daisuke Miyakawa | 673c1d1 | 2009-11-20 11:06:39 +0900 | [diff] [blame] | 28 | private final ArrayList<LineVerifierElem> mLineVerifierElemList; |
| 29 | private int mVCardType; |
| 30 | private int index; |
| 31 | |
Daisuke Miyakawa | 69831d9 | 2010-09-02 10:39:00 -0700 | [diff] [blame] | 32 | public LineVerifier(AndroidTestCase androidTestCase, int vcardType) { |
| 33 | mAndroidTestCase = androidTestCase; |
Daisuke Miyakawa | 673c1d1 | 2009-11-20 11:06:39 +0900 | [diff] [blame] | 34 | mLineVerifierElemList = new ArrayList<LineVerifierElem>(); |
| 35 | mVCardType = vcardType; |
| 36 | } |
| 37 | |
| 38 | public LineVerifierElem addLineVerifierElem() { |
Daisuke Miyakawa | 69831d9 | 2010-09-02 10:39:00 -0700 | [diff] [blame] | 39 | LineVerifierElem lineVerifier = new LineVerifierElem(mAndroidTestCase, mVCardType); |
Daisuke Miyakawa | 673c1d1 | 2009-11-20 11:06:39 +0900 | [diff] [blame] | 40 | mLineVerifierElemList.add(lineVerifier); |
| 41 | return lineVerifier; |
| 42 | } |
| 43 | |
| 44 | public void verify(String vcard) { |
| 45 | if (index >= mLineVerifierElemList.size()) { |
Daisuke Miyakawa | 69831d9 | 2010-09-02 10:39:00 -0700 | [diff] [blame] | 46 | TestCase.fail("Insufficient number of LineVerifier (" + index + ")"); |
Daisuke Miyakawa | 673c1d1 | 2009-11-20 11:06:39 +0900 | [diff] [blame] | 47 | } |
| 48 | |
Daisuke Miyakawa | 69831d9 | 2010-09-02 10:39:00 -0700 | [diff] [blame] | 49 | final LineVerifierElem lineVerifier = mLineVerifierElemList.get(index); |
Daisuke Miyakawa | 673c1d1 | 2009-11-20 11:06:39 +0900 | [diff] [blame] | 50 | lineVerifier.verify(vcard); |
| 51 | |
| 52 | index++; |
| 53 | } |
| 54 | |
| 55 | public boolean onEntryCreated(String vcard) { |
| 56 | verify(vcard); |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | public boolean onInit(Context context) { |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | public void onTerminate() { |
| 65 | } |
| 66 | } |