CPPUNIT_TEST( EncodeDecodePatternB );
CPPUNIT_TEST( EncodeDecodePatternC );
CPPUNIT_TEST( EncodeDecodeRandom );
+ CPPUNIT_TEST( DecodeInvalid );
CPPUNIT_TEST_SUITE_END();
void EncodeDecodeEmpty();
void EncodeDecodePatternB();
void EncodeDecodePatternC();
void EncodeDecodeRandom();
+ void DecodeInvalid();
DECLARE_NO_COPY_CLASS(Base64TestCase)
};
CPPUNIT_ASSERT_EQUAL('\0', shouldBeEmpty[0]);
wxMemoryBuffer bufmt;
- wxString resultmt = wxBase64Encode(bufmt);
- CPPUNIT_ASSERT(resultmt.empty());
+ wxString resultEmpty = wxBase64Encode(bufmt);
+ CPPUNIT_ASSERT(resultEmpty.empty());
- bufmt = wxBase64Decode(resultmt);
- WX_ASSERT_SIZET_EQUAL(0, bufmt.GetDataLen());
+ bufmt = wxBase64Decode(resultEmpty);
+ CPPUNIT_ASSERT_EQUAL(0, bufmt.GetDataLen());
}
void Base64TestCase::EncodeDecodeA()
CPPUNIT_ASSERT_EQUAL(wxString("QQ=="), str);
wxMemoryBuffer buf = wxBase64Decode(str);
- WX_ASSERT_SIZET_EQUAL(1, buf.GetDataLen());
+ CPPUNIT_ASSERT_EQUAL(1, buf.GetDataLen());
CPPUNIT_ASSERT_EQUAL('A', *(char *)buf.GetData());
}
CPPUNIT_ASSERT_EQUAL(wxString("QUI="), str);
wxMemoryBuffer buf = wxBase64Decode(str);
- WX_ASSERT_SIZET_EQUAL(2, buf.GetDataLen());
+ CPPUNIT_ASSERT_EQUAL(2, buf.GetDataLen());
CPPUNIT_ASSERT_EQUAL('A', buf[0]);
CPPUNIT_ASSERT_EQUAL('B', buf[1]);
}
CPPUNIT_ASSERT_EQUAL(wxString("QUJD"), str);
wxMemoryBuffer buf = wxBase64Decode(str);
- WX_ASSERT_SIZET_EQUAL(3, buf.GetDataLen());
+ CPPUNIT_ASSERT_EQUAL(3, buf.GetDataLen());
CPPUNIT_ASSERT_EQUAL('A', buf[0]);
CPPUNIT_ASSERT_EQUAL('B', buf[1]);
CPPUNIT_ASSERT_EQUAL('C', buf[2]);
CPPUNIT_ASSERT_EQUAL(wxString("QUJDRA=="), str);
wxMemoryBuffer buf = wxBase64Decode(str);
- WX_ASSERT_SIZET_EQUAL(4, buf.GetDataLen());
+ CPPUNIT_ASSERT_EQUAL(4, buf.GetDataLen());
CPPUNIT_ASSERT_EQUAL('A', buf[0]);
CPPUNIT_ASSERT_EQUAL('B', buf[1]);
CPPUNIT_ASSERT_EQUAL('C', buf[2]);
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);
+ CPPUNIT_ASSERT_EQUAL( 3, posErr );
+
+ rc = wxBase64Decode(NULL, 0, "one two!", wxNO_LEN,
+ wxBase64DecodeMode_SkipWS, &posErr);
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, rc);
+ CPPUNIT_ASSERT_EQUAL( 7, posErr );
+
+ rc = wxBase64Decode(NULL, 0, "? QQ==", wxNO_LEN,
+ wxBase64DecodeMode_SkipWS, &posErr);
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, rc);
+ CPPUNIT_ASSERT_EQUAL( 0, posErr );
+
+ posErr = (size_t)-1;
+ rc = wxBase64Decode(NULL, 0, " QQ==", wxNO_LEN,
+ wxBase64DecodeMode_SkipWS, &posErr);
+ CPPUNIT_ASSERT_EQUAL( 1, rc );
+ CPPUNIT_ASSERT_EQUAL( -1, posErr );
+
+ rc = wxBase64Decode(NULL, 0, "? QQ==", wxNO_LEN,
+ wxBase64DecodeMode_Relaxed, &posErr);
+ CPPUNIT_ASSERT_EQUAL( 1, rc );
+ CPPUNIT_ASSERT_EQUAL( -1, posErr );
+
+ CPPUNIT_ASSERT( !wxBase64Decode("wxGetApp()").GetDataLen() );
+}
+
#endif // wxUSE_BASE64