Skip to content

Commit 1e10aa4

Browse files
committed
Update tests
1 parent 5f316ca commit 1e10aa4

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

tests/unit/out/refcount/tag_vs_identifier_collision.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,31 @@ impl From<i32> for widget_enum {
2424
}
2525
}
2626
libcc2rs::impl_enum_inc_dec!(widget_enum);
27+
impl ByteRepr for widget_enum {
28+
fn to_bytes(&self, buf: &mut [u8]) {
29+
(*self as i32).to_bytes(buf);
30+
}
31+
fn from_bytes(buf: &[u8]) -> Self {
32+
<widget_enum>::from(i32::from_bytes(buf))
33+
}
34+
}
2735
#[derive(Default)]
2836
pub struct widget {
2937
pub id: Value<i32>,
3038
pub mode: Value<widget_enum>,
3139
}
32-
impl ByteRepr for widget {}
40+
impl ByteRepr for widget {
41+
fn to_bytes(&self, buf: &mut [u8]) {
42+
(*self.id.borrow()).to_bytes(&mut buf[0..4]);
43+
(*self.mode.borrow()).to_bytes(&mut buf[4..8]);
44+
}
45+
fn from_bytes(buf: &[u8]) -> Self {
46+
Self {
47+
id: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
48+
mode: Rc::new(RefCell::new(<widget_enum>::from_bytes(&buf[4..8]))),
49+
}
50+
}
51+
}
3352
#[derive(Default)]
3453
pub struct point_struct {
3554
pub x: Value<i32>,
@@ -115,6 +134,14 @@ impl From<i32> for slot {
115134
}
116135
}
117136
libcc2rs::impl_enum_inc_dec!(slot);
137+
impl ByteRepr for slot {
138+
fn to_bytes(&self, buf: &mut [u8]) {
139+
(*self as i32).to_bytes(buf);
140+
}
141+
fn from_bytes(buf: &[u8]) -> Self {
142+
<slot>::from(i32::from_bytes(buf))
143+
}
144+
}
118145
#[derive(Default)]
119146
pub struct Inner {
120147
pub tag_field: Value<i32>,

tests/unit/out/refcount/union_tagged_struct_arms.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ impl From<i32> for Choice_enum {
2424
}
2525
}
2626
libcc2rs::impl_enum_inc_dec!(Choice_enum);
27+
impl ByteRepr for Choice_enum {
28+
fn to_bytes(&self, buf: &mut [u8]) {
29+
(*self as i32).to_bytes(buf);
30+
}
31+
fn from_bytes(buf: &[u8]) -> Self {
32+
<Choice_enum>::from(i32::from_bytes(buf))
33+
}
34+
}
2735
#[derive(Default)]
2836
pub struct anon_1 {
2937
pub items: Value<Ptr<Ptr<u8>>>,

0 commit comments

Comments
 (0)