Skip to content

Commit

Permalink
Added test for extended attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterb180369 committed Oct 18, 2018
1 parent fdf980f commit ab02eaf
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 6 deletions.
18 changes: 12 additions & 6 deletions BXSwiftUtils.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@
D0606C9520A5CFB50090D981 /* BXInstanceInfoMixin.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0606C9320A5CFB50090D981 /* BXInstanceInfoMixin.swift */; };
D0693F8A20AC1C4500B5893C /* UndoManager+Disabling.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0693F8920AC1C4500B5893C /* UndoManager+Disabling.swift */; };
D0693F8B20AC1C4500B5893C /* UndoManager+Disabling.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0693F8920AC1C4500B5893C /* UndoManager+Disabling.swift */; };
D06CC91F2178B089009C2991 /* String+RegexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06CC91E2178B089009C2991 /* String+RegexTests.swift */; };
D06CC9202178B089009C2991 /* String+RegexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06CC91E2178B089009C2991 /* String+RegexTests.swift */; };
D06F462D209073D0000986B8 /* Collection+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06F462C209073D0000986B8 /* Collection+Codable.swift */; };
D06F462E209073D0000986B8 /* Collection+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06F462C209073D0000986B8 /* Collection+Codable.swift */; };
D0859FD12158F7DD00F624C7 /* URL+Contents.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0859FD02158F7DD00F624C7 /* URL+Contents.swift */; };
Expand All @@ -158,8 +160,8 @@
D089124C215B723C00403100 /* CGRect+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = D089124A215B723C00403100 /* CGRect+String.swift */; };
D08F44E021708CD90060FBAE /* String+Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08F44DF21708CD90060FBAE /* String+Regex.swift */; };
D08F44E121708CD90060FBAE /* String+Regex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08F44DF21708CD90060FBAE /* String+Regex.swift */; };
D08F44E32170A4850060FBAE /* String+RegexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08F44E22170A4850060FBAE /* String+RegexTests.swift */; };
D08F44E42170A4850060FBAE /* String+RegexTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08F44E22170A4850060FBAE /* String+RegexTests.swift */; };
D08F44E32170A4850060FBAE /* URL+ExtendedAttributesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08F44E22170A4850060FBAE /* URL+ExtendedAttributesTests.swift */; };
D08F44E42170A4850060FBAE /* URL+ExtendedAttributesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D08F44E22170A4850060FBAE /* URL+ExtendedAttributesTests.swift */; };
D0C47CE420EE55DA003D3FA3 /* Number+Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0C47CE320EE55DA003D3FA3 /* Number+Random.swift */; };
D0C47CE520EE55DA003D3FA3 /* Number+Random.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0C47CE320EE55DA003D3FA3 /* Number+Random.swift */; };
D0DA3332213DA04A00994E89 /* DispatchGroup+Once.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0DA3331213DA04900994E89 /* DispatchGroup+Once.swift */; };
Expand Down Expand Up @@ -264,6 +266,7 @@
D056D43F205296F100849EF2 /* Synchronized.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Synchronized.swift; sourceTree = "<group>"; };
D0606C9320A5CFB50090D981 /* BXInstanceInfoMixin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BXInstanceInfoMixin.swift; sourceTree = "<group>"; };
D0693F8920AC1C4500B5893C /* UndoManager+Disabling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UndoManager+Disabling.swift"; sourceTree = "<group>"; };
D06CC91E2178B089009C2991 /* String+RegexTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+RegexTests.swift"; sourceTree = "<group>"; };
D06F462C209073D0000986B8 /* Collection+Codable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Collection+Codable.swift"; sourceTree = "<group>"; };
D0859FD02158F7DD00F624C7 /* URL+Contents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "URL+Contents.swift"; sourceTree = "<group>"; };
D0859FD32158F7E200F624C7 /* URL+ExtendedAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "URL+ExtendedAttributes.swift"; sourceTree = "<group>"; };
Expand All @@ -272,7 +275,7 @@
D0891243215A762200403100 /* CGPoint+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGPoint+String.swift"; sourceTree = "<group>"; };
D089124A215B723C00403100 /* CGRect+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGRect+String.swift"; sourceTree = "<group>"; };
D08F44DF21708CD90060FBAE /* String+Regex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Regex.swift"; sourceTree = "<group>"; };
D08F44E22170A4850060FBAE /* String+RegexTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+RegexTests.swift"; sourceTree = "<group>"; };
D08F44E22170A4850060FBAE /* URL+ExtendedAttributesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+ExtendedAttributesTests.swift"; sourceTree = "<group>"; };
D0C47CE320EE55DA003D3FA3 /* Number+Random.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Number+Random.swift"; sourceTree = "<group>"; };
D0DA3331213DA04900994E89 /* DispatchGroup+Once.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchGroup+Once.swift"; sourceTree = "<group>"; };
D0EA52D920F8992300A0EF6D /* MTKTextureLoader+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MTKTextureLoader+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -487,7 +490,8 @@
children = (
48C248132088CF4100DC9317 /* NSAttributedString+CodableTests.swift */,
48AD6C9F2147FD6400225D9C /* String+UniqueByIncrementingTests.swift */,
D08F44E22170A4850060FBAE /* String+RegexTests.swift */,
D06CC91E2178B089009C2991 /* String+RegexTests.swift */,
D08F44E22170A4850060FBAE /* URL+ExtendedAttributesTests.swift */,
);
path = Strings;
sourceTree = "<group>";
Expand Down Expand Up @@ -905,6 +909,7 @@
files = (
4875F2552051EF7F009985EC /* Collection+SafeAccessTests.swift in Sources */,
484D065620592898003C6CA3 /* Array+AllEqualTests.swift in Sources */,
D06CC91F2178B089009C2991 /* String+RegexTests.swift in Sources */,
48DE068D20876E52000246CD /* Dictionary+EnumKeysTests.swift in Sources */,
4853E38A2056BDE400938B82 /* SynchronizedTests.swift in Sources */,
4826E581208F534000A5BA9B /* Array+DecodableTests.swift in Sources */,
Expand All @@ -920,7 +925,7 @@
4875F24F2051ECF9009985EC /* Array+ConcatenationTests.swift in Sources */,
48AD6CA02147FD6400225D9C /* String+UniqueByIncrementingTests.swift in Sources */,
481BE6D62098368E00F12EDF /* Sequence+CompactMap.swift in Sources */,
D08F44E32170A4850060FBAE /* String+RegexTests.swift in Sources */,
D08F44E32170A4850060FBAE /* URL+ExtendedAttributesTests.swift in Sources */,
4853E3902056D11500938B82 /* BXReadWriteLockTests.swift in Sources */,
48A971E52159122800215F9F /* Enum+Comparable.swift in Sources */,
48C248142088CF4100DC9317 /* NSAttributedString+CodableTests.swift in Sources */,
Expand Down Expand Up @@ -995,6 +1000,7 @@
files = (
4875F27B20529A19009985EC /* Collection+SafeAccessTests.swift in Sources */,
484D065720592898003C6CA3 /* Array+AllEqualTests.swift in Sources */,
D06CC9202178B089009C2991 /* String+RegexTests.swift in Sources */,
48DE068E20876E52000246CD /* Dictionary+EnumKeysTests.swift in Sources */,
4853E38B2056BDE400938B82 /* SynchronizedTests.swift in Sources */,
4826E582208F534000A5BA9B /* Array+DecodableTests.swift in Sources */,
Expand All @@ -1010,7 +1016,7 @@
4875F27A20529A17009985EC /* Array+ConcatenationTests.swift in Sources */,
48AD6CA12147FD6400225D9C /* String+UniqueByIncrementingTests.swift in Sources */,
481BE6D72098368E00F12EDF /* Sequence+CompactMap.swift in Sources */,
D08F44E42170A4850060FBAE /* String+RegexTests.swift in Sources */,
D08F44E42170A4850060FBAE /* URL+ExtendedAttributesTests.swift in Sources */,
4853E3912056D11500938B82 /* BXReadWriteLockTests.swift in Sources */,
48A971E62159122800215F9F /* Enum+Comparable.swift in Sources */,
48C248152088CF4100DC9317 /* NSAttributedString+CodableTests.swift in Sources */,
Expand Down
105 changes: 105 additions & 0 deletions BXSwiftUtilsTests/Strings/URL+ExtendedAttributesTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
// URL+ExtendedAttributesTests.swift
// BXSwiftUtils
//
// Created by Peter Baumgartner on 18.10.18.
// Copyright © 2018 Boinx Software Ltd. & Imagine GbR. All rights reserved.
//

import XCTest
import BXSwiftUtils

class URL_ExtendedAttributesTests: XCTestCase
{

private var testURL : URL
{
let path = NSTemporaryDirectory()
return URL(fileURLWithPath:path).appendingPathComponent("test")
}


func testExtendedAttributeExists()
{
let url = self.testURL
try! "This is a test".write(to:url, atomically:true, encoding:.utf8)

let exists = url.hasExtendedAttribute(forName:"com.boinx.unknown")
XCTAssertEqual(exists,false)

try! FileManager.default.removeItem(at:url)
}


func testExtendedAttributeString()
{
let url = self.testURL
let key = "com.boinx.foo"
let value1:String = "bar"

try! "This is a test".write(to:url, atomically:true, encoding:.utf8)

try! url.setExtendedAttribute(value1, forName:key)

let exists1 = url.hasExtendedAttribute(forName:key)
XCTAssertEqual(exists1,true)

let value2:String = try! url.extendedAttribute(forName:key)
XCTAssertEqual(value1,value2)

try! url.removeExtendedAttribute(forName:key)
let exists2 = url.hasExtendedAttribute(forName:key)
XCTAssertEqual(exists2,false)

try! FileManager.default.removeItem(at:url)
}


func testExtendedAttributeInt()
{
let url = self.testURL
let key = "com.boinx.foo"
let value1:Int = 42

try! "This is a test".write(to:url, atomically:true, encoding:.utf8)

try! url.setExtendedAttribute(value1, forName:key)

let exists1 = url.hasExtendedAttribute(forName:key)
XCTAssertEqual(exists1,true)

let value2:Int = try! url.extendedAttribute(forName:key)
XCTAssertEqual(value1,value2)

try! url.removeExtendedAttribute(forName:key)
let exists2 = url.hasExtendedAttribute(forName:key)
XCTAssertEqual(exists2,false)

try! FileManager.default.removeItem(at:url)
}


func testExtendedAttributeBool()
{
let url = self.testURL
let key = "com.boinx.foo"
let value1:Bool = true

try! "This is a test".write(to:url, atomically:true, encoding:.utf8)

try! url.setExtendedAttribute(value1, forName:key)

let exists1 = url.hasExtendedAttribute(forName:key)
XCTAssertEqual(exists1,true)

let value2:Bool = try! url.extendedAttribute(forName:key)
XCTAssertEqual(value1,value2)

try! url.removeExtendedAttribute(forName:key)
let exists2 = url.hasExtendedAttribute(forName:key)
XCTAssertEqual(exists2,false)

try! FileManager.default.removeItem(at:url)
}

}

0 comments on commit ab02eaf

Please sign in to comment.