mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-06 19:40:10 +01:00
compiler/rust: Add a unit test for the memstream abstraction
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31718>
This commit is contained in:
parent
ec24156b31
commit
212e07a70e
3 changed files with 31 additions and 0 deletions
|
|
@ -148,3 +148,24 @@ impl Drop for MemStream {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_memstream() {
|
||||
use std::ffi::CString;
|
||||
|
||||
let mut s = MemStream::new().unwrap();
|
||||
let test_str = "Test string";
|
||||
let test_c_str = CString::new(test_str).unwrap();
|
||||
let test_bytes = test_c_str.as_bytes();
|
||||
|
||||
unsafe {
|
||||
bindings::compiler_rs_fwrite(
|
||||
test_bytes.as_ptr().cast(),
|
||||
1,
|
||||
test_bytes.len(),
|
||||
s.c_file(),
|
||||
);
|
||||
}
|
||||
let res = s.take_utf8_string_lossy().unwrap();
|
||||
assert_eq!(res, test_str);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,3 +26,10 @@ int compiler_rs_fseek(FILE *f, long offset, int whence)
|
|||
{
|
||||
return fseek(f, offset, whence);
|
||||
}
|
||||
|
||||
size_t compiler_rs_fwrite(const void *ptr,
|
||||
size_t size, size_t nmemb,
|
||||
FILE *stream)
|
||||
{
|
||||
return fwrite(ptr, size, nmemb, stream);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,3 +8,6 @@
|
|||
void compiler_rs_free(void *ptr);
|
||||
long compiler_rs_ftell(FILE *f);
|
||||
int compiler_rs_fseek(FILE *f, long offset, int whence);
|
||||
size_t compiler_rs_fwrite(const void *ptr,
|
||||
size_t size, size_t nmemb,
|
||||
FILE *stream);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue