CompressionAlgorithmTests.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. final class CompressionAlgorithmTests: XCTestCase {
  19. func testCompressionAlgorithmSetContains() {
  20. var algorithms = CompressionAlgorithmSet()
  21. XCTAssertFalse(algorithms.contains(.gzip))
  22. XCTAssertFalse(algorithms.contains(.deflate))
  23. XCTAssertFalse(algorithms.contains(.none))
  24. algorithms.formUnion(.gzip)
  25. XCTAssertTrue(algorithms.contains(.gzip))
  26. XCTAssertFalse(algorithms.contains(.deflate))
  27. XCTAssertFalse(algorithms.contains(.none))
  28. algorithms.formUnion(.deflate)
  29. XCTAssertTrue(algorithms.contains(.gzip))
  30. XCTAssertTrue(algorithms.contains(.deflate))
  31. XCTAssertFalse(algorithms.contains(.none))
  32. algorithms.formUnion(.none)
  33. XCTAssertTrue(algorithms.contains(.gzip))
  34. XCTAssertTrue(algorithms.contains(.deflate))
  35. XCTAssertTrue(algorithms.contains(.none))
  36. }
  37. func testCompressionAlgorithmSetElements() {
  38. var algorithms = CompressionAlgorithmSet.all
  39. XCTAssertEqual(Array(algorithms.elements), [.none, .deflate, .gzip])
  40. algorithms.subtract(.deflate)
  41. XCTAssertEqual(Array(algorithms.elements), [.none, .gzip])
  42. algorithms.subtract(.none)
  43. XCTAssertEqual(Array(algorithms.elements), [.gzip])
  44. algorithms.subtract(.gzip)
  45. XCTAssertEqual(Array(algorithms.elements), [])
  46. }
  47. func testCompressionAlgorithmSetElementsIgnoresUnknownBits() {
  48. let algorithms = CompressionAlgorithmSet(rawValue: .max)
  49. XCTAssertEqual(Array(algorithms.elements), [.none, .deflate, .gzip])
  50. }
  51. }