Allow wxAny to contain 'const char*' or 'const wchar_t*'. This was previously not possible since these pointers were converted to wxString, as convenient means to work with string literals. Now pointers (to string literals) are stored instead, and As<wxString>(), comparison operators do the type conversion.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64106 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2010-04-22 13:51:38 +00:00
parent a96160b58f
commit 153107b402
6 changed files with 173 additions and 67 deletions

View File

@@ -32,6 +32,7 @@ public:
private:
CPPUNIT_TEST_SUITE( wxAnyTestCase );
CPPUNIT_TEST( CheckType );
CPPUNIT_TEST( Equality );
CPPUNIT_TEST( As );
CPPUNIT_TEST( GetAs );
@@ -40,6 +41,7 @@ private:
CPPUNIT_TEST( CustomTemplateSpecialization );
CPPUNIT_TEST_SUITE_END();
void CheckType();
void Equality();
void As();
void GetAs();
@@ -164,6 +166,19 @@ wxAnyTestCase::wxAnyTestCase()
m_anyVoidPtr2 = dummyVoidPointer;
}
void wxAnyTestCase::CheckType()
{
wxAny nullAny;
CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(nullAny, wxString));
CPPUNIT_ASSERT(wxANY_CHECK_TYPE(m_anyCharString2, const char*));
CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(m_anyCharString2, wxString));
CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(m_anyCharString2, const wchar_t*));
CPPUNIT_ASSERT(wxANY_CHECK_TYPE(m_anyWcharString2, const wchar_t*));
CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(m_anyWcharString2, wxString));
CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(m_anyWcharString2, const char*));
}
void wxAnyTestCase::Equality()
{
//
@@ -243,8 +258,12 @@ void wxAnyTestCase::As()
wxString k = wxANY_AS(m_anyStringString1, wxString);
CPPUNIT_ASSERT(k == "abc");
wxString l = wxANY_AS(m_anyCharString1, wxString);
const char* cptr = wxANY_AS(m_anyCharString1, const char*);
CPPUNIT_ASSERT(l == "abc");
CPPUNIT_ASSERT(cptr);
wxString m = wxANY_AS(m_anyWcharString1, wxString);
const wchar_t* wcptr = wxANY_AS(m_anyWcharString1, const wchar_t*);
CPPUNIT_ASSERT(wcptr);
CPPUNIT_ASSERT(m == "abc");
bool n = wxANY_AS(m_anyBool1, bool);
CPPUNIT_ASSERT(n);
@@ -488,6 +507,19 @@ void wxAnyTestCase::wxVariantConversions()
CPPUNIT_ASSERT(res);
CPPUNIT_ASSERT(variant.GetString() == "ABC");
// Must be able to build string wxVariant from wxAny built from
// string literal
any = "ABC";
res = any.GetAs(&variant);
CPPUNIT_ASSERT(res);
CPPUNIT_ASSERT(variant.GetType() == "string");
CPPUNIT_ASSERT(variant.GetString() == "ABC");
any = L"ABC";
res = any.GetAs(&variant);
CPPUNIT_ASSERT(res);
CPPUNIT_ASSERT(variant.GetType() == "string");
CPPUNIT_ASSERT(variant.GetString() == L"ABC");
any = vDouble;
double d = wxANY_AS(any, double);
CPPUNIT_ASSERT_DOUBLES_EQUAL(d, TEST_FLOAT_CONST, FEQ_DELTA);