FW: BOOST_CHECK vs. BOST_CHECK_EQUAL, checking equality of wchar_ts

According to the document, BOOST_CHECK is the same as BOST_CHECK_EQUAL. However,I found an exception. Which is listed below, where m_mmf.SetLngGetString(1033, 1) returns a const wchar_t* type. Interestingly, the first two tests fail, while the last two pass. BOOST_CHECK(L"A" == m_mmf.SetLngGetString(1033, 1)); BOOST_CHECK(m_mmf.SetLngGetString(1033, 1) == L"A" ); BOOST_CHECK_EQUAL(L"A", m_mmf.SetLngGetString(1033, 1)); BOOST_CHECK_EQUAL(m_mmf.SetLngGetString(1033, 1), L"A"); Can any one please help to explain it? Thanks

"Tan Zhi"
According to the document, BOOST_CHECK is the same as BOST_CHECK_EQUAL. However,I found an exception. Which is listed below, where m_mmf.SetLngGetString(1033, 1) returns a const wchar_t* type.
Interestingly, the first two tests fail, while the last two pass.
BOOST_CHECK(L"A" == m_mmf.SetLngGetString(1033, 1));
BOOST_CHECK(m_mmf.SetLngGetString(1033, 1) == L"A" );
This actually perform pointers comparizons and almost never produce true.
BOOST_CHECK_EQUAL(L"A", m_mmf.SetLngGetString(1033, 1));
BOOST_CHECK_EQUAL(m_mmf.SetLngGetString(1033, 1), L"A");
Boost.Test includes special treatement to C strings comparisons. As a result actual value are compared not the pointers. That's another reason to prefer BOOST_CHECK_EQUAL to BOOST_CHECK. Gennadiy
Can any one please help to explain it? Thanks

On 7/30/06, Gennadiy Rozental
[snipped]
Interestingly, the first two tests fail, while the last two pass.
BOOST_CHECK(L"A" == m_mmf.SetLngGetString(1033, 1));
BOOST_CHECK(m_mmf.SetLngGetString(1033, 1) == L"A" );
This actually perform pointers comparizons and almost never produce true.
I dont think you can actually be sure about this, since we can't know if SetLngGetString doesnt return a std::wstring or some other type that has implicit conversion from wchar_t. I believe more information is needed to know why the difference is occurring. Though it sure seems like a pointer comparision problem. [snipped]
Gennadiy
best regards, -- Felipe Magno de Almeida

"Felipe Magno de Almeida"
On 7/30/06, Gennadiy Rozental
wrote: [snipped]
Interestingly, the first two tests fail, while the last two pass.
BOOST_CHECK(L"A" == m_mmf.SetLngGetString(1033, 1));
BOOST_CHECK(m_mmf.SetLngGetString(1033, 1) == L"A" );
This actually perform pointers comparizons and almost never produce true.
I dont think you can actually be sure about this, since we can't know if SetLngGetString doesnt return a std::wstring or some other type that has implicit conversion from wchar_t.
Wouldn't you remove the rest of the original message, you would see that it does return wchar_t const*.
where m_mmf.SetLngGetString(1033, 1) returns a const wchar_t* type.
Gennaadiy

On 7/30/06, Gennadiy Rozental
[snipped]
Wouldn't you remove the rest of the original message, you would see that it does return wchar_t const*.
Oops! Sorry!
Gennaadiy
-- Felipe Magno de Almeida
participants (3)
-
Felipe Magno de Almeida
-
Gennadiy Rozental
-
Tan Zhi