Factor out common code in API test.

Change-Id: I596bd943000b41fdd46cbbf33a91a66b57dc3513
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Add missing include statement to header file.

Change-Id: Id4a1f3747eeb92f9d844d9dcaad23b8a977fda2f
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>