forked from Haneke/HanekeSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiskTestCase.swift
48 lines (38 loc) · 1.35 KB
/
DiskTestCase.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// DiskTestCase.swift
// Haneke
//
// Created by Hermes Pique on 8/26/14.
// Copyright (c) 2014 Haneke. All rights reserved.
//
import XCTest
class DiskTestCase : XCTestCase {
lazy var directoryPath : String = {
let documentsPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0] as! String
let directoryPath = documentsPath.stringByAppendingPathComponent(self.name)
return directoryPath
}()
override func setUp() {
super.setUp()
NSFileManager.defaultManager().createDirectoryAtPath(directoryPath, withIntermediateDirectories: true, attributes: nil, error: nil)
}
override func tearDown() {
NSFileManager.defaultManager().removeItemAtPath(directoryPath, error: nil)
super.tearDown()
}
var dataIndex = 0
func writeDataWithLength(length : Int) -> String {
let data = NSData.dataWithLength(length)
return self.writeData(data)
}
func writeData(data : NSData) -> String {
let path = self.uniquePath()
data.writeToFile(path, atomically: true)
return path
}
func uniquePath() -> String {
let path = self.directoryPath.stringByAppendingPathComponent("\(dataIndex)")
dataIndex++
return path
}
}