+// helper class holding the matching MB and WC strings
+//
+// either str or wcs (but not both) may be NULL, this means that the conversion
+// to it should fail
+struct StringConversionData
+{
+ const char *str;
+ const wchar_t *wcs;
+
+ enum
+ {
+ TEST_BOTH = 0, // test both str -> wcs and wcs -> str
+ ONLY_MB2WC = 1 // only test str -> wcs conversion
+ };
+
+ int flags;
+
+ // test that the conversion between str and wcs (subject to flags) succeeds
+ //
+ // the first argument is the index in the test array and is used solely for
+ // diagnostics
+ void Test(size_t n, wxMBConv& conv) const
+ {
+ if ( str )
+ {
+ wxWCharBuffer wbuf = conv.cMB2WC(str);
+
+ if ( wcs )
+ {
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ Message(n, "MB2WC failed"),
+ wbuf.data()
+ );
+
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ Message(n, "MB2WC", wbuf, wcs),
+ wxStrcmp(wbuf, wcs) == 0
+ );
+ }
+ else // conversion is supposed to fail
+ {
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ Message(n, "MB2WC succeeded"),
+ !wbuf.data()
+ );
+ }
+ }
+
+ if ( wcs && !(flags & ONLY_MB2WC) )
+ {
+ wxCharBuffer buf = conv.cWC2MB(wcs);
+
+ if ( str )
+ {
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ Message(n, "WC2MB failed"),
+ buf.data()
+ );
+
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ Message(n, "WC2MB", buf, str),
+ strcmp(buf, str) == 0
+ );
+ }
+ else
+ {
+ CPPUNIT_ASSERT_MESSAGE
+ (
+ Message(n, "WC2MB succeeded"),
+ !buf.data()
+ );
+ }
+ }
+ }
+
+private:
+ static std::string
+ Message(size_t n, const wxString& msg)
+ {
+ return std::string(wxString::Format("#%lu: %s", (unsigned long)n, msg));
+ }
+
+ template <typename T>
+ static std::string
+ Message(size_t n,
+ const char *func,
+ const wxCharTypeBuffer<T>& actual,
+ const T *expected)
+ {
+ return Message(n,
+ wxString::Format("%s returned \"%s\", expected \"%s\"",
+ func, actual.data(), expected));
+ }
+};
+