Skip to content

Commit 198b11d

Browse files
committed
Add string_literals test
1 parent 54df7c2 commit 198b11d

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 mutable_strings: Value<Box<[Ptr<u8>]>> = Rc::new(RefCell::new(Box::new([
14+
Ptr::from_string_literal("a"),
15+
Ptr::from_string_literal("b"),
16+
Ptr::from_string_literal("c"),
17+
])));
18+
let immutable_strings: Value<Box<[Ptr<u8>]>> = Rc::new(RefCell::new(Box::new([
19+
Ptr::from_string_literal("a"),
20+
Ptr::from_string_literal("b"),
21+
Ptr::from_string_literal("c"),
22+
])));
23+
let mutable_string: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal("hello")));
24+
let immutable_string: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal("hello")));
25+
return 0;
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 fn main() {
10+
unsafe {
11+
std::process::exit(main_0() as i32);
12+
}
13+
}
14+
unsafe fn main_0() -> i32 {
15+
let mut mutable_strings: [*mut u8; 3] = [
16+
b"a\0".as_ptr().cast_mut(),
17+
b"b\0".as_ptr().cast_mut(),
18+
b"c\0".as_ptr().cast_mut(),
19+
];
20+
let mut immutable_strings: [*const u8; 3] = [b"a\0".as_ptr(), b"b\0".as_ptr(), b"c\0".as_ptr()];
21+
let mut mutable_string: *mut u8 = b"hello\0".as_ptr().cast_mut();
22+
let mut immutable_string: *const u8 = b"hello\0".as_ptr();
23+
return 0;
24+
}

tests/unit/string_literals.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main() {
2+
char *mutable_strings[] = {"a", "b", "c"};
3+
const char *immutable_strings[] = {"a", "b", "c"};
4+
5+
char *mutable_string = "hello";
6+
const char *immutable_string = "hello";
7+
return 0;
8+
}

0 commit comments

Comments
 (0)