GPBDictionaryTests+Bool.m 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2015 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 <Foundation/Foundation.h>
  31. #import <XCTest/XCTest.h>
  32. #import "GPBDictionary.h"
  33. #import "GPBTestUtilities.h"
  34. #import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
  35. // Pull in the macros (using an external file because expanding all tests
  36. // in a single file makes a file that is failing to work with within Xcode.
  37. //%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
  38. //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt32, uint32_t, 100U, 101U)
  39. // This block of code is generated, do not edit it directly.
  40. // clang-format off
  41. #pragma mark - Bool -> UInt32
  42. @interface GPBBoolUInt32DictionaryTests : XCTestCase
  43. @end
  44. @implementation GPBBoolUInt32DictionaryTests
  45. - (void)testEmpty {
  46. GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
  47. XCTAssertNotNil(dict);
  48. XCTAssertEqual(dict.count, 0U);
  49. XCTAssertFalse([dict getUInt32:NULL forKey:YES]);
  50. [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
  51. #pragma unused(aKey, aValue, stop)
  52. XCTFail(@"Shouldn't get here!");
  53. }];
  54. [dict release];
  55. }
  56. - (void)testOne {
  57. GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
  58. [dict setUInt32:100U forKey:YES];
  59. XCTAssertNotNil(dict);
  60. XCTAssertEqual(dict.count, 1U);
  61. uint32_t value;
  62. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  63. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  64. XCTAssertEqual(value, 100U);
  65. XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
  66. [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
  67. XCTAssertEqual(aKey, YES);
  68. XCTAssertEqual(aValue, 100U);
  69. XCTAssertNotEqual(stop, NULL);
  70. }];
  71. [dict release];
  72. }
  73. - (void)testBasics {
  74. const BOOL kKeys[] = { YES, NO };
  75. const uint32_t kValues[] = { 100U, 101U };
  76. GPBBoolUInt32Dictionary *dict =
  77. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
  78. forKeys:kKeys
  79. count:GPBARRAYSIZE(kValues)];
  80. XCTAssertNotNil(dict);
  81. XCTAssertEqual(dict.count, 2U);
  82. uint32_t value;
  83. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  84. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  85. XCTAssertEqual(value, 100U);
  86. XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
  87. XCTAssertTrue([dict getUInt32:&value forKey:NO]);
  88. XCTAssertEqual(value, 101U);
  89. __block NSUInteger idx = 0;
  90. BOOL *seenKeys = malloc(2 * sizeof(BOOL));
  91. uint32_t *seenValues = malloc(2 * sizeof(uint32_t));
  92. [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
  93. XCTAssertLessThan(idx, 2U);
  94. seenKeys[idx] = aKey;
  95. seenValues[idx] = aValue;
  96. XCTAssertNotEqual(stop, NULL);
  97. ++idx;
  98. }];
  99. for (int i = 0; i < 2; ++i) {
  100. BOOL foundKey = NO;
  101. for (int j = 0; (j < 2) && !foundKey; ++j) {
  102. if (kKeys[i] == seenKeys[j]) {
  103. foundKey = YES;
  104. XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
  105. }
  106. }
  107. XCTAssertTrue(foundKey, @"i = %d", i);
  108. }
  109. free(seenKeys);
  110. free(seenValues);
  111. // Stopping the enumeration.
  112. idx = 0;
  113. [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
  114. #pragma unused(aKey, aValue)
  115. if (idx == 0) *stop = YES;
  116. XCTAssertNotEqual(idx, 2U);
  117. ++idx;
  118. }];
  119. [dict release];
  120. }
  121. - (void)testEquality {
  122. const BOOL kKeys1[] = { YES, NO };
  123. const BOOL kKeys2[] = { NO, YES };
  124. const uint32_t kValues1[] = { 100U, 101U };
  125. const uint32_t kValues2[] = { 101U, 100U };
  126. const uint32_t kValues3[] = { 101U };
  127. GPBBoolUInt32Dictionary *dict1 =
  128. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
  129. forKeys:kKeys1
  130. count:GPBARRAYSIZE(kValues1)];
  131. XCTAssertNotNil(dict1);
  132. GPBBoolUInt32Dictionary *dict1prime =
  133. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
  134. forKeys:kKeys1
  135. count:GPBARRAYSIZE(kValues1)];
  136. XCTAssertNotNil(dict1prime);
  137. GPBBoolUInt32Dictionary *dict2 =
  138. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues2
  139. forKeys:kKeys1
  140. count:GPBARRAYSIZE(kValues2)];
  141. XCTAssertNotNil(dict2);
  142. GPBBoolUInt32Dictionary *dict3 =
  143. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
  144. forKeys:kKeys2
  145. count:GPBARRAYSIZE(kValues1)];
  146. XCTAssertNotNil(dict3);
  147. GPBBoolUInt32Dictionary *dict4 =
  148. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues3
  149. forKeys:kKeys1
  150. count:GPBARRAYSIZE(kValues3)];
  151. XCTAssertNotNil(dict4);
  152. // 1/1Prime should be different objects, but equal.
  153. XCTAssertNotEqual(dict1, dict1prime);
  154. XCTAssertEqualObjects(dict1, dict1prime);
  155. // Equal, so they must have same hash.
  156. XCTAssertEqual([dict1 hash], [dict1prime hash]);
  157. // 2 is same keys, different values; not equal.
  158. XCTAssertNotEqualObjects(dict1, dict2);
  159. // 3 is different keys, same values; not equal.
  160. XCTAssertNotEqualObjects(dict1, dict3);
  161. // 4 Fewer pairs; not equal
  162. XCTAssertNotEqualObjects(dict1, dict4);
  163. [dict1 release];
  164. [dict1prime release];
  165. [dict2 release];
  166. [dict3 release];
  167. [dict4 release];
  168. }
  169. - (void)testCopy {
  170. const BOOL kKeys[] = { YES, NO };
  171. const uint32_t kValues[] = { 100U, 101U };
  172. GPBBoolUInt32Dictionary *dict =
  173. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
  174. forKeys:kKeys
  175. count:GPBARRAYSIZE(kValues)];
  176. XCTAssertNotNil(dict);
  177. GPBBoolUInt32Dictionary *dict2 = [dict copy];
  178. XCTAssertNotNil(dict2);
  179. // Should be new object but equal.
  180. XCTAssertNotEqual(dict, dict2);
  181. XCTAssertEqualObjects(dict, dict2);
  182. XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt32Dictionary class]]);
  183. [dict2 release];
  184. [dict release];
  185. }
  186. - (void)testDictionaryFromDictionary {
  187. const BOOL kKeys[] = { YES, NO };
  188. const uint32_t kValues[] = { 100U, 101U };
  189. GPBBoolUInt32Dictionary *dict =
  190. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
  191. forKeys:kKeys
  192. count:GPBARRAYSIZE(kValues)];
  193. XCTAssertNotNil(dict);
  194. GPBBoolUInt32Dictionary *dict2 =
  195. [[GPBBoolUInt32Dictionary alloc] initWithDictionary:dict];
  196. XCTAssertNotNil(dict2);
  197. // Should be new pointer, but equal objects.
  198. XCTAssertNotEqual(dict, dict2);
  199. XCTAssertEqualObjects(dict, dict2);
  200. [dict2 release];
  201. [dict release];
  202. }
  203. - (void)testAdds {
  204. GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
  205. XCTAssertNotNil(dict);
  206. XCTAssertEqual(dict.count, 0U);
  207. [dict setUInt32:100U forKey:YES];
  208. XCTAssertEqual(dict.count, 1U);
  209. const BOOL kKeys[] = { NO };
  210. const uint32_t kValues[] = { 101U };
  211. GPBBoolUInt32Dictionary *dict2 =
  212. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
  213. forKeys:kKeys
  214. count:GPBARRAYSIZE(kValues)];
  215. XCTAssertNotNil(dict2);
  216. [dict addEntriesFromDictionary:dict2];
  217. XCTAssertEqual(dict.count, 2U);
  218. uint32_t value;
  219. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  220. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  221. XCTAssertEqual(value, 100U);
  222. XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
  223. XCTAssertTrue([dict getUInt32:&value forKey:NO]);
  224. XCTAssertEqual(value, 101U);
  225. [dict2 release];
  226. [dict release];
  227. }
  228. - (void)testRemove {
  229. const BOOL kKeys[] = { YES, NO};
  230. const uint32_t kValues[] = { 100U, 101U };
  231. GPBBoolUInt32Dictionary *dict =
  232. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
  233. forKeys:kKeys
  234. count:GPBARRAYSIZE(kValues)];
  235. XCTAssertNotNil(dict);
  236. XCTAssertEqual(dict.count, 2U);
  237. [dict removeUInt32ForKey:NO];
  238. XCTAssertEqual(dict.count, 1U);
  239. uint32_t value;
  240. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  241. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  242. XCTAssertEqual(value, 100U);
  243. XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
  244. // Remove again does nothing.
  245. [dict removeUInt32ForKey:NO];
  246. XCTAssertEqual(dict.count, 1U);
  247. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  248. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  249. XCTAssertEqual(value, 100U);
  250. XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
  251. [dict removeAll];
  252. XCTAssertEqual(dict.count, 0U);
  253. XCTAssertFalse([dict getUInt32:NULL forKey:YES]);
  254. XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
  255. [dict release];
  256. }
  257. - (void)testInplaceMutation {
  258. const BOOL kKeys[] = { YES, NO };
  259. const uint32_t kValues[] = { 100U, 101U };
  260. GPBBoolUInt32Dictionary *dict =
  261. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
  262. forKeys:kKeys
  263. count:GPBARRAYSIZE(kValues)];
  264. XCTAssertNotNil(dict);
  265. XCTAssertEqual(dict.count, 2U);
  266. uint32_t value;
  267. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  268. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  269. XCTAssertEqual(value, 100U);
  270. XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
  271. XCTAssertTrue([dict getUInt32:&value forKey:NO]);
  272. XCTAssertEqual(value, 101U);
  273. [dict setUInt32:101U forKey:YES];
  274. XCTAssertEqual(dict.count, 2U);
  275. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  276. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  277. XCTAssertEqual(value, 101U);
  278. XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
  279. XCTAssertTrue([dict getUInt32:&value forKey:NO]);
  280. XCTAssertEqual(value, 101U);
  281. [dict setUInt32:100U forKey:NO];
  282. XCTAssertEqual(dict.count, 2U);
  283. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  284. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  285. XCTAssertEqual(value, 101U);
  286. XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
  287. XCTAssertTrue([dict getUInt32:&value forKey:NO]);
  288. XCTAssertEqual(value, 100U);
  289. const BOOL kKeys2[] = { NO, YES };
  290. const uint32_t kValues2[] = { 101U, 100U };
  291. GPBBoolUInt32Dictionary *dict2 =
  292. [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues2
  293. forKeys:kKeys2
  294. count:GPBARRAYSIZE(kValues2)];
  295. XCTAssertNotNil(dict2);
  296. [dict addEntriesFromDictionary:dict2];
  297. XCTAssertEqual(dict.count, 2U);
  298. XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
  299. XCTAssertTrue([dict getUInt32:&value forKey:YES]);
  300. XCTAssertEqual(value, 100U);
  301. XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
  302. XCTAssertTrue([dict getUInt32:&value forKey:NO]);
  303. XCTAssertEqual(value, 101U);
  304. [dict2 release];
  305. [dict release];
  306. }
  307. @end
  308. // clang-format on
  309. //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int32, int32_t, 200, 201)
  310. // This block of code is generated, do not edit it directly.
  311. // clang-format off
  312. #pragma mark - Bool -> Int32
  313. @interface GPBBoolInt32DictionaryTests : XCTestCase
  314. @end
  315. @implementation GPBBoolInt32DictionaryTests
  316. - (void)testEmpty {
  317. GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
  318. XCTAssertNotNil(dict);
  319. XCTAssertEqual(dict.count, 0U);
  320. XCTAssertFalse([dict getInt32:NULL forKey:YES]);
  321. [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
  322. #pragma unused(aKey, aValue, stop)
  323. XCTFail(@"Shouldn't get here!");
  324. }];
  325. [dict release];
  326. }
  327. - (void)testOne {
  328. GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
  329. [dict setInt32:200 forKey:YES];
  330. XCTAssertNotNil(dict);
  331. XCTAssertEqual(dict.count, 1U);
  332. int32_t value;
  333. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  334. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  335. XCTAssertEqual(value, 200);
  336. XCTAssertFalse([dict getInt32:NULL forKey:NO]);
  337. [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
  338. XCTAssertEqual(aKey, YES);
  339. XCTAssertEqual(aValue, 200);
  340. XCTAssertNotEqual(stop, NULL);
  341. }];
  342. [dict release];
  343. }
  344. - (void)testBasics {
  345. const BOOL kKeys[] = { YES, NO };
  346. const int32_t kValues[] = { 200, 201 };
  347. GPBBoolInt32Dictionary *dict =
  348. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
  349. forKeys:kKeys
  350. count:GPBARRAYSIZE(kValues)];
  351. XCTAssertNotNil(dict);
  352. XCTAssertEqual(dict.count, 2U);
  353. int32_t value;
  354. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  355. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  356. XCTAssertEqual(value, 200);
  357. XCTAssertTrue([dict getInt32:NULL forKey:NO]);
  358. XCTAssertTrue([dict getInt32:&value forKey:NO]);
  359. XCTAssertEqual(value, 201);
  360. __block NSUInteger idx = 0;
  361. BOOL *seenKeys = malloc(2 * sizeof(BOOL));
  362. int32_t *seenValues = malloc(2 * sizeof(int32_t));
  363. [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
  364. XCTAssertLessThan(idx, 2U);
  365. seenKeys[idx] = aKey;
  366. seenValues[idx] = aValue;
  367. XCTAssertNotEqual(stop, NULL);
  368. ++idx;
  369. }];
  370. for (int i = 0; i < 2; ++i) {
  371. BOOL foundKey = NO;
  372. for (int j = 0; (j < 2) && !foundKey; ++j) {
  373. if (kKeys[i] == seenKeys[j]) {
  374. foundKey = YES;
  375. XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
  376. }
  377. }
  378. XCTAssertTrue(foundKey, @"i = %d", i);
  379. }
  380. free(seenKeys);
  381. free(seenValues);
  382. // Stopping the enumeration.
  383. idx = 0;
  384. [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
  385. #pragma unused(aKey, aValue)
  386. if (idx == 0) *stop = YES;
  387. XCTAssertNotEqual(idx, 2U);
  388. ++idx;
  389. }];
  390. [dict release];
  391. }
  392. - (void)testEquality {
  393. const BOOL kKeys1[] = { YES, NO };
  394. const BOOL kKeys2[] = { NO, YES };
  395. const int32_t kValues1[] = { 200, 201 };
  396. const int32_t kValues2[] = { 201, 200 };
  397. const int32_t kValues3[] = { 201 };
  398. GPBBoolInt32Dictionary *dict1 =
  399. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
  400. forKeys:kKeys1
  401. count:GPBARRAYSIZE(kValues1)];
  402. XCTAssertNotNil(dict1);
  403. GPBBoolInt32Dictionary *dict1prime =
  404. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
  405. forKeys:kKeys1
  406. count:GPBARRAYSIZE(kValues1)];
  407. XCTAssertNotNil(dict1prime);
  408. GPBBoolInt32Dictionary *dict2 =
  409. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues2
  410. forKeys:kKeys1
  411. count:GPBARRAYSIZE(kValues2)];
  412. XCTAssertNotNil(dict2);
  413. GPBBoolInt32Dictionary *dict3 =
  414. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
  415. forKeys:kKeys2
  416. count:GPBARRAYSIZE(kValues1)];
  417. XCTAssertNotNil(dict3);
  418. GPBBoolInt32Dictionary *dict4 =
  419. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues3
  420. forKeys:kKeys1
  421. count:GPBARRAYSIZE(kValues3)];
  422. XCTAssertNotNil(dict4);
  423. // 1/1Prime should be different objects, but equal.
  424. XCTAssertNotEqual(dict1, dict1prime);
  425. XCTAssertEqualObjects(dict1, dict1prime);
  426. // Equal, so they must have same hash.
  427. XCTAssertEqual([dict1 hash], [dict1prime hash]);
  428. // 2 is same keys, different values; not equal.
  429. XCTAssertNotEqualObjects(dict1, dict2);
  430. // 3 is different keys, same values; not equal.
  431. XCTAssertNotEqualObjects(dict1, dict3);
  432. // 4 Fewer pairs; not equal
  433. XCTAssertNotEqualObjects(dict1, dict4);
  434. [dict1 release];
  435. [dict1prime release];
  436. [dict2 release];
  437. [dict3 release];
  438. [dict4 release];
  439. }
  440. - (void)testCopy {
  441. const BOOL kKeys[] = { YES, NO };
  442. const int32_t kValues[] = { 200, 201 };
  443. GPBBoolInt32Dictionary *dict =
  444. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
  445. forKeys:kKeys
  446. count:GPBARRAYSIZE(kValues)];
  447. XCTAssertNotNil(dict);
  448. GPBBoolInt32Dictionary *dict2 = [dict copy];
  449. XCTAssertNotNil(dict2);
  450. // Should be new object but equal.
  451. XCTAssertNotEqual(dict, dict2);
  452. XCTAssertEqualObjects(dict, dict2);
  453. XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt32Dictionary class]]);
  454. [dict2 release];
  455. [dict release];
  456. }
  457. - (void)testDictionaryFromDictionary {
  458. const BOOL kKeys[] = { YES, NO };
  459. const int32_t kValues[] = { 200, 201 };
  460. GPBBoolInt32Dictionary *dict =
  461. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
  462. forKeys:kKeys
  463. count:GPBARRAYSIZE(kValues)];
  464. XCTAssertNotNil(dict);
  465. GPBBoolInt32Dictionary *dict2 =
  466. [[GPBBoolInt32Dictionary alloc] initWithDictionary:dict];
  467. XCTAssertNotNil(dict2);
  468. // Should be new pointer, but equal objects.
  469. XCTAssertNotEqual(dict, dict2);
  470. XCTAssertEqualObjects(dict, dict2);
  471. [dict2 release];
  472. [dict release];
  473. }
  474. - (void)testAdds {
  475. GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
  476. XCTAssertNotNil(dict);
  477. XCTAssertEqual(dict.count, 0U);
  478. [dict setInt32:200 forKey:YES];
  479. XCTAssertEqual(dict.count, 1U);
  480. const BOOL kKeys[] = { NO };
  481. const int32_t kValues[] = { 201 };
  482. GPBBoolInt32Dictionary *dict2 =
  483. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
  484. forKeys:kKeys
  485. count:GPBARRAYSIZE(kValues)];
  486. XCTAssertNotNil(dict2);
  487. [dict addEntriesFromDictionary:dict2];
  488. XCTAssertEqual(dict.count, 2U);
  489. int32_t value;
  490. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  491. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  492. XCTAssertEqual(value, 200);
  493. XCTAssertTrue([dict getInt32:NULL forKey:NO]);
  494. XCTAssertTrue([dict getInt32:&value forKey:NO]);
  495. XCTAssertEqual(value, 201);
  496. [dict2 release];
  497. [dict release];
  498. }
  499. - (void)testRemove {
  500. const BOOL kKeys[] = { YES, NO};
  501. const int32_t kValues[] = { 200, 201 };
  502. GPBBoolInt32Dictionary *dict =
  503. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
  504. forKeys:kKeys
  505. count:GPBARRAYSIZE(kValues)];
  506. XCTAssertNotNil(dict);
  507. XCTAssertEqual(dict.count, 2U);
  508. [dict removeInt32ForKey:NO];
  509. XCTAssertEqual(dict.count, 1U);
  510. int32_t value;
  511. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  512. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  513. XCTAssertEqual(value, 200);
  514. XCTAssertFalse([dict getInt32:NULL forKey:NO]);
  515. // Remove again does nothing.
  516. [dict removeInt32ForKey:NO];
  517. XCTAssertEqual(dict.count, 1U);
  518. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  519. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  520. XCTAssertEqual(value, 200);
  521. XCTAssertFalse([dict getInt32:NULL forKey:NO]);
  522. [dict removeAll];
  523. XCTAssertEqual(dict.count, 0U);
  524. XCTAssertFalse([dict getInt32:NULL forKey:YES]);
  525. XCTAssertFalse([dict getInt32:NULL forKey:NO]);
  526. [dict release];
  527. }
  528. - (void)testInplaceMutation {
  529. const BOOL kKeys[] = { YES, NO };
  530. const int32_t kValues[] = { 200, 201 };
  531. GPBBoolInt32Dictionary *dict =
  532. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
  533. forKeys:kKeys
  534. count:GPBARRAYSIZE(kValues)];
  535. XCTAssertNotNil(dict);
  536. XCTAssertEqual(dict.count, 2U);
  537. int32_t value;
  538. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  539. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  540. XCTAssertEqual(value, 200);
  541. XCTAssertTrue([dict getInt32:NULL forKey:NO]);
  542. XCTAssertTrue([dict getInt32:&value forKey:NO]);
  543. XCTAssertEqual(value, 201);
  544. [dict setInt32:201 forKey:YES];
  545. XCTAssertEqual(dict.count, 2U);
  546. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  547. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  548. XCTAssertEqual(value, 201);
  549. XCTAssertTrue([dict getInt32:NULL forKey:NO]);
  550. XCTAssertTrue([dict getInt32:&value forKey:NO]);
  551. XCTAssertEqual(value, 201);
  552. [dict setInt32:200 forKey:NO];
  553. XCTAssertEqual(dict.count, 2U);
  554. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  555. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  556. XCTAssertEqual(value, 201);
  557. XCTAssertTrue([dict getInt32:NULL forKey:NO]);
  558. XCTAssertTrue([dict getInt32:&value forKey:NO]);
  559. XCTAssertEqual(value, 200);
  560. const BOOL kKeys2[] = { NO, YES };
  561. const int32_t kValues2[] = { 201, 200 };
  562. GPBBoolInt32Dictionary *dict2 =
  563. [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues2
  564. forKeys:kKeys2
  565. count:GPBARRAYSIZE(kValues2)];
  566. XCTAssertNotNil(dict2);
  567. [dict addEntriesFromDictionary:dict2];
  568. XCTAssertEqual(dict.count, 2U);
  569. XCTAssertTrue([dict getInt32:NULL forKey:YES]);
  570. XCTAssertTrue([dict getInt32:&value forKey:YES]);
  571. XCTAssertEqual(value, 200);
  572. XCTAssertTrue([dict getInt32:NULL forKey:NO]);
  573. XCTAssertTrue([dict getInt32:&value forKey:NO]);
  574. XCTAssertEqual(value, 201);
  575. [dict2 release];
  576. [dict release];
  577. }
  578. @end
  579. // clang-format on
  580. //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt64, uint64_t, 300U, 301U)
  581. // This block of code is generated, do not edit it directly.
  582. // clang-format off
  583. #pragma mark - Bool -> UInt64
  584. @interface GPBBoolUInt64DictionaryTests : XCTestCase
  585. @end
  586. @implementation GPBBoolUInt64DictionaryTests
  587. - (void)testEmpty {
  588. GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
  589. XCTAssertNotNil(dict);
  590. XCTAssertEqual(dict.count, 0U);
  591. XCTAssertFalse([dict getUInt64:NULL forKey:YES]);
  592. [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
  593. #pragma unused(aKey, aValue, stop)
  594. XCTFail(@"Shouldn't get here!");
  595. }];
  596. [dict release];
  597. }
  598. - (void)testOne {
  599. GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
  600. [dict setUInt64:300U forKey:YES];
  601. XCTAssertNotNil(dict);
  602. XCTAssertEqual(dict.count, 1U);
  603. uint64_t value;
  604. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  605. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  606. XCTAssertEqual(value, 300U);
  607. XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
  608. [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
  609. XCTAssertEqual(aKey, YES);
  610. XCTAssertEqual(aValue, 300U);
  611. XCTAssertNotEqual(stop, NULL);
  612. }];
  613. [dict release];
  614. }
  615. - (void)testBasics {
  616. const BOOL kKeys[] = { YES, NO };
  617. const uint64_t kValues[] = { 300U, 301U };
  618. GPBBoolUInt64Dictionary *dict =
  619. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
  620. forKeys:kKeys
  621. count:GPBARRAYSIZE(kValues)];
  622. XCTAssertNotNil(dict);
  623. XCTAssertEqual(dict.count, 2U);
  624. uint64_t value;
  625. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  626. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  627. XCTAssertEqual(value, 300U);
  628. XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
  629. XCTAssertTrue([dict getUInt64:&value forKey:NO]);
  630. XCTAssertEqual(value, 301U);
  631. __block NSUInteger idx = 0;
  632. BOOL *seenKeys = malloc(2 * sizeof(BOOL));
  633. uint64_t *seenValues = malloc(2 * sizeof(uint64_t));
  634. [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
  635. XCTAssertLessThan(idx, 2U);
  636. seenKeys[idx] = aKey;
  637. seenValues[idx] = aValue;
  638. XCTAssertNotEqual(stop, NULL);
  639. ++idx;
  640. }];
  641. for (int i = 0; i < 2; ++i) {
  642. BOOL foundKey = NO;
  643. for (int j = 0; (j < 2) && !foundKey; ++j) {
  644. if (kKeys[i] == seenKeys[j]) {
  645. foundKey = YES;
  646. XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
  647. }
  648. }
  649. XCTAssertTrue(foundKey, @"i = %d", i);
  650. }
  651. free(seenKeys);
  652. free(seenValues);
  653. // Stopping the enumeration.
  654. idx = 0;
  655. [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
  656. #pragma unused(aKey, aValue)
  657. if (idx == 0) *stop = YES;
  658. XCTAssertNotEqual(idx, 2U);
  659. ++idx;
  660. }];
  661. [dict release];
  662. }
  663. - (void)testEquality {
  664. const BOOL kKeys1[] = { YES, NO };
  665. const BOOL kKeys2[] = { NO, YES };
  666. const uint64_t kValues1[] = { 300U, 301U };
  667. const uint64_t kValues2[] = { 301U, 300U };
  668. const uint64_t kValues3[] = { 301U };
  669. GPBBoolUInt64Dictionary *dict1 =
  670. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
  671. forKeys:kKeys1
  672. count:GPBARRAYSIZE(kValues1)];
  673. XCTAssertNotNil(dict1);
  674. GPBBoolUInt64Dictionary *dict1prime =
  675. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
  676. forKeys:kKeys1
  677. count:GPBARRAYSIZE(kValues1)];
  678. XCTAssertNotNil(dict1prime);
  679. GPBBoolUInt64Dictionary *dict2 =
  680. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues2
  681. forKeys:kKeys1
  682. count:GPBARRAYSIZE(kValues2)];
  683. XCTAssertNotNil(dict2);
  684. GPBBoolUInt64Dictionary *dict3 =
  685. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
  686. forKeys:kKeys2
  687. count:GPBARRAYSIZE(kValues1)];
  688. XCTAssertNotNil(dict3);
  689. GPBBoolUInt64Dictionary *dict4 =
  690. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues3
  691. forKeys:kKeys1
  692. count:GPBARRAYSIZE(kValues3)];
  693. XCTAssertNotNil(dict4);
  694. // 1/1Prime should be different objects, but equal.
  695. XCTAssertNotEqual(dict1, dict1prime);
  696. XCTAssertEqualObjects(dict1, dict1prime);
  697. // Equal, so they must have same hash.
  698. XCTAssertEqual([dict1 hash], [dict1prime hash]);
  699. // 2 is same keys, different values; not equal.
  700. XCTAssertNotEqualObjects(dict1, dict2);
  701. // 3 is different keys, same values; not equal.
  702. XCTAssertNotEqualObjects(dict1, dict3);
  703. // 4 Fewer pairs; not equal
  704. XCTAssertNotEqualObjects(dict1, dict4);
  705. [dict1 release];
  706. [dict1prime release];
  707. [dict2 release];
  708. [dict3 release];
  709. [dict4 release];
  710. }
  711. - (void)testCopy {
  712. const BOOL kKeys[] = { YES, NO };
  713. const uint64_t kValues[] = { 300U, 301U };
  714. GPBBoolUInt64Dictionary *dict =
  715. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
  716. forKeys:kKeys
  717. count:GPBARRAYSIZE(kValues)];
  718. XCTAssertNotNil(dict);
  719. GPBBoolUInt64Dictionary *dict2 = [dict copy];
  720. XCTAssertNotNil(dict2);
  721. // Should be new object but equal.
  722. XCTAssertNotEqual(dict, dict2);
  723. XCTAssertEqualObjects(dict, dict2);
  724. XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt64Dictionary class]]);
  725. [dict2 release];
  726. [dict release];
  727. }
  728. - (void)testDictionaryFromDictionary {
  729. const BOOL kKeys[] = { YES, NO };
  730. const uint64_t kValues[] = { 300U, 301U };
  731. GPBBoolUInt64Dictionary *dict =
  732. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
  733. forKeys:kKeys
  734. count:GPBARRAYSIZE(kValues)];
  735. XCTAssertNotNil(dict);
  736. GPBBoolUInt64Dictionary *dict2 =
  737. [[GPBBoolUInt64Dictionary alloc] initWithDictionary:dict];
  738. XCTAssertNotNil(dict2);
  739. // Should be new pointer, but equal objects.
  740. XCTAssertNotEqual(dict, dict2);
  741. XCTAssertEqualObjects(dict, dict2);
  742. [dict2 release];
  743. [dict release];
  744. }
  745. - (void)testAdds {
  746. GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
  747. XCTAssertNotNil(dict);
  748. XCTAssertEqual(dict.count, 0U);
  749. [dict setUInt64:300U forKey:YES];
  750. XCTAssertEqual(dict.count, 1U);
  751. const BOOL kKeys[] = { NO };
  752. const uint64_t kValues[] = { 301U };
  753. GPBBoolUInt64Dictionary *dict2 =
  754. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
  755. forKeys:kKeys
  756. count:GPBARRAYSIZE(kValues)];
  757. XCTAssertNotNil(dict2);
  758. [dict addEntriesFromDictionary:dict2];
  759. XCTAssertEqual(dict.count, 2U);
  760. uint64_t value;
  761. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  762. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  763. XCTAssertEqual(value, 300U);
  764. XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
  765. XCTAssertTrue([dict getUInt64:&value forKey:NO]);
  766. XCTAssertEqual(value, 301U);
  767. [dict2 release];
  768. [dict release];
  769. }
  770. - (void)testRemove {
  771. const BOOL kKeys[] = { YES, NO};
  772. const uint64_t kValues[] = { 300U, 301U };
  773. GPBBoolUInt64Dictionary *dict =
  774. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
  775. forKeys:kKeys
  776. count:GPBARRAYSIZE(kValues)];
  777. XCTAssertNotNil(dict);
  778. XCTAssertEqual(dict.count, 2U);
  779. [dict removeUInt64ForKey:NO];
  780. XCTAssertEqual(dict.count, 1U);
  781. uint64_t value;
  782. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  783. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  784. XCTAssertEqual(value, 300U);
  785. XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
  786. // Remove again does nothing.
  787. [dict removeUInt64ForKey:NO];
  788. XCTAssertEqual(dict.count, 1U);
  789. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  790. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  791. XCTAssertEqual(value, 300U);
  792. XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
  793. [dict removeAll];
  794. XCTAssertEqual(dict.count, 0U);
  795. XCTAssertFalse([dict getUInt64:NULL forKey:YES]);
  796. XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
  797. [dict release];
  798. }
  799. - (void)testInplaceMutation {
  800. const BOOL kKeys[] = { YES, NO };
  801. const uint64_t kValues[] = { 300U, 301U };
  802. GPBBoolUInt64Dictionary *dict =
  803. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
  804. forKeys:kKeys
  805. count:GPBARRAYSIZE(kValues)];
  806. XCTAssertNotNil(dict);
  807. XCTAssertEqual(dict.count, 2U);
  808. uint64_t value;
  809. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  810. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  811. XCTAssertEqual(value, 300U);
  812. XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
  813. XCTAssertTrue([dict getUInt64:&value forKey:NO]);
  814. XCTAssertEqual(value, 301U);
  815. [dict setUInt64:301U forKey:YES];
  816. XCTAssertEqual(dict.count, 2U);
  817. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  818. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  819. XCTAssertEqual(value, 301U);
  820. XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
  821. XCTAssertTrue([dict getUInt64:&value forKey:NO]);
  822. XCTAssertEqual(value, 301U);
  823. [dict setUInt64:300U forKey:NO];
  824. XCTAssertEqual(dict.count, 2U);
  825. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  826. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  827. XCTAssertEqual(value, 301U);
  828. XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
  829. XCTAssertTrue([dict getUInt64:&value forKey:NO]);
  830. XCTAssertEqual(value, 300U);
  831. const BOOL kKeys2[] = { NO, YES };
  832. const uint64_t kValues2[] = { 301U, 300U };
  833. GPBBoolUInt64Dictionary *dict2 =
  834. [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues2
  835. forKeys:kKeys2
  836. count:GPBARRAYSIZE(kValues2)];
  837. XCTAssertNotNil(dict2);
  838. [dict addEntriesFromDictionary:dict2];
  839. XCTAssertEqual(dict.count, 2U);
  840. XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
  841. XCTAssertTrue([dict getUInt64:&value forKey:YES]);
  842. XCTAssertEqual(value, 300U);
  843. XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
  844. XCTAssertTrue([dict getUInt64:&value forKey:NO]);
  845. XCTAssertEqual(value, 301U);
  846. [dict2 release];
  847. [dict release];
  848. }
  849. @end
  850. // clang-format on
  851. //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int64, int64_t, 400, 401)
  852. // This block of code is generated, do not edit it directly.
  853. // clang-format off
  854. #pragma mark - Bool -> Int64
  855. @interface GPBBoolInt64DictionaryTests : XCTestCase
  856. @end
  857. @implementation GPBBoolInt64DictionaryTests
  858. - (void)testEmpty {
  859. GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
  860. XCTAssertNotNil(dict);
  861. XCTAssertEqual(dict.count, 0U);
  862. XCTAssertFalse([dict getInt64:NULL forKey:YES]);
  863. [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
  864. #pragma unused(aKey, aValue, stop)
  865. XCTFail(@"Shouldn't get here!");
  866. }];
  867. [dict release];
  868. }
  869. - (void)testOne {
  870. GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
  871. [dict setInt64:400 forKey:YES];
  872. XCTAssertNotNil(dict);
  873. XCTAssertEqual(dict.count, 1U);
  874. int64_t value;
  875. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  876. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  877. XCTAssertEqual(value, 400);
  878. XCTAssertFalse([dict getInt64:NULL forKey:NO]);
  879. [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
  880. XCTAssertEqual(aKey, YES);
  881. XCTAssertEqual(aValue, 400);
  882. XCTAssertNotEqual(stop, NULL);
  883. }];
  884. [dict release];
  885. }
  886. - (void)testBasics {
  887. const BOOL kKeys[] = { YES, NO };
  888. const int64_t kValues[] = { 400, 401 };
  889. GPBBoolInt64Dictionary *dict =
  890. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
  891. forKeys:kKeys
  892. count:GPBARRAYSIZE(kValues)];
  893. XCTAssertNotNil(dict);
  894. XCTAssertEqual(dict.count, 2U);
  895. int64_t value;
  896. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  897. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  898. XCTAssertEqual(value, 400);
  899. XCTAssertTrue([dict getInt64:NULL forKey:NO]);
  900. XCTAssertTrue([dict getInt64:&value forKey:NO]);
  901. XCTAssertEqual(value, 401);
  902. __block NSUInteger idx = 0;
  903. BOOL *seenKeys = malloc(2 * sizeof(BOOL));
  904. int64_t *seenValues = malloc(2 * sizeof(int64_t));
  905. [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
  906. XCTAssertLessThan(idx, 2U);
  907. seenKeys[idx] = aKey;
  908. seenValues[idx] = aValue;
  909. XCTAssertNotEqual(stop, NULL);
  910. ++idx;
  911. }];
  912. for (int i = 0; i < 2; ++i) {
  913. BOOL foundKey = NO;
  914. for (int j = 0; (j < 2) && !foundKey; ++j) {
  915. if (kKeys[i] == seenKeys[j]) {
  916. foundKey = YES;
  917. XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
  918. }
  919. }
  920. XCTAssertTrue(foundKey, @"i = %d", i);
  921. }
  922. free(seenKeys);
  923. free(seenValues);
  924. // Stopping the enumeration.
  925. idx = 0;
  926. [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
  927. #pragma unused(aKey, aValue)
  928. if (idx == 0) *stop = YES;
  929. XCTAssertNotEqual(idx, 2U);
  930. ++idx;
  931. }];
  932. [dict release];
  933. }
  934. - (void)testEquality {
  935. const BOOL kKeys1[] = { YES, NO };
  936. const BOOL kKeys2[] = { NO, YES };
  937. const int64_t kValues1[] = { 400, 401 };
  938. const int64_t kValues2[] = { 401, 400 };
  939. const int64_t kValues3[] = { 401 };
  940. GPBBoolInt64Dictionary *dict1 =
  941. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
  942. forKeys:kKeys1
  943. count:GPBARRAYSIZE(kValues1)];
  944. XCTAssertNotNil(dict1);
  945. GPBBoolInt64Dictionary *dict1prime =
  946. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
  947. forKeys:kKeys1
  948. count:GPBARRAYSIZE(kValues1)];
  949. XCTAssertNotNil(dict1prime);
  950. GPBBoolInt64Dictionary *dict2 =
  951. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues2
  952. forKeys:kKeys1
  953. count:GPBARRAYSIZE(kValues2)];
  954. XCTAssertNotNil(dict2);
  955. GPBBoolInt64Dictionary *dict3 =
  956. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
  957. forKeys:kKeys2
  958. count:GPBARRAYSIZE(kValues1)];
  959. XCTAssertNotNil(dict3);
  960. GPBBoolInt64Dictionary *dict4 =
  961. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues3
  962. forKeys:kKeys1
  963. count:GPBARRAYSIZE(kValues3)];
  964. XCTAssertNotNil(dict4);
  965. // 1/1Prime should be different objects, but equal.
  966. XCTAssertNotEqual(dict1, dict1prime);
  967. XCTAssertEqualObjects(dict1, dict1prime);
  968. // Equal, so they must have same hash.
  969. XCTAssertEqual([dict1 hash], [dict1prime hash]);
  970. // 2 is same keys, different values; not equal.
  971. XCTAssertNotEqualObjects(dict1, dict2);
  972. // 3 is different keys, same values; not equal.
  973. XCTAssertNotEqualObjects(dict1, dict3);
  974. // 4 Fewer pairs; not equal
  975. XCTAssertNotEqualObjects(dict1, dict4);
  976. [dict1 release];
  977. [dict1prime release];
  978. [dict2 release];
  979. [dict3 release];
  980. [dict4 release];
  981. }
  982. - (void)testCopy {
  983. const BOOL kKeys[] = { YES, NO };
  984. const int64_t kValues[] = { 400, 401 };
  985. GPBBoolInt64Dictionary *dict =
  986. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
  987. forKeys:kKeys
  988. count:GPBARRAYSIZE(kValues)];
  989. XCTAssertNotNil(dict);
  990. GPBBoolInt64Dictionary *dict2 = [dict copy];
  991. XCTAssertNotNil(dict2);
  992. // Should be new object but equal.
  993. XCTAssertNotEqual(dict, dict2);
  994. XCTAssertEqualObjects(dict, dict2);
  995. XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt64Dictionary class]]);
  996. [dict2 release];
  997. [dict release];
  998. }
  999. - (void)testDictionaryFromDictionary {
  1000. const BOOL kKeys[] = { YES, NO };
  1001. const int64_t kValues[] = { 400, 401 };
  1002. GPBBoolInt64Dictionary *dict =
  1003. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
  1004. forKeys:kKeys
  1005. count:GPBARRAYSIZE(kValues)];
  1006. XCTAssertNotNil(dict);
  1007. GPBBoolInt64Dictionary *dict2 =
  1008. [[GPBBoolInt64Dictionary alloc] initWithDictionary:dict];
  1009. XCTAssertNotNil(dict2);
  1010. // Should be new pointer, but equal objects.
  1011. XCTAssertNotEqual(dict, dict2);
  1012. XCTAssertEqualObjects(dict, dict2);
  1013. [dict2 release];
  1014. [dict release];
  1015. }
  1016. - (void)testAdds {
  1017. GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
  1018. XCTAssertNotNil(dict);
  1019. XCTAssertEqual(dict.count, 0U);
  1020. [dict setInt64:400 forKey:YES];
  1021. XCTAssertEqual(dict.count, 1U);
  1022. const BOOL kKeys[] = { NO };
  1023. const int64_t kValues[] = { 401 };
  1024. GPBBoolInt64Dictionary *dict2 =
  1025. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
  1026. forKeys:kKeys
  1027. count:GPBARRAYSIZE(kValues)];
  1028. XCTAssertNotNil(dict2);
  1029. [dict addEntriesFromDictionary:dict2];
  1030. XCTAssertEqual(dict.count, 2U);
  1031. int64_t value;
  1032. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  1033. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  1034. XCTAssertEqual(value, 400);
  1035. XCTAssertTrue([dict getInt64:NULL forKey:NO]);
  1036. XCTAssertTrue([dict getInt64:&value forKey:NO]);
  1037. XCTAssertEqual(value, 401);
  1038. [dict2 release];
  1039. [dict release];
  1040. }
  1041. - (void)testRemove {
  1042. const BOOL kKeys[] = { YES, NO};
  1043. const int64_t kValues[] = { 400, 401 };
  1044. GPBBoolInt64Dictionary *dict =
  1045. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
  1046. forKeys:kKeys
  1047. count:GPBARRAYSIZE(kValues)];
  1048. XCTAssertNotNil(dict);
  1049. XCTAssertEqual(dict.count, 2U);
  1050. [dict removeInt64ForKey:NO];
  1051. XCTAssertEqual(dict.count, 1U);
  1052. int64_t value;
  1053. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  1054. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  1055. XCTAssertEqual(value, 400);
  1056. XCTAssertFalse([dict getInt64:NULL forKey:NO]);
  1057. // Remove again does nothing.
  1058. [dict removeInt64ForKey:NO];
  1059. XCTAssertEqual(dict.count, 1U);
  1060. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  1061. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  1062. XCTAssertEqual(value, 400);
  1063. XCTAssertFalse([dict getInt64:NULL forKey:NO]);
  1064. [dict removeAll];
  1065. XCTAssertEqual(dict.count, 0U);
  1066. XCTAssertFalse([dict getInt64:NULL forKey:YES]);
  1067. XCTAssertFalse([dict getInt64:NULL forKey:NO]);
  1068. [dict release];
  1069. }
  1070. - (void)testInplaceMutation {
  1071. const BOOL kKeys[] = { YES, NO };
  1072. const int64_t kValues[] = { 400, 401 };
  1073. GPBBoolInt64Dictionary *dict =
  1074. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
  1075. forKeys:kKeys
  1076. count:GPBARRAYSIZE(kValues)];
  1077. XCTAssertNotNil(dict);
  1078. XCTAssertEqual(dict.count, 2U);
  1079. int64_t value;
  1080. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  1081. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  1082. XCTAssertEqual(value, 400);
  1083. XCTAssertTrue([dict getInt64:NULL forKey:NO]);
  1084. XCTAssertTrue([dict getInt64:&value forKey:NO]);
  1085. XCTAssertEqual(value, 401);
  1086. [dict setInt64:401 forKey:YES];
  1087. XCTAssertEqual(dict.count, 2U);
  1088. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  1089. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  1090. XCTAssertEqual(value, 401);
  1091. XCTAssertTrue([dict getInt64:NULL forKey:NO]);
  1092. XCTAssertTrue([dict getInt64:&value forKey:NO]);
  1093. XCTAssertEqual(value, 401);
  1094. [dict setInt64:400 forKey:NO];
  1095. XCTAssertEqual(dict.count, 2U);
  1096. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  1097. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  1098. XCTAssertEqual(value, 401);
  1099. XCTAssertTrue([dict getInt64:NULL forKey:NO]);
  1100. XCTAssertTrue([dict getInt64:&value forKey:NO]);
  1101. XCTAssertEqual(value, 400);
  1102. const BOOL kKeys2[] = { NO, YES };
  1103. const int64_t kValues2[] = { 401, 400 };
  1104. GPBBoolInt64Dictionary *dict2 =
  1105. [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues2
  1106. forKeys:kKeys2
  1107. count:GPBARRAYSIZE(kValues2)];
  1108. XCTAssertNotNil(dict2);
  1109. [dict addEntriesFromDictionary:dict2];
  1110. XCTAssertEqual(dict.count, 2U);
  1111. XCTAssertTrue([dict getInt64:NULL forKey:YES]);
  1112. XCTAssertTrue([dict getInt64:&value forKey:YES]);
  1113. XCTAssertEqual(value, 400);
  1114. XCTAssertTrue([dict getInt64:NULL forKey:NO]);
  1115. XCTAssertTrue([dict getInt64:&value forKey:NO]);
  1116. XCTAssertEqual(value, 401);
  1117. [dict2 release];
  1118. [dict release];
  1119. }
  1120. @end
  1121. // clang-format on
  1122. //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Bool, BOOL, NO, YES)
  1123. // This block of code is generated, do not edit it directly.
  1124. // clang-format off
  1125. #pragma mark - Bool -> Bool
  1126. @interface GPBBoolBoolDictionaryTests : XCTestCase
  1127. @end
  1128. @implementation GPBBoolBoolDictionaryTests
  1129. - (void)testEmpty {
  1130. GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
  1131. XCTAssertNotNil(dict);
  1132. XCTAssertEqual(dict.count, 0U);
  1133. XCTAssertFalse([dict getBool:NULL forKey:YES]);
  1134. [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
  1135. #pragma unused(aKey, aValue, stop)
  1136. XCTFail(@"Shouldn't get here!");
  1137. }];
  1138. [dict release];
  1139. }
  1140. - (void)testOne {
  1141. GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
  1142. [dict setBool:NO forKey:YES];
  1143. XCTAssertNotNil(dict);
  1144. XCTAssertEqual(dict.count, 1U);
  1145. BOOL value;
  1146. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1147. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1148. XCTAssertEqual(value, NO);
  1149. XCTAssertFalse([dict getBool:NULL forKey:NO]);
  1150. [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
  1151. XCTAssertEqual(aKey, YES);
  1152. XCTAssertEqual(aValue, NO);
  1153. XCTAssertNotEqual(stop, NULL);
  1154. }];
  1155. [dict release];
  1156. }
  1157. - (void)testBasics {
  1158. const BOOL kKeys[] = { YES, NO };
  1159. const BOOL kValues[] = { NO, YES };
  1160. GPBBoolBoolDictionary *dict =
  1161. [[GPBBoolBoolDictionary alloc] initWithBools:kValues
  1162. forKeys:kKeys
  1163. count:GPBARRAYSIZE(kValues)];
  1164. XCTAssertNotNil(dict);
  1165. XCTAssertEqual(dict.count, 2U);
  1166. BOOL value;
  1167. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1168. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1169. XCTAssertEqual(value, NO);
  1170. XCTAssertTrue([dict getBool:NULL forKey:NO]);
  1171. XCTAssertTrue([dict getBool:&value forKey:NO]);
  1172. XCTAssertEqual(value, YES);
  1173. __block NSUInteger idx = 0;
  1174. BOOL *seenKeys = malloc(2 * sizeof(BOOL));
  1175. BOOL *seenValues = malloc(2 * sizeof(BOOL));
  1176. [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
  1177. XCTAssertLessThan(idx, 2U);
  1178. seenKeys[idx] = aKey;
  1179. seenValues[idx] = aValue;
  1180. XCTAssertNotEqual(stop, NULL);
  1181. ++idx;
  1182. }];
  1183. for (int i = 0; i < 2; ++i) {
  1184. BOOL foundKey = NO;
  1185. for (int j = 0; (j < 2) && !foundKey; ++j) {
  1186. if (kKeys[i] == seenKeys[j]) {
  1187. foundKey = YES;
  1188. XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
  1189. }
  1190. }
  1191. XCTAssertTrue(foundKey, @"i = %d", i);
  1192. }
  1193. free(seenKeys);
  1194. free(seenValues);
  1195. // Stopping the enumeration.
  1196. idx = 0;
  1197. [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
  1198. #pragma unused(aKey, aValue)
  1199. if (idx == 0) *stop = YES;
  1200. XCTAssertNotEqual(idx, 2U);
  1201. ++idx;
  1202. }];
  1203. [dict release];
  1204. }
  1205. - (void)testEquality {
  1206. const BOOL kKeys1[] = { YES, NO };
  1207. const BOOL kKeys2[] = { NO, YES };
  1208. const BOOL kValues1[] = { NO, YES };
  1209. const BOOL kValues2[] = { YES, NO };
  1210. const BOOL kValues3[] = { YES };
  1211. GPBBoolBoolDictionary *dict1 =
  1212. [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
  1213. forKeys:kKeys1
  1214. count:GPBARRAYSIZE(kValues1)];
  1215. XCTAssertNotNil(dict1);
  1216. GPBBoolBoolDictionary *dict1prime =
  1217. [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
  1218. forKeys:kKeys1
  1219. count:GPBARRAYSIZE(kValues1)];
  1220. XCTAssertNotNil(dict1prime);
  1221. GPBBoolBoolDictionary *dict2 =
  1222. [[GPBBoolBoolDictionary alloc] initWithBools:kValues2
  1223. forKeys:kKeys1
  1224. count:GPBARRAYSIZE(kValues2)];
  1225. XCTAssertNotNil(dict2);
  1226. GPBBoolBoolDictionary *dict3 =
  1227. [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
  1228. forKeys:kKeys2
  1229. count:GPBARRAYSIZE(kValues1)];
  1230. XCTAssertNotNil(dict3);
  1231. GPBBoolBoolDictionary *dict4 =
  1232. [[GPBBoolBoolDictionary alloc] initWithBools:kValues3
  1233. forKeys:kKeys1
  1234. count:GPBARRAYSIZE(kValues3)];
  1235. XCTAssertNotNil(dict4);
  1236. // 1/1Prime should be different objects, but equal.
  1237. XCTAssertNotEqual(dict1, dict1prime);
  1238. XCTAssertEqualObjects(dict1, dict1prime);
  1239. // Equal, so they must have same hash.
  1240. XCTAssertEqual([dict1 hash], [dict1prime hash]);
  1241. // 2 is same keys, different values; not equal.
  1242. XCTAssertNotEqualObjects(dict1, dict2);
  1243. // 3 is different keys, same values; not equal.
  1244. XCTAssertNotEqualObjects(dict1, dict3);
  1245. // 4 Fewer pairs; not equal
  1246. XCTAssertNotEqualObjects(dict1, dict4);
  1247. [dict1 release];
  1248. [dict1prime release];
  1249. [dict2 release];
  1250. [dict3 release];
  1251. [dict4 release];
  1252. }
  1253. - (void)testCopy {
  1254. const BOOL kKeys[] = { YES, NO };
  1255. const BOOL kValues[] = { NO, YES };
  1256. GPBBoolBoolDictionary *dict =
  1257. [[GPBBoolBoolDictionary alloc] initWithBools:kValues
  1258. forKeys:kKeys
  1259. count:GPBARRAYSIZE(kValues)];
  1260. XCTAssertNotNil(dict);
  1261. GPBBoolBoolDictionary *dict2 = [dict copy];
  1262. XCTAssertNotNil(dict2);
  1263. // Should be new object but equal.
  1264. XCTAssertNotEqual(dict, dict2);
  1265. XCTAssertEqualObjects(dict, dict2);
  1266. XCTAssertTrue([dict2 isKindOfClass:[GPBBoolBoolDictionary class]]);
  1267. [dict2 release];
  1268. [dict release];
  1269. }
  1270. - (void)testDictionaryFromDictionary {
  1271. const BOOL kKeys[] = { YES, NO };
  1272. const BOOL kValues[] = { NO, YES };
  1273. GPBBoolBoolDictionary *dict =
  1274. [[GPBBoolBoolDictionary alloc] initWithBools:kValues
  1275. forKeys:kKeys
  1276. count:GPBARRAYSIZE(kValues)];
  1277. XCTAssertNotNil(dict);
  1278. GPBBoolBoolDictionary *dict2 =
  1279. [[GPBBoolBoolDictionary alloc] initWithDictionary:dict];
  1280. XCTAssertNotNil(dict2);
  1281. // Should be new pointer, but equal objects.
  1282. XCTAssertNotEqual(dict, dict2);
  1283. XCTAssertEqualObjects(dict, dict2);
  1284. [dict2 release];
  1285. [dict release];
  1286. }
  1287. - (void)testAdds {
  1288. GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
  1289. XCTAssertNotNil(dict);
  1290. XCTAssertEqual(dict.count, 0U);
  1291. [dict setBool:NO forKey:YES];
  1292. XCTAssertEqual(dict.count, 1U);
  1293. const BOOL kKeys[] = { NO };
  1294. const BOOL kValues[] = { YES };
  1295. GPBBoolBoolDictionary *dict2 =
  1296. [[GPBBoolBoolDictionary alloc] initWithBools:kValues
  1297. forKeys:kKeys
  1298. count:GPBARRAYSIZE(kValues)];
  1299. XCTAssertNotNil(dict2);
  1300. [dict addEntriesFromDictionary:dict2];
  1301. XCTAssertEqual(dict.count, 2U);
  1302. BOOL value;
  1303. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1304. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1305. XCTAssertEqual(value, NO);
  1306. XCTAssertTrue([dict getBool:NULL forKey:NO]);
  1307. XCTAssertTrue([dict getBool:&value forKey:NO]);
  1308. XCTAssertEqual(value, YES);
  1309. [dict2 release];
  1310. [dict release];
  1311. }
  1312. - (void)testRemove {
  1313. const BOOL kKeys[] = { YES, NO};
  1314. const BOOL kValues[] = { NO, YES };
  1315. GPBBoolBoolDictionary *dict =
  1316. [[GPBBoolBoolDictionary alloc] initWithBools:kValues
  1317. forKeys:kKeys
  1318. count:GPBARRAYSIZE(kValues)];
  1319. XCTAssertNotNil(dict);
  1320. XCTAssertEqual(dict.count, 2U);
  1321. [dict removeBoolForKey:NO];
  1322. XCTAssertEqual(dict.count, 1U);
  1323. BOOL value;
  1324. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1325. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1326. XCTAssertEqual(value, NO);
  1327. XCTAssertFalse([dict getBool:NULL forKey:NO]);
  1328. // Remove again does nothing.
  1329. [dict removeBoolForKey:NO];
  1330. XCTAssertEqual(dict.count, 1U);
  1331. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1332. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1333. XCTAssertEqual(value, NO);
  1334. XCTAssertFalse([dict getBool:NULL forKey:NO]);
  1335. [dict removeAll];
  1336. XCTAssertEqual(dict.count, 0U);
  1337. XCTAssertFalse([dict getBool:NULL forKey:YES]);
  1338. XCTAssertFalse([dict getBool:NULL forKey:NO]);
  1339. [dict release];
  1340. }
  1341. - (void)testInplaceMutation {
  1342. const BOOL kKeys[] = { YES, NO };
  1343. const BOOL kValues[] = { NO, YES };
  1344. GPBBoolBoolDictionary *dict =
  1345. [[GPBBoolBoolDictionary alloc] initWithBools:kValues
  1346. forKeys:kKeys
  1347. count:GPBARRAYSIZE(kValues)];
  1348. XCTAssertNotNil(dict);
  1349. XCTAssertEqual(dict.count, 2U);
  1350. BOOL value;
  1351. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1352. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1353. XCTAssertEqual(value, NO);
  1354. XCTAssertTrue([dict getBool:NULL forKey:NO]);
  1355. XCTAssertTrue([dict getBool:&value forKey:NO]);
  1356. XCTAssertEqual(value, YES);
  1357. [dict setBool:YES forKey:YES];
  1358. XCTAssertEqual(dict.count, 2U);
  1359. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1360. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1361. XCTAssertEqual(value, YES);
  1362. XCTAssertTrue([dict getBool:NULL forKey:NO]);
  1363. XCTAssertTrue([dict getBool:&value forKey:NO]);
  1364. XCTAssertEqual(value, YES);
  1365. [dict setBool:NO forKey:NO];
  1366. XCTAssertEqual(dict.count, 2U);
  1367. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1368. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1369. XCTAssertEqual(value, YES);
  1370. XCTAssertTrue([dict getBool:NULL forKey:NO]);
  1371. XCTAssertTrue([dict getBool:&value forKey:NO]);
  1372. XCTAssertEqual(value, NO);
  1373. const BOOL kKeys2[] = { NO, YES };
  1374. const BOOL kValues2[] = { YES, NO };
  1375. GPBBoolBoolDictionary *dict2 =
  1376. [[GPBBoolBoolDictionary alloc] initWithBools:kValues2
  1377. forKeys:kKeys2
  1378. count:GPBARRAYSIZE(kValues2)];
  1379. XCTAssertNotNil(dict2);
  1380. [dict addEntriesFromDictionary:dict2];
  1381. XCTAssertEqual(dict.count, 2U);
  1382. XCTAssertTrue([dict getBool:NULL forKey:YES]);
  1383. XCTAssertTrue([dict getBool:&value forKey:YES]);
  1384. XCTAssertEqual(value, NO);
  1385. XCTAssertTrue([dict getBool:NULL forKey:NO]);
  1386. XCTAssertTrue([dict getBool:&value forKey:NO]);
  1387. XCTAssertEqual(value, YES);
  1388. [dict2 release];
  1389. [dict release];
  1390. }
  1391. @end
  1392. // clang-format on
  1393. //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Float, float, 500.f, 501.f)
  1394. // This block of code is generated, do not edit it directly.
  1395. // clang-format off
  1396. #pragma mark - Bool -> Float
  1397. @interface GPBBoolFloatDictionaryTests : XCTestCase
  1398. @end
  1399. @implementation GPBBoolFloatDictionaryTests
  1400. - (void)testEmpty {
  1401. GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
  1402. XCTAssertNotNil(dict);
  1403. XCTAssertEqual(dict.count, 0U);
  1404. XCTAssertFalse([dict getFloat:NULL forKey:YES]);
  1405. [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
  1406. #pragma unused(aKey, aValue, stop)
  1407. XCTFail(@"Shouldn't get here!");
  1408. }];
  1409. [dict release];
  1410. }
  1411. - (void)testOne {
  1412. GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
  1413. [dict setFloat:500.f forKey:YES];
  1414. XCTAssertNotNil(dict);
  1415. XCTAssertEqual(dict.count, 1U);
  1416. float value;
  1417. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1418. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1419. XCTAssertEqual(value, 500.f);
  1420. XCTAssertFalse([dict getFloat:NULL forKey:NO]);
  1421. [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
  1422. XCTAssertEqual(aKey, YES);
  1423. XCTAssertEqual(aValue, 500.f);
  1424. XCTAssertNotEqual(stop, NULL);
  1425. }];
  1426. [dict release];
  1427. }
  1428. - (void)testBasics {
  1429. const BOOL kKeys[] = { YES, NO };
  1430. const float kValues[] = { 500.f, 501.f };
  1431. GPBBoolFloatDictionary *dict =
  1432. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
  1433. forKeys:kKeys
  1434. count:GPBARRAYSIZE(kValues)];
  1435. XCTAssertNotNil(dict);
  1436. XCTAssertEqual(dict.count, 2U);
  1437. float value;
  1438. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1439. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1440. XCTAssertEqual(value, 500.f);
  1441. XCTAssertTrue([dict getFloat:NULL forKey:NO]);
  1442. XCTAssertTrue([dict getFloat:&value forKey:NO]);
  1443. XCTAssertEqual(value, 501.f);
  1444. __block NSUInteger idx = 0;
  1445. BOOL *seenKeys = malloc(2 * sizeof(BOOL));
  1446. float *seenValues = malloc(2 * sizeof(float));
  1447. [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
  1448. XCTAssertLessThan(idx, 2U);
  1449. seenKeys[idx] = aKey;
  1450. seenValues[idx] = aValue;
  1451. XCTAssertNotEqual(stop, NULL);
  1452. ++idx;
  1453. }];
  1454. for (int i = 0; i < 2; ++i) {
  1455. BOOL foundKey = NO;
  1456. for (int j = 0; (j < 2) && !foundKey; ++j) {
  1457. if (kKeys[i] == seenKeys[j]) {
  1458. foundKey = YES;
  1459. XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
  1460. }
  1461. }
  1462. XCTAssertTrue(foundKey, @"i = %d", i);
  1463. }
  1464. free(seenKeys);
  1465. free(seenValues);
  1466. // Stopping the enumeration.
  1467. idx = 0;
  1468. [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
  1469. #pragma unused(aKey, aValue)
  1470. if (idx == 0) *stop = YES;
  1471. XCTAssertNotEqual(idx, 2U);
  1472. ++idx;
  1473. }];
  1474. [dict release];
  1475. }
  1476. - (void)testEquality {
  1477. const BOOL kKeys1[] = { YES, NO };
  1478. const BOOL kKeys2[] = { NO, YES };
  1479. const float kValues1[] = { 500.f, 501.f };
  1480. const float kValues2[] = { 501.f, 500.f };
  1481. const float kValues3[] = { 501.f };
  1482. GPBBoolFloatDictionary *dict1 =
  1483. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
  1484. forKeys:kKeys1
  1485. count:GPBARRAYSIZE(kValues1)];
  1486. XCTAssertNotNil(dict1);
  1487. GPBBoolFloatDictionary *dict1prime =
  1488. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
  1489. forKeys:kKeys1
  1490. count:GPBARRAYSIZE(kValues1)];
  1491. XCTAssertNotNil(dict1prime);
  1492. GPBBoolFloatDictionary *dict2 =
  1493. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues2
  1494. forKeys:kKeys1
  1495. count:GPBARRAYSIZE(kValues2)];
  1496. XCTAssertNotNil(dict2);
  1497. GPBBoolFloatDictionary *dict3 =
  1498. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
  1499. forKeys:kKeys2
  1500. count:GPBARRAYSIZE(kValues1)];
  1501. XCTAssertNotNil(dict3);
  1502. GPBBoolFloatDictionary *dict4 =
  1503. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues3
  1504. forKeys:kKeys1
  1505. count:GPBARRAYSIZE(kValues3)];
  1506. XCTAssertNotNil(dict4);
  1507. // 1/1Prime should be different objects, but equal.
  1508. XCTAssertNotEqual(dict1, dict1prime);
  1509. XCTAssertEqualObjects(dict1, dict1prime);
  1510. // Equal, so they must have same hash.
  1511. XCTAssertEqual([dict1 hash], [dict1prime hash]);
  1512. // 2 is same keys, different values; not equal.
  1513. XCTAssertNotEqualObjects(dict1, dict2);
  1514. // 3 is different keys, same values; not equal.
  1515. XCTAssertNotEqualObjects(dict1, dict3);
  1516. // 4 Fewer pairs; not equal
  1517. XCTAssertNotEqualObjects(dict1, dict4);
  1518. [dict1 release];
  1519. [dict1prime release];
  1520. [dict2 release];
  1521. [dict3 release];
  1522. [dict4 release];
  1523. }
  1524. - (void)testCopy {
  1525. const BOOL kKeys[] = { YES, NO };
  1526. const float kValues[] = { 500.f, 501.f };
  1527. GPBBoolFloatDictionary *dict =
  1528. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
  1529. forKeys:kKeys
  1530. count:GPBARRAYSIZE(kValues)];
  1531. XCTAssertNotNil(dict);
  1532. GPBBoolFloatDictionary *dict2 = [dict copy];
  1533. XCTAssertNotNil(dict2);
  1534. // Should be new object but equal.
  1535. XCTAssertNotEqual(dict, dict2);
  1536. XCTAssertEqualObjects(dict, dict2);
  1537. XCTAssertTrue([dict2 isKindOfClass:[GPBBoolFloatDictionary class]]);
  1538. [dict2 release];
  1539. [dict release];
  1540. }
  1541. - (void)testDictionaryFromDictionary {
  1542. const BOOL kKeys[] = { YES, NO };
  1543. const float kValues[] = { 500.f, 501.f };
  1544. GPBBoolFloatDictionary *dict =
  1545. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
  1546. forKeys:kKeys
  1547. count:GPBARRAYSIZE(kValues)];
  1548. XCTAssertNotNil(dict);
  1549. GPBBoolFloatDictionary *dict2 =
  1550. [[GPBBoolFloatDictionary alloc] initWithDictionary:dict];
  1551. XCTAssertNotNil(dict2);
  1552. // Should be new pointer, but equal objects.
  1553. XCTAssertNotEqual(dict, dict2);
  1554. XCTAssertEqualObjects(dict, dict2);
  1555. [dict2 release];
  1556. [dict release];
  1557. }
  1558. - (void)testAdds {
  1559. GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
  1560. XCTAssertNotNil(dict);
  1561. XCTAssertEqual(dict.count, 0U);
  1562. [dict setFloat:500.f forKey:YES];
  1563. XCTAssertEqual(dict.count, 1U);
  1564. const BOOL kKeys[] = { NO };
  1565. const float kValues[] = { 501.f };
  1566. GPBBoolFloatDictionary *dict2 =
  1567. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
  1568. forKeys:kKeys
  1569. count:GPBARRAYSIZE(kValues)];
  1570. XCTAssertNotNil(dict2);
  1571. [dict addEntriesFromDictionary:dict2];
  1572. XCTAssertEqual(dict.count, 2U);
  1573. float value;
  1574. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1575. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1576. XCTAssertEqual(value, 500.f);
  1577. XCTAssertTrue([dict getFloat:NULL forKey:NO]);
  1578. XCTAssertTrue([dict getFloat:&value forKey:NO]);
  1579. XCTAssertEqual(value, 501.f);
  1580. [dict2 release];
  1581. [dict release];
  1582. }
  1583. - (void)testRemove {
  1584. const BOOL kKeys[] = { YES, NO};
  1585. const float kValues[] = { 500.f, 501.f };
  1586. GPBBoolFloatDictionary *dict =
  1587. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
  1588. forKeys:kKeys
  1589. count:GPBARRAYSIZE(kValues)];
  1590. XCTAssertNotNil(dict);
  1591. XCTAssertEqual(dict.count, 2U);
  1592. [dict removeFloatForKey:NO];
  1593. XCTAssertEqual(dict.count, 1U);
  1594. float value;
  1595. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1596. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1597. XCTAssertEqual(value, 500.f);
  1598. XCTAssertFalse([dict getFloat:NULL forKey:NO]);
  1599. // Remove again does nothing.
  1600. [dict removeFloatForKey:NO];
  1601. XCTAssertEqual(dict.count, 1U);
  1602. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1603. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1604. XCTAssertEqual(value, 500.f);
  1605. XCTAssertFalse([dict getFloat:NULL forKey:NO]);
  1606. [dict removeAll];
  1607. XCTAssertEqual(dict.count, 0U);
  1608. XCTAssertFalse([dict getFloat:NULL forKey:YES]);
  1609. XCTAssertFalse([dict getFloat:NULL forKey:NO]);
  1610. [dict release];
  1611. }
  1612. - (void)testInplaceMutation {
  1613. const BOOL kKeys[] = { YES, NO };
  1614. const float kValues[] = { 500.f, 501.f };
  1615. GPBBoolFloatDictionary *dict =
  1616. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
  1617. forKeys:kKeys
  1618. count:GPBARRAYSIZE(kValues)];
  1619. XCTAssertNotNil(dict);
  1620. XCTAssertEqual(dict.count, 2U);
  1621. float value;
  1622. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1623. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1624. XCTAssertEqual(value, 500.f);
  1625. XCTAssertTrue([dict getFloat:NULL forKey:NO]);
  1626. XCTAssertTrue([dict getFloat:&value forKey:NO]);
  1627. XCTAssertEqual(value, 501.f);
  1628. [dict setFloat:501.f forKey:YES];
  1629. XCTAssertEqual(dict.count, 2U);
  1630. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1631. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1632. XCTAssertEqual(value, 501.f);
  1633. XCTAssertTrue([dict getFloat:NULL forKey:NO]);
  1634. XCTAssertTrue([dict getFloat:&value forKey:NO]);
  1635. XCTAssertEqual(value, 501.f);
  1636. [dict setFloat:500.f forKey:NO];
  1637. XCTAssertEqual(dict.count, 2U);
  1638. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1639. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1640. XCTAssertEqual(value, 501.f);
  1641. XCTAssertTrue([dict getFloat:NULL forKey:NO]);
  1642. XCTAssertTrue([dict getFloat:&value forKey:NO]);
  1643. XCTAssertEqual(value, 500.f);
  1644. const BOOL kKeys2[] = { NO, YES };
  1645. const float kValues2[] = { 501.f, 500.f };
  1646. GPBBoolFloatDictionary *dict2 =
  1647. [[GPBBoolFloatDictionary alloc] initWithFloats:kValues2
  1648. forKeys:kKeys2
  1649. count:GPBARRAYSIZE(kValues2)];
  1650. XCTAssertNotNil(dict2);
  1651. [dict addEntriesFromDictionary:dict2];
  1652. XCTAssertEqual(dict.count, 2U);
  1653. XCTAssertTrue([dict getFloat:NULL forKey:YES]);
  1654. XCTAssertTrue([dict getFloat:&value forKey:YES]);
  1655. XCTAssertEqual(value, 500.f);
  1656. XCTAssertTrue([dict getFloat:NULL forKey:NO]);
  1657. XCTAssertTrue([dict getFloat:&value forKey:NO]);
  1658. XCTAssertEqual(value, 501.f);
  1659. [dict2 release];
  1660. [dict release];
  1661. }
  1662. @end
  1663. // clang-format on
  1664. //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Double, double, 600., 601.)
  1665. // This block of code is generated, do not edit it directly.
  1666. // clang-format off
  1667. #pragma mark - Bool -> Double
  1668. @interface GPBBoolDoubleDictionaryTests : XCTestCase
  1669. @end
  1670. @implementation GPBBoolDoubleDictionaryTests
  1671. - (void)testEmpty {
  1672. GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
  1673. XCTAssertNotNil(dict);
  1674. XCTAssertEqual(dict.count, 0U);
  1675. XCTAssertFalse([dict getDouble:NULL forKey:YES]);
  1676. [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
  1677. #pragma unused(aKey, aValue, stop)
  1678. XCTFail(@"Shouldn't get here!");
  1679. }];
  1680. [dict release];
  1681. }
  1682. - (void)testOne {
  1683. GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
  1684. [dict setDouble:600. forKey:YES];
  1685. XCTAssertNotNil(dict);
  1686. XCTAssertEqual(dict.count, 1U);
  1687. double value;
  1688. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1689. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1690. XCTAssertEqual(value, 600.);
  1691. XCTAssertFalse([dict getDouble:NULL forKey:NO]);
  1692. [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
  1693. XCTAssertEqual(aKey, YES);
  1694. XCTAssertEqual(aValue, 600.);
  1695. XCTAssertNotEqual(stop, NULL);
  1696. }];
  1697. [dict release];
  1698. }
  1699. - (void)testBasics {
  1700. const BOOL kKeys[] = { YES, NO };
  1701. const double kValues[] = { 600., 601. };
  1702. GPBBoolDoubleDictionary *dict =
  1703. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
  1704. forKeys:kKeys
  1705. count:GPBARRAYSIZE(kValues)];
  1706. XCTAssertNotNil(dict);
  1707. XCTAssertEqual(dict.count, 2U);
  1708. double value;
  1709. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1710. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1711. XCTAssertEqual(value, 600.);
  1712. XCTAssertTrue([dict getDouble:NULL forKey:NO]);
  1713. XCTAssertTrue([dict getDouble:&value forKey:NO]);
  1714. XCTAssertEqual(value, 601.);
  1715. __block NSUInteger idx = 0;
  1716. BOOL *seenKeys = malloc(2 * sizeof(BOOL));
  1717. double *seenValues = malloc(2 * sizeof(double));
  1718. [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
  1719. XCTAssertLessThan(idx, 2U);
  1720. seenKeys[idx] = aKey;
  1721. seenValues[idx] = aValue;
  1722. XCTAssertNotEqual(stop, NULL);
  1723. ++idx;
  1724. }];
  1725. for (int i = 0; i < 2; ++i) {
  1726. BOOL foundKey = NO;
  1727. for (int j = 0; (j < 2) && !foundKey; ++j) {
  1728. if (kKeys[i] == seenKeys[j]) {
  1729. foundKey = YES;
  1730. XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
  1731. }
  1732. }
  1733. XCTAssertTrue(foundKey, @"i = %d", i);
  1734. }
  1735. free(seenKeys);
  1736. free(seenValues);
  1737. // Stopping the enumeration.
  1738. idx = 0;
  1739. [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
  1740. #pragma unused(aKey, aValue)
  1741. if (idx == 0) *stop = YES;
  1742. XCTAssertNotEqual(idx, 2U);
  1743. ++idx;
  1744. }];
  1745. [dict release];
  1746. }
  1747. - (void)testEquality {
  1748. const BOOL kKeys1[] = { YES, NO };
  1749. const BOOL kKeys2[] = { NO, YES };
  1750. const double kValues1[] = { 600., 601. };
  1751. const double kValues2[] = { 601., 600. };
  1752. const double kValues3[] = { 601. };
  1753. GPBBoolDoubleDictionary *dict1 =
  1754. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
  1755. forKeys:kKeys1
  1756. count:GPBARRAYSIZE(kValues1)];
  1757. XCTAssertNotNil(dict1);
  1758. GPBBoolDoubleDictionary *dict1prime =
  1759. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
  1760. forKeys:kKeys1
  1761. count:GPBARRAYSIZE(kValues1)];
  1762. XCTAssertNotNil(dict1prime);
  1763. GPBBoolDoubleDictionary *dict2 =
  1764. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues2
  1765. forKeys:kKeys1
  1766. count:GPBARRAYSIZE(kValues2)];
  1767. XCTAssertNotNil(dict2);
  1768. GPBBoolDoubleDictionary *dict3 =
  1769. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
  1770. forKeys:kKeys2
  1771. count:GPBARRAYSIZE(kValues1)];
  1772. XCTAssertNotNil(dict3);
  1773. GPBBoolDoubleDictionary *dict4 =
  1774. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues3
  1775. forKeys:kKeys1
  1776. count:GPBARRAYSIZE(kValues3)];
  1777. XCTAssertNotNil(dict4);
  1778. // 1/1Prime should be different objects, but equal.
  1779. XCTAssertNotEqual(dict1, dict1prime);
  1780. XCTAssertEqualObjects(dict1, dict1prime);
  1781. // Equal, so they must have same hash.
  1782. XCTAssertEqual([dict1 hash], [dict1prime hash]);
  1783. // 2 is same keys, different values; not equal.
  1784. XCTAssertNotEqualObjects(dict1, dict2);
  1785. // 3 is different keys, same values; not equal.
  1786. XCTAssertNotEqualObjects(dict1, dict3);
  1787. // 4 Fewer pairs; not equal
  1788. XCTAssertNotEqualObjects(dict1, dict4);
  1789. [dict1 release];
  1790. [dict1prime release];
  1791. [dict2 release];
  1792. [dict3 release];
  1793. [dict4 release];
  1794. }
  1795. - (void)testCopy {
  1796. const BOOL kKeys[] = { YES, NO };
  1797. const double kValues[] = { 600., 601. };
  1798. GPBBoolDoubleDictionary *dict =
  1799. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
  1800. forKeys:kKeys
  1801. count:GPBARRAYSIZE(kValues)];
  1802. XCTAssertNotNil(dict);
  1803. GPBBoolDoubleDictionary *dict2 = [dict copy];
  1804. XCTAssertNotNil(dict2);
  1805. // Should be new object but equal.
  1806. XCTAssertNotEqual(dict, dict2);
  1807. XCTAssertEqualObjects(dict, dict2);
  1808. XCTAssertTrue([dict2 isKindOfClass:[GPBBoolDoubleDictionary class]]);
  1809. [dict2 release];
  1810. [dict release];
  1811. }
  1812. - (void)testDictionaryFromDictionary {
  1813. const BOOL kKeys[] = { YES, NO };
  1814. const double kValues[] = { 600., 601. };
  1815. GPBBoolDoubleDictionary *dict =
  1816. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
  1817. forKeys:kKeys
  1818. count:GPBARRAYSIZE(kValues)];
  1819. XCTAssertNotNil(dict);
  1820. GPBBoolDoubleDictionary *dict2 =
  1821. [[GPBBoolDoubleDictionary alloc] initWithDictionary:dict];
  1822. XCTAssertNotNil(dict2);
  1823. // Should be new pointer, but equal objects.
  1824. XCTAssertNotEqual(dict, dict2);
  1825. XCTAssertEqualObjects(dict, dict2);
  1826. [dict2 release];
  1827. [dict release];
  1828. }
  1829. - (void)testAdds {
  1830. GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
  1831. XCTAssertNotNil(dict);
  1832. XCTAssertEqual(dict.count, 0U);
  1833. [dict setDouble:600. forKey:YES];
  1834. XCTAssertEqual(dict.count, 1U);
  1835. const BOOL kKeys[] = { NO };
  1836. const double kValues[] = { 601. };
  1837. GPBBoolDoubleDictionary *dict2 =
  1838. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
  1839. forKeys:kKeys
  1840. count:GPBARRAYSIZE(kValues)];
  1841. XCTAssertNotNil(dict2);
  1842. [dict addEntriesFromDictionary:dict2];
  1843. XCTAssertEqual(dict.count, 2U);
  1844. double value;
  1845. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1846. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1847. XCTAssertEqual(value, 600.);
  1848. XCTAssertTrue([dict getDouble:NULL forKey:NO]);
  1849. XCTAssertTrue([dict getDouble:&value forKey:NO]);
  1850. XCTAssertEqual(value, 601.);
  1851. [dict2 release];
  1852. [dict release];
  1853. }
  1854. - (void)testRemove {
  1855. const BOOL kKeys[] = { YES, NO};
  1856. const double kValues[] = { 600., 601. };
  1857. GPBBoolDoubleDictionary *dict =
  1858. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
  1859. forKeys:kKeys
  1860. count:GPBARRAYSIZE(kValues)];
  1861. XCTAssertNotNil(dict);
  1862. XCTAssertEqual(dict.count, 2U);
  1863. [dict removeDoubleForKey:NO];
  1864. XCTAssertEqual(dict.count, 1U);
  1865. double value;
  1866. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1867. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1868. XCTAssertEqual(value, 600.);
  1869. XCTAssertFalse([dict getDouble:NULL forKey:NO]);
  1870. // Remove again does nothing.
  1871. [dict removeDoubleForKey:NO];
  1872. XCTAssertEqual(dict.count, 1U);
  1873. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1874. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1875. XCTAssertEqual(value, 600.);
  1876. XCTAssertFalse([dict getDouble:NULL forKey:NO]);
  1877. [dict removeAll];
  1878. XCTAssertEqual(dict.count, 0U);
  1879. XCTAssertFalse([dict getDouble:NULL forKey:YES]);
  1880. XCTAssertFalse([dict getDouble:NULL forKey:NO]);
  1881. [dict release];
  1882. }
  1883. - (void)testInplaceMutation {
  1884. const BOOL kKeys[] = { YES, NO };
  1885. const double kValues[] = { 600., 601. };
  1886. GPBBoolDoubleDictionary *dict =
  1887. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
  1888. forKeys:kKeys
  1889. count:GPBARRAYSIZE(kValues)];
  1890. XCTAssertNotNil(dict);
  1891. XCTAssertEqual(dict.count, 2U);
  1892. double value;
  1893. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1894. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1895. XCTAssertEqual(value, 600.);
  1896. XCTAssertTrue([dict getDouble:NULL forKey:NO]);
  1897. XCTAssertTrue([dict getDouble:&value forKey:NO]);
  1898. XCTAssertEqual(value, 601.);
  1899. [dict setDouble:601. forKey:YES];
  1900. XCTAssertEqual(dict.count, 2U);
  1901. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1902. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1903. XCTAssertEqual(value, 601.);
  1904. XCTAssertTrue([dict getDouble:NULL forKey:NO]);
  1905. XCTAssertTrue([dict getDouble:&value forKey:NO]);
  1906. XCTAssertEqual(value, 601.);
  1907. [dict setDouble:600. forKey:NO];
  1908. XCTAssertEqual(dict.count, 2U);
  1909. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1910. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1911. XCTAssertEqual(value, 601.);
  1912. XCTAssertTrue([dict getDouble:NULL forKey:NO]);
  1913. XCTAssertTrue([dict getDouble:&value forKey:NO]);
  1914. XCTAssertEqual(value, 600.);
  1915. const BOOL kKeys2[] = { NO, YES };
  1916. const double kValues2[] = { 601., 600. };
  1917. GPBBoolDoubleDictionary *dict2 =
  1918. [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues2
  1919. forKeys:kKeys2
  1920. count:GPBARRAYSIZE(kValues2)];
  1921. XCTAssertNotNil(dict2);
  1922. [dict addEntriesFromDictionary:dict2];
  1923. XCTAssertEqual(dict.count, 2U);
  1924. XCTAssertTrue([dict getDouble:NULL forKey:YES]);
  1925. XCTAssertTrue([dict getDouble:&value forKey:YES]);
  1926. XCTAssertEqual(value, 600.);
  1927. XCTAssertTrue([dict getDouble:NULL forKey:NO]);
  1928. XCTAssertTrue([dict getDouble:&value forKey:NO]);
  1929. XCTAssertEqual(value, 601.);
  1930. [dict2 release];
  1931. [dict release];
  1932. }
  1933. @end
  1934. // clang-format on
  1935. //%PDDM-EXPAND TESTS_FOR_BOOL_KEY_OBJECT_VALUE(Object, NSString*, @"abc", @"def")
  1936. // This block of code is generated, do not edit it directly.
  1937. // clang-format off
  1938. #pragma mark - Bool -> Object
  1939. @interface GPBBoolObjectDictionaryTests : XCTestCase
  1940. @end
  1941. @implementation GPBBoolObjectDictionaryTests
  1942. - (void)testEmpty {
  1943. GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
  1944. XCTAssertNotNil(dict);
  1945. XCTAssertEqual(dict.count, 0U);
  1946. XCTAssertNil([dict objectForKey:YES]);
  1947. [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
  1948. #pragma unused(aKey, aObject, stop)
  1949. XCTFail(@"Shouldn't get here!");
  1950. }];
  1951. [dict release];
  1952. }
  1953. - (void)testOne {
  1954. GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
  1955. [dict setObject:@"abc" forKey:YES];
  1956. XCTAssertNotNil(dict);
  1957. XCTAssertEqual(dict.count, 1U);
  1958. XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
  1959. XCTAssertNil([dict objectForKey:NO]);
  1960. [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
  1961. XCTAssertEqual(aKey, YES);
  1962. XCTAssertEqualObjects(aObject, @"abc");
  1963. XCTAssertNotEqual(stop, NULL);
  1964. }];
  1965. [dict release];
  1966. }
  1967. - (void)testBasics {
  1968. const BOOL kKeys[] = { YES, NO };
  1969. const NSString* kObjects[] = { @"abc", @"def" };
  1970. GPBBoolObjectDictionary<NSString*> *dict =
  1971. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
  1972. forKeys:kKeys
  1973. count:GPBARRAYSIZE(kObjects)];
  1974. XCTAssertNotNil(dict);
  1975. XCTAssertEqual(dict.count, 2U);
  1976. XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
  1977. XCTAssertEqualObjects([dict objectForKey:NO], @"def");
  1978. __block NSUInteger idx = 0;
  1979. BOOL *seenKeys = malloc(2 * sizeof(BOOL));
  1980. NSString* *seenObjects = malloc(2 * sizeof(NSString*));
  1981. [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
  1982. XCTAssertLessThan(idx, 2U);
  1983. seenKeys[idx] = aKey;
  1984. seenObjects[idx] = aObject;
  1985. XCTAssertNotEqual(stop, NULL);
  1986. ++idx;
  1987. }];
  1988. for (int i = 0; i < 2; ++i) {
  1989. BOOL foundKey = NO;
  1990. for (int j = 0; (j < 2) && !foundKey; ++j) {
  1991. if (kKeys[i] == seenKeys[j]) {
  1992. foundKey = YES;
  1993. XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
  1994. }
  1995. }
  1996. XCTAssertTrue(foundKey, @"i = %d", i);
  1997. }
  1998. free(seenKeys);
  1999. free(seenObjects);
  2000. // Stopping the enumeration.
  2001. idx = 0;
  2002. [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
  2003. #pragma unused(aKey, aObject)
  2004. if (idx == 0) *stop = YES;
  2005. XCTAssertNotEqual(idx, 2U);
  2006. ++idx;
  2007. }];
  2008. [dict release];
  2009. }
  2010. - (void)testEquality {
  2011. const BOOL kKeys1[] = { YES, NO };
  2012. const BOOL kKeys2[] = { NO, YES };
  2013. const NSString* kObjects1[] = { @"abc", @"def" };
  2014. const NSString* kObjects2[] = { @"def", @"abc" };
  2015. const NSString* kObjects3[] = { @"def" };
  2016. GPBBoolObjectDictionary<NSString*> *dict1 =
  2017. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
  2018. forKeys:kKeys1
  2019. count:GPBARRAYSIZE(kObjects1)];
  2020. XCTAssertNotNil(dict1);
  2021. GPBBoolObjectDictionary<NSString*> *dict1prime =
  2022. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
  2023. forKeys:kKeys1
  2024. count:GPBARRAYSIZE(kObjects1)];
  2025. XCTAssertNotNil(dict1prime);
  2026. GPBBoolObjectDictionary<NSString*> *dict2 =
  2027. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
  2028. forKeys:kKeys1
  2029. count:GPBARRAYSIZE(kObjects2)];
  2030. XCTAssertNotNil(dict2);
  2031. GPBBoolObjectDictionary<NSString*> *dict3 =
  2032. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
  2033. forKeys:kKeys2
  2034. count:GPBARRAYSIZE(kObjects1)];
  2035. XCTAssertNotNil(dict3);
  2036. GPBBoolObjectDictionary<NSString*> *dict4 =
  2037. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects3
  2038. forKeys:kKeys1
  2039. count:GPBARRAYSIZE(kObjects3)];
  2040. XCTAssertNotNil(dict4);
  2041. // 1/1Prime should be different objects, but equal.
  2042. XCTAssertNotEqual(dict1, dict1prime);
  2043. XCTAssertEqualObjects(dict1, dict1prime);
  2044. // Equal, so they must have same hash.
  2045. XCTAssertEqual([dict1 hash], [dict1prime hash]);
  2046. // 2 is same keys, different objects; not equal.
  2047. XCTAssertNotEqualObjects(dict1, dict2);
  2048. // 3 is different keys, same objects; not equal.
  2049. XCTAssertNotEqualObjects(dict1, dict3);
  2050. // 4 Fewer pairs; not equal
  2051. XCTAssertNotEqualObjects(dict1, dict4);
  2052. [dict1 release];
  2053. [dict1prime release];
  2054. [dict2 release];
  2055. [dict3 release];
  2056. [dict4 release];
  2057. }
  2058. - (void)testCopy {
  2059. const BOOL kKeys[] = { YES, NO };
  2060. const NSString* kObjects[] = { @"abc", @"def" };
  2061. GPBBoolObjectDictionary<NSString*> *dict =
  2062. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
  2063. forKeys:kKeys
  2064. count:GPBARRAYSIZE(kObjects)];
  2065. XCTAssertNotNil(dict);
  2066. GPBBoolObjectDictionary<NSString*> *dict2 = [dict copy];
  2067. XCTAssertNotNil(dict2);
  2068. // Should be new object but equal.
  2069. XCTAssertNotEqual(dict, dict2);
  2070. XCTAssertEqualObjects(dict, dict2);
  2071. XCTAssertTrue([dict2 isKindOfClass:[GPBBoolObjectDictionary class]]);
  2072. [dict2 release];
  2073. [dict release];
  2074. }
  2075. - (void)testDictionaryFromDictionary {
  2076. const BOOL kKeys[] = { YES, NO };
  2077. const NSString* kObjects[] = { @"abc", @"def" };
  2078. GPBBoolObjectDictionary<NSString*> *dict =
  2079. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
  2080. forKeys:kKeys
  2081. count:GPBARRAYSIZE(kObjects)];
  2082. XCTAssertNotNil(dict);
  2083. GPBBoolObjectDictionary<NSString*> *dict2 =
  2084. [[GPBBoolObjectDictionary alloc] initWithDictionary:dict];
  2085. XCTAssertNotNil(dict2);
  2086. // Should be new pointer, but equal objects.
  2087. XCTAssertNotEqual(dict, dict2);
  2088. XCTAssertEqualObjects(dict, dict2);
  2089. [dict2 release];
  2090. [dict release];
  2091. }
  2092. - (void)testAdds {
  2093. GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
  2094. XCTAssertNotNil(dict);
  2095. XCTAssertEqual(dict.count, 0U);
  2096. [dict setObject:@"abc" forKey:YES];
  2097. XCTAssertEqual(dict.count, 1U);
  2098. const BOOL kKeys[] = { NO };
  2099. const NSString* kObjects[] = { @"def" };
  2100. GPBBoolObjectDictionary<NSString*> *dict2 =
  2101. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
  2102. forKeys:kKeys
  2103. count:GPBARRAYSIZE(kObjects)];
  2104. XCTAssertNotNil(dict2);
  2105. [dict addEntriesFromDictionary:dict2];
  2106. XCTAssertEqual(dict.count, 2U);
  2107. XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
  2108. XCTAssertEqualObjects([dict objectForKey:NO], @"def");
  2109. [dict2 release];
  2110. [dict release];
  2111. }
  2112. - (void)testRemove {
  2113. const BOOL kKeys[] = { YES, NO};
  2114. const NSString* kObjects[] = { @"abc", @"def" };
  2115. GPBBoolObjectDictionary<NSString*> *dict =
  2116. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
  2117. forKeys:kKeys
  2118. count:GPBARRAYSIZE(kObjects)];
  2119. XCTAssertNotNil(dict);
  2120. XCTAssertEqual(dict.count, 2U);
  2121. [dict removeObjectForKey:NO];
  2122. XCTAssertEqual(dict.count, 1U);
  2123. XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
  2124. XCTAssertNil([dict objectForKey:NO]);
  2125. // Remove again does nothing.
  2126. [dict removeObjectForKey:NO];
  2127. XCTAssertEqual(dict.count, 1U);
  2128. XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
  2129. XCTAssertNil([dict objectForKey:NO]);
  2130. [dict removeAll];
  2131. XCTAssertEqual(dict.count, 0U);
  2132. XCTAssertNil([dict objectForKey:YES]);
  2133. XCTAssertNil([dict objectForKey:NO]);
  2134. [dict release];
  2135. }
  2136. - (void)testInplaceMutation {
  2137. const BOOL kKeys[] = { YES, NO };
  2138. const NSString* kObjects[] = { @"abc", @"def" };
  2139. GPBBoolObjectDictionary<NSString*> *dict =
  2140. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
  2141. forKeys:kKeys
  2142. count:GPBARRAYSIZE(kObjects)];
  2143. XCTAssertNotNil(dict);
  2144. XCTAssertEqual(dict.count, 2U);
  2145. XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
  2146. XCTAssertEqualObjects([dict objectForKey:NO], @"def");
  2147. [dict setObject:@"def" forKey:YES];
  2148. XCTAssertEqual(dict.count, 2U);
  2149. XCTAssertEqualObjects([dict objectForKey:YES], @"def");
  2150. XCTAssertEqualObjects([dict objectForKey:NO], @"def");
  2151. [dict setObject:@"abc" forKey:NO];
  2152. XCTAssertEqual(dict.count, 2U);
  2153. XCTAssertEqualObjects([dict objectForKey:YES], @"def");
  2154. XCTAssertEqualObjects([dict objectForKey:NO], @"abc");
  2155. const BOOL kKeys2[] = { NO, YES };
  2156. const NSString* kObjects2[] = { @"def", @"abc" };
  2157. GPBBoolObjectDictionary<NSString*> *dict2 =
  2158. [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
  2159. forKeys:kKeys2
  2160. count:GPBARRAYSIZE(kObjects2)];
  2161. XCTAssertNotNil(dict2);
  2162. [dict addEntriesFromDictionary:dict2];
  2163. XCTAssertEqual(dict.count, 2U);
  2164. XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
  2165. XCTAssertEqualObjects([dict objectForKey:NO], @"def");
  2166. [dict2 release];
  2167. [dict release];
  2168. }
  2169. @end
  2170. // clang-format on
  2171. //%PDDM-EXPAND-END (8 expansions)