CompressionAlgorithmTests.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2024, gRPC Authors All rights reserved.
  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 GRPCCore
  17. import XCTest
  18. @available(gRPCSwift 2.0, *)
  19. final class CompressionAlgorithmTests: XCTestCase {
  20. func testCompressionAlgorithmSetContains() {
  21. var algorithms = CompressionAlgorithmSet()
  22. XCTAssertFalse(algorithms.contains(.gzip))
  23. XCTAssertFalse(algorithms.contains(.deflate))
  24. XCTAssertFalse(algorithms.contains(.none))
  25. algorithms.formUnion(.gzip)
  26. XCTAssertTrue(algorithms.contains(.gzip))
  27. XCTAssertFalse(algorithms.contains(.deflate))
  28. XCTAssertFalse(algorithms.contains(.none))
  29. algorithms.formUnion(.deflate)
  30. XCTAssertTrue(algorithms.contains(.gzip))
  31. XCTAssertTrue(algorithms.contains(.deflate))
  32. XCTAssertFalse(algorithms.contains(.none))
  33. algorithms.formUnion(.none)
  34. XCTAssertTrue(algorithms.contains(.gzip))
  35. XCTAssertTrue(algorithms.contains(.deflate))
  36. XCTAssertTrue(algorithms.contains(.none))
  37. }
  38. func testCompressionAlgorithmSetElements() {
  39. var algorithms = CompressionAlgorithmSet.all
  40. XCTAssertEqual(Array(algorithms.elements), [.none, .deflate, .gzip])
  41. algorithms.subtract(.deflate)
  42. XCTAssertEqual(Array(algorithms.elements), [.none, .gzip])
  43. algorithms.subtract(.none)
  44. XCTAssertEqual(Array(algorithms.elements), [.gzip])
  45. algorithms.subtract(.gzip)
  46. XCTAssertEqual(Array(algorithms.elements), [])
  47. }
  48. func testCompressionAlgorithmSetElementsIgnoresUnknownBits() {
  49. let algorithms = CompressionAlgorithmSet(rawValue: .max)
  50. XCTAssertEqual(Array(algorithms.elements), [.none, .deflate, .gzip])
  51. }
  52. }