Home | History | Annotate | Download | only in content
      1 /*
      2  * Copyright (C) 2010 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 
     17 package com.android.server;
     18 
     19 import android.accounts.Account;
     20 import android.os.Bundle;
     21 import android.test.AndroidTestCase;
     22 import android.test.suitebuilder.annotation.SmallTest;
     23 
     24 import com.android.server.content.SyncOperation;
     25 
     26 /**
     27  * You can run those tests with:
     28  *
     29  * adb shell am instrument
     30  * -e debug false
     31  * -w
     32  * -e class android.content.SyncOperationTest com.android.frameworks.coretests/android.test.InstrumentationTestRunner
     33  */
     34 
     35 public class SyncOperationTest extends AndroidTestCase {
     36 
     37     @SmallTest
     38     public void testToKey() {
     39         Account account1 = new Account("account1", "type1");
     40         Account account2 = new Account("account2", "type2");
     41 
     42         Bundle b1 = new Bundle();
     43         Bundle b2 = new Bundle();
     44         b2.putBoolean("b2", true);
     45 
     46         SyncOperation op1 = new SyncOperation(account1, 0,
     47                 1,
     48                 SyncOperation.REASON_PERIODIC,
     49                 "authority1",
     50                 b1,
     51                 100,
     52                 1000,
     53                 10000,
     54                 false);
     55 
     56         // Same as op1 but different time infos
     57         SyncOperation op2 = new SyncOperation(account1, 0,
     58                 1,
     59                 SyncOperation.REASON_PERIODIC,
     60                 "authority1",
     61                 b1,
     62                 200,
     63                 2000,
     64                 20000,
     65                 false);
     66 
     67         // Same as op1 but different authority
     68         SyncOperation op3 = new SyncOperation(account1, 0,
     69                 1,
     70                 SyncOperation.REASON_PERIODIC,
     71                 "authority2",
     72                 b1,
     73                 100,
     74                 1000,
     75                 10000,
     76                 false);
     77 
     78         // Same as op1 but different account
     79         SyncOperation op4 = new SyncOperation(account2, 0,
     80                 1,
     81                 SyncOperation.REASON_PERIODIC,
     82                 "authority1",
     83                 b1,
     84                 100,
     85                 1000,
     86                 10000,
     87                 false);
     88 
     89         // Same as op1 but different bundle
     90         SyncOperation op5 = new SyncOperation(account1, 0,
     91                 1,
     92                 SyncOperation.REASON_PERIODIC,
     93                 "authority1",
     94                 b2,
     95                 100,
     96                 1000,
     97                 10000,
     98                 false);
     99 
    100         assertEquals(op1.key, op2.key);
    101         assertNotSame(op1.key, op3.key);
    102         assertNotSame(op1.key, op4.key);
    103         assertNotSame(op1.key, op5.key);
    104     }
    105 }
    106