DDLogFileManagerTests.m 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Software License Agreement (BSD License)
  2. //
  3. // Copyright (c) 2010-2025, Deusty, LLC
  4. // All rights reserved.
  5. //
  6. // Redistribution and use of this software in source and binary forms,
  7. // with or without modification, are permitted provided that the following conditions are met:
  8. //
  9. // * Redistributions of source code must retain the above copyright notice,
  10. // this list of conditions and the following disclaimer.
  11. //
  12. // * Neither the name of Deusty nor the names of its contributors may be used
  13. // to endorse or promote products derived from this software without specific
  14. // prior written permission of Deusty, LLC.
  15. @import XCTest;
  16. #import "DDSampleFileManager.h"
  17. #pragma mark DDLogFileManagerDefault
  18. @interface DDLogFileManagerDefaultTests : XCTestCase
  19. @property (nonatomic, strong, readwrite) DDLogFileManagerDefault *logFileManager;
  20. @end
  21. @implementation DDLogFileManagerDefaultTests
  22. - (void)setUp {
  23. [super setUp];
  24. [self setUpLogFileManager];
  25. }
  26. - (void)tearDown {
  27. [super tearDown];
  28. self.logFileManager = nil;
  29. }
  30. - (void)setUpLogFileManager {
  31. self.logFileManager = [[DDSampleFileManager alloc] initWithLogFileHeader:@"header"];
  32. }
  33. - (void)testCreateNewLogFile {
  34. __autoreleasing NSError *creationError;
  35. NSString *filePath = [self.logFileManager createNewLogFileWithError:&creationError];
  36. XCTAssertNil(creationError);
  37. XCTAssertTrue([self.logFileManager isLogFile:filePath.lastPathComponent]);
  38. __autoreleasing NSError *error = nil;
  39. NSData *data = [NSData dataWithContentsOfFile:filePath options:NSDataReadingUncached error:&error];
  40. XCTAssertNil(error);
  41. XCTAssertEqualObjects([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding], @"header\n");
  42. }
  43. @end