Bug 1825055 [wpt PR 39247] - Add support for allowing elements with display:contents...
[gecko.git] / nsprpub / pr / tests / randseed.c
blob2ca14c7af0e846d2024e2456ffaca9a80861bf4f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 ** File: rngseed.c
8 ** Description:
9 ** Test NSPR's Random Number Seed generator
11 ** Initial test: Just make sure it outputs some data.
13 ** ... more? ... check some iterations to ensure it is random (no dupes)
14 ** ... more? ... histogram distribution of random numbers
17 #include "plgetopt.h"
18 #include "nspr.h"
19 #include "prrng.h"
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
25 ** Test harness infrastructure
27 PRLogModuleInfo *lm;
28 PRLogModuleLevel msgLevel = PR_LOG_NONE;
29 PRIntn debug = 0;
30 PRUint32 failed_already = 0;
31 /* end Test harness infrastructure */
33 PRIntn optRandCount = 30;
34 char buf[40];
35 PRSize bufSize = sizeof(buf);
36 PRSize rSize;
37 PRIntn i;
40 ** Emit help text for this test
42 static void Help( void )
44 printf("Template: Help(): display your help message(s) here");
45 exit(1);
46 } /* end Help() */
48 static void PrintRand( void *buf, PRIntn size )
50 PRUint32 *rp = buf;
51 PRIntn i;
53 printf("%4.4d--\n", size );
54 while (size > 0 ) {
55 switch( size ) {
56 case 1 :
57 printf("%2.2X\n", *(rp++) );
58 size -= 4;
59 break;
60 case 2 :
61 printf("%4.4X\n", *(rp++) );
62 size -= 4;
63 break;
64 case 3 :
65 printf("%6.6X\n", *(rp++) );
66 size -= 4;
67 break;
68 default:
69 while ( size >= 4) {
70 PRIntn i = 3;
71 do {
72 printf("%8.8X ", *(rp++) );
73 size -= 4;
74 } while( i-- );
75 i = 3;
76 printf("\n");
78 break;
79 } /* end switch() */
80 } /* end while() */
81 } /* end PrintRand() */
84 int main(int argc, char **argv)
88 ** Get command line options
90 PLOptStatus os;
91 PLOptState *opt = PL_CreateOptState(argc, argv, "hdv");
93 while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
95 if (PL_OPT_BAD == os) {
96 continue;
98 switch (opt->option)
100 case 'd': /* debug */
101 debug = 1;
102 msgLevel = PR_LOG_ERROR;
103 break;
104 case 'v': /* verbose mode */
105 msgLevel = PR_LOG_DEBUG;
106 break;
107 case 'h': /* help message */
108 Help();
109 break;
110 default:
111 break;
114 PL_DestroyOptState(opt);
117 lm = PR_NewLogModule("Test"); /* Initialize logging */
118 for ( i = 0; i < optRandCount ; i++ ) {
119 memset( buf, 0, bufSize );
120 rSize = PR_GetRandomNoise( buf, bufSize );
121 if (!rSize) {
122 fprintf(stderr, "Not implemented\n" );
123 failed_already = PR_TRUE;
124 break;
126 if (debug) {
127 PrintRand( buf, rSize );
131 if (debug) {
132 printf("%s\n", (failed_already)? "FAIL" : "PASS");
134 return( (failed_already == PR_TRUE )? 1 : 0 );
135 } /* main() */
136 /* end template.c */