RCNConfigValueTest.m 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
  18. @interface FIRRemoteConfigValueTest : XCTestCase
  19. @end
  20. @implementation FIRRemoteConfigValueTest
  21. - (void)testConfigValueWithDifferentValueTypes {
  22. NSString *valueA = @"0.33333";
  23. NSData *dataA = [valueA dataUsingEncoding:NSUTF8StringEncoding];
  24. FIRRemoteConfigValue *configValueA =
  25. [[FIRRemoteConfigValue alloc] initWithData:dataA source:FIRRemoteConfigSourceRemote];
  26. XCTAssertEqualObjects(configValueA.stringValue, valueA);
  27. XCTAssertEqualObjects(configValueA.dataValue, dataA);
  28. XCTAssertEqualObjects(configValueA.numberValue, configValueA.numberValue);
  29. XCTAssertEqual(configValueA.boolValue, valueA.boolValue);
  30. NSString *valueB = @"NO";
  31. FIRRemoteConfigValue *configValueB =
  32. [[FIRRemoteConfigValue alloc] initWithData:[valueB dataUsingEncoding:NSUTF8StringEncoding]
  33. source:FIRRemoteConfigSourceRemote];
  34. XCTAssertEqual(configValueB.boolValue, valueB.boolValue);
  35. // Test JSON value.
  36. NSDictionary<NSString *, NSString *> *JSONDictionary = @{@"key1" : @"value1"};
  37. NSArray<NSDictionary<NSString *, NSString *> *> *JSONArray =
  38. @[ @{@"key1" : @"value1"}, @{@"key2" : @"value2"} ];
  39. NSError *error;
  40. NSData *JSONData = [NSJSONSerialization dataWithJSONObject:JSONDictionary options:0 error:&error];
  41. FIRRemoteConfigValue *configValueC =
  42. [[FIRRemoteConfigValue alloc] initWithData:JSONData source:FIRRemoteConfigSourceRemote];
  43. XCTAssertEqualObjects(configValueC.JSONValue, JSONDictionary);
  44. NSData *JSONArrayData = [NSJSONSerialization dataWithJSONObject:JSONArray options:0 error:&error];
  45. FIRRemoteConfigValue *configValueD =
  46. [[FIRRemoteConfigValue alloc] initWithData:JSONArrayData source:FIRRemoteConfigSourceRemote];
  47. XCTAssertEqualObjects(configValueD.JSONValue, JSONArray);
  48. }
  49. - (void)testFIRRemoteConfigValueToNumber {
  50. FIRRemoteConfigValue *value;
  51. NSString *strValue = @"0.33";
  52. NSData *data = [strValue dataUsingEncoding:NSUTF8StringEncoding];
  53. value = [[FIRRemoteConfigValue alloc] initWithData:data source:FIRRemoteConfigSourceRemote];
  54. XCTAssertEqual(value.numberValue.floatValue, strValue.floatValue);
  55. strValue = @"3.14159265358979";
  56. data = [strValue dataUsingEncoding:NSUTF8StringEncoding];
  57. value = [[FIRRemoteConfigValue alloc] initWithData:data source:FIRRemoteConfigSourceRemote];
  58. XCTAssertEqual(value.numberValue.doubleValue, strValue.doubleValue);
  59. strValue = @"1000000000";
  60. data = [strValue dataUsingEncoding:NSUTF8StringEncoding];
  61. value = [[FIRRemoteConfigValue alloc] initWithData:data source:FIRRemoteConfigSourceRemote];
  62. XCTAssertEqual(value.numberValue.intValue, strValue.intValue);
  63. strValue = @"1000000000123";
  64. data = [strValue dataUsingEncoding:NSUTF8StringEncoding];
  65. value = [[FIRRemoteConfigValue alloc] initWithData:data source:FIRRemoteConfigSourceRemote];
  66. XCTAssertEqual(value.numberValue.longLongValue, strValue.longLongValue);
  67. }
  68. @end