Update CGenerator

This pull request adds test tool for CGenerator and some bug fixes.