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/. */
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
25 ** Test harness infrastructure
28 PRLogModuleLevel msgLevel
= PR_LOG_NONE
;
30 PRUint32 failed_already
= 0;
31 /* end Test harness infrastructure */
33 PRIntn optRandCount
= 30;
35 PRSize bufSize
= sizeof(buf
);
40 ** Emit help text for this test
42 static void Help( void )
44 printf("Template: Help(): display your help message(s) here");
48 static void PrintRand( void *buf
, PRIntn size
)
53 printf("%4.4d--\n", size
);
57 printf("%2.2X\n", *(rp
++) );
61 printf("%4.4X\n", *(rp
++) );
65 printf("%6.6X\n", *(rp
++) );
72 printf("%8.8X ", *(rp
++) );
81 } /* end PrintRand() */
84 int main(int argc
, char **argv
)
88 ** Get command line options
91 PLOptState
*opt
= PL_CreateOptState(argc
, argv
, "hdv");
93 while (PL_OPT_EOL
!= (os
= PL_GetNextOpt(opt
)))
95 if (PL_OPT_BAD
== os
) {
100 case 'd': /* debug */
102 msgLevel
= PR_LOG_ERROR
;
104 case 'v': /* verbose mode */
105 msgLevel
= PR_LOG_DEBUG
;
107 case 'h': /* help message */
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
);
122 fprintf(stderr
, "Not implemented\n" );
123 failed_already
= PR_TRUE
;
127 PrintRand( buf
, rSize
);
132 printf("%s\n", (failed_already
)? "FAIL" : "PASS");
134 return( (failed_already
== PR_TRUE
)? 1 : 0 );