FIRMutableDictionaryTest.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2018 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/FIRMutableDictionary.h>
  16. const static NSString *const kKey = @"testKey1";
  17. const static NSString *const kValue = @"testValue1";
  18. const static NSString *const kKey2 = @"testKey2";
  19. const static NSString *const kValue2 = @"testValue2";
  20. @interface FIRMutableDictionaryTest : FIRTestCase
  21. @property(nonatomic) FIRMutableDictionary *dictionary;
  22. @end
  23. @implementation FIRMutableDictionaryTest
  24. - (void)setUp {
  25. [super setUp];
  26. self.dictionary = [[FIRMutableDictionary alloc] init];
  27. }
  28. - (void)tearDown {
  29. self.dictionary = nil;
  30. [super tearDown];
  31. }
  32. - (void)testSetGetAndRemove {
  33. XCTAssertNil([self.dictionary objectForKey:kKey]);
  34. [self.dictionary setObject:kValue forKey:kKey];
  35. XCTAssertEqual(kValue, [self.dictionary objectForKey:kKey]);
  36. [self.dictionary removeObjectForKey:kKey];
  37. XCTAssertNil([self.dictionary objectForKey:kKey]);
  38. }
  39. - (void)testSetGetAndRemoveKeyed {
  40. XCTAssertNil(self.dictionary[kKey]);
  41. self.dictionary[kKey] = kValue;
  42. XCTAssertEqual(kValue, self.dictionary[kKey]);
  43. [self.dictionary removeObjectForKey:kKey];
  44. XCTAssertNil(self.dictionary[kKey]);
  45. }
  46. - (void)testRemoveAll {
  47. XCTAssertNil(self.dictionary[kKey]);
  48. XCTAssertNil(self.dictionary[kKey2]);
  49. self.dictionary[kKey] = kValue;
  50. self.dictionary[kKey2] = kValue2;
  51. [self.dictionary removeAllObjects];
  52. XCTAssertNil(self.dictionary[kKey]);
  53. XCTAssertNil(self.dictionary[kKey2]);
  54. }
  55. - (void)testCount {
  56. XCTAssertEqual([self.dictionary count], 0);
  57. self.dictionary[kKey] = kValue;
  58. XCTAssertEqual([self.dictionary count], 1);
  59. self.dictionary[kKey2] = kValue2;
  60. XCTAssertEqual([self.dictionary count], 2);
  61. [self.dictionary removeAllObjects];
  62. XCTAssertEqual([self.dictionary count], 0);
  63. }
  64. - (void)testUnderlyingDictionary {
  65. XCTAssertEqual([self.dictionary count], 0);
  66. self.dictionary[kKey] = kValue;
  67. self.dictionary[kKey2] = kValue2;
  68. NSDictionary *dict = self.dictionary.dictionary;
  69. XCTAssertEqual([dict count], 2);
  70. XCTAssertEqual(dict[kKey], kValue);
  71. XCTAssertEqual(dict[kKey2], kValue2);
  72. }
  73. @end