Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I embed unicode string constants in a source file?
    text
    copied!<p>I'm writing some unit tests which are going to verify our handling of various resources that use other character sets apart from the normal latin alphabet: Cyrilic, Hebrew etc.</p> <p>The problem I have is that I cannot find a way to embed the expectations in the test source file: here's an example of what I'm trying to do...</p> <pre><code>/// /// Protected: TestGetHebrewConfigString /// void CPrIniFileReaderTest::TestGetHebrewConfigString() { prwstring strHebrewTestFilePath = GetTestFilePath( strHebrewTestFileName ); CPrIniFileReader prIniListReader( strHebrewTestFilePath.c_str() ); prIniListReader.SetCurrentSection( strHebrewSubSection ); CPPUNIT_ASSERT( prIniListReader.GetConfigString( L"דונדארןמע" ) == L"דונהשךוק") ); } </code></pre> <p>This quite simply doesnt work. Previously I worked around this using a macro which calls a routine to transform a narrow string to a wide string (we use towstring all over the place in our applications so it's existing code)</p> <pre><code>#define UNICODE_CONSTANT( CONSTANT ) towstring( CONSTANT ) wstring towstring( LPCSTR lpszValue ) { wostringstream os; os &lt;&lt; lpszValue; return os.str(); } </code></pre> <p>The assertion in the test above then became:</p> <pre><code>CPPUNIT_ASSERT( prIniListReader.GetConfigString( UNICODE_CONSTANT( "דונדארןמע" ) ) == UNICODE_CONSTANT( "דונהשךוק" ) ); </code></pre> <p>This worked OK on OS X but now I'm porting to linux and I'm finding that the tests are all failing: it all feels rather hackish as well. Can anyone tell me if they have a nicer solution to this problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload