FIRCLSUtilityTests.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #include "FIRCLSUtility.h"
  15. #import <Foundation/Foundation.h>
  16. #import <XCTest/XCTest.h>
  17. #include "FIRCLSByteUtility.h"
  18. @interface FIRCLSUtilityTests : XCTestCase
  19. @end
  20. @implementation FIRCLSUtilityTests
  21. - (void)setUp {
  22. [super setUp];
  23. // Put setup code here. This method is called before the invocation of each test method in the
  24. // class.
  25. }
  26. - (void)tearDown {
  27. // Put teardown code here. This method is called after the invocation of each test method in the
  28. // class.
  29. [super tearDown];
  30. }
  31. - (void)testHexFromByte {
  32. char output[2] = {0, 0};
  33. FIRCLSHexFromByte('A', output);
  34. XCTAssertEqual(output[0], '4', @"");
  35. XCTAssertEqual(output[1], '1', @"");
  36. }
  37. - (void)testHexFromByteForNotPrintableCharacter {
  38. char output[2] = {0, 0};
  39. FIRCLSHexFromByte(0xd0, output);
  40. XCTAssertEqual(output[0], 'd', @"");
  41. XCTAssertEqual(output[1], '0', @"");
  42. }
  43. - (void)testHexToString {
  44. const uint8_t bytes[8] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
  45. char string[(sizeof(bytes) * 2) + 1];
  46. FIRCLSSafeHexToString(bytes, 8, string);
  47. string[(sizeof(bytes) * 2)] = 0;
  48. XCTAssertEqualObjects([NSString stringWithUTF8String:string], @"6162636465666768", @"");
  49. }
  50. - (void)testHexToStringWithNonPrintableCharacters {
  51. const uint8_t bytes[4] = {0x52, 0xd0, 0x4e, 0x1f};
  52. char string[(sizeof(bytes) * 2) + 1];
  53. FIRCLSSafeHexToString(bytes, 4, string);
  54. XCTAssertEqualObjects([NSString stringWithUTF8String:string], @"52d04e1f", @"");
  55. }
  56. @end