Browse Source

Add minimalistic integration tests

master
Matteo Cypriani 3 years ago
parent
commit
0f42459d7b
5 changed files with 42 additions and 1 deletions
  1. 4
    1
      src/metadata/mod.rs
  2. BIN
      tests/minimal_v1.nrg
  3. BIN
      tests/minimal_v2.nrg
  4. 19
    0
      tests/nrg_v1.rs
  5. 19
    0
      tests/nrg_v2.rs

+ 4
- 1
src/metadata/mod.rs View File

@@ -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`.
///
/// `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
/// can read the first data chunk's offset (32 bits for NRG v1 or 64 bits for
/// 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 {
// Input file too small
return Err(NrgError::NrgFormat(

BIN
tests/minimal_v1.nrg View File


BIN
tests/minimal_v2.nrg View File


+ 19
- 0
tests/nrg_v1.rs View File

@@ -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);
}

+ 19
- 0
tests/nrg_v2.rs View File

@@ -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…
Cancel
Save