Add minimalistic integration tests
This commit is contained in:
parent
5a6feec1d6
commit
0f42459d7b
|
@ -73,10 +73,13 @@ pub fn read_nrg_metadata(fd: &mut File) -> Result<NrgMetadata, NrgError> {
|
||||||
|
|
||||||
/// Determines the NRG format of an open NRG image `fd` of file `file_size`.
|
/// Determines the NRG format of an open NRG image `fd` of file `file_size`.
|
||||||
///
|
///
|
||||||
|
/// `fd`'s offset at call-time doesn't matter, as this function will seek to
|
||||||
|
/// read the relevant data.
|
||||||
|
///
|
||||||
/// The offset is left after the main chunk ID, therefore the calling function
|
/// The offset is left after the main chunk ID, therefore the calling function
|
||||||
/// can read the first data chunk's offset (32 bits for NRG v1 or 64 bits for
|
/// can read the first data chunk's offset (32 bits for NRG v1 or 64 bits for
|
||||||
/// NRG v2) directly without seeking.
|
/// NRG v2) directly without seeking.
|
||||||
fn read_nrg_version(fd: &mut File, file_size: u64) -> Result<u8, NrgError> {
|
pub fn read_nrg_version(fd: &mut File, file_size: u64) -> Result<u8, NrgError> {
|
||||||
if file_size < 12 {
|
if file_size < 12 {
|
||||||
// Input file too small
|
// Input file too small
|
||||||
return Err(NrgError::NrgFormat(
|
return Err(NrgError::NrgFormat(
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,19 @@
|
||||||
|
extern crate nrgrip;
|
||||||
|
use nrgrip::metadata;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{Seek, SeekFrom};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nrg_format() {
|
||||||
|
let mut img = PathBuf::new();
|
||||||
|
img.push("tests");
|
||||||
|
img.push("minimal_v1.nrg");
|
||||||
|
let mut fd = File::open(img)
|
||||||
|
.expect("File::open()");
|
||||||
|
let size = fd.seek(SeekFrom::End(0))
|
||||||
|
.expect("fd.seek()");
|
||||||
|
let ver = metadata::read_nrg_version(&mut fd, size)
|
||||||
|
.expect("read_nrg_version()");
|
||||||
|
assert_eq!(ver, 1);
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
extern crate nrgrip;
|
||||||
|
use nrgrip::metadata;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{Seek, SeekFrom};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn nrg_format() {
|
||||||
|
let mut img = PathBuf::new();
|
||||||
|
img.push("tests");
|
||||||
|
img.push("minimal_v2.nrg");
|
||||||
|
let mut fd = File::open(img)
|
||||||
|
.expect("File::open()");
|
||||||
|
let size = fd.seek(SeekFrom::End(0))
|
||||||
|
.expect("fd.seek()");
|
||||||
|
let ver = metadata::read_nrg_version(&mut fd, size)
|
||||||
|
.expect("read_nrg_version()");
|
||||||
|
assert_eq!(ver, 2);
|
||||||
|
}
|
Loading…
Reference in New Issue