Skip to content

Commit 2002980

Browse files
committed
Add initialize rlist test
1 parent 3acd6a5 commit 2002980

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

tests/unit/initializer_list.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <cassert>
2+
#include <cstddef>
3+
#include <initializer_list>
4+
#include <vector>
5+
6+
size_t f(std::initializer_list<int> bytes) {
7+
std::vector<int> *buf = new std::vector<int>(bytes);
8+
size_t n = bytes.size();
9+
delete buf;
10+
return n;
11+
}
12+
13+
int main() {
14+
assert(f({1, 2, 3}) == 3);
15+
return 0;
16+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 f_0(bytes: Vec<i32>) -> u64 {
10+
let bytes: Value<Vec<i32>> = Rc::new(RefCell::new(bytes));
11+
let buf: Value<Ptr<Vec<i32>>> = Rc::new(RefCell::new(Ptr::alloc((*bytes.borrow()))));
12+
let n: Value<u64> = Rc::new(RefCell::new((*bytes.borrow()).len() as u64));
13+
(*buf.borrow()).delete();
14+
return (*n.borrow());
15+
}
16+
pub fn main() {
17+
std::process::exit(main_0());
18+
}
19+
fn main_0() -> i32 {
20+
assert!(
21+
(({
22+
let _bytes: Vec<i32> = vec![1, 2, 3];
23+
f_0(_bytes)
24+
}) == 3_u64)
25+
);
26+
return 0;
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
pub unsafe fn f_0(mut bytes: Vec<i32>) -> u64 {
10+
let mut buf: *mut Vec<i32> = (Box::leak(Box::new(bytes)) as *mut Vec<i32>);
11+
let mut n: u64 = bytes.len() as u64;
12+
::std::mem::drop(Box::from_raw(buf));
13+
return n;
14+
}
15+
pub fn main() {
16+
unsafe {
17+
std::process::exit(main_0() as i32);
18+
}
19+
}
20+
unsafe fn main_0() -> i32 {
21+
assert!(
22+
((unsafe {
23+
let _bytes: Vec<i32> = vec![1, 2, 3];
24+
f_0(_bytes)
25+
}) == (3_u64))
26+
);
27+
return 0;
28+
}

0 commit comments

Comments
 (0)