1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <math.h>
17 #include <stdlib.h>
18 #include "functionalext.h"
19
20 #define TEST_JRAND_SIZE 3
21 #define TWO 2
22 #define THIRTYONE 31
23
24 /**
25 * @tc.name : jrand48_0100
26 * @tc.desc : Use [1, 2, 3] as parameters to generate a long integer random number
27 * @tc.level : Level 0
28 */
jrand48_0100(void)29 void jrand48_0100(void)
30 {
31 unsigned short s[TEST_JRAND_SIZE] = {1, 2, 3};
32 long rev = jrand48(s);
33 EXPECT_TRUE("jrand48_0100", rev < pow(TWO, THIRTYONE) && rev > -pow(TWO, THIRTYONE));
34 }
35
36 /**
37 * @tc.name : jrand48_0200
38 * @tc.desc : Use [0, 0, 0] as parameters to generate a long integer random number
39 * @tc.level : Level 0
40 */
jrand48_0200(void)41 void jrand48_0200(void)
42 {
43 unsigned short s[TEST_JRAND_SIZE] = {0, 0, 0};
44 long rev = jrand48(s);
45 EXPECT_EQ("jrand48_0200", rev, 0);
46 }
47
48 /**
49 * @tc.name : mrand48_0100
50 * @tc.desc : Verify mrand48 process success. Generate a long integer random number
51 * @tc.level : Level 0
52 */
mrand48_0100(void)53 void mrand48_0100(void)
54 {
55 unsigned short p[7] = {0x0102, 0x0304, 0x0506, 0x0708, 0x090a, 0x0b0c, 0x0d0e};
56 lcong48(p);
57 long ret = mrand48();
58 EXPECT_TRUE("mrand48_0100", ret < pow(TWO, THIRTYONE) && ret > -pow(TWO, THIRTYONE));
59 }
60
main(void)61 int main(void)
62 {
63 mrand48_0100();
64 jrand48_0100();
65 jrand48_0200();
66 return t_status;
67 }