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: http://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:
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;
//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.