FIRAppDistributionMachOTests.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2020 Google LLC
  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 <Foundation/Foundation.h>
  15. #import <XCTest/XCTest.h>
  16. #import "FirebaseAppDistribution/Sources/FIRAppDistributionMachO.h"
  17. #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  18. @interface FIRAppDistributionMachOTests : XCTestCase
  19. @end
  20. @implementation FIRAppDistributionMachOTests
  21. - (NSString*)resourcePath:(NSString*)path {
  22. NSBundle* bundle = [NSBundle bundleForClass:[self class]];
  23. // Swift Package Manager uses a different bundle structure for resources, so explicitly get the
  24. // nested bundle. In Swift we could have used `Bundle.module` to access it, but that isn't
  25. // surfaced in ObjC.
  26. #if SWIFT_PACKAGE
  27. NSString* nestedBundlePath = [bundle pathForResource:@"Firebase_AppDistributionUnit"
  28. ofType:@"bundle"];
  29. bundle = [NSBundle bundleWithPath:nestedBundlePath];
  30. #endif // SWIFT_PACKAGE
  31. NSString* resourcePath = [bundle resourcePath];
  32. return [resourcePath stringByAppendingPathComponent:path];
  33. }
  34. - (void)testCodeHashForSingleArchIntelSimulator {
  35. FIRAppDistributionMachO* macho;
  36. macho = [[FIRAppDistributionMachO alloc] initWithPath:[self resourcePath:@"x86_64-executable"]];
  37. XCTAssertEqualObjects([macho codeHash], @"442eb836efe1f56bf8a65b2a0a78b2f8d3e792e7");
  38. }
  39. - (void)testCodeHashForMultipleArch {
  40. FIRAppDistributionMachO* macho;
  41. macho =
  42. [[FIRAppDistributionMachO alloc] initWithPath:[self resourcePath:@"armv7-armv7s-executable"]];
  43. XCTAssertEqualObjects([macho codeHash], @"80cc0ec0af8a0169831abcc73177eb2b57990bc0");
  44. }
  45. - (void)testCodeHashForNonExistentBinary {
  46. FIRAppDistributionMachO* macho;
  47. macho = [[FIRAppDistributionMachO alloc] initWithPath:[self resourcePath:@"missing-file"]];
  48. XCTAssertEqualObjects([macho codeHash], @"da39a3ee5e6b4b0d3255bfef95601890afd80709");
  49. }
  50. @end