Commits

Bill Garrison committed 98073f9

Fixes #2

  • Participants
  • Parent commits 203b7d0
  • Tags 1.0.8

Comments (0)

Files changed (2)

NSURL+SOExtendedAttributes.m

     
     /* */
     
+    NSData *xattrData = nil;
+    
     if (dataSize == -1) {
         /* Clean up memory */
         if (valueDataBuffer) {
             *outError = [NSError errorWithDomain:[posixError domain] code:[posixError code] userInfo:augmentedErrorInfo];
         }
         
+    } else {
+        xattrData = [[NSData alloc] initWithBytesNoCopy:valueDataBuffer length:dataSize freeWhenDone:YES];
     }
     
-    return [[NSData alloc] initWithBytesNoCopy:valueDataBuffer length:dataSize freeWhenDone:YES];
+    return xattrData;
 }
 
 - (BOOL) setExtendedAttributeData:(NSData *)data name:(NSString *)name error:(NSError * __autoreleasing *)outError

UnitTests/SOExtendedAttributes_UnitTests.m

     STAssertFalse ([targetURL hasExtendedAttributeWithName:@"Total Eclipse of the Heart"], @"postcondition violated");
 }
 
-#pragma mark -
-#pragma mark Removal Tests
+#pragma mark - Getter Tests
+
+- (void) testGetNonexistentAttribute
+{
+    STAssertTrue([self createTestURLForTest:_cmd], @"Couldn't create test file");
+    NSError *error = nil;
+    
+    /* Ask for value of nonexistent extended attribute */
+    id xattrValue = [targetURL valueOfExtendedAttributeWithName:@"geordi.laforge" error:&error];
+    
+    STAssertNil (xattrValue, @"Expected nil value for nonexistent extended attribute");
+    STAssertTrue (error.code == ENOATTR, @"Expected 'attribute not found' error");
+}
+
+#pragma mark - Removal Tests
 
 - (void) testRemoveNonexistentAttribute
 {
     STAssertTrue([self createTestURLForTest:_cmd], @"Couldn't create test file");
     NSError *error = nil;
     
-    /* Create a test file */
-    
-
-    
     /* Removing non-existent attribs is OK. */
     BOOL didRemove = [targetURL removeExtendedAttributeWithName:@"Jughead" error:&error];
     STAssertTrue (didRemove, @"%@", error);
 {
     STAssertTrue([self createTestURLForTest:_cmd], @"Couldn't create test file");
     
-    /* Create a test file */
-    
-
-    
     NSError *error = nil;
     NSString *attribName = @"net.standardorbit.latinPlaceholderText";
     id attribValue = @"Lorem ipsum dolor sit amet";