| 1 |
use super::fixture::FixtureCli; |
| 2 |
use std::path::PathBuf; |
| 3 |
use std::process::Command; |
| 4 |
|
| 5 |
|
| 6 |
#[derive(Debug, Copy, Clone, PartialEq)] |
| 7 |
enum Repair { |
| 8 |
TestOnly, |
| 9 |
TestAndRepair, |
| 10 |
} |
| 11 |
|
| 12 |
|
| 13 |
static JSON_BAD_CONTENT: &'static str = "\ |
| 14 |
{ |
| 15 |
\"head\": { |
| 16 |
\"encoding\": \"utf-8\" |
| 17 |
} |
| 18 |
, |
| 19 |
\"views\": |
| 20 |
[ |
| 21 |
] |
| 22 |
, |
| 23 |
\"nodes\": |
| 24 |
[ |
| 25 |
{ |
| 26 |
\"classifier\": { |
| 27 |
\"id\": 1, |
| 28 |
\"main_type\": 121, |
| 29 |
\"type\": \"Component\", |
| 30 |
\"stereotype\": \"subsystem\", |
| 31 |
\"name\": \"AngleSteering\", |
| 32 |
\"uuid\": \"8190a2ed-df2e-4427-8ebb-0272cd62149a\", |
| 33 |
\"features\": |
| 34 |
[ |
| 35 |
] |
| 36 |
} |
| 37 |
} |
| 38 |
] |
| 39 |
, |
| 40 |
\"edges\": |
| 41 |
[ |
| 42 |
] |
| 43 |
} |
| 44 |
"; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
pub(super) fn testcase_repair_new_cfu1(environment: &mut FixtureCli) -> Result<(), ()> { |
| 61 |
test_repair_or_test( |
| 62 |
Repair::TestAndRepair, |
| 63 |
"sqlite3_db.cfu1", |
| 64 |
"Errors found: 1", |
| 65 |
environment, |
| 66 |
) |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
pub(super) fn testcase_test_new_cfu1(environment: &mut FixtureCli) -> Result<(), ()> { |
| 84 |
test_repair_or_test( |
| 85 |
Repair::TestOnly, |
| 86 |
"sqlite3_db.cfu1", |
| 87 |
"Errors found: 1", |
| 88 |
environment, |
| 89 |
) |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
pub(super) fn testcase_repair_json_rw(environment: &mut FixtureCli) -> Result<(), ()> { |
| 107 |
environment.create_file( |
| 108 |
"test.cfuJ", |
| 109 |
JSON_BAD_CONTENT, |
| 110 |
super::fixture::Permissions::ReadWrite, |
| 111 |
); |
| 112 |
test_repair_or_test( |
| 113 |
Repair::TestAndRepair, |
| 114 |
"test.cfuJ", |
| 115 |
"Errors fixed: 1", |
| 116 |
environment, |
| 117 |
) |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
pub(super) fn testcase_test_json_ro(environment: &mut FixtureCli) -> Result<(), ()> { |
| 135 |
environment.create_file( |
| 136 |
"test.cfuJ", |
| 137 |
JSON_BAD_CONTENT, |
| 138 |
super::fixture::Permissions::ReadOnly, |
| 139 |
); |
| 140 |
test_repair_or_test( |
| 141 |
Repair::TestOnly, |
| 142 |
"test.cfuJ", |
| 143 |
"Errors found: 2", |
| 144 |
environment, |
| 145 |
) |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
fn test_repair_or_test( |
| 166 |
repair: Repair, |
| 167 |
file_name: &str, |
| 168 |
expected_output: &str, |
| 169 |
environment: &mut FixtureCli, |
| 170 |
) -> Result<(), ()> { |
| 171 |
|
| 172 |
let mut db_to_use = PathBuf::from(environment.temp_dir); |
| 173 |
db_to_use.push(file_name); |
| 174 |
let db_to_use_param = db_to_use.into_os_string().into_string().unwrap(); |
| 175 |
|
| 176 |
let repair_param: &str = match repair { |
| 177 |
Repair::TestOnly => "-t", |
| 178 |
Repair::TestAndRepair => "-r", |
| 179 |
}; |
| 180 |
print!( |
| 181 |
"call: {} {} {}\n", |
| 182 |
environment.exe_to_test, repair_param, db_to_use_param |
| 183 |
); |
| 184 |
let output = Command::new(environment.exe_to_test) |
| 185 |
.args(&[repair_param, &db_to_use_param]) |
| 186 |
.output() |
| 187 |
.expect("Err at running process"); |
| 188 |
|
| 189 |
let stdout = match std::string::String::from_utf8(output.stdout) { |
| 190 |
Ok(stdout) => stdout, |
| 191 |
Err(_err) => return Result::Err(()), |
| 192 |
}; |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
let as_expected = stdout.contains(expected_output); |
| 197 |
|
| 198 |
|
| 199 |
let exit_ok: bool = output.status.success(); |
| 200 |
|
| 201 |
print!("stdout: <<{}>>:{}\n", stdout, stdout.len()); |
| 202 |
if as_expected && !exit_ok { |
| 203 |
Result::Ok(()) |
| 204 |
} else { |
| 205 |
Result::Err(()) |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|