GPBTestUtilities.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // https://developers.google.com/protocol-buffers/
  4. //
  5. // Redistribution and use in source and binary forms, with or without
  6. // modification, are permitted provided that the following conditions are
  7. // met:
  8. //
  9. // * Redistributions of source code must retain the above copyright
  10. // notice, this list of conditions and the following disclaimer.
  11. // * Redistributions in binary form must reproduce the above
  12. // copyright notice, this list of conditions and the following disclaimer
  13. // in the documentation and/or other materials provided with the
  14. // distribution.
  15. // * Neither the name of Google Inc. nor the names of its
  16. // contributors may be used to endorse or promote products derived from
  17. // this software without specific prior written permission.
  18. //
  19. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #import <XCTest/XCTest.h>
  31. @class TestAllExtensions;
  32. @class TestAllTypes;
  33. @class TestMap;
  34. @class TestPackedTypes;
  35. @class TestPackedExtensions;
  36. @class TestUnpackedTypes;
  37. @class TestUnpackedExtensions;
  38. @class GPBExtensionRegistry;
  39. static inline NSData *DataFromCStr(const char *str) {
  40. return [NSData dataWithBytes:str length:strlen(str)];
  41. }
  42. // Helper for uses of C arrays in tests cases.
  43. #ifndef GPBARRAYSIZE
  44. #define GPBARRAYSIZE(a) ((sizeof(a) / sizeof((a[0]))))
  45. #endif // GPBARRAYSIZE
  46. // The number of repetitions of any repeated objects inside of test messages.
  47. extern const uint32_t kGPBDefaultRepeatCount;
  48. @interface GPBTestCase : XCTestCase
  49. - (void)setAllFields:(TestAllTypes *)message repeatedCount:(uint32_t)count;
  50. - (void)clearAllFields:(TestAllTypes *)message;
  51. - (void)setAllExtensions:(TestAllExtensions *)message
  52. repeatedCount:(uint32_t)count;
  53. - (void)setPackedFields:(TestPackedTypes *)message
  54. repeatedCount:(uint32_t)count;
  55. - (void)setUnpackedFields:(TestUnpackedTypes *)message
  56. repeatedCount:(uint32_t)count;
  57. - (void)setPackedExtensions:(TestPackedExtensions *)message
  58. repeatedCount:(uint32_t)count;
  59. - (void)setUnpackedExtensions:(TestUnpackedExtensions *)message
  60. repeatedCount:(uint32_t)count;
  61. - (void)setAllMapFields:(TestMap *)message numEntries:(uint32_t)count;
  62. - (TestAllTypes *)allSetRepeatedCount:(uint32_t)count;
  63. - (TestAllExtensions *)allExtensionsSetRepeatedCount:(uint32_t)count;
  64. - (TestPackedTypes *)packedSetRepeatedCount:(uint32_t)count;
  65. - (TestPackedExtensions *)packedExtensionsSetRepeatedCount:(uint32_t)count;
  66. - (void)assertAllFieldsSet:(TestAllTypes *)message
  67. repeatedCount:(uint32_t)count;
  68. - (void)assertAllExtensionsSet:(TestAllExtensions *)message
  69. repeatedCount:(uint32_t)count;
  70. - (void)assertRepeatedFieldsModified:(TestAllTypes *)message
  71. repeatedCount:(uint32_t)count;
  72. - (void)assertRepeatedExtensionsModified:(TestAllExtensions *)message
  73. repeatedCount:(uint32_t)count;
  74. - (void)assertExtensionsClear:(TestAllExtensions *)message;
  75. - (void)assertClear:(TestAllTypes *)message;
  76. - (void)assertPackedFieldsSet:(TestPackedTypes *)message
  77. repeatedCount:(uint32_t)count;
  78. - (void)assertPackedExtensionsSet:(TestPackedExtensions *)message
  79. repeatedCount:(uint32_t)count;
  80. - (void)modifyRepeatedExtensions:(TestAllExtensions *)message;
  81. - (void)modifyRepeatedFields:(TestAllTypes *)message;
  82. - (GPBExtensionRegistry *)extensionRegistry;
  83. - (NSData *)getDataFileNamed:(NSString *)name dataToWrite:(NSData *)dataToWrite;
  84. - (void)assertAllFieldsKVCMatch:(TestAllTypes *)message;
  85. - (void)setAllFieldsViaKVC:(TestAllTypes *)message
  86. repeatedCount:(uint32_t)count;
  87. - (void)assertClearKVC:(TestAllTypes *)message;
  88. @end