Project

General

Profile

Regarding the WTestEnvironment documentation

Added by Aleksander Fular over 10 years ago

Hello,

I have question regarding this documentation:

http://webtoolkit.eu/wt/doc/reference/html/classWt_1_1Test_1_1WTestEnvironment.html#details

Code snippet clearly states that the MyApplication instance should be created as a scoped variable so it would be deleted at the end of the testX function.

However when I do it this way i just get crashes due to probably double delete.

Doesnt WTestEnvironment deletes all registered sessions?

Regards,


Replies (2)

RE: Regarding the WTestEnvironment documentation - Added by Koen Deforche over 10 years ago

That should work indeed. That's also how all our test cases are typically written (including those in test/ of Wt).

There must be something else that is wrong?

RE: Regarding the WTestEnvironment documentation - Added by Aleksander Fular over 10 years ago

Yep, You are correct - it seems that WApplication deregisters itself from its owner upon destruction as expected.

It was standard case of misuse smart pointer i had:

boost::scoped_ptr<Home> home;
boost::scoped_ptr<Wt::Test::WTestEnvironment> testEnvironment;
<pre>
instead of:
<pre>
boost::scoped_ptr<Home> home;
boost::scoped_ptr<Wt::Test::WTestEnvironment> testEnvironment;

Since I already made this post a bit about testing I will add one more thing the test code represent another small issue:

TEST_F(WtTest, whenNoApplicationAvailable_CreationWtTextWithoutTextWillSuccess) {
    Wt::WText();
}

void createWtTextWithText() {
    Wt::WText("some text");
}
bool didCreateWtTextThrowSehException() {
    __try {
        createWtTextWithText();
        return false;
    }
    __except(filterException(GetExceptionCode(), GetExceptionInformation ())) {
    }
    return true;
}

TEST_F(WtTest, whenNoApplicationAvailable_CreationWtTextWithTextWillFail) {
    if (didCreateWtTextThrowSehException() == false)
        FAIL() << "Expected throw in this case.";
    }

TEST_F(WtTest, whenApplicationAvailable_CreationWtTextWithTextWillNotFail) {
    Wt::Test::WTestEnvironment environment;
    Wt::WApplication app(environment);
    Wt::WText("some text");
}

It seems that when widgets do have something to render (in this case - text) they require at least one instance of WApplication to be available in the system.

If there is none.. well the app will crash with access violation - I guess I will have to make one base TestFixture for all tests that create some kind of Widget Objects.

    (1-2/2)