menumodel test: don't get stuck in a loop
authorRyan Lortie <desrt@desrt.ca>
Fri, 2 Dec 2011 22:47:34 +0000 (17:47 -0500)
committerRyan Lortie <desrt@desrt.ca>
Thu, 8 Dec 2011 23:05:14 +0000 (18:05 -0500)
Sometimes randa and randb end up having the same state, causing them to
return the same stream of 'random numbers'.  This is a problem for the
testcase that is looping to find unequal menus.

If we find ourselves in this state, throw one of the random generators
away and recreate it so we have a better chance of getting some unequal
menus.

gio/tests/gmenumodel.c

index 59ffaac..aa42943 100644 (file)
@@ -506,6 +506,13 @@ test_equality (void)
           g_assert_cmpstr (as->str, ==, bs->str);
           g_string_free (bs, TRUE);
           g_string_free (as, TRUE);
+
+          /* we're here because randa and randb just generated equal
+           * menus.  they may do it again, so throw away randb and make
+           * a fresh one.
+           */
+          g_rand_free (randb);
+          randb = g_rand_new_with_seed (g_rand_int (randa));
         }
       else
         /* make sure we get enough unequals (ie: no GRand failure) */