nullpointer exception

152 views
Skip to first unread message

rsam70

unread,
Jun 24, 2012, 4:27:54 PM6/24/12
to Google C++ Testing Framework
Hi,

i've a basic constructor test where a null pointer is being used. I
want to catch this behavior

TEST( List, CreateException )
{
EXPECT_DEATH( listInit( NULL ), "null pointer");
}

the following flags are used
::testing::FLAGS_gtest_catch_exceptions =true;
::testing::FLAGS_gtest_throw_on_failure=true;

the following output is produced by the exec.:

[ RUN ] List.Create
[ OK ] List.Create (0 ms)
[ RUN ] List.CreateException

D:\\unittests\TestC\Release>TeC.exe
Running all generic component tests
Note: Randomizing tests' orders with a seed of 40757 .
[==========] Running 15 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 6 tests from List
[ RUN ] List.GetHeadOneElement
[ OK ] List.GetHeadOneElement (0 ms)
[ RUN ] List.GetHeadEmptyList
[ OK ] List.GetHeadEmptyList (0 ms)
[ RUN ] List.Create
[ OK ] List.Create (0 ms)
[ RUN ] List.CreateException
Running all generic component tests
../src/listTest.cpp:173: Failure
Death test: listInit( __null )
Result: died but not with expected error.
Expected: null pointer
Actual msg:
[ DEATH ]
terminate called after throwing an instance of
'testing::GoogleTestFailureExcept
ion'
what(): ../src/listTest.cpp:173: Failure
Death test: listInit( __null )
Result: died but not with expected error.
Expected: null pointer
Actual msg:
[ DEATH ]

This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information.

This test fails. How can i make this work.
listInit is c based calling context.

Thx.

Greg Miller

unread,
Jun 25, 2012, 9:42:54 AM6/25/12
to rsam70, Google C++ Testing Framework
Hi.

The statement EXPECT_DEATH( listInit( NULL ), "null pointer"); says that you expect the process to die and print the string "null pointer". My guess is that the process is dying but the string "null pointer" is not printed. Make sure you're checking for the correct string (actually, that argument is a regex).

Greg

Vlad Losev

unread,
Jun 25, 2012, 1:01:15 PM6/25/12
to Google C++ Testing Framework
Do not override gtest_throw_on_failure. Per the documentation, it's for use with other testing frameworks.
Reply all
Reply to author
Forward
0 new messages