Skip to content

Commit e85659f

Browse files
committed
Update tests
1 parent 34627ea commit e85659f

9 files changed

Lines changed: 519 additions & 5 deletions

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ bool ConverterRefCount::VisitMemberExpr(clang::MemberExpr *expr) {
14951495
Buffer buf(*this);
14961496
PushExprKind push(*this,
14971497
isLValue() ? ExprKind::LValue : ExprKind::RValue);
1498-
Converter::ConvertMemberExpr(expr); // e.g. (*u.borrow()).i
1498+
Converter::ConvertMemberExpr(expr);
14991499
str = std::move(buf).str();
15001500
}
15011501
str += "()";
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[derive(Clone, Copy, PartialEq, Debug, Default)]
10+
enum widget_enum {
11+
#[default]
12+
MODE_IDLE = 0,
13+
MODE_ACTIVE = 1,
14+
MODE_DONE = 2,
15+
}
16+
impl From<i32> for widget_enum {
17+
fn from(n: i32) -> widget_enum {
18+
match n {
19+
0 => widget_enum::MODE_IDLE,
20+
1 => widget_enum::MODE_ACTIVE,
21+
2 => widget_enum::MODE_DONE,
22+
_ => panic!("invalid widget_enum value: {}", n),
23+
}
24+
}
25+
}
26+
libcc2rs::impl_enum_inc_dec!(widget_enum);
27+
#[derive(Default)]
28+
pub struct widget {
29+
pub id: Value<i32>,
30+
pub mode: Value<widget_enum>,
31+
}
32+
impl ByteRepr for widget {}
33+
#[derive(Default)]
34+
pub struct point_struct {
35+
pub x: Value<i32>,
36+
pub y: Value<i32>,
37+
}
38+
impl ByteRepr for point_struct {
39+
fn to_bytes(&self, buf: &mut [u8]) {
40+
(*self.x.borrow()).to_bytes(&mut buf[0..4]);
41+
(*self.y.borrow()).to_bytes(&mut buf[4..8]);
42+
}
43+
fn from_bytes(buf: &[u8]) -> Self {
44+
Self {
45+
x: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
46+
y: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
47+
}
48+
}
49+
}
50+
#[derive(Clone)]
51+
pub struct point {
52+
__store: libcc2rs::UnionStorage,
53+
}
54+
impl point {
55+
pub fn whole(&self) -> Ptr<i32> {
56+
self.__store.reinterpret(0)
57+
}
58+
pub fn half(&self) -> Ptr<i16> {
59+
self.__store.reinterpret(0)
60+
}
61+
}
62+
impl Default for point {
63+
fn default() -> Self {
64+
point {
65+
__store: libcc2rs::UnionStorage::new(4),
66+
}
67+
}
68+
}
69+
impl ByteRepr for point {}
70+
#[derive(Clone)]
71+
pub struct slot_union {
72+
__store: libcc2rs::UnionStorage,
73+
}
74+
impl slot_union {
75+
pub fn i(&self) -> Ptr<i32> {
76+
self.__store.reinterpret(0)
77+
}
78+
pub fn u(&self) -> Ptr<u32> {
79+
self.__store.reinterpret(0)
80+
}
81+
}
82+
impl Default for slot_union {
83+
fn default() -> Self {
84+
slot_union {
85+
__store: libcc2rs::UnionStorage::new(4),
86+
}
87+
}
88+
}
89+
impl ByteRepr for slot_union {}
90+
#[derive(Clone, Copy, PartialEq, Debug, Default)]
91+
enum slot {
92+
#[default]
93+
SLOT_A = 0,
94+
SLOT_B = 1,
95+
}
96+
impl From<i32> for slot {
97+
fn from(n: i32) -> slot {
98+
match n {
99+
0 => slot::SLOT_A,
100+
1 => slot::SLOT_B,
101+
_ => panic!("invalid slot value: {}", n),
102+
}
103+
}
104+
}
105+
libcc2rs::impl_enum_inc_dec!(slot);
106+
#[derive(Default)]
107+
pub struct Inner {
108+
pub tag_field: Value<i32>,
109+
}
110+
impl ByteRepr for Inner {
111+
fn to_bytes(&self, buf: &mut [u8]) {
112+
(*self.tag_field.borrow()).to_bytes(&mut buf[0..4]);
113+
}
114+
fn from_bytes(buf: &[u8]) -> Self {
115+
Self {
116+
tag_field: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
117+
}
118+
}
119+
}
120+
#[derive(Default)]
121+
pub struct Outer {
122+
pub field: Value<Inner>,
123+
}
124+
impl ByteRepr for Outer {}
125+
#[derive(Default)]
126+
pub struct Inner_struct {
127+
pub typedef_field: Value<i32>,
128+
}
129+
impl ByteRepr for Inner_struct {
130+
fn to_bytes(&self, buf: &mut [u8]) {
131+
(*self.typedef_field.borrow()).to_bytes(&mut buf[0..4]);
132+
}
133+
fn from_bytes(buf: &[u8]) -> Self {
134+
Self {
135+
typedef_field: Rc::new(RefCell::new(<i32>::from_bytes(&buf[0..4]))),
136+
}
137+
}
138+
}
139+
pub fn is_active_0(w: Ptr<widget>) -> i32 {
140+
let w: Value<Ptr<widget>> = Rc::new(RefCell::new(w));
141+
return (({
142+
let _lhs = ((*(*(*w.borrow()).upgrade().deref()).mode.borrow()) as u32).clone();
143+
_lhs == ((widget_enum::MODE_ACTIVE as i32) as u32)
144+
}) as i32);
145+
}
146+
pub fn main() {
147+
std::process::exit(main_0());
148+
}
149+
fn main_0() -> i32 {
150+
let w: Value<widget> = <Value<widget>>::default();
151+
(*(*w.borrow()).id.borrow_mut()) = 7;
152+
(*(*w.borrow()).mode.borrow_mut()) = widget_enum::MODE_ACTIVE;
153+
assert!(
154+
(({
155+
let _w: Ptr<widget> = (w.as_pointer());
156+
is_active_0(_w)
157+
}) != 0)
158+
);
159+
(*(*w.borrow()).mode.borrow_mut()) = widget_enum::MODE_DONE;
160+
assert!(
161+
(((((*(*w.borrow()).mode.borrow()) as u32) == ((widget_enum::MODE_DONE as i32) as u32))
162+
as i32)
163+
!= 0)
164+
);
165+
let p: Value<point_struct> = <Value<point_struct>>::default();
166+
(*(*p.borrow()).x.borrow_mut()) = 3;
167+
(*(*p.borrow()).y.borrow_mut()) = 4;
168+
assert!((((((*(*p.borrow()).x.borrow()) + (*(*p.borrow()).y.borrow())) == 7) as i32) != 0));
169+
let up: Value<point> = <Value<point>>::default();
170+
(*up.borrow_mut()).whole().write(5);
171+
assert!((((((*up.borrow()).whole().read()) == 5) as i32) != 0));
172+
let b: Value<slot_union> = <Value<slot_union>>::default();
173+
(*b.borrow_mut()).i().write(9);
174+
assert!((((((*b.borrow()).i().read()) == 9) as i32) != 0));
175+
let e: Value<slot> = Rc::new(RefCell::new(slot::SLOT_B));
176+
assert!((((((*e.borrow()) as u32) == ((slot::SLOT_B as i32) as u32)) as i32) != 0));
177+
let inner_tag: Value<Inner> = <Value<Inner>>::default();
178+
(*(*inner_tag.borrow()).tag_field.borrow_mut()) = 11;
179+
assert!(((((*(*inner_tag.borrow()).tag_field.borrow()) == 11) as i32) != 0));
180+
let inner_typedef: Value<Inner_struct> = <Value<Inner_struct>>::default();
181+
(*(*inner_typedef.borrow()).typedef_field.borrow_mut()) = 22;
182+
assert!(((((*(*inner_typedef.borrow()).typedef_field.borrow()) == 22) as i32) != 0));
183+
let o: Value<Outer> = <Value<Outer>>::default();
184+
(*(*(*o.borrow()).field.borrow()).tag_field.borrow_mut()) = 33;
185+
assert!(((((*(*(*o.borrow()).field.borrow()).tag_field.borrow()) == 33) as i32) != 0));
186+
return (*(*w.borrow()).id.borrow());
187+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[derive(Clone)]
10+
pub struct basic {
11+
__store: libcc2rs::UnionStorage,
12+
}
13+
impl basic {
14+
pub fn i(&self) -> Ptr<i32> {
15+
self.__store.reinterpret(0)
16+
}
17+
pub fn f(&self) -> Ptr<f32> {
18+
self.__store.reinterpret(0)
19+
}
20+
}
21+
impl Default for basic {
22+
fn default() -> Self {
23+
basic {
24+
__store: libcc2rs::UnionStorage::new(4),
25+
}
26+
}
27+
}
28+
impl ByteRepr for basic {}
29+
pub fn main() {
30+
std::process::exit(main_0());
31+
}
32+
fn main_0() -> i32 {
33+
let u: Value<basic> = <Value<basic>>::default();
34+
(*u.borrow_mut()).i().write(42);
35+
assert!((((((*u.borrow()).i().read()) == 42) as i32) != 0));
36+
(*u.borrow_mut()).f().write(3.140000105E+0);
37+
assert!((((((*u.borrow()).f().read()) == 3.140000105E+0) as i32) != 0));
38+
return 0;
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
pub fn main() {
10+
std::process::exit(main_0());
11+
}
12+
fn main_0() -> i32 {
13+
let x: Value<i64> = Rc::new(RefCell::new((-1_i32 as i64)));
14+
#[derive(Clone)]
15+
pub struct anon_0 {
16+
__store: libcc2rs::UnionStorage,
17+
}
18+
impl anon_0 {
19+
pub fn as_unsigned(&self) -> Ptr<Ptr<u64>> {
20+
self.__store.reinterpret(0)
21+
}
22+
pub fn as_signed(&self) -> Ptr<Ptr<i64>> {
23+
self.__store.reinterpret(0)
24+
}
25+
}
26+
impl Default for anon_0 {
27+
fn default() -> Self {
28+
anon_0 {
29+
__store: libcc2rs::UnionStorage::new(8),
30+
}
31+
}
32+
}
33+
impl ByteRepr for anon_0 {};
34+
let pp: Value<anon_0> = <Value<anon_0>>::default();
35+
(*pp.borrow_mut()).as_signed().write((x.as_pointer()));
36+
((*pp.borrow()).as_unsigned().read()).write(42_u64);
37+
assert!(((((*x.borrow()) == 42_i64) as i32) != 0));
38+
return 0;
39+
}

0 commit comments

Comments
 (0)