]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/base64/base64.cpp
converting temporary wxString to const wxChar* and storing that doesn't work (and...
[wxWidgets.git] / tests / base64 / base64.cpp
index 7b492d7e69477bcd15c695434d086fd8d5e54578..a63512aca2cdaa73f6a19c122ab3a84cefd7e596 100644 (file)
@@ -90,6 +90,7 @@ private:
         CPPUNIT_TEST( EncodeDecodePatternB );
         CPPUNIT_TEST( EncodeDecodePatternC );
         CPPUNIT_TEST( EncodeDecodeRandom );
+        CPPUNIT_TEST( DecodeInvalid );
     CPPUNIT_TEST_SUITE_END();
 
     void EncodeDecodeEmpty();
@@ -102,6 +103,7 @@ private:
     void EncodeDecodePatternB();
     void EncodeDecodePatternC();
     void EncodeDecodeRandom();
+    void DecodeInvalid();
 
     DECLARE_NO_COPY_CLASS(Base64TestCase)
 };
@@ -233,4 +235,36 @@ void Base64TestCase::EncodeDecodeRandom()
     CPPUNIT_ASSERT(wxBase64Encode(buff2, size, buff2, realsize));
 }
 
+void Base64TestCase::DecodeInvalid()
+{
+    size_t rc, posErr;
+    rc = wxBase64Decode(NULL, 0, "one two!", wxNO_LEN,
+                        wxBase64DecodeMode_Strict, &posErr);
+    CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, rc);
+    WX_ASSERT_SIZET_EQUAL( 3, posErr );
+
+    rc = wxBase64Decode(NULL, 0, "one two!", wxNO_LEN,
+                        wxBase64DecodeMode_SkipWS, &posErr);
+    CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, rc);
+    WX_ASSERT_SIZET_EQUAL( 7, posErr );
+
+    rc = wxBase64Decode(NULL, 0, "? QQ==", wxNO_LEN,
+                        wxBase64DecodeMode_SkipWS, &posErr);
+    CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, rc);
+    WX_ASSERT_SIZET_EQUAL( 0, posErr );
+
+    posErr = (size_t)-1;
+    rc = wxBase64Decode(NULL, 0, " QQ==", wxNO_LEN,
+                        wxBase64DecodeMode_SkipWS, &posErr);
+    WX_ASSERT_SIZET_EQUAL( 1, rc );
+    WX_ASSERT_SIZET_EQUAL( -1, posErr );
+
+    rc = wxBase64Decode(NULL, 0, "? QQ==", wxNO_LEN,
+                        wxBase64DecodeMode_Relaxed, &posErr);
+    WX_ASSERT_SIZET_EQUAL( 1, rc );
+    WX_ASSERT_SIZET_EQUAL( -1, posErr );
+
+    CPPUNIT_ASSERT( !wxBase64Decode("wxGetApp()").GetDataLen() );
+}
+
 #endif // wxUSE_BASE64