Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Runtime exception in the test case generated!

LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in C/C++test
Exceptions in QString in the test cases generated...
Consider the following code Snippet!! - Its a Qt based application... In one of the generated test case, we have:

CODE

...
....
const ::QChar * _arg1_0 = 0 ;
/* Initializing constructor argument 2 (unknown) */
int _arg2_0 = cpptestLimitsGetMaxInt();
::QString _text (_arg1_0, _arg2_0); // QString ( const QChar * unicode, int size )
......
......


As per the details of the constructor, which reads this -> "Constructs a string initialized with the first size characters of the QChar array unicode. "

Since we are passing 'cpptestLimitsGetMaxInt()' to the size argument, the constructor, throws an assertion, which is thrown back to the test case -> which I think is the bug!!
So, the test cases generated in this case (in my case - most % of assertions are of this kind !! ) are faulty... Is there any workarounds for this problem?

Any help would be of great use to me..

Thanks
Muthu

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    edited September 2007
    Hi Muthu,

    This isn't a bug at all. It's simply what happens when QString constructor is called with incorrect arguments. C++Test created this test-case because it has *no* way of knowing that the QString constructor doesn't "like" these arguments. Simply verify this test-case, which tells C++Test that this is normal, expected behavior.

    C++Test deliberately tries to find "corner cases" which cause functions to fail in odd ways. In this case it's simulating a condition which may happen with an un- or improperly initialized argument.

    Alternatively, change the test-case, (it's just source code), to use arguments which you know to be correct, which allows C++Test to verify correct, as well as incorrect behavior.

    --Rich
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    I may not be right on this, but I thought if a test case was throwing an exception, you needed to modify the way C++Test calls the test case to let C++Test know that expect this function to throw an exception.

    CPPTEST_TEST_EXCEPTION(testcase­name,ExcType)

    To verify test cases, use the following assertions in the generated test class file:
    // Asserts that given expression throws an exception of specified type
    CPPTEST_ASSERT_THROW(expression, ExceptionType)
    // Asserts that given expression throws an exception of specified type
    CPPTEST_ASSERT_THROW_MESSAGE(message, expression, ExceptionType)
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭

    I may not be right on this, but I thought if a test case was throwing an exception, you needed to modify the way C++Test calls the test case to let C++Test know that expect this function to throw an exception.

    Yes, that's one way of dealing with this -- you can select this test result in the C++Test view, right click and select "Verify" to accomplish the same thing automatically, by the way.

    Basically there's two ways of dealing with this:

    1/ Validate/verify the test result -- IOW: Tell C++Test that this is exactly what you are expecting; or
    2/ Change the test such that it doesn't fail -- basically making C++Test "more intelligent".

    --Rich