]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/crt.cpp
Don't call base class SetLabel() from GTKSetLabelForLabel().
[wxWidgets.git] / tests / strings / crt.cpp
index 70ad0d9fed68de66f7a4affba73d93103d3320c7..6010ef85cd1f0002ae71d96241955a3c1f884603 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Vaclav Slavik
 // Created:     2004-06-03
 // RCS-ID:      $Id$
-// Copyright:   (c) 2004 Vaclav Slavik 
+// Copyright:   (c) 2004 Vaclav Slavik
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -44,17 +44,25 @@ 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 );
         CPPUNIT_TEST( Strpbrk );
+        CPPUNIT_TEST( Strnlen );
     CPPUNIT_TEST_SUITE_END();
 
     void SetGetEnv();
+#if wxUSE_UNICODE
+    void Strchr();
+#endif // wxUSE_UNICODE
     void Strcmp();
     void Strspn();
     void Strcspn();
     void Strpbrk();
+    void Strnlen();
 
     DECLARE_NO_COPY_CLASS(CrtTestCase)
 };
@@ -67,16 +75,40 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CrtTestCase, "CrtTestCase" );
 
 void CrtTestCase::SetGetEnv()
 {
+#define TESTVAR_NAME wxT("WXTESTVAR")
+
     wxString val;
-    wxSetEnv(_T("TESTVAR"), _T("value"));
-    CPPUNIT_ASSERT( wxGetEnv(_T("TESTVAR"), &val) == true );
-    CPPUNIT_ASSERT( val == _T("value") );
-    wxSetEnv(_T("TESTVAR"), _T("something else"));
-    CPPUNIT_ASSERT( wxGetEnv(_T("TESTVAR"), &val) );
-    CPPUNIT_ASSERT( val == _T("something else") );
-    CPPUNIT_ASSERT( wxUnsetEnv(_T("TESTVAR")) );
-    CPPUNIT_ASSERT( wxGetEnv(_T("TESTVAR"), NULL) == false );
+    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, wxT("something else"));
+    CPPUNIT_ASSERT( wxGetEnv(TESTVAR_NAME, &val) );
+    CPPUNIT_ASSERT_EQUAL( "something else", val );
+    CPPUNIT_ASSERT_EQUAL( "something else", wxString(wxGetenv(TESTVAR_NAME)) );
+
+    CPPUNIT_ASSERT( wxUnsetEnv(TESTVAR_NAME) );
+    CPPUNIT_ASSERT( !wxGetEnv(TESTVAR_NAME, NULL) );
+    CPPUNIT_ASSERT( !wxGetenv(TESTVAR_NAME) );
+
+#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()
 {
@@ -205,7 +237,40 @@ void CrtTestCase::Strpbrk()
     CPPUNIT_ASSERT_EQUAL(  ',', *wxStrpbrk(strWX.c_str(), s.mb_str()) );
     CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWX.c_str(), s.wc_str()) );
 
-    CPPUNIT_ASSERT_EQUAL( (const char *)NULL, wxStrpbrk(strWX, "xyz") );
-    CPPUNIT_ASSERT_EQUAL( (const wchar_t *)NULL, wxStrpbrk(strWX.c_str(), L"xyz") );
+    CPPUNIT_ASSERT( !wxStrpbrk(strWX, "xyz") );
+    CPPUNIT_ASSERT( !wxStrpbrk(strWX.c_str(), L"xyz") );
 }
 
+void CrtTestCase::Strnlen()
+{
+    // other misc tests for wxStrnlen(const char*, size_t)
+
+    CPPUNIT_ASSERT_EQUAL(  (size_t)0, wxStrnlen("", 0) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)0, wxStrnlen("", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)0, wxStrnlen("1234", 0) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)2, wxStrnlen("1234", 2) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)4, wxStrnlen("1234", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)7, wxStrnlen("1234567", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)8, wxStrnlen("12345678", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)8, wxStrnlen("123456789", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)9, wxStrnlen("123456789", 12) );
+
+    // other misc tests for wxStrnlen(const wchar_t*, size_t)
+
+    CPPUNIT_ASSERT_EQUAL(  (size_t)0, wxStrnlen(L"", 0) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)0, wxStrnlen(L"", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)0, wxStrnlen(L"1234", 0) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)2, wxStrnlen(L"1234", 2) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)4, wxStrnlen(L"1234", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)7, wxStrnlen(L"1234567", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)8, wxStrnlen(L"12345678", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)8, wxStrnlen(L"123456789", 8) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)9, wxStrnlen(L"123456789", 12) );
+
+    // wxStrlen() is only for NULL-terminated strings:
+    CPPUNIT_ASSERT_EQUAL(  (size_t)4, wxStrnlen("1234" "\0" "78", 12) );
+    CPPUNIT_ASSERT_EQUAL(  (size_t)4, wxStrnlen(L"1234" L"\0" L"5678", 12) );
+}
+
+
+