• 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 <float.h>
17 #include <math.h>
18 #include <stdlib.h>
19 #include "test.h"
20 
21 typedef void (*TEST_FUN)();
22 
23 #define EXPECT_DOUBLE_EQ(a, b)                                             \
24     do {                                                                   \
25         if (!(fabs(a - b) < DBL_EPSILON))                                  \
26             t_error("%s failed: %f is not equal to %f\n", __func__, a, b); \
27     } while (0)
28 
29 /**
30  * @tc.name      : atof_0100
31  * @tc.desc      : Convert a string to a double
32  * @tc.level     : Level 0
33  */
atof_0100()34 void atof_0100()
35 {
36     const char *str = "123456.00";
37     double result = atof(str);
38     EXPECT_DOUBLE_EQ(result, 123456.00);
39 }
40 
41 TEST_FUN G_Fun_Array[] = {
42     atof_0100,
43 };
44 
main(int argc,char * argv[])45 int main(int argc, char *argv[])
46 {
47     int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
48     for (int pos = 0; pos < num; ++pos) {
49         G_Fun_Array[pos]();
50     }
51 
52     return t_status;
53 }