Home | History | Annotate | Download | only in testutils
      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  */
     16 package com.android.vcard.tests.testutils;
     17 
     18 import android.content.ContentValues;
     19 import android.test.AndroidTestCase;
     20 
     21 import com.android.vcard.VCardConfig;
     22 import com.android.vcard.tests.testutils.VCardVerifier;
     23 
     24 /**
     25  * BaseClass for vCard unit tests with utility classes.
     26  * Please do not add each unit test here.
     27  */
     28 public abstract class VCardTestsBase extends AndroidTestCase {
     29     public static final int V21 = VCardConfig.VCARD_TYPE_V21_GENERIC;
     30     public static final int V30 = VCardConfig.VCARD_TYPE_V30_GENERIC;
     31     public static final int V40 = VCardConfig.VCARD_TYPE_V40_GENERIC;
     32 
     33     // Do not modify these during tests.
     34     protected final ContentValues mContentValuesForQP;
     35     protected final ContentValues mContentValuesForSJis;
     36     protected final ContentValues mContentValuesForUtf8;
     37     protected final ContentValues mContentValuesForQPAndSJis;
     38     protected final ContentValues mContentValuesForQPAndUtf8;
     39     protected final ContentValues mContentValuesForBase64V21;
     40     protected final ContentValues mContentValuesForBase64V30;
     41 
     42     protected VCardVerifier mVerifier;
     43     /**
     44      * true when we shouldn't call {@link VCardVerifier#verify()}.
     45      */
     46     private boolean mSkipVerification;
     47 
     48     public VCardTestsBase() {
     49         super();
     50         // Not using constants in vCard code since it may be wrong.
     51         mContentValuesForQP = new ContentValues();
     52         mContentValuesForQP.put("ENCODING", "QUOTED-PRINTABLE");
     53         mContentValuesForSJis = new ContentValues();
     54         mContentValuesForSJis.put("CHARSET", "SHIFT_JIS");
     55         mContentValuesForUtf8 = new ContentValues();
     56         mContentValuesForUtf8.put("CHARSET", "UTF-8");
     57         mContentValuesForQPAndSJis = new ContentValues();
     58         mContentValuesForQPAndSJis.put("ENCODING", "QUOTED-PRINTABLE");
     59         mContentValuesForQPAndSJis.put("CHARSET", "SHIFT_JIS");
     60         mContentValuesForQPAndUtf8 = new ContentValues();
     61         mContentValuesForQPAndUtf8.put("ENCODING", "QUOTED-PRINTABLE");
     62         mContentValuesForQPAndUtf8.put("CHARSET", "UTF-8");
     63         mContentValuesForBase64V21 = new ContentValues();
     64         mContentValuesForBase64V21.put("ENCODING", "BASE64");
     65         mContentValuesForBase64V30 = new ContentValues();
     66         mContentValuesForBase64V30.put("ENCODING", "b");
     67     }
     68 
     69     @Override
     70     public void testAndroidTestCaseSetupProperly() {
     71         super.testAndroidTestCaseSetupProperly();
     72         mSkipVerification = true;
     73     }
     74 
     75     /**
     76      * Calls super's {@link #setUp()} and prepares {@link VCardVerifier}. We call
     77      * {@link VCardVerifier#verify()} on {@link #tearDown()}.
     78      */
     79     @Override
     80     public final void setUp() throws Exception{
     81         super.setUp();
     82         mVerifier = new VCardVerifier(this);
     83         mSkipVerification = false;
     84     }
     85 
     86     /**
     87      * Calls super's {@link #tearDown()} and {@link VCardVerifier#verify()}.
     88      */
     89     @Override
     90     public final void tearDown() throws Exception {
     91         // We don't want to forget to call verify() as it makes unit test successful silently even
     92         // when it shouldn't be, while each test case tends become so large to manage and sometimes
     93         // we had forgotten to call the method. That is why we override setUp()/tearDown() here.
     94         if (!mSkipVerification) {
     95             mVerifier.verify();
     96         }
     97         super.tearDown();
     98     }
     99 }
    100