samedi 27 février 2016

How to compare char* with string in boost unit test?

I have got code like below:

BOOST_FIXTURE_TEST_CASE(test, TestSuite1)
{
    unsigned int length = 5;
    char* content1=new char[length];
    content1="abcde";
    string content2("abcde");

    BOOST_REQUIRE( length == content2.length() );

    for(unsigned int i=0;i<5;++i)
    {
        BOOST_CHECK( content1[i] == content2[i] );
    }

    if(content1 != nullptr)
    {
        delete[] content1;
        content1 = nullptr;
    }
}

The question is how to compare char* with string in boost unit test? I have used loop, but I don't know if it is a good way. Is there any better solution? Thank you very much.

Aucun commentaire:

Enregistrer un commentaire