Skip to content

Commit 084744a

Browse files
committed
Update tests
1 parent 6d8ce1c commit 084744a

2 files changed

Lines changed: 33 additions & 54 deletions

File tree

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

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,65 +7,54 @@ use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
99
#[derive()]
10-
pub struct WOFF2Params {
11-
pub extended_metadata: Value<Vec<u8>>,
12-
pub brotli_quality: Value<i32>,
13-
pub allow_transforms: Value<bool>,
10+
pub struct S {
11+
pub a: Value<i32>,
12+
pub b: Value<bool>,
1413
}
15-
impl WOFF2Params {
16-
pub fn WOFF2Params() -> Self {
14+
impl S {
15+
pub fn S() -> Self {
1716
let mut this = Self {
18-
extended_metadata: Rc::new(RefCell::new(
19-
Ptr::from_string_literal(b"")
20-
.to_c_string_iterator()
21-
.chain(std::iter::once(0))
22-
.collect::<Vec<u8>>(),
23-
)),
24-
brotli_quality: Rc::new(RefCell::new(11)),
25-
allow_transforms: Rc::new(RefCell::new(true)),
17+
a: Rc::new(RefCell::new(11)),
18+
b: Rc::new(RefCell::new(true)),
2619
};
2720
this
2821
}
2922
}
30-
impl Clone for WOFF2Params {
23+
impl Clone for S {
3124
fn clone(&self) -> Self {
3225
let mut this = Self {
33-
extended_metadata: Rc::new(RefCell::new((*self.extended_metadata.borrow()).clone())),
34-
brotli_quality: Rc::new(RefCell::new((*self.brotli_quality.borrow()))),
35-
allow_transforms: Rc::new(RefCell::new((*self.allow_transforms.borrow()))),
26+
a: Rc::new(RefCell::new((*self.a.borrow()))),
27+
b: Rc::new(RefCell::new((*self.b.borrow()))),
3628
};
3729
this
3830
}
3931
}
40-
impl Default for WOFF2Params {
32+
impl Default for S {
4133
fn default() -> Self {
42-
{ WOFF2Params::WOFF2Params() }
34+
{ S::S() }
4335
}
4436
}
45-
impl ByteRepr for WOFF2Params {
37+
impl ByteRepr for S {
4638
fn byte_size() -> usize {
47-
40
39+
8
4840
}
4941
fn to_bytes(&self, buf: &mut [u8]) {
50-
(*self.extended_metadata.borrow()).to_bytes(&mut buf[0..32]);
51-
(*self.brotli_quality.borrow()).to_bytes(&mut buf[32..36]);
52-
(*self.allow_transforms.borrow()).to_bytes(&mut buf[36..37]);
42+
(*self.a.borrow()).to_bytes(&mut buf[0..4]);
43+
(*self.b.borrow()).to_bytes(&mut buf[4..5]);
5344
}
5445
fn from_bytes(buf: &[u8]) -> Self {
5546
Self {
56-
extended_metadata: Rc::new(RefCell::new(<Vec<u8>>::from_bytes(&buf[0..32]))),
57-
brotli_quality: Rc::new(RefCell::new(<i32>::from_bytes(&buf[32..36]))),
58-
allow_transforms: Rc::new(RefCell::new(<bool>::from_bytes(&buf[36..37]))),
47+
a: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
48+
b: Rc::new(RefCell::new(<bool>::from_bytes(&buf[4..5]))),
5949
}
6050
}
6151
}
6252
pub fn main() {
6353
std::process::exit(main_0());
6454
}
6555
fn main_0() -> i32 {
66-
let params: Value<WOFF2Params> = Rc::new(RefCell::new(WOFF2Params::WOFF2Params()));
67-
assert!((((*(*params.borrow()).extended_metadata.borrow()).len() - 1) == 0_usize));
68-
assert!(((*(*params.borrow()).brotli_quality.borrow()) == 11));
69-
assert!((((*(*params.borrow()).allow_transforms.borrow()) as i32) == (true as i32)));
56+
let s: Value<S> = Rc::new(RefCell::new(S::S()));
57+
assert!(((*(*s.borrow()).a.borrow()) == 11));
58+
assert!((((*(*s.borrow()).b.borrow()) as i32) == (true as i32)));
7059
return 0;
7160
}

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,20 @@ use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
99
#[repr(C)]
10-
#[derive(Clone)]
11-
pub struct WOFF2Params {
12-
pub extended_metadata: Vec<libc::c_char>,
13-
pub brotli_quality: i32,
14-
pub allow_transforms: bool,
10+
#[derive(Copy, Clone)]
11+
pub struct S {
12+
pub a: i32,
13+
pub b: bool,
1514
}
16-
impl WOFF2Params {
17-
pub unsafe fn WOFF2Params() -> Self {
18-
let mut this = Self {
19-
extended_metadata: {
20-
let s = c"".as_ptr();
21-
std::slice::from_raw_parts(s, (0..).take_while(|&i| *s.add(i) != 0).count() + 1)
22-
.to_vec()
23-
},
24-
brotli_quality: 11,
25-
allow_transforms: true,
26-
};
15+
impl S {
16+
pub unsafe fn S() -> Self {
17+
let mut this = Self { a: 11, b: true };
2718
this
2819
}
2920
}
30-
impl Default for WOFF2Params {
21+
impl Default for S {
3122
fn default() -> Self {
32-
unsafe { WOFF2Params::WOFF2Params() }
23+
unsafe { S::S() }
3324
}
3425
}
3526
pub fn main() {
@@ -38,9 +29,8 @@ pub fn main() {
3829
}
3930
}
4031
unsafe fn main_0() -> i32 {
41-
let mut params: WOFF2Params = WOFF2Params::WOFF2Params();
42-
assert!(((params.extended_metadata.len() - 1) == (0_usize)));
43-
assert!(((params.brotli_quality) == (11)));
44-
assert!(((params.allow_transforms as i32) == (true as i32)));
32+
let mut s: S = S::S();
33+
assert!(((s.a) == (11)));
34+
assert!(((s.b as i32) == (true as i32)));
4535
return 0;
4636
}

0 commit comments

Comments
 (0)