GPBDictionaryTests+Bool.m 83 KB

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