• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdio.h>
17 #include <stdlib.h>
18 #include "test.h"
19 
20 unsigned int seed_ = 123;
21 
22 /**
23  * @tc.name      : rand_r_0100
24  * @tc.desc      : The return value obtained by calling rand_d is different when testing different random number seeds
25  * @tc.level     : Level 0
26  */
rand_r_0100(void)27 void rand_r_0100(void)
28 {
29     unsigned int seed = 10;
30     int a_result = rand_r(&seed);
31     seed = 200;
32     int b_result = rand_r(&seed);
33     if (a_result == b_result) {
34         t_error("%s rand_r error change seed get result is all %d\n", __func__, a_result);
35     }
36 }
37 
38 /**
39  * @tc.name      : rand_r_0200
40  * @tc.desc      : When the test changes the same random number seed, the return value obtained by calling rand_d is
41  *                 the same
42  * @tc.level     : Level 1
43  */
rand_r_0200(void)44 void rand_r_0200(void)
45 {
46     unsigned int seed = seed_;
47     int a_result = rand_r(&seed);
48     seed = seed_;
49     int b_result = rand_r(&seed);
50     if (a_result != b_result) {
51         t_error("%s rand_r error get result is %d and %d \n", __func__, a_result, b_result);
52     }
53 }
54 
55 /**
56  * @tc.name      : rand_r_0300
57  * @tc.desc      : Test that the function return value obtained by calling the rand_d function twice in a row is
58  *                 different
59  * @tc.level     : Level 1
60  */
rand_r_0300(void)61 void rand_r_0300(void)
62 {
63     unsigned int seed = 10;
64     int a_result = rand_r(&seed);
65     int b_result = rand_r(&seed);
66     if (a_result == b_result) {
67         t_error("%s rand_r error change seed get result is all %d\n", __func__, a_result);
68     }
69 }
70 
main(int argc,char * argv[])71 int main(int argc, char *argv[])
72 {
73     rand_r_0100();
74     rand_r_0200();
75     rand_r_0300();
76     return t_status;
77 }