Fix csgeneric_unittest

- Wrapped lines in cigeneric_unittest.cpp to 80 columns
- Make use of helper functions for error checks where possible
- Expect rather than assert where possible
- Safety checks to prevent buffer overflows/out of bounds access