Fixed issue #4259. Improved assert messages in all tests. Minor code cleanup (still much to do).
(cherry picked from commit 7b452ff in maintenance 3.x branch)
Merge pull request #4262 from Donnerbart/fixIssue4259PortFromMaintenanceBranch

Cherry pick of fixed issue #4259 (from maintenance 3.x branch)