FPRTestUtils.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright 2020 Google LLC
  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. #import <Foundation/Foundation.h>
  15. #import "FirebasePerformance/Sources/FPRNanoPbUtils.h"
  16. #import "FirebasePerformance/Sources/Timer/FIRTrace+Internal.h"
  17. #import "FirebasePerformance/Sources/Timer/FIRTrace+Private.h"
  18. #import "FirebasePerformance/Sources/Loggers/FPRGDTEvent.h"
  19. #import <GoogleDataTransport/GoogleDataTransport.h>
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface FPRTestUtils : NSObject
  22. /** Default initializer. */
  23. - (instancetype)init NS_UNAVAILABLE;
  24. /** Provide the NSBundle instance that can to be used for testing. SPM tests will have a different
  25. * bundle when compared to the default unit test bundle. */
  26. + (NSBundle *)getBundle;
  27. /** Creates a Performance Trace object. */
  28. + (FIRTrace *)createRandomTraceWithName:(NSString *)name;
  29. /** Add verbose session to specific Performance Trace object. */
  30. + (FIRTrace *)addVerboseSessionToTrace:(FIRTrace *)trace;
  31. /** Creates a random Performance Metric Proto object. */
  32. + (firebase_perf_v1_PerfMetric)createRandomPerfMetric:(NSString *)traceName;
  33. /**
  34. * Creates a random Performance Metric Proto object, with verbose
  35. * session ID if it is set as verbose.
  36. */
  37. + (firebase_perf_v1_PerfMetric)createVerboseRandomPerfMetric:(NSString *)traceName;
  38. /** Creates a random internal Performance Metric Proto object. */
  39. + (firebase_perf_v1_PerfMetric)createRandomInternalPerfMetric:(NSString *)traceName;
  40. /** Creates a random network request Performance Metric Proto object. */
  41. + (firebase_perf_v1_PerfMetric)createRandomNetworkPerfMetric:(NSString *)url;
  42. /** Creates a random gauge Performance Metric Proto object. */
  43. + (firebase_perf_v1_PerfMetric)createRandomGaugePerfMetric;
  44. /** Creates a random GDTCOREvent object. */
  45. + (GDTCOREvent *)createRandomTraceGDTEvent:(NSString *)traceName;
  46. /** Creates a random GDTCOREvent object with internal trace event. */
  47. + (GDTCOREvent *)createRandomInternalTraceGDTEvent:(NSString *)traceName;
  48. /** Creates a random GDTCOREvent object with network event. */
  49. + (GDTCOREvent *)createRandomNetworkGDTEvent:(NSString *)url;
  50. /** Creates a NSData object by copying the given bytes array and returns the reference.
  51. *
  52. * @param pbData The pbData to dedoded as NSData
  53. * @return A reference to NSData
  54. */
  55. extern NSData *_Nullable FPRDecodeData(pb_bytes_array_t *_Nonnull pbData);
  56. /** Creates a NSString object by copying the given bytes array and returns the reference.
  57. *
  58. * @param pbData The pbData to dedoded as NSString
  59. * @return A reference to the NSString
  60. * @note This method may cause heap-buffer overflow
  61. */
  62. extern NSString *_Nullable FPRDecodeString(pb_bytes_array_t *_Nonnull pbData);
  63. /** Creates a NSDictionary by copying the given bytes from the StringToStringMap object and returns
  64. * the reference.
  65. *
  66. * @param map The reference to a StringToStringMap object to be decoded.
  67. * @param count The number of entries in the dictionary.
  68. * @return A reference to the dictionary
  69. */
  70. extern NSDictionary<NSString *, NSString *> *_Nullable FPRDecodeStringToStringMap(
  71. StringToStringMap *_Nullable map, NSInteger count);
  72. /** Creates a NSDictionary by copying the given bytes from the StringToNumberMap object and returns
  73. * the reference.
  74. *
  75. * @param map The reference to a StringToNumberMap object to be decoded.
  76. * @param count The number of entries in the dictionary.
  77. * @return A reference to the dictionary
  78. */
  79. extern NSDictionary<NSString *, NSNumber *> *_Nullable FPRDecodeStringToNumberMap(
  80. StringToNumberMap *_Nullable map, NSInteger count);
  81. @end
  82. NS_ASSUME_NONNULL_END