GPBDictionaryTests+Bool.m 82 KB

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