private:
CPPUNIT_TEST_SUITE( wxAnyTestCase );
+ CPPUNIT_TEST( CheckType );
CPPUNIT_TEST( Equality );
CPPUNIT_TEST( As );
CPPUNIT_TEST( GetAs );
CPPUNIT_TEST( CustomTemplateSpecialization );
CPPUNIT_TEST_SUITE_END();
+ void CheckType();
void Equality();
void As();
void GetAs();
// Let's use a number with first digit after decimal dot less than 5,
// so that we don't have to worry about whether conversion from float
// to int truncates or rounds.
-const double TEST_FLOAT_CONST = 123.456;
+const float TEST_FLOAT_CONST = 123.456f;
+const double TEST_DOUBLE_CONST = 123.456;
const double FEQ_DELTA = 0.001;
m_anyCharString1("abc"),
m_anyWcharString1(L"abc"),
m_anyBool1(true),
- m_anyFloatDouble1((float)TEST_FLOAT_CONST),
- m_anyDoubleDouble1((double)TEST_FLOAT_CONST),
+ m_anyFloatDouble1(TEST_FLOAT_CONST),
+ m_anyDoubleDouble1(TEST_DOUBLE_CONST),
m_anyWxObjectPtr1(dummyWxObjectPointer),
m_anyVoidPtr1(dummyVoidPointer),
m_anyDateTime1(wxDateTime::Now())
m_anyCharString2 = "abc";
m_anyWcharString2 = L"abc";
m_anyBool2 = true;
- m_anyFloatDouble2 = (float)TEST_FLOAT_CONST;
- m_anyDoubleDouble2 = (double)TEST_FLOAT_CONST;
+ m_anyFloatDouble2 = TEST_FLOAT_CONST;
+ m_anyDoubleDouble2 = TEST_DOUBLE_CONST;
m_anyDateTime2 = m_testDateTime;
m_anyUniChar1 = wxUniChar('A');
m_anyWxObjectPtr2 = dummyWxObjectPointer;
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()
{
//
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);
+
+ // Make sure the stored float that comes back is -identical-.
+ // So do not use delta comparison here.
float o = wxANY_AS(m_anyFloatDouble1, float);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(o, TEST_FLOAT_CONST, FEQ_DELTA);
+ CPPUNIT_ASSERT_EQUAL(o, TEST_FLOAT_CONST);
+
double p = wxANY_AS(m_anyDoubleDouble1, double);
- CPPUNIT_ASSERT_DOUBLES_EQUAL(p, TEST_FLOAT_CONST, FEQ_DELTA);
+ CPPUNIT_ASSERT_EQUAL(p, TEST_DOUBLE_CONST);
+
wxUniChar chr = wxANY_AS(m_anyUniChar1, wxUniChar);
CPPUNIT_ASSERT(chr == 'A');
wxDateTime q = wxANY_AS(m_anyDateTime1, wxDateTime);
CPPUNIT_ASSERT(variant.GetType() == "ulonglong");
CPPUNIT_ASSERT(variant.GetLong() == 1000);
- // FIXME-VC6: for VC6, any = variant needs to be any = wxAny(variant).
- // Note that 'wxAny any = variant' does work, probably because
- // ctor is used in that case instead of assignment operator.
- any = wxAny(vString);
+ any = vString;
CPPUNIT_ASSERT(any == "ABC");
res = any.GetAs(&variant);
CPPUNIT_ASSERT(res);
CPPUNIT_ASSERT(variant.GetString() == "ABC");
- any = wxAny(vDouble);
+ // 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);
res = any.GetAs(&variant);
TEST_FLOAT_CONST,
FEQ_DELTA);
- any = wxAny(vBool);
+ any = vBool;
CPPUNIT_ASSERT(wxANY_AS(any, bool) == true);
res = any.GetAs(&variant);
CPPUNIT_ASSERT(res);