TestNanoPBHelpers.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Copyright 2022 Google LLC
  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. import XCTest
  16. #if SWIFT_PACKAGE
  17. import FirebaseSessionsObjC
  18. #endif // SWIFT_PACKAGE
  19. @testable import FirebaseSessions
  20. // The file and line fields in this function capture the file and line of the
  21. // function call site in the test, and pass them to XCTAssert. Without this, the
  22. // test will attribute the test failure to this function instead of the call in the test.
  23. func assertEqualProtoString(_ value: UnsafeMutablePointer<pb_bytes_array_t>!, expected: String,
  24. fieldName: String, file: StaticString = #filePath,
  25. line: UInt = #line) {
  26. if value == nil {
  27. XCTAssert(
  28. false,
  29. "Field \(fieldName) is nil, but we expected \"\(expected)\"",
  30. file: file,
  31. line: line
  32. )
  33. } else {
  34. XCTAssert(
  35. FIRSESIsPBStringEqual(value, expected),
  36. "Field \(fieldName) does not match expected value \"\(expected)\"",
  37. file: file,
  38. line: line
  39. )
  40. }
  41. }