Browse Source

Add minimalistic integration tests

Matteo Cypriani 2 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> {
73 73
 
74 74
 /// Determines the NRG format of an open NRG image `fd` of file `file_size`.
75 75
 ///
76
+/// `fd`'s offset at call-time doesn't matter, as this function will seek to
77
+/// read the relevant data.
78
+///
76 79
 /// The offset is left after the main chunk ID, therefore the calling function
77 80
 /// can read the first data chunk's offset (32 bits for NRG v1 or 64 bits for
78 81
 /// NRG v2) directly without seeking.
79
-fn read_nrg_version(fd: &mut File, file_size: u64) -> Result<u8, NrgError> {
82
+pub fn read_nrg_version(fd: &mut File, file_size: u64) -> Result<u8, NrgError> {
80 83
     if file_size < 12 {
81 84
         // Input file too small
82 85
         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 @@
1
+extern crate nrgrip;
2
+use nrgrip::metadata;
3
+use std::fs::File;
4
+use std::io::{Seek, SeekFrom};
5
+use std::path::PathBuf;
6
+
7
+#[test]
8
+fn nrg_format() {
9
+    let mut img = PathBuf::new();
10
+    img.push("tests");
11
+    img.push("minimal_v1.nrg");
12
+    let mut fd = File::open(img)
13
+        .expect("File::open()");
14
+    let size = fd.seek(SeekFrom::End(0))
15
+        .expect("fd.seek()");
16
+    let ver = metadata::read_nrg_version(&mut fd, size)
17
+        .expect("read_nrg_version()");
18
+    assert_eq!(ver, 1);
19
+}

+ 19
- 0
tests/nrg_v2.rs View File

@@ -0,0 +1,19 @@
1
+extern crate nrgrip;
2
+use nrgrip::metadata;
3
+use std::fs::File;
4
+use std::io::{Seek, SeekFrom};
5
+use std::path::PathBuf;
6
+
7
+#[test]
8
+fn nrg_format() {
9
+    let mut img = PathBuf::new();
10
+    img.push("tests");
11
+    img.push("minimal_v2.nrg");
12
+    let mut fd = File::open(img)
13
+        .expect("File::open()");
14
+    let size = fd.seek(SeekFrom::End(0))
15
+        .expect("fd.seek()");
16
+    let ver = metadata::read_nrg_version(&mut fd, size)
17
+        .expect("read_nrg_version()");
18
+    assert_eq!(ver, 2);
19
+}

Loading…
Cancel
Save