FIRCLSInternalReportTests.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
  15. #import <XCTest/XCTest.h>
  16. @interface FIRCLSInternalReportTests : XCTestCase
  17. @end
  18. @implementation FIRCLSInternalReportTests
  19. - (NSString *)resourcePath {
  20. return [[NSBundle bundleForClass:[self class]] resourcePath];
  21. }
  22. - (NSString *)pathForResource:(NSString *)name {
  23. return [[self resourcePath] stringByAppendingPathComponent:name];
  24. }
  25. - (void)testCustomExceptionsNeedToBeSubmitted {
  26. NSString *name = @"metadata_only_report";
  27. NSString *tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent:name];
  28. // make sure to remove anything that was there previously
  29. [[NSFileManager defaultManager] removeItemAtPath:tempPath error:nil];
  30. NSString *resourcePath = [self pathForResource:name];
  31. [[NSFileManager defaultManager] copyItemAtPath:resourcePath toPath:tempPath error:nil];
  32. FIRCLSInternalReport *report = [[FIRCLSInternalReport alloc] initWithPath:tempPath];
  33. NSString *customAPath = [report pathForContentFile:FIRCLSReportCustomExceptionAFile];
  34. NSString *customBPath = [report pathForContentFile:FIRCLSReportCustomExceptionBFile];
  35. XCTAssertFalse(report.hasAnyEvents, @"metadata only should not need to be submitted");
  36. [[NSFileManager defaultManager] createFileAtPath:customAPath
  37. contents:[NSData data]
  38. attributes:nil];
  39. XCTAssert(report.hasAnyEvents, @"with the A file present, needs to be submitted");
  40. [[NSFileManager defaultManager] createFileAtPath:customBPath
  41. contents:[NSData data]
  42. attributes:nil];
  43. // with A and B, also needs
  44. XCTAssert(report.hasAnyEvents, @"with both the A and B files present, needs to be submitted");
  45. XCTAssert([[NSFileManager defaultManager] removeItemAtPath:customAPath error:nil]);
  46. XCTAssert(report.hasAnyEvents, @"with the B file present, needs to be submitted");
  47. }
  48. @end