diff --git a/agb/src/agb_alloc/block_allocator.rs b/agb/src/agb_alloc/block_allocator.rs index 03bd4359..f876e0a5 100644 --- a/agb/src/agb_alloc/block_allocator.rs +++ b/agb/src/agb_alloc/block_allocator.rs @@ -75,7 +75,7 @@ unsafe impl GlobalAlloc for BlockAllocator { // find a block that this current request fits in let block_layout = Layout::new::(); let (full_layout, offset) = block_layout.extend(layout).unwrap(); - + { let state = self.state.lock(); let mut current_block = state.first_block; diff --git a/agb/src/agb_alloc/mod.rs b/agb/src/agb_alloc/mod.rs index b67ff9ff..edc8efc1 100644 --- a/agb/src/agb_alloc/mod.rs +++ b/agb/src/agb_alloc/mod.rs @@ -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); + } }