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[] = { '\xc2', '\xbf', '\xc3', '\xa5', '\xc3', '\xb1', 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---------------------------------------------------------------------------
     samples/utf8_code.cpp:33
     ¿åñ
     ===============================================================================
     1 test cases selected
     
                    Sum   Critical   Non-critical
     PASSED   :       1          1              0

      

While the test program

     
     #include <crpcut.hpp>
     
     TEST(output_string)
     {
       static const char str[] = { '\xc2', '\xbf', '\xc3', '\xa5', '\xc3', '\xb1', 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---------------------------------------------------------------------------
     samples/iso8859_1_code.cpp:33
     ¿åñ
     ===============================================================================
     1 test cases selected
     
                    Sum   Critical   Non-critical
     PASSED   :       1          1              0

      

which gives the character sequence a different appearance.