Skip to content

Commit c66a712

Browse files
committed
Update tests
1 parent 7db5002 commit c66a712

49 files changed

Lines changed: 547 additions & 137 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pub struct widget {
1111
pub id: Value<i32>,
1212
}
1313
impl ByteRepr for widget {
14+
fn byte_size() -> usize {
15+
4
16+
}
1417
fn to_bytes(&self, buf: &mut [u8]) {
1518
(*self.id.borrow()).to_bytes(&mut buf[0..4]);
1619
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ impl Clone for Inner {
1919
}
2020
}
2121
impl ByteRepr for Inner {
22+
fn byte_size() -> usize {
23+
4
24+
}
2225
fn to_bytes(&self, buf: &mut [u8]) {
2326
(*self.value.borrow()).to_bytes(&mut buf[0..4]);
2427
}

‎tests/unit/out/refcount/anonymous-struct.rs‎

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ impl Clone for Outer_Named {
2121
}
2222
}
2323
impl ByteRepr for Outer_Named {
24+
fn byte_size() -> usize {
25+
8
26+
}
2427
fn to_bytes(&self, buf: &mut [u8]) {
2528
(*self.a.borrow()).to_bytes(&mut buf[0..4]);
2629
(*self.b.borrow()).to_bytes(&mut buf[4..8]);
@@ -47,6 +50,9 @@ impl Clone for anon_0 {
4750
}
4851
}
4952
impl ByteRepr for anon_0 {
53+
fn byte_size() -> usize {
54+
8
55+
}
5056
fn to_bytes(&self, buf: &mut [u8]) {
5157
(*self.c.borrow()).to_bytes(&mut buf[0..4]);
5258
(*self.d.borrow()).to_bytes(&mut buf[4..8]);
@@ -73,6 +79,9 @@ impl Clone for anon_1 {
7379
}
7480
}
7581
impl ByteRepr for anon_1 {
82+
fn byte_size() -> usize {
83+
8
84+
}
7685
fn to_bytes(&self, buf: &mut [u8]) {
7786
(*self.g.borrow()).to_bytes(&mut buf[0..4]);
7887
(*self.h.borrow()).to_bytes(&mut buf[4..8]);
@@ -99,6 +108,9 @@ impl Clone for anon_2 {
99108
}
100109
}
101110
impl ByteRepr for anon_2 {
111+
fn byte_size() -> usize {
112+
8
113+
}
102114
fn to_bytes(&self, buf: &mut [u8]) {
103115
(*self.e.borrow()).to_bytes(&mut buf[0..4]);
104116
(*self.f.borrow()).to_bytes(&mut buf[4..8]);
@@ -123,6 +135,9 @@ impl Clone for anon_4 {
123135
}
124136
}
125137
impl ByteRepr for anon_4 {
138+
fn byte_size() -> usize {
139+
4
140+
}
126141
fn to_bytes(&self, buf: &mut [u8]) {
127142
(*self.j.borrow()).to_bytes(&mut buf[0..4]);
128143
}
@@ -145,6 +160,9 @@ impl Clone for anon_5 {
145160
}
146161
}
147162
impl ByteRepr for anon_5 {
163+
fn byte_size() -> usize {
164+
4
165+
}
148166
fn to_bytes(&self, buf: &mut [u8]) {
149167
(*self.k.borrow()).to_bytes(&mut buf[0..4]);
150168
}
@@ -170,7 +188,23 @@ impl Clone for anon_3 {
170188
this
171189
}
172190
}
173-
impl ByteRepr for anon_3 {}
191+
impl ByteRepr for anon_3 {
192+
fn byte_size() -> usize {
193+
12
194+
}
195+
fn to_bytes(&self, buf: &mut [u8]) {
196+
(*self.i.borrow()).to_bytes(&mut buf[0..4]);
197+
(*self.inner_named.borrow()).to_bytes(&mut buf[4..8]);
198+
(*self.anon_5.borrow()).to_bytes(&mut buf[8..12]);
199+
}
200+
fn from_bytes(buf: &[u8]) -> Self {
201+
Self {
202+
i: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
203+
inner_named: Rc::new(RefCell::new(<anon_4>::from_bytes(&buf[4..8]))),
204+
anon_5: Rc::new(RefCell::new(<anon_5>::from_bytes(&buf[8..12]))),
205+
}
206+
}
207+
}
174208
#[derive(Default)]
175209
pub struct Outer {
176210
pub named: Value<Outer_Named>,
@@ -191,7 +225,27 @@ impl Clone for Outer {
191225
this
192226
}
193227
}
194-
impl ByteRepr for Outer {}
228+
impl ByteRepr for Outer {
229+
fn byte_size() -> usize {
230+
44
231+
}
232+
fn to_bytes(&self, buf: &mut [u8]) {
233+
(*self.named.borrow()).to_bytes(&mut buf[0..8]);
234+
(*self.anonymous_named_0.borrow()).to_bytes(&mut buf[8..16]);
235+
(*self.anonymous_named_1.borrow()).to_bytes(&mut buf[16..24]);
236+
(*self.anon_2.borrow()).to_bytes(&mut buf[24..32]);
237+
(*self.anon_3.borrow()).to_bytes(&mut buf[32..44]);
238+
}
239+
fn from_bytes(buf: &[u8]) -> Self {
240+
Self {
241+
named: Rc::new(RefCell::new(<Outer_Named>::from_bytes(&buf[0..8]))),
242+
anonymous_named_0: Rc::new(RefCell::new(<anon_0>::from_bytes(&buf[8..16]))),
243+
anonymous_named_1: Rc::new(RefCell::new(<anon_1>::from_bytes(&buf[16..24]))),
244+
anon_2: Rc::new(RefCell::new(<anon_2>::from_bytes(&buf[24..32]))),
245+
anon_3: Rc::new(RefCell::new(<anon_3>::from_bytes(&buf[32..44]))),
246+
}
247+
}
248+
}
195249
pub fn main() {
196250
std::process::exit(main_0());
197251
}
@@ -274,6 +328,9 @@ fn main_0() -> i32 {
274328
}
275329
}
276330
impl ByteRepr for anon_6 {
331+
fn byte_size() -> usize {
332+
8
333+
}
277334
fn to_bytes(&self, buf: &mut [u8]) {
278335
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
279336
(*self.z.borrow()).to_bytes(&mut buf[4..8]);

‎tests/unit/out/refcount/anonymous-struct_c.rs‎

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub struct Named {
1212
pub b: Value<i32>,
1313
}
1414
impl ByteRepr for Named {
15+
fn byte_size() -> usize {
16+
8
17+
}
1518
fn to_bytes(&self, buf: &mut [u8]) {
1619
(*self.a.borrow()).to_bytes(&mut buf[0..4]);
1720
(*self.b.borrow()).to_bytes(&mut buf[4..8]);
@@ -29,6 +32,9 @@ pub struct anon_0 {
2932
pub d: Value<i32>,
3033
}
3134
impl ByteRepr for anon_0 {
35+
fn byte_size() -> usize {
36+
8
37+
}
3238
fn to_bytes(&self, buf: &mut [u8]) {
3339
(*self.c.borrow()).to_bytes(&mut buf[0..4]);
3440
(*self.d.borrow()).to_bytes(&mut buf[4..8]);
@@ -46,6 +52,9 @@ pub struct anon_1 {
4652
pub h: Value<i32>,
4753
}
4854
impl ByteRepr for anon_1 {
55+
fn byte_size() -> usize {
56+
8
57+
}
4958
fn to_bytes(&self, buf: &mut [u8]) {
5059
(*self.g.borrow()).to_bytes(&mut buf[0..4]);
5160
(*self.h.borrow()).to_bytes(&mut buf[4..8]);
@@ -63,6 +72,9 @@ pub struct anon_2 {
6372
pub f: Value<i32>,
6473
}
6574
impl ByteRepr for anon_2 {
75+
fn byte_size() -> usize {
76+
8
77+
}
6678
fn to_bytes(&self, buf: &mut [u8]) {
6779
(*self.e.borrow()).to_bytes(&mut buf[0..4]);
6880
(*self.f.borrow()).to_bytes(&mut buf[4..8]);
@@ -79,6 +91,9 @@ pub struct anon_4 {
7991
pub j: Value<i32>,
8092
}
8193
impl ByteRepr for anon_4 {
94+
fn byte_size() -> usize {
95+
4
96+
}
8297
fn to_bytes(&self, buf: &mut [u8]) {
8398
(*self.j.borrow()).to_bytes(&mut buf[0..4]);
8499
}
@@ -93,6 +108,9 @@ pub struct anon_5 {
93108
pub k: Value<i32>,
94109
}
95110
impl ByteRepr for anon_5 {
111+
fn byte_size() -> usize {
112+
4
113+
}
96114
fn to_bytes(&self, buf: &mut [u8]) {
97115
(*self.k.borrow()).to_bytes(&mut buf[0..4]);
98116
}
@@ -108,7 +126,23 @@ pub struct anon_3 {
108126
pub inner_named: Value<anon_4>,
109127
pub anon_5: Value<anon_5>,
110128
}
111-
impl ByteRepr for anon_3 {}
129+
impl ByteRepr for anon_3 {
130+
fn byte_size() -> usize {
131+
12
132+
}
133+
fn to_bytes(&self, buf: &mut [u8]) {
134+
(*self.i.borrow()).to_bytes(&mut buf[0..4]);
135+
(*self.inner_named.borrow()).to_bytes(&mut buf[4..8]);
136+
(*self.anon_5.borrow()).to_bytes(&mut buf[8..12]);
137+
}
138+
fn from_bytes(buf: &[u8]) -> Self {
139+
Self {
140+
i: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
141+
inner_named: Rc::new(RefCell::new(<anon_4>::from_bytes(&buf[4..8]))),
142+
anon_5: Rc::new(RefCell::new(<anon_5>::from_bytes(&buf[8..12]))),
143+
}
144+
}
145+
}
112146
#[derive(Default)]
113147
pub struct Outer {
114148
pub named: Value<Named>,
@@ -117,7 +151,27 @@ pub struct Outer {
117151
pub anon_2: Value<anon_2>,
118152
pub anon_3: Value<anon_3>,
119153
}
120-
impl ByteRepr for Outer {}
154+
impl ByteRepr for Outer {
155+
fn byte_size() -> usize {
156+
44
157+
}
158+
fn to_bytes(&self, buf: &mut [u8]) {
159+
(*self.named.borrow()).to_bytes(&mut buf[0..8]);
160+
(*self.anon0.borrow()).to_bytes(&mut buf[8..16]);
161+
(*self.anon1.borrow()).to_bytes(&mut buf[16..24]);
162+
(*self.anon_2.borrow()).to_bytes(&mut buf[24..32]);
163+
(*self.anon_3.borrow()).to_bytes(&mut buf[32..44]);
164+
}
165+
fn from_bytes(buf: &[u8]) -> Self {
166+
Self {
167+
named: Rc::new(RefCell::new(<Named>::from_bytes(&buf[0..8]))),
168+
anon0: Rc::new(RefCell::new(<anon_0>::from_bytes(&buf[8..16]))),
169+
anon1: Rc::new(RefCell::new(<anon_1>::from_bytes(&buf[16..24]))),
170+
anon_2: Rc::new(RefCell::new(<anon_2>::from_bytes(&buf[24..32]))),
171+
anon_3: Rc::new(RefCell::new(<anon_3>::from_bytes(&buf[32..44]))),
172+
}
173+
}
174+
}
121175
pub fn main() {
122176
std::process::exit(main_0());
123177
}
@@ -176,6 +230,9 @@ fn main_0() -> i32 {
176230
pub z: Value<i32>,
177231
}
178232
impl ByteRepr for anon_6 {
233+
fn byte_size() -> usize {
234+
8
235+
}
179236
fn to_bytes(&self, buf: &mut [u8]) {
180237
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
181238
(*self.z.borrow()).to_bytes(&mut buf[4..8]);

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

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ impl From<i32> for anon_0 {
2222
}
2323
}
2424
libcc2rs::impl_enum_inc_dec!(anon_0);
25-
impl ByteRepr for anon_0 {
26-
fn to_bytes(&self, buf: &mut [u8]) {
27-
(*self as i32).to_bytes(buf);
28-
}
29-
fn from_bytes(buf: &[u8]) -> Self {
30-
<anon_0>::from(i32::from_bytes(buf))
31-
}
32-
}
3325
#[derive(Clone, Copy, PartialEq, Debug, Default)]
3426
enum anon_1 {
3527
#[default]
@@ -46,14 +38,6 @@ impl From<i32> for anon_1 {
4638
}
4739
}
4840
libcc2rs::impl_enum_inc_dec!(anon_1);
49-
impl ByteRepr for anon_1 {
50-
fn to_bytes(&self, buf: &mut [u8]) {
51-
(*self as i32).to_bytes(buf);
52-
}
53-
fn from_bytes(buf: &[u8]) -> Self {
54-
<anon_1>::from(i32::from_bytes(buf))
55-
}
56-
}
5741
#[derive(Default)]
5842
pub struct S {
5943
pub a: Value<i32>,
@@ -67,6 +51,9 @@ impl Clone for S {
6751
}
6852
}
6953
impl ByteRepr for S {
54+
fn byte_size() -> usize {
55+
4
56+
}
7057
fn to_bytes(&self, buf: &mut [u8]) {
7158
(*self.a.borrow()).to_bytes(&mut buf[0..4]);
7259
}
@@ -92,14 +79,6 @@ impl From<i32> for TdEnum {
9279
}
9380
}
9481
libcc2rs::impl_enum_inc_dec!(TdEnum);
95-
impl ByteRepr for TdEnum {
96-
fn to_bytes(&self, buf: &mut [u8]) {
97-
(*self as i32).to_bytes(buf);
98-
}
99-
fn from_bytes(buf: &[u8]) -> Self {
100-
<TdEnum>::from(i32::from_bytes(buf))
101-
}
102-
}
10382
#[derive(Clone, Copy, PartialEq, Debug, Default)]
10483
enum anon_2 {
10584
#[default]
@@ -116,14 +95,6 @@ impl From<i32> for anon_2 {
11695
}
11796
}
11897
libcc2rs::impl_enum_inc_dec!(anon_2);
119-
impl ByteRepr for anon_2 {
120-
fn to_bytes(&self, buf: &mut [u8]) {
121-
(*self as i32).to_bytes(buf);
122-
}
123-
fn from_bytes(buf: &[u8]) -> Self {
124-
<anon_2>::from(i32::from_bytes(buf))
125-
}
126-
}
12798
#[derive(Default)]
12899
pub struct WithAnonField {
129100
pub a: Value<i32>,
@@ -138,18 +109,7 @@ impl Clone for WithAnonField {
138109
this
139110
}
140111
}
141-
impl ByteRepr for WithAnonField {
142-
fn to_bytes(&self, buf: &mut [u8]) {
143-
(*self.a.borrow()).to_bytes(&mut buf[0..4]);
144-
(*self.field.borrow()).to_bytes(&mut buf[4..8]);
145-
}
146-
fn from_bytes(buf: &[u8]) -> Self {
147-
Self {
148-
a: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
149-
field: Rc::new(RefCell::new(<anon_2>::from_bytes(&buf[4..8]))),
150-
}
151-
}
152-
}
112+
impl ByteRepr for WithAnonField {}
153113
pub fn main() {
154114
std::process::exit(main_0());
155115
}
@@ -170,14 +130,6 @@ fn main_0() -> i32 {
170130
}
171131
}
172132
libcc2rs::impl_enum_inc_dec!(anon_3);
173-
impl ByteRepr for anon_3 {
174-
fn to_bytes(&self, buf: &mut [u8]) {
175-
(*self as i32).to_bytes(buf);
176-
}
177-
fn from_bytes(buf: &[u8]) -> Self {
178-
<anon_3>::from(i32::from_bytes(buf))
179-
}
180-
};
181133
assert!(((anon_0::FIRST_A as i32) != (anon_0::FIRST_B as i32)));
182134
assert!(((anon_1::SECOND_A as i32) != (anon_1::SECOND_B as i32)));
183135
assert!(((anon_3::THIRD_A as i32) != (anon_3::THIRD_B as i32)));

0 commit comments

Comments
 (0)