diff options
author | David Li <li.davidm96@gmail.com> | 2016-01-03 10:40:01 -0700 |
---|---|---|
committer | David Li <li.davidm96@gmail.com> | 2016-01-03 10:40:01 -0700 |
commit | 7ffec2b2ffe4246a6fe63f5b59ca399ae236236f (patch) | |
tree | 1f1e85fe55d9bc46921afeac8cf2aed20b524ef1 /src/lib.rs | |
parent | c845bc3877ce7722e4b161951af1e5c236cfc099 (diff) |
Fix write_byte, add basic tests
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with rustv. If not, see <http://www.gnu.org/licenses/>. -#![feature(associated_consts)] +#![feature(step_by)] pub mod isa; pub mod binary; pub mod memory; @@ -57,4 +57,25 @@ mod tests { assert_eq!(dm_cache_doubleword.parse_address(0xFFFFFFFD), (0x7FFFFFF, 3, 5)); } + + #[test] + fn memory_rw() { + use memory::*; + let size = 0xFF; + let mut memory = Memory::new(size); + + assert_eq!(memory.write_word(0, 0xF0), + Err(MemoryError::InvalidAddress)); + assert_eq!(memory.write_byte(0, 0xF0), + Err(MemoryError::InvalidAddress)); + assert_eq!(memory.write_byte(1, 0xF0), + Err(MemoryError::InvalidAddress)); + assert_eq!(memory.write_byte(2, 0xF0), + Err(MemoryError::InvalidAddress)); + + for address in (4..size).step_by(4) { + assert_eq!(memory.write_word(address, 0xF0), Ok(())); + assert_eq!(memory.read_word(address), Ok(0xF0)); + } + } } |