1570af302Sopenharmony_ci/* 2570af302Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4570af302Sopenharmony_ci * you may not use this file except in compliance with the License. 5570af302Sopenharmony_ci * You may obtain a copy of the License at 6570af302Sopenharmony_ci * 7570af302Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8570af302Sopenharmony_ci * 9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12570af302Sopenharmony_ci * See the License for the specific language governing permissions and 13570af302Sopenharmony_ci * limitations under the License. 14570af302Sopenharmony_ci */ 15570af302Sopenharmony_ci 16570af302Sopenharmony_ci#include <stdlib.h> 17570af302Sopenharmony_ci#include <stdio.h> 18570af302Sopenharmony_ci#include "functionalext.h" 19570af302Sopenharmony_ci 20570af302Sopenharmony_ci#define POSITIVE_NUM 0 21570af302Sopenharmony_ci#define NEGATIVE_NUM 1 22570af302Sopenharmony_ci 23570af302Sopenharmony_ci/** 24570af302Sopenharmony_ci * @tc.name : fcvt_0100 25570af302Sopenharmony_ci * @tc.desc : Basic conversion test for fcvt. 26570af302Sopenharmony_ci * @tc.level : level 0 27570af302Sopenharmony_ci */ 28570af302Sopenharmony_civoid fcvt_0100() 29570af302Sopenharmony_ci{ 30570af302Sopenharmony_ci int decpt, sign; 31570af302Sopenharmony_ci char *result = fcvt(123.456, 2, &decpt, &sign); 32570af302Sopenharmony_ci printf("result==%s\n", result); 33570af302Sopenharmony_ci EXPECT_STREQ("fcvt_0100", result, "12346"); 34570af302Sopenharmony_ci EXPECT_EQ("fcvt_0100_decpt", decpt, 3); 35570af302Sopenharmony_ci EXPECT_EQ("fcvt_0100_sign", sign, POSITIVE_NUM); 36570af302Sopenharmony_ci} 37570af302Sopenharmony_ci 38570af302Sopenharmony_civoid fcvt_0200() 39570af302Sopenharmony_ci{ 40570af302Sopenharmony_ci int decpt, sign; 41570af302Sopenharmony_ci char *result = fcvt(123.454, 2, &decpt, &sign); 42570af302Sopenharmony_ci printf("result==%s\n", result); 43570af302Sopenharmony_ci EXPECT_STREQ("fcvt_0100", result, "12345"); 44570af302Sopenharmony_ci EXPECT_EQ("fcvt_0100_decpt", decpt, 3); 45570af302Sopenharmony_ci EXPECT_EQ("fcvt_0100_sign", sign, POSITIVE_NUM); 46570af302Sopenharmony_ci} 47570af302Sopenharmony_ci/** 48570af302Sopenharmony_ci * @tc.name : fcvt_0200 49570af302Sopenharmony_ci * @tc.desc : Zero value conversion test for fcvt. 50570af302Sopenharmony_ci * @tc.level : level 0 51570af302Sopenharmony_ci */ 52570af302Sopenharmony_civoid fcvt_0300() 53570af302Sopenharmony_ci{ 54570af302Sopenharmony_ci int decpt, sign; 55570af302Sopenharmony_ci char *result = fcvt(0.0, 2, &decpt, &sign); 56570af302Sopenharmony_ci printf("result==%s\n", result); 57570af302Sopenharmony_ci EXPECT_STREQ("fcvt_0300", result, "000"); 58570af302Sopenharmony_ci EXPECT_EQ("fcvt_0300_decpt", decpt, 1); 59570af302Sopenharmony_ci EXPECT_EQ("fcvt_0300_sign", sign, POSITIVE_NUM); 60570af302Sopenharmony_ci} 61570af302Sopenharmony_ci 62570af302Sopenharmony_ci/** 63570af302Sopenharmony_ci * @tc.name : fcvt_0300 64570af302Sopenharmony_ci * @tc.desc : Negative value conversion test for fcvt. 65570af302Sopenharmony_ci * @tc.level : level 0 66570af302Sopenharmony_ci */ 67570af302Sopenharmony_civoid fcvt_0400() 68570af302Sopenharmony_ci{ 69570af302Sopenharmony_ci int decpt, sign; 70570af302Sopenharmony_ci char *result = fcvt(-123.456, 2, &decpt, &sign); 71570af302Sopenharmony_ci printf("result==%s\n", result); 72570af302Sopenharmony_ci EXPECT_STREQ("fcvt_0400", result, "12346"); 73570af302Sopenharmony_ci EXPECT_EQ("fcvt_0400_decpt", decpt, 3); 74570af302Sopenharmony_ci EXPECT_EQ("fcvt_0400_sign", sign, NEGATIVE_NUM); 75570af302Sopenharmony_ci} 76570af302Sopenharmony_ci 77570af302Sopenharmony_ci/** 78570af302Sopenharmony_ci * @tc.name : fcvt_0400 79570af302Sopenharmony_ci * @tc.desc : Test with a large number of digits after the decimal point. 80570af302Sopenharmony_ci * @tc.level : level 0 81570af302Sopenharmony_ci */ 82570af302Sopenharmony_civoid fcvt_0500() 83570af302Sopenharmony_ci{ 84570af302Sopenharmony_ci int decpt, sign; 85570af302Sopenharmony_ci char *result = fcvt(123.456, 10, &decpt, &sign); 86570af302Sopenharmony_ci printf("result==%s\n", result); 87570af302Sopenharmony_ci // Here, the expected string is just an example, you might need to adjust based on actual behavior. 88570af302Sopenharmony_ci EXPECT_STREQ("fcvt_0500", result, "1234560000000"); 89570af302Sopenharmony_ci EXPECT_EQ("fcvt_0500_decpt", decpt, 3); 90570af302Sopenharmony_ci EXPECT_EQ("fcvt_0500_sign", sign, POSITIVE_NUM); 91570af302Sopenharmony_ci} 92570af302Sopenharmony_ci 93570af302Sopenharmony_ciint main(void) 94570af302Sopenharmony_ci{ 95570af302Sopenharmony_ci fcvt_0100(); 96570af302Sopenharmony_ci fcvt_0200(); 97570af302Sopenharmony_ci fcvt_0300(); 98570af302Sopenharmony_ci fcvt_0400(); 99570af302Sopenharmony_ci fcvt_0500(); 100570af302Sopenharmony_ci return t_status; 101570af302Sopenharmony_ci} 102