Note that there are some explanatory texts on larger screens.

plurals
  1. POUnittesting with glib results in segfault with g_test_fail()
    text
    copied!<p>I have been trying out glib for unittesting and have run into trouble. I am interested for a way to not abort the remaining part of the test if a single part fails. I have been trying to do this using g_test_fail() which works but results in a segfault as the test ends. If I comment out g_test_fail() the test is reported as being a success with a normal program termination.</p> <p>Stepping through the program with gdb I can tell that the test function exits as expected and the fault occurs somewhere in the glib library.</p> <p>Any ideas?</p> <p>My example test file is as follows:</p> <pre><code>// // Unit Test with GLib // // #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;glib.h&gt; typedef struct TestFixture_T { unsigned int uiA; unsigned int uiB; char szString[16]; } TestFixture_T; void TestFixtureContructor(TestFixture_T* pFixture, gconstpointer pg) { pFixture-&gt;uiA = 1u; pFixture-&gt;uiB = 2u; strcpy(pFixture-&gt;szString, "Blank"); } void TestFixtureDestructor(TestFixture_T* pFixture, gconstpointer pg) { pFixture-&gt;uiA = 0u; pFixture-&gt;uiB = 0u; strcpy(pFixture-&gt;szString, ""); } gboolean TestFixtureCompare( TestFixture_T* pFixtureA, TestFixture_T* pFixtureB ) { return pFixtureA-&gt;uiA == pFixtureB-&gt;uiA &amp;&amp; pFixtureA-&gt;uiB == pFixtureB-&gt;uiB &amp;&amp; strcmp(pFixtureA-&gt;szString, pFixtureB-&gt;szString) == 0; } void test_this(TestFixture_T* pFixtureInput, gconstpointer pg) { TestFixture_T LocalFixture; TestFixtureContructor( &amp;LocalFixture, NULL ); if( !TestFixtureCompare( &amp;LocalFixture, pFixtureInput ) ) { g_test_fail(); // &lt;-- This is the trouble spot. Comment this out and there is no segfault. } } int main(int argc, char** argv) { /* Initialize test framework */ g_test_init( &amp;argc, &amp;argv, NULL ); /* Add test */ TestFixture_T Fixture; g_test_add( "/MyFirstTest", TestFixture_T, &amp;Fixture, TestFixtureContructor, test_this, TestFixtureDestructor ); g_test_add( "/MySecondTest", TestFixture_T, &amp;Fixture, NULL, test_this, NULL ); int result = g_test_run(); printf( "...aaaaand scene!\n" ); return result; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload