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 <stdlib.h> 17#include <stdio.h> 18#include "functionalext.h" 19 20#define POSITIVE_NUM 0 21#define NEGATIVE_NUM 1 22 23/** 24 * @tc.name : fcvt_0100 25 * @tc.desc : Basic conversion test for fcvt. 26 * @tc.level : level 0 27 */ 28void fcvt_0100() 29{ 30 int decpt, sign; 31 char *result = fcvt(123.456, 2, &decpt, &sign); 32 printf("result==%s\n", result); 33 EXPECT_STREQ("fcvt_0100", result, "12346"); 34 EXPECT_EQ("fcvt_0100_decpt", decpt, 3); 35 EXPECT_EQ("fcvt_0100_sign", sign, POSITIVE_NUM); 36} 37 38void fcvt_0200() 39{ 40 int decpt, sign; 41 char *result = fcvt(123.454, 2, &decpt, &sign); 42 printf("result==%s\n", result); 43 EXPECT_STREQ("fcvt_0100", result, "12345"); 44 EXPECT_EQ("fcvt_0100_decpt", decpt, 3); 45 EXPECT_EQ("fcvt_0100_sign", sign, POSITIVE_NUM); 46} 47/** 48 * @tc.name : fcvt_0200 49 * @tc.desc : Zero value conversion test for fcvt. 50 * @tc.level : level 0 51 */ 52void fcvt_0300() 53{ 54 int decpt, sign; 55 char *result = fcvt(0.0, 2, &decpt, &sign); 56 printf("result==%s\n", result); 57 EXPECT_STREQ("fcvt_0300", result, "000"); 58 EXPECT_EQ("fcvt_0300_decpt", decpt, 1); 59 EXPECT_EQ("fcvt_0300_sign", sign, POSITIVE_NUM); 60} 61 62/** 63 * @tc.name : fcvt_0300 64 * @tc.desc : Negative value conversion test for fcvt. 65 * @tc.level : level 0 66 */ 67void fcvt_0400() 68{ 69 int decpt, sign; 70 char *result = fcvt(-123.456, 2, &decpt, &sign); 71 printf("result==%s\n", result); 72 EXPECT_STREQ("fcvt_0400", result, "12346"); 73 EXPECT_EQ("fcvt_0400_decpt", decpt, 3); 74 EXPECT_EQ("fcvt_0400_sign", sign, NEGATIVE_NUM); 75} 76 77/** 78 * @tc.name : fcvt_0400 79 * @tc.desc : Test with a large number of digits after the decimal point. 80 * @tc.level : level 0 81 */ 82void fcvt_0500() 83{ 84 int decpt, sign; 85 char *result = fcvt(123.456, 10, &decpt, &sign); 86 printf("result==%s\n", result); 87 // Here, the expected string is just an example, you might need to adjust based on actual behavior. 88 EXPECT_STREQ("fcvt_0500", result, "1234560000000"); 89 EXPECT_EQ("fcvt_0500_decpt", decpt, 3); 90 EXPECT_EQ("fcvt_0500_sign", sign, POSITIVE_NUM); 91} 92 93int main(void) 94{ 95 fcvt_0100(); 96 fcvt_0200(); 97 fcvt_0300(); 98 fcvt_0400(); 99 fcvt_0500(); 100 return t_status; 101} 102