tst-random2.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Test initstate saving the old state.
  2. Copyright (C) 2005-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. static int
  19. do_test (void)
  20. {
  21. int pass;
  22. int ret = 0;
  23. long int r[2];
  24. for (pass = 0; pass < 2; pass++)
  25. {
  26. srandom (0x12344321);
  27. int j;
  28. for (j = 0; j < 3; ++j)
  29. random ();
  30. if (pass == 1)
  31. {
  32. char state[128];
  33. char *ostate = initstate (0x34562101, state, 128);
  34. if (setstate (ostate) != state)
  35. {
  36. puts ("setstate (ostate) != state");
  37. ret = 1;
  38. }
  39. }
  40. random ();
  41. r[pass] = random ();
  42. }
  43. if (r[0] != r[1])
  44. {
  45. printf ("%ld != %ld\n", r[0], r[1]);
  46. ret = 1;
  47. }
  48. return ret;
  49. }
  50. #define TEST_FUNCTION do_test ()
  51. #include "../test-skeleton.c"