1d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar/*
2d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* Copyright (C) 2014 The Android Open Source Project
3d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar*
4d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* Licensed under the Apache License, Version 2.0 (the "License");
5d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* you may not use this file except in compliance with the License.
6d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* You may obtain a copy of the License at
7d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar*
8d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar*      http://www.apache.org/licenses/LICENSE-2.0
9d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar*
10d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* Unless required by applicable law or agreed to in writing, software
11d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* distributed under the License is distributed on an "AS IS" BASIS,
12d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* See the License for the specific language governing permissions and
14d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar* limitations under the License.
15d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar*/
16d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarpackage android.animation;
17d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
18d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport android.test.ActivityInstrumentationTestCase2;
19d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
20d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport java.util.HashSet;
21d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport java.util.Set;
22d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport java.util.concurrent.CountDownLatch;
23d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport java.util.concurrent.TimeUnit;
24d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
25d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport com.android.frameworks.coretests.R;
26d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
27d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarpublic class AnimatorInflaterTest extends ActivityInstrumentationTestCase2<BasicAnimatorActivity>  {
28d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    Set<Integer> identityHashes = new HashSet<Integer>();
29d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
30d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    public AnimatorInflaterTest() {
31d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        super(BasicAnimatorActivity.class);
32d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    }
33d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
34d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    private void assertUnique(Object object) {
35d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        assertUnique(object, "");
36d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    }
37d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
38d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    private void assertUnique(Object object, String msg) {
39d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        final int code = System.identityHashCode(object);
40d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        assertTrue("object should be unique " + msg + ", obj:" + object, identityHashes.add(code));
41d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
42d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    }
43d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
44d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    public void testLoadStateListAnimator() {
45d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        StateListAnimator sla1 = AnimatorInflater.loadStateListAnimator(getActivity(),
46d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar                R.anim.test_state_anim);
47d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        sla1.setTarget(getActivity().mAnimatingButton);
48d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        StateListAnimator sla2 = AnimatorInflater.loadStateListAnimator(getActivity(),
49d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar                R.anim.test_state_anim);
50d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        assertNull(sla2.getTarget());
51d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        for (StateListAnimator sla : new StateListAnimator[]{sla1, sla2}) {
52d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar            assertUnique(sla);
53d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar            assertEquals(3, sla.getTuples().size());
54d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar            for (StateListAnimator.Tuple tuple : sla.getTuples()) {
55d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar                assertUnique(tuple);
56d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar                assertUnique(tuple.getAnimator());
57d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar            }
58d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar        }
59d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar    }
60d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar
61d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar}
62