Skip to content

Commit c369f7b

Browse files
committed
Update tests
1 parent cb2a416 commit c369f7b

2 files changed

Lines changed: 123 additions & 25 deletions

File tree

‎tests/unit/out/refcount/printfs.rs‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ pub fn fn_0(mut v: Vec<i8>) -> Vec<i8> {
1818
pub fn fn2_1(v: Ptr<Vec<i8>>) -> Ptr<Vec<i8>> {
1919
return (v).clone();
2020
}
21+
pub fn log_to_2(mut out: Ptr<CFile>, mut fmt: Ptr<i8>, mut args_2: Ptr<i8>, mut args_3: i32) {
22+
{
23+
let __s = libcc2rs::format_c(
24+
&fmt.to_rust_string(),
25+
&[((args_2).clone()).into(), (args_3).into()],
26+
);
27+
out.with_mut(|__f| __f.write(__s.as_bytes())) as i32
28+
};
29+
}
30+
pub fn log_to_3(mut out: Ptr<CFile>, mut fmt: Ptr<i8>, mut args: i32) {
31+
{
32+
let __s = libcc2rs::format_c(&fmt.to_rust_string(), &[(args).into()]);
33+
out.with_mut(|__f| __f.write(__s.as_bytes())) as i32
34+
};
35+
}
36+
pub fn log_fmt_4(mut fmt: Ptr<i8>, mut v: i32) {
37+
{
38+
let __s = libcc2rs::format_c(&fmt.to_rust_string(), &[(v).into()]);
39+
libcc2rs::c_stdout().with_mut(|__f| __f.write(__s.as_bytes())) as i32
40+
};
41+
}
2142
pub fn main() {
2243
__cpp2rust_init_globals();
2344
std::process::exit(main_0());
@@ -53,6 +74,22 @@ fn main_0() -> i32 {
5374
"{}",
5475
(Ptr::<Vec<i8>>::decay(&({ fn2_1(s.as_pointer(),) })) as Ptr<i8>)
5576
);
77+
({
78+
log_to_2(
79+
libcc2rs::c_stdout(),
80+
Ptr::<i8>::from_string_literal(b"%s %d\n"),
81+
Ptr::<i8>::from_string_literal(b"runtime"),
82+
4,
83+
)
84+
});
85+
({
86+
log_to_3(
87+
libcc2rs::c_stderr(),
88+
Ptr::<i8>::from_string_literal(b"%d\n"),
89+
5,
90+
)
91+
});
92+
({ log_fmt_4(Ptr::<i8>::from_string_literal(b"%d\n"), 6) });
5693
println!("{{}} {} {}", 5_u64, (-6_i32 as i64));
5794
return 0;
5895
}

‎tests/unit/out/unsafe/printfs.rs‎

Lines changed: 86 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,106 @@ pub unsafe fn fn_0(mut v: Vec<libc::c_char>) -> Vec<libc::c_char> {
2222
pub unsafe fn fn2_1(v: *const Vec<libc::c_char>) -> *const Vec<libc::c_char> {
2323
return v;
2424
}
25+
pub unsafe fn log_to_2(
26+
mut out: *mut ::libc::FILE,
27+
mut fmt: *const libc::c_char,
28+
mut args_2: *const libc::c_char,
29+
mut args_3: i32,
30+
) {
31+
(unsafe {
32+
libc::fprintf(
33+
out as *mut ::libc::FILE,
34+
fmt as *const libc::c_char,
35+
(args_2),
36+
(args_3),
37+
)
38+
});
39+
}
40+
pub unsafe fn log_to_3(mut out: *mut ::libc::FILE, mut fmt: *const libc::c_char, mut args: i32) {
41+
(unsafe { libc::fprintf(out as *mut ::libc::FILE, fmt as *const libc::c_char, (args)) });
42+
}
43+
pub unsafe fn log_fmt_4(mut fmt: *const libc::c_char, mut v: i32) {
44+
(unsafe { libc::printf(fmt as *const libc::c_char, (v)) });
45+
}
2546
pub fn main() {
2647
unsafe {
2748
__cpp2rust_init_globals();
2849
std::process::exit(main_0() as i32);
2950
}
3051
}
3152
unsafe fn main_0() -> i32 {
32-
printf(c"%s\n".as_ptr() as *const i8, c"fprintf stdout".as_ptr());
33-
printf(c"%d %u %ld\n".as_ptr() as *const i8, 1, 2_u32, 3_i64);
34-
printf(c"hello world".as_ptr() as *const i8);
53+
(unsafe {
54+
libc::fprintf(
55+
libcc2rs::stdout_unsafe() as *mut ::libc::FILE,
56+
c"%s\n".as_ptr() as *const libc::c_char,
57+
(c"fprintf stdout".as_ptr()),
58+
)
59+
});
60+
(unsafe {
61+
libc::fprintf(
62+
libcc2rs::stdout_unsafe() as *mut ::libc::FILE,
63+
c"%d %u %ld\n".as_ptr() as *const libc::c_char,
64+
(1),
65+
(2_u32),
66+
(3_i64),
67+
)
68+
});
69+
(unsafe {
70+
libc::fprintf(
71+
libcc2rs::stdout_unsafe() as *mut ::libc::FILE,
72+
c"hello world".as_ptr() as *const libc::c_char,
73+
)
74+
});
3575
let mut in_: *mut ::libc::FILE = libcc2rs::stdin_unsafe();
3676
assert!(!((in_).is_null()));
37-
printf(c"%s\n".as_ptr() as *const i8, c"printf".as_ptr());
38-
printf(c"hello world".as_ptr() as *const i8);
77+
(unsafe {
78+
libc::printf(
79+
c"%s\n".as_ptr() as *const libc::c_char,
80+
(c"printf".as_ptr()),
81+
)
82+
});
83+
(unsafe { libc::printf(c"hello world".as_ptr() as *const libc::c_char) });
3984
let mut s: Vec<libc::c_char> = {
4085
let s = c"a string".as_ptr();
4186
std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1).to_vec()
4287
};
43-
printf(c"%s\n".as_ptr() as *const i8, s.as_mut_ptr());
44-
printf(
45-
c"%s\n".as_ptr() as *const i8,
46-
(unsafe {
47-
fn_0({
48-
let s = c"foo".as_ptr();
49-
std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1)
50-
.to_vec()
88+
(unsafe { libc::printf(c"%s\n".as_ptr() as *const libc::c_char, (s.as_mut_ptr())) });
89+
(unsafe {
90+
libc::printf(
91+
c"%s\n".as_ptr() as *const libc::c_char,
92+
((unsafe {
93+
fn_0({
94+
let s = c"foo".as_ptr();
95+
std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1)
96+
.to_vec()
97+
})
5198
})
52-
})
53-
.as_ptr(),
54-
);
55-
printf(
56-
c"%s\n".as_ptr() as *const i8,
57-
(*(unsafe { fn2_1(&s) })).as_ptr(),
58-
);
59-
printf(
60-
c"{} %ju %jd\n".as_ptr() as *const i8,
61-
5_u64,
62-
(-6_i32 as i64),
63-
);
99+
.as_ptr()),
100+
)
101+
});
102+
(unsafe {
103+
libc::printf(
104+
c"%s\n".as_ptr() as *const libc::c_char,
105+
((*(unsafe { fn2_1(&s) })).as_ptr()),
106+
)
107+
});
108+
(unsafe {
109+
log_to_2(
110+
libcc2rs::stdout_unsafe(),
111+
c"%s %d\n".as_ptr(),
112+
c"runtime".as_ptr(),
113+
4,
114+
)
115+
});
116+
(unsafe { log_to_3(libcc2rs::stderr_unsafe(), c"%d\n".as_ptr(), 5) });
117+
(unsafe { log_fmt_4(c"%d\n".as_ptr(), 6) });
118+
(unsafe {
119+
libc::printf(
120+
c"{} %ju %jd\n".as_ptr() as *const libc::c_char,
121+
(5_u64),
122+
(-6_i32 as i64),
123+
)
124+
});
64125
return 0;
65126
}
66127
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)