test create mem check
This commit is contained in:
parent
b29cd7cc82
commit
6945128f72
@ -73,6 +73,13 @@ impl Section{
|
||||
|
||||
Section{addr:addr, len:len, content:content}
|
||||
}
|
||||
|
||||
|
||||
fn print_Section(s: &Section){
|
||||
println!("ADDR :: {}", s.addr);
|
||||
println!("LEN :: {}", s.len);
|
||||
println!("CONTENT :: {:?}", s.content);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -86,12 +93,18 @@ struct Mem_Checker{
|
||||
|
||||
|
||||
impl Mem_Checker{
|
||||
fn from(path: &String) /*-> Mem_Checker*/{
|
||||
|
||||
fn from(path: &String) -> Mem_Checker {
|
||||
|
||||
let file = fs::File::open("test_file_section.txt").expect("Wrong filename");
|
||||
let reader = io::BufReader::new(file);
|
||||
|
||||
let mut pc: usize = 0;
|
||||
let mut sp: usize = 0;
|
||||
let mut sections: Vec<Section> = Vec::new();
|
||||
|
||||
let mut tmp_addr_str: String = String::new();
|
||||
let mut tmp_len_str: String = String::new();
|
||||
|
||||
for (i,line) in reader.lines().enumerate() {
|
||||
|
||||
@ -107,8 +120,38 @@ impl Mem_Checker{
|
||||
}
|
||||
else {
|
||||
//Lecture des sections
|
||||
if current_line.contains(' ') {
|
||||
//lecture ligne ADDR LEN
|
||||
let next_word_index = current_line.find(' ').unwrap();
|
||||
tmp_addr_str = String::from(¤t_line[0..next_word_index]);
|
||||
tmp_len_str = String::from(¤t_line[next_word_index+1..]);
|
||||
}
|
||||
else {
|
||||
//lecture ligne CONTENT
|
||||
let section_f = SectionFormat{
|
||||
addr: tmp_addr_str.clone(),
|
||||
len: tmp_len_str.clone(),
|
||||
content: current_line,
|
||||
};
|
||||
sections.push(Section::from(§ion_f));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Mem_Checker{pc:pc, sp:sp, sections:sections}
|
||||
}
|
||||
|
||||
|
||||
fn print_Mem_Checker(m_c: &Mem_Checker){
|
||||
println!("PC :: {}", m_c.pc);
|
||||
println!("SP :: {}", m_c.sp);
|
||||
|
||||
for(i,s) in m_c.sections.iter().enumerate() {
|
||||
println!("\nSection {}\n", i);
|
||||
Section::print_Section(&s);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +164,7 @@ fn string_hex_to_usize(s: &String) -> usize{
|
||||
let base: usize = 16;
|
||||
|
||||
for (i,c )in s.chars().enumerate(){
|
||||
print!("Current char :: {} :: Current pow :: {} ::", c, max_pow - (i as u32));
|
||||
//println!("Current char :: {} :: Current pow :: {} ::", c, max_pow - (i as u32));
|
||||
let tmp: usize = (one_hex_to_dec(c) as usize);
|
||||
ret_value += base.pow(max_pow - (i as u32))*tmp;
|
||||
}
|
||||
@ -185,6 +228,13 @@ fn test_show_sections_file(){
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_create_Mem_Chercker(){
|
||||
let path: String = "osef".to_string();
|
||||
let m_c = Mem_Checker::from(&path);
|
||||
Mem_Checker::print_Mem_Checker(&m_c);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_string_hex_to_usize(){
|
||||
|
Loading…
Reference in New Issue
Block a user