这两天查cts 的fail, android.animation中有3个fail。
分别为testCurrentPlayTime,testCancel,testSetCurrentPlayTime,在此对着三个fail我的跟踪解析情况做一说明。
1. testCancel:如前一封mail说的,是testCode本身有点问题,后来我改了testcode验证:按照4.1的写法,我写了脚本跑整个包10遍,测了两遍脚本,相当于20遍,未重现。注:按ICS的testcode,跑完10遍这个会fail2~3遍的。
2. testCurrentPlayTime:其测试用例如下:
public void testCurrentPlayTime()throws Throwable {
startAnimation(mValueAnimator);
Thread.sleep(200);
这里的值原来是100,我改成了200进行测试,也是用刚才的脚本共跑了20遍未出错。
long currentPlayTime = mValueAnimator.getCurrentPlayTime();
assertTrue(currentPlayTime > 0);
}
我简单说明为什么我把上面的100改成了200就ok了。因为startAnimation(mValueAnimator);会在UI线程去调用\framework\base\core\java\android\animation\ValueAnimator.java中的start函数,这个函数会进行一系列的处理,包括发送消息出去等。
mValueAnimator.getCurrentPlayTime();这个函数如下: public long getCurrentPlayTime() {
if(!mInitialized) Log.d(TAG,"mInitialized is false!!!");
if(mPlayingState ==STOPPED) Log.d(TAG, "mPlayingState == STOPPED!!!");
if (!mInitialized || mPlayingState ==STOPPED) {
Log.d(TAG,"getCurrentPlayTime");
return 0;
}
longcurrentTime=AnimationUtils.currentAnimationTimeMillis();
Log.d(TAG,"getCurrentPlayTime,currentTime is "+currentTime);
return currentTime - mStartTime;
}
其中的mPlayingState如果是STOPPED的话,就会返回0.而这个mPlayingState的初始值是STOPPED,是在上面所说的start函数中会发消息出去,然后有handler去处理。如果在100ms内处理的话,就不会fail,但是若getCurrentPlayTime在处理完之前调用,就会得到0,所以就fail。
错误时打的log:(getCurrentPlayTime在handleMessage之前)
D/ValueAnimator( 3336): animationHandler.sendEmptyMessage(ANIMATION_START)
D/ValueAnimator( 3336): Start the animation playing
D/ValueAnimator( 3336): This sets the initial value of the animation, prior to actually starting it running
D/ValueAnimator( 3336): mInitialized is false!!!
D/ValueAnimator( 3336): mPlayingState == STOPPED!!!
D/ValueAnimator( 3336): getCurrentPlayTime
D/ValueAnimator( 3336): setCurrentPlayTime!!!currentTime is 4215917
D/ValueAnimator( 3336): before animationFrame-----------mStartTime is 4215917
D/ValueAnimator( 3336): after animationFrame-----------mStartTime is 4215917
D/ValueAnimator( 3336): onAnimationStart
D/ValueAnimator( 3336): animationHandler.sendEmptyMessage(ANIMATION_START)
I/TAG ( 1828): sync time from stream----------------------@@@
D/ValueAnimator( 3336): mPlayingState == STOPPED!!!
D/ValueAnimator( 3336): getCurrentPlayTime
D/ValueAnimator( 3336): handleMessage:ANIMATION_START
D/ValueAnimator( 3336): startAnimation----Called internally to start an animation by adding it to the active animations list. Must be called on the UI thread
D/ValueAnimator( 3336): anim.startAnimation-----------
D/ValueAnimator( 3336): startAnimation----Called internally to start an animation by adding it to the active animations list. Must be called on the UI thread
D/ValueAnimator( 3336): anim.startAnimation-----------
D/ValueAnimator( 3336): handleMessage:ANIMATION_START
正确时打的log:(getCurrentPlayTime在handleMessage之后)
D/ValueAnimator( 3305): animationHandler.sendEmptyMessage(ANIMATION_START)
D/ValueAnimator( 3305): Start the animation playing
D/ValueAnimator( 3305): This sets the initial value of the animation, prior to actually starting it running
D/ValueAnimator( 3305): mInitialized is false!!!
D/ValueAnimator( 3305): mPlayingState == STOPPED!!!
D/ValueAnimator( 3305): getCurrentPlayTime
D/ValueAnimator( 3305): setCurrentPlayTime!!!currentTime is 4213321
D/ValueAnimator( 3305): before animationFrame-----------mStartTime is 4213321
D/ValueAnimator( 3305): after animationFrame-----------mStartTime is 4213321
D/ValueAnimator( 3305): onAnimationStart
D/ValueAnimator( 3305): animationHandler.sendEmptyMessage(ANIMATION_START)
D/ValueAnimator( 3305): handleMessage:ANIMATION_START
D/ValueAnimator( 3305): startAnimation----Called internally to start an animation by adding it to the active animations list. Must be called on the UI thread
D/ValueAnimator( 3305): anim.startAnimation-----------
D/ValueAnimator( 3305): startAnimation----Called internally to start an animation by adding it to the active animations list. Must be called on the UI thread
D/ValueAnimator( 3305): anim.startAnimation-----------
D/ValueAnimator( 3305): handleMessage:ANIMATION_S