Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hyatt committed Mar 6, 2018
1 parent 534d1e0 commit e87d01f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# M4ATools

A description of this package.
M4A file handling utilities
11 changes: 11 additions & 0 deletions Sources/M4ATools/M4AFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,17 @@ public class M4AFile {
try data.write(to: url)
}

/// Generates the data of an M4A file
///
/// - returns: `Data` of the file
public func write() -> Data {
var data = Data()
for block in blocks {
data = block.write(data)
}
return data
}

/// Retrieves metadata of the `String` type
///
/// - parameters:
Expand Down
17 changes: 7 additions & 10 deletions Tests/M4AToolsTests/M4AToolsTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import XCTest
@testable import M4ATools

/// M4ATools tests
class M4AToolsTests: XCTestCase {

/// Loads a M4A file
Expand All @@ -15,11 +16,9 @@ class M4AToolsTests: XCTestCase {
/// Loads and then writes a M4A file
func testWriteFile() {
let outURL = URL(fileURLWithPath: "/tmp/foo.m4a")
let bundle = Bundle(for: type(of: self))
let url = bundle.url(forResource: "sample-metadata", withExtension: "m4a")


do {
let audio = try M4AFile(url: url!)
let audio = try M4AFile(data: AudioFiles.sampleMetadata)
try audio.write(url: outURL)
} catch {
XCTFail()
Expand All @@ -42,16 +41,14 @@ class M4AToolsTests: XCTestCase {

/// Loads a M4A file and writes metadata
func testWriteMetadata() {
let out = URL(fileURLWithPath: "/tmp/writetest.m4a")

do {
var m4a = try M4AFile(data: AudioFiles.sampleMetadata)
m4a.setStringMetadata(.sortingArtist, value: "Arty Artist")
m4a.setIntMetadata(.gapless, value: 1)
m4a.setTwoIntMetadata(.track, value: (3, 8))
try m4a.write(url: out)
let data = m4a.write()

m4a = try M4AFile(url: out)
m4a = try M4AFile(data: data)
XCTAssert(m4a.getIntMetadata(.gapless) == 1)
XCTAssert(m4a.getStringMetadata(.sortingArtist) == "Arty Artist")
guard let track = m4a.getTwoIntMetadata(.track) else {
Expand All @@ -63,8 +60,8 @@ class M4AToolsTests: XCTestCase {
XCTFail()
}
}


/// Used by `swift test`
static var allTests = [
("Test Load File", testLoadFile),
("Test Write File", testWriteFile),
Expand Down

0 comments on commit e87d01f

Please sign in to comment.