Add some more allocation tests

This commit is contained in:
Gwilym Kuiper 2021-08-16 23:20:51 +01:00
parent b30cc7715c
commit 22189eb809
2 changed files with 47 additions and 1 deletions

View file

@ -25,6 +25,8 @@ mod test {
use super::*;
use alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;
#[test_case]
fn test_box(_gba: &mut crate::Gba) {
@ -42,4 +44,48 @@ mod test {
address
);
}
#[test_case]
fn test_vec(_gba: &mut crate::Gba) {
let mut v = Vec::with_capacity(5);
for i in 0..100 {
v.push(i);
}
for i in 0..100 {
assert_eq!(v[i], i);
}
}
#[test_case]
fn test_creating_and_removing_things(_gba: &mut crate::Gba) {
let item = Box::new(1);
for i in 0..1_000 {
let x = Box::new(i);
assert_eq!(*x, i);
let address = &*x as *const _ as usize;
assert!(
address >= EWRAM_START && address < EWRAM_END,
"ewram is located between 0x0200_0000 and 0x0204_0000, address was actually found to be {:#010X}",
address
);
}
assert_eq!(*item, 1);
}
#[test_case]
fn test_adding_to_2_different_vectors(_gba: &mut crate::Gba) {
let mut v1 = vec![1, 2, 3];
let mut v2 = vec![4, 5, 6];
for i in 0..100 {
v1.push(i + 100);
v2.push(i + 1000);
}
assert_eq!(v1[40], 137);
assert_eq!(v2[78], 1075);
}
}