Home | History | Annotate | Download | only in animation
      1 /*
      2 * Copyright (C) 2014 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 android.animation;
     17 
     18 import android.support.test.filters.LargeTest;
     19 import android.test.ActivityInstrumentationTestCase2;
     20 
     21 import java.util.HashSet;
     22 import java.util.Set;
     23 import java.util.concurrent.CountDownLatch;
     24 import java.util.concurrent.TimeUnit;
     25 
     26 import com.android.frameworks.coretests.R;
     27 
     28 @LargeTest
     29 public class AnimatorInflaterTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity>  {
     30     Set<Integer> identityHashes = new HashSet<Integer>();
     31 
     32     public AnimatorInflaterTest() {
     33         super(BasicAnimatorActivity.class);
     34     }
     35 
     36     private void assertUnique(Object object) {
     37         assertUnique(object, "");
     38     }
     39 
     40     private void assertUnique(Object object, String msg) {
     41         final int code = System.identityHashCode(object);
     42         assertTrue("object should be unique " + msg + ", obj:" + object, identityHashes.add(code));
     43 
     44     }
     45 
     46     public void testLoadStateListAnimator() {
     47         StateListAnimator sla1 = AnimatorInflater.loadStateListAnimator(getActivity(),
     48                 R.anim.test_state_anim);
     49         sla1.setTarget(getActivity().mAnimatingButton);
     50         StateListAnimator sla2 = AnimatorInflater.loadStateListAnimator(getActivity(),
     51                 R.anim.test_state_anim);
     52         assertNull(sla2.getTarget());
     53         for (StateListAnimator sla : new StateListAnimator[]{sla1, sla2}) {
     54             assertUnique(sla);
     55             assertEquals(3, sla.getTuples().size());
     56             for (StateListAnimator.Tuple tuple : sla.getTuples()) {
     57                 assertUnique(tuple);
     58                 assertUnique(tuple.getAnimator());
     59             }
     60         }
     61     }
     62 
     63 }
     64