FIRBundleUtilTest.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2017 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 "FIRTestCase.h"
  15. #import <FirebaseCore/FIRBundleUtil.h>
  16. static NSString *const kResultPath = @"resultPath";
  17. static NSString *const kResourceName = @"resourceName";
  18. static NSString *const kFileType = @"fileType";
  19. @interface FIRBundleUtilTest : FIRTestCase
  20. @property(nonatomic, strong) id mockBundle;
  21. @end
  22. @implementation FIRBundleUtilTest
  23. - (void)setUp {
  24. [super setUp];
  25. self.mockBundle = OCMClassMock([NSBundle class]);
  26. }
  27. - (void)testRelevantBundles_mainIsFirst {
  28. // Pointer compare to same instance of main bundle.
  29. XCTAssertEqual([NSBundle mainBundle], [FIRBundleUtil relevantBundles][0]);
  30. }
  31. // TODO: test that adding a bundle appears in "all bundles"
  32. // once the use-case is understood.
  33. - (void)testFindOptionsDictionaryPath {
  34. [OCMStub([self.mockBundle pathForResource:kResourceName ofType:kFileType]) andReturn:kResultPath];
  35. XCTAssertEqualObjects([FIRBundleUtil optionsDictionaryPathWithResourceName:kResourceName
  36. andFileType:kFileType
  37. inBundles:@[ self.mockBundle ]],
  38. kResultPath);
  39. }
  40. - (void)testFindOptionsDictionaryPath_notFound {
  41. XCTAssertNil([FIRBundleUtil optionsDictionaryPathWithResourceName:kResourceName
  42. andFileType:kFileType
  43. inBundles:@[ self.mockBundle ]]);
  44. }
  45. - (void)testFindOptionsDictionaryPath_secondBundle {
  46. NSBundle *mockBundleEmpty = OCMClassMock([NSBundle class]);
  47. [OCMStub([self.mockBundle pathForResource:kResourceName ofType:kFileType]) andReturn:kResultPath];
  48. NSArray *bundles = @[ mockBundleEmpty, self.mockBundle ];
  49. XCTAssertEqualObjects([FIRBundleUtil optionsDictionaryPathWithResourceName:kResourceName
  50. andFileType:kFileType
  51. inBundles:bundles],
  52. kResultPath);
  53. }
  54. - (void)testBundleIdentifierExistsInBundles {
  55. NSString *bundleID = @"com.google.test";
  56. [OCMStub([self.mockBundle bundleIdentifier]) andReturn:bundleID];
  57. XCTAssertTrue([FIRBundleUtil hasBundleIdentifier:bundleID inBundles:@[ self.mockBundle ]]);
  58. }
  59. - (void)testBundleIdentifierExistsInBundles_notExist {
  60. [OCMStub([self.mockBundle bundleIdentifier]) andReturn:@"com.google.test"];
  61. XCTAssertFalse([FIRBundleUtil hasBundleIdentifier:@"not-exist" inBundles:@[ self.mockBundle ]]);
  62. }
  63. - (void)testBundleIdentifierExistsInBundles_emptyBundlesArray {
  64. XCTAssertFalse([FIRBundleUtil hasBundleIdentifier:@"com.google.test" inBundles:@[]]);
  65. }
  66. @end