Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
9cf33d8b
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9cf33d8b
编写于
8月 01, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 01, 2023
浏览文件
操作
浏览文件
下载
差异文件
!1012 Fix bug of vfprintf
Merge pull request !1012 from yinchuang/printf_bug
上级
f939f263
c0bfb700
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
102 addition
and
40 deletion
+102
-40
libc-test/src/functionalext/supplement/stdio/sprintf.c
libc-test/src/functionalext/supplement/stdio/sprintf.c
+98
-39
porting/linux/user/src/stdio/vfprintf.c
porting/linux/user/src/stdio/vfprintf.c
+4
-1
未找到文件。
libc-test/src/functionalext/supplement/stdio/sprintf.c
浏览文件 @
9cf33d8b
/*
/*
* Copyright (C) 202
2
Huawei Device Co., Ltd.
* Copyright (C) 202
3
Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* You may obtain a copy of the License at
...
@@ -17,55 +17,114 @@
...
@@ -17,55 +17,114 @@
#include <stdlib.h>
#include <stdlib.h>
#include "functionalext.h"
#include "functionalext.h"
const
int32_t
SPRINTF_0100_RESULT
=
4
;
#define BUFFER_SIZE 1024
const
int32_t
SPRINTF_0200_RESULT
=
5
;
const
int32_t
SPRINTF_0300_RESULT
=
19
;
const
int32_t
SECOND_PARAM
=
2
;
const
int32_t
THIRD_PARAM
=
12345
;
/**
void
sprintf_specifier_tests
(
void
)
* @tc.name : sprintf_0100
* @tc.desc : Verify sprintf process success with two params
* @tc.level : Level 0
*/
void
sprintf_0100
(
void
)
{
{
char
str
[
1024
];
char
str
[
BUFFER_SIZE
];
int
ret
=
sprintf
(
str
,
"test"
);
int
ret
=
0
;
EXPECT_EQ
(
"sprintf_0100"
,
ret
,
SPRINTF_0100_RESULT
);
EXPECT_STREQ
(
"sprintf_0100"
,
str
,
"test"
);
ret
=
sprintf
(
str
,
"test"
);
EXPECT_EQ
(
"sprintf_specifier_null"
,
ret
,
4
);
EXPECT_STREQ
(
"sprintf_specifier_null"
,
str
,
"test"
);
ret
=
sprintf
(
str
,
"%d,%i"
,
1
,
2
);
EXPECT_EQ
(
"sprintf_specifier_integer"
,
ret
,
3
);
EXPECT_STREQ
(
"sprintf_specifier_integer"
,
str
,
"1,2"
);
ret
=
sprintf
(
str
,
"%u,%u"
,
1
,
-
1
);
EXPECT_EQ
(
"sprintf_specifier_Unsigned_integer"
,
ret
,
12
);
EXPECT_STREQ
(
"sprintf_specifier_Unsigned_integer"
,
str
,
"1,4294967295"
);
ret
=
sprintf
(
str
,
"%o"
,
9
);
EXPECT_EQ
(
"sprintf_specifier_octal_integer"
,
ret
,
2
);
EXPECT_STREQ
(
"sprintf_specifier_octal_integer"
,
str
,
"11"
);
ret
=
sprintf
(
str
,
"%x,%X"
,
15
,
15
);
EXPECT_EQ
(
"sprintf_specifier_hexadecimal_integer"
,
ret
,
3
);
EXPECT_STREQ
(
"sprintf_specifier_hexadecimal_integer"
,
str
,
"f,F"
);
ret
=
sprintf
(
str
,
"%f,%F"
,
1
.
23
,
1
.
23
);
EXPECT_EQ
(
"sprintf_specifier_float"
,
ret
,
17
);
EXPECT_STREQ
(
"sprintf_specifier_float"
,
str
,
"1.230000,1.230000"
);
ret
=
sprintf
(
str
,
"%e,%E"
,
1
.
23
,
1
.
23
);
EXPECT_EQ
(
"sprintf_specifier_scientific_notation"
,
ret
,
25
);
EXPECT_STREQ
(
"sprintf_specifier_scientific_notation"
,
str
,
"1.230000e+00,1.230000E+00"
);
ret
=
sprintf
(
str
,
"%c"
,
'1'
);
EXPECT_EQ
(
"sprintf_specifier_char"
,
ret
,
1
);
EXPECT_STREQ
(
"sprintf_specifier_char"
,
str
,
"1"
);
ret
=
sprintf
(
str
,
"%s,%s"
,
"123"
,
"456"
);
EXPECT_EQ
(
"sprintf_specifier_str"
,
ret
,
7
);
EXPECT_STREQ
(
"sprintf_specifier_str"
,
str
,
"123,456"
);
ret
=
sprintf
(
str
,
"%p"
,
6618688
);
EXPECT_EQ
(
"sprintf_specifier_pointer_address"
,
ret
,
8
);
EXPECT_STREQ
(
"sprintf_specifier_pointer_address"
,
str
,
"0x64fe40"
);
ret
=
sprintf
(
str
,
"%%test"
);
EXPECT_EQ
(
"sprintf_specifier_double_percent_sign"
,
ret
,
5
);
EXPECT_STREQ
(
"sprintf_specifier_double_percent_sign"
,
str
,
"%test"
);
ret
=
sprintf
(
str
,
"%3$d,%2$s,%1$c"
,
'a'
,
"bc"
,
123
);
EXPECT_EQ
(
"sprintf_$_symbol"
,
ret
,
8
);
EXPECT_STREQ
(
"sprintf_$_symbol"
,
str
,
"123,bc,a"
);
}
}
/**
void
sprintf_flag_tests
(
void
)
* @tc.name : sprintf_0200
* @tc.desc : Verify sprintf process success with three params(the thrid praram type is int_32)
* @tc.level : Level 0
*/
void
sprintf_0200
(
void
)
{
{
char
str
[
1024
];
char
str
[
BUFFER_SIZE
];
int
ret
=
sprintf
(
str
,
"test%d"
,
SECOND_PARAM
);
int
ret
=
0
;
EXPECT_EQ
(
"sprintf_0200"
,
ret
,
SPRINTF_0200_RESULT
);
EXPECT_STREQ
(
"sprintf_0200"
,
str
,
"test2"
);
ret
=
sprintf
(
str
,
"%+d %+d %d %d"
,
-
1
,
1
,
-
1
,
1
);
EXPECT_EQ
(
"sprintf_flag_+_and_space"
,
ret
,
10
);
EXPECT_STREQ
(
"sprintf_flag_+_and_space"
,
str
,
"-1 +1 -1 1"
);
ret
=
sprintf
(
str
,
"%#o,%#x,%#X"
,
9
,
9
,
9
);
EXPECT_EQ
(
"sprintf_flag_#"
,
ret
,
11
);
EXPECT_STREQ
(
"sprintf_flag_#"
,
str
,
"011,0x9,0X9"
);
ret
=
sprintf
(
str
,
"%5d,%05d,%0-5d"
,
123
,
123
,
123
);
EXPECT_EQ
(
"sprintf_flag_-_and_0"
,
ret
,
17
);
EXPECT_STREQ
(
"sprintf_flag_-_and_0"
,
str
,
" 123,00123,123 "
);
}
}
/**
void
sprintf_width_tests
(
void
)
* @tc.name : sprintf_0300
* @tc.desc : Verify sprintf process success with three params(the thrid praram type is string)
* @tc.level : Level 0
*/
void
sprintf_0300
(
void
)
{
{
char
str
[
1024
];
char
str
[
BUFFER_SIZE
];
int
ret
=
sprintf
(
str
,
"testname:%s%d"
,
"test3"
,
THIRD_PARAM
);
int
ret
=
0
;
EXPECT_EQ
(
"sprintf_0300"
,
ret
,
SPRINTF_0300_RESULT
);
ret
=
sprintf
(
str
,
"%d,%3d,%10d"
,
12345
,
12345
,
12345
);
EXPECT_STREQ
(
"sprintf_0300"
,
str
,
"testname:test312345"
);
EXPECT_EQ
(
"sprintf_width_num"
,
ret
,
22
);
EXPECT_STREQ
(
"sprintf_width_num"
,
str
,
"12345,12345, 12345"
);
ret
=
sprintf
(
str
,
"%*d"
,
10
,
12345
);
EXPECT_EQ
(
"sprintf_width_*"
,
ret
,
10
);
EXPECT_STREQ
(
"sprintf_width_*"
,
str
,
" 12345"
);
}
void
sprintf_precision_tests
(
void
)
{
char
str
[
BUFFER_SIZE
];
int
ret
=
0
;
ret
=
sprintf
(
str
,
"%f,%.3f"
,
1
.
2345
,
1
.
2345
);
EXPECT_EQ
(
"sprintf_precision_num"
,
ret
,
14
);
EXPECT_STREQ
(
"sprintf_precision_num"
,
str
,
"1.234500,1.234"
);
ret
=
sprintf
(
str
,
"%.*f"
,
3
,
1
.
2345
);
EXPECT_EQ
(
"sprintf_precision_*"
,
ret
,
5
);
EXPECT_STREQ
(
"sprintf_precision_*"
,
str
,
"1.234"
);
}
}
int
main
(
void
)
int
main
(
void
)
{
{
sprintf_0100
();
// %[flags][width][.precision][length]specifier
sprintf_0200
();
sprintf_specifier_tests
();
sprintf_0300
();
sprintf_flag_tests
();
sprintf_width_tests
();
sprintf_precision_tests
();
return
t_status
;
return
t_status
;
}
}
porting/linux/user/src/stdio/vfprintf.c
浏览文件 @
9cf33d8b
...
@@ -469,9 +469,12 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
...
@@ -469,9 +469,12 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
if
(
isdigit
(
s
[
1
])
&&
s
[
2
]
==
'$'
)
{
if
(
isdigit
(
s
[
1
])
&&
s
[
2
]
==
'$'
)
{
if
(
!
nl_arg_filled
)
{
if
(
!
nl_arg_filled
)
{
if
(
printf_core
(
0
,
fmt
,
ap
,
nl_arg
,
nl_type
,
1
)
<
0
)
{
va_list
ap_copy
;
va_copy
(
ap_copy
,
*
ap
);
if
(
printf_core
(
0
,
fmt
,
&
ap_copy
,
nl_arg
,
nl_type
,
1
)
<
0
)
{
return
-
1
;
return
-
1
;
}
}
va_end
(
ap_copy
);
}
}
l10n
=
1
;
l10n
=
1
;
argpos
=
s
[
1
]
-
'0'
;
argpos
=
s
[
1
]
-
'0'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录