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 <stdarg.h> 17570af302Sopenharmony_ci#include <stdio.h> 18570af302Sopenharmony_ci#include <string.h> 19570af302Sopenharmony_ci#include <wchar.h> 20570af302Sopenharmony_ci#include "test.h" 21570af302Sopenharmony_ci 22570af302Sopenharmony_ci#define MAX (20) 23570af302Sopenharmony_ci 24570af302Sopenharmony_ci/** 25570af302Sopenharmony_ci * @tc.name : vswprintf_0100 26570af302Sopenharmony_ci * @tc.desc : Write formatted data %d to string from variable argument list 27570af302Sopenharmony_ci * @tc.level : Level 0 28570af302Sopenharmony_ci */ 29570af302Sopenharmony_civoid vswprintf_0100(wchar_t *format, ...) 30570af302Sopenharmony_ci{ 31570af302Sopenharmony_ci wchar_t buffer[MAX]; 32570af302Sopenharmony_ci va_list aptr; 33570af302Sopenharmony_ci va_start(aptr, format); 34570af302Sopenharmony_ci int result = vswprintf(buffer, MAX, format, aptr); 35570af302Sopenharmony_ci va_end(aptr); 36570af302Sopenharmony_ci if (result < 0) { 37570af302Sopenharmony_ci t_error("%s vswprintf get result is less than 0", __func__); 38570af302Sopenharmony_ci } 39570af302Sopenharmony_ci if (wcscmp(buffer, L"1")) { 40570af302Sopenharmony_ci t_error("%s wrong string written to buf", __func__); 41570af302Sopenharmony_ci } 42570af302Sopenharmony_ci} 43570af302Sopenharmony_ci 44570af302Sopenharmony_ci/** 45570af302Sopenharmony_ci * @tc.name : vswprintf_0200 46570af302Sopenharmony_ci * @tc.desc : Write formatted data %f to string from variable argument list 47570af302Sopenharmony_ci * @tc.level : Level 1 48570af302Sopenharmony_ci */ 49570af302Sopenharmony_civoid vswprintf_0200(wchar_t *format, ...) 50570af302Sopenharmony_ci{ 51570af302Sopenharmony_ci wchar_t buffer[MAX]; 52570af302Sopenharmony_ci va_list aptr; 53570af302Sopenharmony_ci va_start(aptr, format); 54570af302Sopenharmony_ci int result = vswprintf(buffer, MAX, format, aptr); 55570af302Sopenharmony_ci va_end(aptr); 56570af302Sopenharmony_ci if (result < 0) { 57570af302Sopenharmony_ci t_error("%s vswprintf get result is less than 0", __func__); 58570af302Sopenharmony_ci } 59570af302Sopenharmony_ci if (wcsncmp(buffer, L"3.0", 3)) { 60570af302Sopenharmony_ci t_error("%s wrong string written to buf", __func__); 61570af302Sopenharmony_ci } 62570af302Sopenharmony_ci} 63570af302Sopenharmony_ci 64570af302Sopenharmony_ci/** 65570af302Sopenharmony_ci * @tc.name : vswprintf_0300 66570af302Sopenharmony_ci * @tc.desc : Write formatted data %s to string from variable argument list 67570af302Sopenharmony_ci * @tc.level : Level 1 68570af302Sopenharmony_ci */ 69570af302Sopenharmony_civoid vswprintf_0300(wchar_t *format, ...) 70570af302Sopenharmony_ci{ 71570af302Sopenharmony_ci wchar_t buffer[MAX]; 72570af302Sopenharmony_ci va_list aptr; 73570af302Sopenharmony_ci va_start(aptr, format); 74570af302Sopenharmony_ci int result = vswprintf(buffer, MAX, format, aptr); 75570af302Sopenharmony_ci va_end(aptr); 76570af302Sopenharmony_ci if (result < 0) { 77570af302Sopenharmony_ci t_error("%s vsprintf get result is less than 0", __func__); 78570af302Sopenharmony_ci } 79570af302Sopenharmony_ci if (wcscmp(buffer, L"vswprintf test")) { 80570af302Sopenharmony_ci t_error("%s wrong string written to buf", __func__); 81570af302Sopenharmony_ci } 82570af302Sopenharmony_ci} 83570af302Sopenharmony_ci 84570af302Sopenharmony_ciint main(int argc, char *argv[]) 85570af302Sopenharmony_ci{ 86570af302Sopenharmony_ci int i = 1; 87570af302Sopenharmony_ci float f = 3.0f; 88570af302Sopenharmony_ci wchar_t str[] = L"vswprintf test"; 89570af302Sopenharmony_ci vswprintf_0100(L"%d", i); 90570af302Sopenharmony_ci vswprintf_0200(L"%f", f); 91570af302Sopenharmony_ci vswprintf_0300(L"%ls", str); 92570af302Sopenharmony_ci return t_status; 93570af302Sopenharmony_ci}