FIRCLSInternalReportTests.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #if SWIFT_PACKAGE
  21. NSBundle *bundle = SWIFTPM_MODULE_BUNDLE;
  22. return [bundle.resourcePath stringByAppendingPathComponent:@"Data"];
  23. #else
  24. NSBundle *bundle = [NSBundle bundleForClass:[self class]];
  25. return bundle.resourcePath;
  26. #endif
  27. }
  28. - (NSString *)pathForResource:(NSString *)name {
  29. return [[self resourcePath] stringByAppendingPathComponent:name];
  30. }
  31. - (void)testCustomExceptionsNeedToBeSubmitted {
  32. NSString *name = @"metadata_only_report";
  33. NSString *tempPath = [NSTemporaryDirectory() stringByAppendingPathComponent:name];
  34. // make sure to remove anything that was there previously
  35. [[NSFileManager defaultManager] removeItemAtPath:tempPath error:nil];
  36. NSString *resourcePath = [self pathForResource:name];
  37. [[NSFileManager defaultManager] copyItemAtPath:resourcePath toPath:tempPath error:nil];
  38. FIRCLSInternalReport *report = [[FIRCLSInternalReport alloc] initWithPath:tempPath];
  39. NSString *customAPath = [report pathForContentFile:FIRCLSReportCustomExceptionAFile];
  40. NSString *customBPath = [report pathForContentFile:FIRCLSReportCustomExceptionBFile];
  41. XCTAssertFalse(report.hasAnyEvents, @"metadata only should not need to be submitted");
  42. [[NSFileManager defaultManager] createFileAtPath:customAPath
  43. contents:[NSData data]
  44. attributes:nil];
  45. XCTAssert(report.hasAnyEvents, @"with the A file present, needs to be submitted");
  46. [[NSFileManager defaultManager] createFileAtPath:customBPath
  47. contents:[NSData data]
  48. attributes:nil];
  49. // with A and B, also needs
  50. XCTAssert(report.hasAnyEvents, @"with both the A and B files present, needs to be submitted");
  51. XCTAssert([[NSFileManager defaultManager] removeItemAtPath:customAPath error:nil]);
  52. XCTAssert(report.hasAnyEvents, @"with the B file present, needs to be submitted");
  53. }
  54. @end