Android.animation cts fail(1)

        这两天查cts 的fail, android.animation中有3个fail。

分别为testCurrentPlayTimetestCancel,testSetCurrentPlayTime,在此对着三个fail我的跟踪解析情况做一说明

1.      testCancel:如前一封mail说的,是testCode本身有点问题,后来我改了testcode验证:按照4.1的写法,我写了脚本跑整个包10遍,测了两遍脚本,相当于20遍,未重现。注:按ICStestcode,跑完10遍这个会fail23遍的。

2.      testCurrentPlayTime其测试用例如下:  

public void testCurrentPlayTime()throws Throwable {

       startAnimation(mValueAnimator);

       Thread.sleep(200); 这里的值原来是100,我改成了200进行测试,也是用刚才的脚本共跑了20遍未出错。

       long currentPlayTime = mValueAnimator.getCurrentPlayTime();

       assertTrue(currentPlayTime  >  0);

    }

 

   我简单说明为什么我把上面的100改成了200ok了。因为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(getCurrentPlayTimehandleMessage之前)

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(getCurrentPlayTimehandleMessage之后)

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_START
D/ValueAnimator( 3305): getCurrentPlayTime,currentTime is 4213429

所以100ms的时间并不能保证animation每次可以真正可以跑起来,导致出错。

1.       testSetCurrentPlayTime

这个fail还没有报,但是其实重现率还是蛮高的,所以我也一起说明了。其测试用例如下:

    public voidtestSetCurrentPlayTime() throws Throwable {

        Objectobject = mActivity.view.newBall;

        StringpropertyName = "backgroundColor";

        intstartColor = mActivity.view.RED;

        intendColor = mActivity.view.BLUE;

        longplayTime = 10000l;

        Object[]values = {new Integer(startColor), new Integer(endColor)};

       ArgbEvaluator evaluator = new ArgbEvaluator();

       ObjectAnimator colorAnimator = ObjectAnimator.ofObject(object,propertyName,

               evaluator, values);

       colorAnimator.setCurrentPlayTime(playTime);

        longactualPlayTime = colorAnimator.getCurrentPlayTime();

        assertEquals(playTime, actualPlayTime);

    }

首先调用setCurrentPlayTime,然后调用getCurrentPlayTime,然后让set下去的时间和get出来的时间相等。从意思上说,本来写这个测试用例也是合理的。但是

跟到setCurrentPlayTimegetCurrentPlayTime这两个函数的实现中去,就会发现是有问题的。

Set函数如下:

    public voidsetCurrentPlayTime(long playTime) {

       initAnimation();

        longcurrentTime = AnimationUtils.currentAnimationTimeMillis();

                        Log.d(TAG,"setCurrentPlayTime!!!currentTime is "+ currentTime);

        if(mPlayingState != RUNNING) {

           mSeekTime = playTime;

           mPlayingState = SEEKED;

        }

        mStartTime= currentTime - playTime;

                        Log.d(TAG,"before animationFrame-----------mStartTime is "+ mStartTime);

        animationFrame(currentTime);

                        Log.d(TAG,"after animationFrame-----------mStartTime is "+ mStartTime);

    }

      Get函数如下:

    /**

     * Gets thecurrent position of the animation in time, which is equal to the current

     * time minusthe time that the animation started. An animation that is not yet started will

     * return avalue of zero.

     *

     * @return Thecurrent position in time of the animation.

     */

    public longgetCurrentPlayTime() {

       if(!mInitialized) Log.d(TAG, "mInitialized is false!!!");

                        if(mPlayingState== STOPPED) Log.d(TAG, "mPlayingState == STOPPED!!!");

        if(!mInitialized || mPlayingState == STOPPED) {

                                    Log.d(TAG,"getCurrentPlayTime");

            return0;

        }

                        longcurrentTime=AnimationUtils.currentAnimationTimeMillis();

                        Log.d(TAG,"getCurrentPlayTime,currentTime is "+currentTime);

        returncurrentTime - mStartTime;

    }

 

其中的mStateTime是全局共用的,所以在set中赋值,在get中用到。

currentTime(get)表示getCurrentPlayTime中用到的当前时间

currentTime(set)表示setCurrentPlayTime中用到的当前时间

所以如果按照这个测试用例的话,currentTime(get)-mStartTime=currentTime(get)-currentTime(set)+playTime=playtime

其成立的前提是currentTime(get)-currentTime(set)非常接近,可以看作相等,否则超过了毫秒的数量级,两者不相等,就会fail了。

如下面的 log D/ValueAnimator( 2352): setCurrentPlayTime!!!currentTime is 311653
D/ValueAnimator( 2352): before animationFrame-----------mStartTime is 301653
D/ValueAnimator( 2352): after animationFrame-----------mStartTime is 301653
D/ValueAnimator( 2352): getCurrentPlayTime,currentTime is 311654

currentTime(get)=3011654currentTime(set)=3011653,两者相差了1毫秒,所以出错了。

JB中去掉了这个testCase,不知道是不是后来考虑到了这个原因。

 

关于Android.Animation包中的3fail,我做了上面的说明,如有不对之处,请指教。我认为是testCase本身有问题的也已经改动并验证过。

但是,要想改掉这几个fail(不改cts testCode),我不知道该怎么改,请各位路过的大神留下宝贵意见,谢谢!!或者有google官方的对这方面的说明也欢迎提供~~~




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值