]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/crt.cpp
applying editor part of patch, see #15003
[wxWidgets.git] / tests / strings / crt.cpp
index e4e69caa1697fe2bd8a03d09afc8971be367704d..068a59748ce25abd4bd2006745dabc66fb8d625e 100644 (file)
@@ -44,6 +44,9 @@ public:
 private:
     CPPUNIT_TEST_SUITE( CrtTestCase );
         CPPUNIT_TEST( SetGetEnv );
+#if wxUSE_UNICODE
+        CPPUNIT_TEST( Strchr );
+#endif // wxUSE_UNICODE
         CPPUNIT_TEST( Strcmp );
         CPPUNIT_TEST( Strspn );
         CPPUNIT_TEST( Strcspn );
@@ -52,6 +55,9 @@ private:
     CPPUNIT_TEST_SUITE_END();
 
     void SetGetEnv();
+#if wxUSE_UNICODE
+    void Strchr();
+#endif // wxUSE_UNICODE
     void Strcmp();
     void Strspn();
     void Strcspn();
@@ -64,20 +70,20 @@ private:
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( CrtTestCase );
 
-// also include in it's own registry so that these tests can be run alone
+// also include in its own registry so that these tests can be run alone
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CrtTestCase, "CrtTestCase" );
 
 void CrtTestCase::SetGetEnv()
 {
-#define TESTVAR_NAME _T("WXTESTVAR")
+#define TESTVAR_NAME wxT("WXTESTVAR")
 
     wxString val;
-    wxSetEnv(TESTVAR_NAME, _T("value"));
+    wxSetEnv(TESTVAR_NAME, wxT("value"));
     CPPUNIT_ASSERT( wxGetEnv(TESTVAR_NAME, &val) );
     CPPUNIT_ASSERT_EQUAL( "value", val );
     CPPUNIT_ASSERT_EQUAL( "value", wxString(wxGetenv(TESTVAR_NAME)) );
 
-    wxSetEnv(TESTVAR_NAME, _T("something else"));
+    wxSetEnv(TESTVAR_NAME, wxT("something else"));
     CPPUNIT_ASSERT( wxGetEnv(TESTVAR_NAME, &val) );
     CPPUNIT_ASSERT_EQUAL( "something else", val );
     CPPUNIT_ASSERT_EQUAL( "something else", wxString(wxGetenv(TESTVAR_NAME)) );
@@ -89,6 +95,21 @@ void CrtTestCase::SetGetEnv()
 #undef TESTVAR_NAME
 }
 
+#if wxUSE_UNICODE
+void CrtTestCase::Strchr()
+{
+    // test that searching for a wide character in a narrow string simply
+    // doesn't find it but doesn't fail with an assert (#11487)
+    const wxUniChar smiley = *wxString::FromUTF8("\xe2\x98\xba").begin();
+
+    CPPUNIT_ASSERT( !wxStrchr("hello", smiley) );
+
+    // but searching for an explicitly wide character does find it
+    CPPUNIT_ASSERT( wxStrchr(wxString::FromUTF8(":-) == \xe2\x98\xba"),
+                    static_cast<wchar_t>(smiley)) );
+}
+#endif // wxUSE_UNICODE
+
 void CrtTestCase::Strcmp()
 {
     // this code tests if all possible ways of calling wxStrcmp() compile: