the Compartmented Robust Posix C++ Unit Test system

crpcut::set_charset()

Define the character set for strings produced from test cases.

Used in: Before calling crpcut::run(). Typically in main().

The prototype is:

void crpcut::set_charset(const char*charset)

The parameter charset must be a character set name recognised by the iconv_open() function. All output from the test program will be converted from this character set to the defined output character set. See also -C name / --output-charset=name.

Example: the test program

     
     #include <crpcut.hpp>
     
     TEST(output_string)
     {
       static const char str[] = { 0xc2, 0xbf, 0xc3, 0xa5, 0xc3, 0xb1, 0 };
       INFO << str;
     }
     
     int main(int argc, char *argv[])
     {
       return crpcut::run(argc, argv);
     }

      

uses the default UTF-8 encoding for its strings:


     PASSED: output_string
     info---------------------------------------------------------------------------
     ¿åñ
     ===============================================================================
     Total 1 test cases selected
     UNTESTED : 0
     PASSED   : 1
     FAILED   : 0

      

While the test program

     
     #include <crpcut.hpp>
     
     TEST(output_string)
     {
       static const char str[] = { 0xc2, 0xbf, 0xc3, 0xa5, 0xc3, 0xb1, 0 };
       INFO << str;
     }
     
     int main(int argc, char *argv[])
     {
       crpcut::set_charset("ISO8859-1");
       return crpcut::run(argc, argv);
     }

      

defines the character set to ISO8859-1 when outputting the exact same character sequence:


     PASSED: output_string
     info---------------------------------------------------------------------------
     ¿åñ
     ===============================================================================
     Total 1 test cases selected
     UNTESTED : 0
     PASSED   : 1
     FAILED   : 0

      

which gives the character sequence a different appearence.