ctest: Consolidate test timeout selection logic
Test timeout selection was previously spread out over several locations. Consolidate it in a single place to make it easier to follow.
Also consolidate test cases, and fix a corner case with TIMEOUT=0 and --timeout.
Edited by Brad King