Improving the Cat Parade (Part 3)

I was recently running hopper on a device that supported screen rotation and I realized that my test coverage was completely missing the rotation scenario.  The device would switch between portrait and landscape mode if the user took a specific action, but Hopper is automated and limited to standard key presses, so it would never take this action.

Once again, I extended FocusApp a little to improve my test coverage.  When FocusApp starts, I have it create a thread that calls ChangeDisplaySettingsEx() at random intervals to flip the orientation between different angles. 

The original sources for FocusApp are here: https://blogs.msdn.com/hopperx/archive/2005/11/30/the-cat-parade.aspx

To give you an idea of how I implemented the rotation, here's a bit of sample of the code:

...
    DEVMODE devMode;
...
Inside a while loop:
...
        //Wait for a random number of minutes before rotating the screen.

        //Reinitialize the structure.
        memset(&devMode, 0x00, sizeof(devMode));
        devMode.dmSize = sizeof(devMode);
        devMode.dmFields = DM_DISPLAYORIENTATION;

        //Figure out which orientation should be used this time.
        if (DMDO_0 == devMode.dmDisplayOrientation)
        {
            //Currently at 0 degrees, so flip to 90 degress.
            devMode.dmDisplayOrientation = DMDO_90;
        }

        else
        {
            //Currently at 90 degrees, so flip back to 0 degrees.
            devMode.dmDisplayOrientation = DMDO_0;
        }

        //Now apply the new orientation to the screen.
        ChangeDisplaySettingsEx(NULL, &devMode, NULL, CDS_RESET, NULL);
...

Not all devices use the orientations DMDO_0 or DMDO_90 and some device support more than two orientations, so, modify the code to alternate between all of the orientations your test devices supports.  Also, the interval between rotations is pretty much arbitrary, but it's important to make the interval random and variable to get good coverage.  In my testing, the rotation is done on a separate thread that randomly sleeps for 1 to 30 minutes each time through the loop.

Comments

  • Anonymous
    November 30, 2007
    We found another approach to get hopper to test our application for orientation changes. We dropped a copy of a simple test tool, for which the free exe and source can be found at: http://www.mobidogs.com/dPage25.aspx into the start directory of the emulator image that we are using to test our application. We also cleaned out most of the other links from the Start Menu folder as suggested to increase the exposure of the app through our standard version focusapp.exe. Now, hopper randomly does the work for us to fire up the orientation test app and randomly change the orientation. Just another alternative for those of you looking for a quick way to test your apps with hopper and including orientation changes into the mix. One thing to note... this test tool is written with CF 2 so it runs fine on WM 6.0 devices and emulators without modification, however if you are targeting earlier devices you will need to either load CF 2 onto that device/emulator or you will need to rewrite your own version of the utility in either CF1 (with pinvokes) or native code. However, I don't believe that there any Smartphone devices pre WM 6.0 that do dynamic orientation changes, so this would probably only apply to PPC apps or other special scenarios.

  • Anonymous
    December 05, 2007
    That's a cool alternative to writing code.  Thanks for sharing!