12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450 |
- // Protocol Buffers - Google's data interchange format
- // Copyright 2015 Google Inc. All rights reserved.
- // https://developers.google.com/protocol-buffers/
- //
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions are
- // met:
- //
- // * Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- // * Redistributions in binary form must reproduce the above
- // copyright notice, this list of conditions and the following disclaimer
- // in the documentation and/or other materials provided with the
- // distribution.
- // * Neither the name of Google Inc. nor the names of its
- // contributors may be used to endorse or promote products derived from
- // this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- #import <Foundation/Foundation.h>
- #import <XCTest/XCTest.h>
- #import "GPBDictionary.h"
- #import "GPBTestUtilities.h"
- #import "google/protobuf/UnittestRuntimeProto2.pbobjc.h"
- // Pull in the macros (using an external file because expanding all tests
- // in a single file makes a file that is failing to work with within Xcode.
- //%PDDM-IMPORT-DEFINES GPBDictionaryTests.pddm
- //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt32, uint32_t, 100U, 101U)
- // This block of code is generated, do not edit it directly.
- #pragma mark - Bool -> UInt32
- @interface GPBBoolUInt32DictionaryTests : XCTestCase
- @end
- @implementation GPBBoolUInt32DictionaryTests
- - (void)testEmpty {
- GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getUInt32:NULL forKey:YES]);
- [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
- #pragma unused(aKey, aValue, stop)
- XCTFail(@"Shouldn't get here!");
- }];
- [dict release];
- }
- - (void)testOne {
- GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
- [dict setUInt32:100U forKey:YES];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 1U);
- uint32_t value;
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 100U);
- XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
- [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
- XCTAssertEqual(aKey, YES);
- XCTAssertEqual(aValue, 100U);
- XCTAssertNotEqual(stop, NULL);
- }];
- [dict release];
- }
- - (void)testBasics {
- const BOOL kKeys[] = { YES, NO };
- const uint32_t kValues[] = { 100U, 101U };
- GPBBoolUInt32Dictionary *dict =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- uint32_t value;
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 100U);
- XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt32:&value forKey:NO]);
- XCTAssertEqual(value, 101U);
- __block NSUInteger idx = 0;
- BOOL *seenKeys = malloc(2 * sizeof(BOOL));
- uint32_t *seenValues = malloc(2 * sizeof(uint32_t));
- [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
- XCTAssertLessThan(idx, 2U);
- seenKeys[idx] = aKey;
- seenValues[idx] = aValue;
- XCTAssertNotEqual(stop, NULL);
- ++idx;
- }];
- for (int i = 0; i < 2; ++i) {
- BOOL foundKey = NO;
- for (int j = 0; (j < 2) && !foundKey; ++j) {
- if (kKeys[i] == seenKeys[j]) {
- foundKey = YES;
- XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
- }
- }
- XCTAssertTrue(foundKey, @"i = %d", i);
- }
- free(seenKeys);
- free(seenValues);
- // Stopping the enumeration.
- idx = 0;
- [dict enumerateKeysAndUInt32sUsingBlock:^(BOOL aKey, uint32_t aValue, BOOL *stop) {
- #pragma unused(aKey, aValue)
- if (idx == 0) *stop = YES;
- XCTAssertNotEqual(idx, 2U);
- ++idx;
- }];
- [dict release];
- }
- - (void)testEquality {
- const BOOL kKeys1[] = { YES, NO };
- const BOOL kKeys2[] = { NO, YES };
- const uint32_t kValues1[] = { 100U, 101U };
- const uint32_t kValues2[] = { 101U, 100U };
- const uint32_t kValues3[] = { 101U };
- GPBBoolUInt32Dictionary *dict1 =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1);
- GPBBoolUInt32Dictionary *dict1prime =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1prime);
- GPBBoolUInt32Dictionary *dict2 =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues2
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- GPBBoolUInt32Dictionary *dict3 =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues1
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict3);
- GPBBoolUInt32Dictionary *dict4 =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues3
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues3)];
- XCTAssertNotNil(dict4);
- // 1/1Prime should be different objects, but equal.
- XCTAssertNotEqual(dict1, dict1prime);
- XCTAssertEqualObjects(dict1, dict1prime);
- // Equal, so they must have same hash.
- XCTAssertEqual([dict1 hash], [dict1prime hash]);
- // 2 is same keys, different values; not equal.
- XCTAssertNotEqualObjects(dict1, dict2);
- // 3 is different keys, same values; not equal.
- XCTAssertNotEqualObjects(dict1, dict3);
- // 4 Fewer pairs; not equal
- XCTAssertNotEqualObjects(dict1, dict4);
- [dict1 release];
- [dict1prime release];
- [dict2 release];
- [dict3 release];
- [dict4 release];
- }
- - (void)testCopy {
- const BOOL kKeys[] = { YES, NO };
- const uint32_t kValues[] = { 100U, 101U };
- GPBBoolUInt32Dictionary *dict =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolUInt32Dictionary *dict2 = [dict copy];
- XCTAssertNotNil(dict2);
- // Should be new object but equal.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt32Dictionary class]]);
- [dict2 release];
- [dict release];
- }
- - (void)testDictionaryFromDictionary {
- const BOOL kKeys[] = { YES, NO };
- const uint32_t kValues[] = { 100U, 101U };
- GPBBoolUInt32Dictionary *dict =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolUInt32Dictionary *dict2 =
- [[GPBBoolUInt32Dictionary alloc] initWithDictionary:dict];
- XCTAssertNotNil(dict2);
- // Should be new pointer, but equal objects.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- [dict2 release];
- [dict release];
- }
- - (void)testAdds {
- GPBBoolUInt32Dictionary *dict = [[GPBBoolUInt32Dictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- [dict setUInt32:100U forKey:YES];
- XCTAssertEqual(dict.count, 1U);
- const BOOL kKeys[] = { NO };
- const uint32_t kValues[] = { 101U };
- GPBBoolUInt32Dictionary *dict2 =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- uint32_t value;
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 100U);
- XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt32:&value forKey:NO]);
- XCTAssertEqual(value, 101U);
- [dict2 release];
- [dict release];
- }
- - (void)testRemove {
- const BOOL kKeys[] = { YES, NO};
- const uint32_t kValues[] = { 100U, 101U };
- GPBBoolUInt32Dictionary *dict =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- [dict removeUInt32ForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- uint32_t value;
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 100U);
- XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
- // Remove again does nothing.
- [dict removeUInt32ForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 100U);
- XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
- [dict removeAll];
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getUInt32:NULL forKey:YES]);
- XCTAssertFalse([dict getUInt32:NULL forKey:NO]);
- [dict release];
- }
- - (void)testInplaceMutation {
- const BOOL kKeys[] = { YES, NO };
- const uint32_t kValues[] = { 100U, 101U };
- GPBBoolUInt32Dictionary *dict =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- uint32_t value;
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 100U);
- XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt32:&value forKey:NO]);
- XCTAssertEqual(value, 101U);
- [dict setUInt32:101U forKey:YES];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 101U);
- XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt32:&value forKey:NO]);
- XCTAssertEqual(value, 101U);
- [dict setUInt32:100U forKey:NO];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 101U);
- XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt32:&value forKey:NO]);
- XCTAssertEqual(value, 100U);
- const BOOL kKeys2[] = { NO, YES };
- const uint32_t kValues2[] = { 101U, 100U };
- GPBBoolUInt32Dictionary *dict2 =
- [[GPBBoolUInt32Dictionary alloc] initWithUInt32s:kValues2
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getUInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt32:&value forKey:YES]);
- XCTAssertEqual(value, 100U);
- XCTAssertTrue([dict getUInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt32:&value forKey:NO]);
- XCTAssertEqual(value, 101U);
- [dict2 release];
- [dict release];
- }
- @end
- //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int32, int32_t, 200, 201)
- // This block of code is generated, do not edit it directly.
- #pragma mark - Bool -> Int32
- @interface GPBBoolInt32DictionaryTests : XCTestCase
- @end
- @implementation GPBBoolInt32DictionaryTests
- - (void)testEmpty {
- GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getInt32:NULL forKey:YES]);
- [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
- #pragma unused(aKey, aValue, stop)
- XCTFail(@"Shouldn't get here!");
- }];
- [dict release];
- }
- - (void)testOne {
- GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
- [dict setInt32:200 forKey:YES];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 1U);
- int32_t value;
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 200);
- XCTAssertFalse([dict getInt32:NULL forKey:NO]);
- [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
- XCTAssertEqual(aKey, YES);
- XCTAssertEqual(aValue, 200);
- XCTAssertNotEqual(stop, NULL);
- }];
- [dict release];
- }
- - (void)testBasics {
- const BOOL kKeys[] = { YES, NO };
- const int32_t kValues[] = { 200, 201 };
- GPBBoolInt32Dictionary *dict =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- int32_t value;
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 200);
- XCTAssertTrue([dict getInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getInt32:&value forKey:NO]);
- XCTAssertEqual(value, 201);
- __block NSUInteger idx = 0;
- BOOL *seenKeys = malloc(2 * sizeof(BOOL));
- int32_t *seenValues = malloc(2 * sizeof(int32_t));
- [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
- XCTAssertLessThan(idx, 2U);
- seenKeys[idx] = aKey;
- seenValues[idx] = aValue;
- XCTAssertNotEqual(stop, NULL);
- ++idx;
- }];
- for (int i = 0; i < 2; ++i) {
- BOOL foundKey = NO;
- for (int j = 0; (j < 2) && !foundKey; ++j) {
- if (kKeys[i] == seenKeys[j]) {
- foundKey = YES;
- XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
- }
- }
- XCTAssertTrue(foundKey, @"i = %d", i);
- }
- free(seenKeys);
- free(seenValues);
- // Stopping the enumeration.
- idx = 0;
- [dict enumerateKeysAndInt32sUsingBlock:^(BOOL aKey, int32_t aValue, BOOL *stop) {
- #pragma unused(aKey, aValue)
- if (idx == 0) *stop = YES;
- XCTAssertNotEqual(idx, 2U);
- ++idx;
- }];
- [dict release];
- }
- - (void)testEquality {
- const BOOL kKeys1[] = { YES, NO };
- const BOOL kKeys2[] = { NO, YES };
- const int32_t kValues1[] = { 200, 201 };
- const int32_t kValues2[] = { 201, 200 };
- const int32_t kValues3[] = { 201 };
- GPBBoolInt32Dictionary *dict1 =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1);
- GPBBoolInt32Dictionary *dict1prime =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1prime);
- GPBBoolInt32Dictionary *dict2 =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues2
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- GPBBoolInt32Dictionary *dict3 =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues1
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict3);
- GPBBoolInt32Dictionary *dict4 =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues3
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues3)];
- XCTAssertNotNil(dict4);
- // 1/1Prime should be different objects, but equal.
- XCTAssertNotEqual(dict1, dict1prime);
- XCTAssertEqualObjects(dict1, dict1prime);
- // Equal, so they must have same hash.
- XCTAssertEqual([dict1 hash], [dict1prime hash]);
- // 2 is same keys, different values; not equal.
- XCTAssertNotEqualObjects(dict1, dict2);
- // 3 is different keys, same values; not equal.
- XCTAssertNotEqualObjects(dict1, dict3);
- // 4 Fewer pairs; not equal
- XCTAssertNotEqualObjects(dict1, dict4);
- [dict1 release];
- [dict1prime release];
- [dict2 release];
- [dict3 release];
- [dict4 release];
- }
- - (void)testCopy {
- const BOOL kKeys[] = { YES, NO };
- const int32_t kValues[] = { 200, 201 };
- GPBBoolInt32Dictionary *dict =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolInt32Dictionary *dict2 = [dict copy];
- XCTAssertNotNil(dict2);
- // Should be new object but equal.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt32Dictionary class]]);
- [dict2 release];
- [dict release];
- }
- - (void)testDictionaryFromDictionary {
- const BOOL kKeys[] = { YES, NO };
- const int32_t kValues[] = { 200, 201 };
- GPBBoolInt32Dictionary *dict =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolInt32Dictionary *dict2 =
- [[GPBBoolInt32Dictionary alloc] initWithDictionary:dict];
- XCTAssertNotNil(dict2);
- // Should be new pointer, but equal objects.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- [dict2 release];
- [dict release];
- }
- - (void)testAdds {
- GPBBoolInt32Dictionary *dict = [[GPBBoolInt32Dictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- [dict setInt32:200 forKey:YES];
- XCTAssertEqual(dict.count, 1U);
- const BOOL kKeys[] = { NO };
- const int32_t kValues[] = { 201 };
- GPBBoolInt32Dictionary *dict2 =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- int32_t value;
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 200);
- XCTAssertTrue([dict getInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getInt32:&value forKey:NO]);
- XCTAssertEqual(value, 201);
- [dict2 release];
- [dict release];
- }
- - (void)testRemove {
- const BOOL kKeys[] = { YES, NO};
- const int32_t kValues[] = { 200, 201 };
- GPBBoolInt32Dictionary *dict =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- [dict removeInt32ForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- int32_t value;
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 200);
- XCTAssertFalse([dict getInt32:NULL forKey:NO]);
- // Remove again does nothing.
- [dict removeInt32ForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 200);
- XCTAssertFalse([dict getInt32:NULL forKey:NO]);
- [dict removeAll];
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getInt32:NULL forKey:YES]);
- XCTAssertFalse([dict getInt32:NULL forKey:NO]);
- [dict release];
- }
- - (void)testInplaceMutation {
- const BOOL kKeys[] = { YES, NO };
- const int32_t kValues[] = { 200, 201 };
- GPBBoolInt32Dictionary *dict =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- int32_t value;
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 200);
- XCTAssertTrue([dict getInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getInt32:&value forKey:NO]);
- XCTAssertEqual(value, 201);
- [dict setInt32:201 forKey:YES];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 201);
- XCTAssertTrue([dict getInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getInt32:&value forKey:NO]);
- XCTAssertEqual(value, 201);
- [dict setInt32:200 forKey:NO];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 201);
- XCTAssertTrue([dict getInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getInt32:&value forKey:NO]);
- XCTAssertEqual(value, 200);
- const BOOL kKeys2[] = { NO, YES };
- const int32_t kValues2[] = { 201, 200 };
- GPBBoolInt32Dictionary *dict2 =
- [[GPBBoolInt32Dictionary alloc] initWithInt32s:kValues2
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getInt32:NULL forKey:YES]);
- XCTAssertTrue([dict getInt32:&value forKey:YES]);
- XCTAssertEqual(value, 200);
- XCTAssertTrue([dict getInt32:NULL forKey:NO]);
- XCTAssertTrue([dict getInt32:&value forKey:NO]);
- XCTAssertEqual(value, 201);
- [dict2 release];
- [dict release];
- }
- @end
- //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(UInt64, uint64_t, 300U, 301U)
- // This block of code is generated, do not edit it directly.
- #pragma mark - Bool -> UInt64
- @interface GPBBoolUInt64DictionaryTests : XCTestCase
- @end
- @implementation GPBBoolUInt64DictionaryTests
- - (void)testEmpty {
- GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getUInt64:NULL forKey:YES]);
- [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
- #pragma unused(aKey, aValue, stop)
- XCTFail(@"Shouldn't get here!");
- }];
- [dict release];
- }
- - (void)testOne {
- GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
- [dict setUInt64:300U forKey:YES];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 1U);
- uint64_t value;
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 300U);
- XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
- [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
- XCTAssertEqual(aKey, YES);
- XCTAssertEqual(aValue, 300U);
- XCTAssertNotEqual(stop, NULL);
- }];
- [dict release];
- }
- - (void)testBasics {
- const BOOL kKeys[] = { YES, NO };
- const uint64_t kValues[] = { 300U, 301U };
- GPBBoolUInt64Dictionary *dict =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- uint64_t value;
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 300U);
- XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt64:&value forKey:NO]);
- XCTAssertEqual(value, 301U);
- __block NSUInteger idx = 0;
- BOOL *seenKeys = malloc(2 * sizeof(BOOL));
- uint64_t *seenValues = malloc(2 * sizeof(uint64_t));
- [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
- XCTAssertLessThan(idx, 2U);
- seenKeys[idx] = aKey;
- seenValues[idx] = aValue;
- XCTAssertNotEqual(stop, NULL);
- ++idx;
- }];
- for (int i = 0; i < 2; ++i) {
- BOOL foundKey = NO;
- for (int j = 0; (j < 2) && !foundKey; ++j) {
- if (kKeys[i] == seenKeys[j]) {
- foundKey = YES;
- XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
- }
- }
- XCTAssertTrue(foundKey, @"i = %d", i);
- }
- free(seenKeys);
- free(seenValues);
- // Stopping the enumeration.
- idx = 0;
- [dict enumerateKeysAndUInt64sUsingBlock:^(BOOL aKey, uint64_t aValue, BOOL *stop) {
- #pragma unused(aKey, aValue)
- if (idx == 0) *stop = YES;
- XCTAssertNotEqual(idx, 2U);
- ++idx;
- }];
- [dict release];
- }
- - (void)testEquality {
- const BOOL kKeys1[] = { YES, NO };
- const BOOL kKeys2[] = { NO, YES };
- const uint64_t kValues1[] = { 300U, 301U };
- const uint64_t kValues2[] = { 301U, 300U };
- const uint64_t kValues3[] = { 301U };
- GPBBoolUInt64Dictionary *dict1 =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1);
- GPBBoolUInt64Dictionary *dict1prime =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1prime);
- GPBBoolUInt64Dictionary *dict2 =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues2
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- GPBBoolUInt64Dictionary *dict3 =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues1
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict3);
- GPBBoolUInt64Dictionary *dict4 =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues3
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues3)];
- XCTAssertNotNil(dict4);
- // 1/1Prime should be different objects, but equal.
- XCTAssertNotEqual(dict1, dict1prime);
- XCTAssertEqualObjects(dict1, dict1prime);
- // Equal, so they must have same hash.
- XCTAssertEqual([dict1 hash], [dict1prime hash]);
- // 2 is same keys, different values; not equal.
- XCTAssertNotEqualObjects(dict1, dict2);
- // 3 is different keys, same values; not equal.
- XCTAssertNotEqualObjects(dict1, dict3);
- // 4 Fewer pairs; not equal
- XCTAssertNotEqualObjects(dict1, dict4);
- [dict1 release];
- [dict1prime release];
- [dict2 release];
- [dict3 release];
- [dict4 release];
- }
- - (void)testCopy {
- const BOOL kKeys[] = { YES, NO };
- const uint64_t kValues[] = { 300U, 301U };
- GPBBoolUInt64Dictionary *dict =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolUInt64Dictionary *dict2 = [dict copy];
- XCTAssertNotNil(dict2);
- // Should be new object but equal.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- XCTAssertTrue([dict2 isKindOfClass:[GPBBoolUInt64Dictionary class]]);
- [dict2 release];
- [dict release];
- }
- - (void)testDictionaryFromDictionary {
- const BOOL kKeys[] = { YES, NO };
- const uint64_t kValues[] = { 300U, 301U };
- GPBBoolUInt64Dictionary *dict =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolUInt64Dictionary *dict2 =
- [[GPBBoolUInt64Dictionary alloc] initWithDictionary:dict];
- XCTAssertNotNil(dict2);
- // Should be new pointer, but equal objects.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- [dict2 release];
- [dict release];
- }
- - (void)testAdds {
- GPBBoolUInt64Dictionary *dict = [[GPBBoolUInt64Dictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- [dict setUInt64:300U forKey:YES];
- XCTAssertEqual(dict.count, 1U);
- const BOOL kKeys[] = { NO };
- const uint64_t kValues[] = { 301U };
- GPBBoolUInt64Dictionary *dict2 =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- uint64_t value;
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 300U);
- XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt64:&value forKey:NO]);
- XCTAssertEqual(value, 301U);
- [dict2 release];
- [dict release];
- }
- - (void)testRemove {
- const BOOL kKeys[] = { YES, NO};
- const uint64_t kValues[] = { 300U, 301U };
- GPBBoolUInt64Dictionary *dict =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- [dict removeUInt64ForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- uint64_t value;
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 300U);
- XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
- // Remove again does nothing.
- [dict removeUInt64ForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 300U);
- XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
- [dict removeAll];
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getUInt64:NULL forKey:YES]);
- XCTAssertFalse([dict getUInt64:NULL forKey:NO]);
- [dict release];
- }
- - (void)testInplaceMutation {
- const BOOL kKeys[] = { YES, NO };
- const uint64_t kValues[] = { 300U, 301U };
- GPBBoolUInt64Dictionary *dict =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- uint64_t value;
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 300U);
- XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt64:&value forKey:NO]);
- XCTAssertEqual(value, 301U);
- [dict setUInt64:301U forKey:YES];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 301U);
- XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt64:&value forKey:NO]);
- XCTAssertEqual(value, 301U);
- [dict setUInt64:300U forKey:NO];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 301U);
- XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt64:&value forKey:NO]);
- XCTAssertEqual(value, 300U);
- const BOOL kKeys2[] = { NO, YES };
- const uint64_t kValues2[] = { 301U, 300U };
- GPBBoolUInt64Dictionary *dict2 =
- [[GPBBoolUInt64Dictionary alloc] initWithUInt64s:kValues2
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getUInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getUInt64:&value forKey:YES]);
- XCTAssertEqual(value, 300U);
- XCTAssertTrue([dict getUInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getUInt64:&value forKey:NO]);
- XCTAssertEqual(value, 301U);
- [dict2 release];
- [dict release];
- }
- @end
- //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Int64, int64_t, 400, 401)
- // This block of code is generated, do not edit it directly.
- #pragma mark - Bool -> Int64
- @interface GPBBoolInt64DictionaryTests : XCTestCase
- @end
- @implementation GPBBoolInt64DictionaryTests
- - (void)testEmpty {
- GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getInt64:NULL forKey:YES]);
- [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
- #pragma unused(aKey, aValue, stop)
- XCTFail(@"Shouldn't get here!");
- }];
- [dict release];
- }
- - (void)testOne {
- GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
- [dict setInt64:400 forKey:YES];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 1U);
- int64_t value;
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 400);
- XCTAssertFalse([dict getInt64:NULL forKey:NO]);
- [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
- XCTAssertEqual(aKey, YES);
- XCTAssertEqual(aValue, 400);
- XCTAssertNotEqual(stop, NULL);
- }];
- [dict release];
- }
- - (void)testBasics {
- const BOOL kKeys[] = { YES, NO };
- const int64_t kValues[] = { 400, 401 };
- GPBBoolInt64Dictionary *dict =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- int64_t value;
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 400);
- XCTAssertTrue([dict getInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getInt64:&value forKey:NO]);
- XCTAssertEqual(value, 401);
- __block NSUInteger idx = 0;
- BOOL *seenKeys = malloc(2 * sizeof(BOOL));
- int64_t *seenValues = malloc(2 * sizeof(int64_t));
- [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
- XCTAssertLessThan(idx, 2U);
- seenKeys[idx] = aKey;
- seenValues[idx] = aValue;
- XCTAssertNotEqual(stop, NULL);
- ++idx;
- }];
- for (int i = 0; i < 2; ++i) {
- BOOL foundKey = NO;
- for (int j = 0; (j < 2) && !foundKey; ++j) {
- if (kKeys[i] == seenKeys[j]) {
- foundKey = YES;
- XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
- }
- }
- XCTAssertTrue(foundKey, @"i = %d", i);
- }
- free(seenKeys);
- free(seenValues);
- // Stopping the enumeration.
- idx = 0;
- [dict enumerateKeysAndInt64sUsingBlock:^(BOOL aKey, int64_t aValue, BOOL *stop) {
- #pragma unused(aKey, aValue)
- if (idx == 0) *stop = YES;
- XCTAssertNotEqual(idx, 2U);
- ++idx;
- }];
- [dict release];
- }
- - (void)testEquality {
- const BOOL kKeys1[] = { YES, NO };
- const BOOL kKeys2[] = { NO, YES };
- const int64_t kValues1[] = { 400, 401 };
- const int64_t kValues2[] = { 401, 400 };
- const int64_t kValues3[] = { 401 };
- GPBBoolInt64Dictionary *dict1 =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1);
- GPBBoolInt64Dictionary *dict1prime =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1prime);
- GPBBoolInt64Dictionary *dict2 =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues2
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- GPBBoolInt64Dictionary *dict3 =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues1
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict3);
- GPBBoolInt64Dictionary *dict4 =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues3
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues3)];
- XCTAssertNotNil(dict4);
- // 1/1Prime should be different objects, but equal.
- XCTAssertNotEqual(dict1, dict1prime);
- XCTAssertEqualObjects(dict1, dict1prime);
- // Equal, so they must have same hash.
- XCTAssertEqual([dict1 hash], [dict1prime hash]);
- // 2 is same keys, different values; not equal.
- XCTAssertNotEqualObjects(dict1, dict2);
- // 3 is different keys, same values; not equal.
- XCTAssertNotEqualObjects(dict1, dict3);
- // 4 Fewer pairs; not equal
- XCTAssertNotEqualObjects(dict1, dict4);
- [dict1 release];
- [dict1prime release];
- [dict2 release];
- [dict3 release];
- [dict4 release];
- }
- - (void)testCopy {
- const BOOL kKeys[] = { YES, NO };
- const int64_t kValues[] = { 400, 401 };
- GPBBoolInt64Dictionary *dict =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolInt64Dictionary *dict2 = [dict copy];
- XCTAssertNotNil(dict2);
- // Should be new object but equal.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- XCTAssertTrue([dict2 isKindOfClass:[GPBBoolInt64Dictionary class]]);
- [dict2 release];
- [dict release];
- }
- - (void)testDictionaryFromDictionary {
- const BOOL kKeys[] = { YES, NO };
- const int64_t kValues[] = { 400, 401 };
- GPBBoolInt64Dictionary *dict =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolInt64Dictionary *dict2 =
- [[GPBBoolInt64Dictionary alloc] initWithDictionary:dict];
- XCTAssertNotNil(dict2);
- // Should be new pointer, but equal objects.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- [dict2 release];
- [dict release];
- }
- - (void)testAdds {
- GPBBoolInt64Dictionary *dict = [[GPBBoolInt64Dictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- [dict setInt64:400 forKey:YES];
- XCTAssertEqual(dict.count, 1U);
- const BOOL kKeys[] = { NO };
- const int64_t kValues[] = { 401 };
- GPBBoolInt64Dictionary *dict2 =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- int64_t value;
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 400);
- XCTAssertTrue([dict getInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getInt64:&value forKey:NO]);
- XCTAssertEqual(value, 401);
- [dict2 release];
- [dict release];
- }
- - (void)testRemove {
- const BOOL kKeys[] = { YES, NO};
- const int64_t kValues[] = { 400, 401 };
- GPBBoolInt64Dictionary *dict =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- [dict removeInt64ForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- int64_t value;
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 400);
- XCTAssertFalse([dict getInt64:NULL forKey:NO]);
- // Remove again does nothing.
- [dict removeInt64ForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 400);
- XCTAssertFalse([dict getInt64:NULL forKey:NO]);
- [dict removeAll];
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getInt64:NULL forKey:YES]);
- XCTAssertFalse([dict getInt64:NULL forKey:NO]);
- [dict release];
- }
- - (void)testInplaceMutation {
- const BOOL kKeys[] = { YES, NO };
- const int64_t kValues[] = { 400, 401 };
- GPBBoolInt64Dictionary *dict =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- int64_t value;
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 400);
- XCTAssertTrue([dict getInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getInt64:&value forKey:NO]);
- XCTAssertEqual(value, 401);
- [dict setInt64:401 forKey:YES];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 401);
- XCTAssertTrue([dict getInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getInt64:&value forKey:NO]);
- XCTAssertEqual(value, 401);
- [dict setInt64:400 forKey:NO];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 401);
- XCTAssertTrue([dict getInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getInt64:&value forKey:NO]);
- XCTAssertEqual(value, 400);
- const BOOL kKeys2[] = { NO, YES };
- const int64_t kValues2[] = { 401, 400 };
- GPBBoolInt64Dictionary *dict2 =
- [[GPBBoolInt64Dictionary alloc] initWithInt64s:kValues2
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getInt64:NULL forKey:YES]);
- XCTAssertTrue([dict getInt64:&value forKey:YES]);
- XCTAssertEqual(value, 400);
- XCTAssertTrue([dict getInt64:NULL forKey:NO]);
- XCTAssertTrue([dict getInt64:&value forKey:NO]);
- XCTAssertEqual(value, 401);
- [dict2 release];
- [dict release];
- }
- @end
- //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Bool, BOOL, NO, YES)
- // This block of code is generated, do not edit it directly.
- #pragma mark - Bool -> Bool
- @interface GPBBoolBoolDictionaryTests : XCTestCase
- @end
- @implementation GPBBoolBoolDictionaryTests
- - (void)testEmpty {
- GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getBool:NULL forKey:YES]);
- [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
- #pragma unused(aKey, aValue, stop)
- XCTFail(@"Shouldn't get here!");
- }];
- [dict release];
- }
- - (void)testOne {
- GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
- [dict setBool:NO forKey:YES];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 1U);
- BOOL value;
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, NO);
- XCTAssertFalse([dict getBool:NULL forKey:NO]);
- [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
- XCTAssertEqual(aKey, YES);
- XCTAssertEqual(aValue, NO);
- XCTAssertNotEqual(stop, NULL);
- }];
- [dict release];
- }
- - (void)testBasics {
- const BOOL kKeys[] = { YES, NO };
- const BOOL kValues[] = { NO, YES };
- GPBBoolBoolDictionary *dict =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- BOOL value;
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, NO);
- XCTAssertTrue([dict getBool:NULL forKey:NO]);
- XCTAssertTrue([dict getBool:&value forKey:NO]);
- XCTAssertEqual(value, YES);
- __block NSUInteger idx = 0;
- BOOL *seenKeys = malloc(2 * sizeof(BOOL));
- BOOL *seenValues = malloc(2 * sizeof(BOOL));
- [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
- XCTAssertLessThan(idx, 2U);
- seenKeys[idx] = aKey;
- seenValues[idx] = aValue;
- XCTAssertNotEqual(stop, NULL);
- ++idx;
- }];
- for (int i = 0; i < 2; ++i) {
- BOOL foundKey = NO;
- for (int j = 0; (j < 2) && !foundKey; ++j) {
- if (kKeys[i] == seenKeys[j]) {
- foundKey = YES;
- XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
- }
- }
- XCTAssertTrue(foundKey, @"i = %d", i);
- }
- free(seenKeys);
- free(seenValues);
- // Stopping the enumeration.
- idx = 0;
- [dict enumerateKeysAndBoolsUsingBlock:^(BOOL aKey, BOOL aValue, BOOL *stop) {
- #pragma unused(aKey, aValue)
- if (idx == 0) *stop = YES;
- XCTAssertNotEqual(idx, 2U);
- ++idx;
- }];
- [dict release];
- }
- - (void)testEquality {
- const BOOL kKeys1[] = { YES, NO };
- const BOOL kKeys2[] = { NO, YES };
- const BOOL kValues1[] = { NO, YES };
- const BOOL kValues2[] = { YES, NO };
- const BOOL kValues3[] = { YES };
- GPBBoolBoolDictionary *dict1 =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1);
- GPBBoolBoolDictionary *dict1prime =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1prime);
- GPBBoolBoolDictionary *dict2 =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues2
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- GPBBoolBoolDictionary *dict3 =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues1
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict3);
- GPBBoolBoolDictionary *dict4 =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues3
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues3)];
- XCTAssertNotNil(dict4);
- // 1/1Prime should be different objects, but equal.
- XCTAssertNotEqual(dict1, dict1prime);
- XCTAssertEqualObjects(dict1, dict1prime);
- // Equal, so they must have same hash.
- XCTAssertEqual([dict1 hash], [dict1prime hash]);
- // 2 is same keys, different values; not equal.
- XCTAssertNotEqualObjects(dict1, dict2);
- // 3 is different keys, same values; not equal.
- XCTAssertNotEqualObjects(dict1, dict3);
- // 4 Fewer pairs; not equal
- XCTAssertNotEqualObjects(dict1, dict4);
- [dict1 release];
- [dict1prime release];
- [dict2 release];
- [dict3 release];
- [dict4 release];
- }
- - (void)testCopy {
- const BOOL kKeys[] = { YES, NO };
- const BOOL kValues[] = { NO, YES };
- GPBBoolBoolDictionary *dict =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolBoolDictionary *dict2 = [dict copy];
- XCTAssertNotNil(dict2);
- // Should be new object but equal.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- XCTAssertTrue([dict2 isKindOfClass:[GPBBoolBoolDictionary class]]);
- [dict2 release];
- [dict release];
- }
- - (void)testDictionaryFromDictionary {
- const BOOL kKeys[] = { YES, NO };
- const BOOL kValues[] = { NO, YES };
- GPBBoolBoolDictionary *dict =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolBoolDictionary *dict2 =
- [[GPBBoolBoolDictionary alloc] initWithDictionary:dict];
- XCTAssertNotNil(dict2);
- // Should be new pointer, but equal objects.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- [dict2 release];
- [dict release];
- }
- - (void)testAdds {
- GPBBoolBoolDictionary *dict = [[GPBBoolBoolDictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- [dict setBool:NO forKey:YES];
- XCTAssertEqual(dict.count, 1U);
- const BOOL kKeys[] = { NO };
- const BOOL kValues[] = { YES };
- GPBBoolBoolDictionary *dict2 =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- BOOL value;
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, NO);
- XCTAssertTrue([dict getBool:NULL forKey:NO]);
- XCTAssertTrue([dict getBool:&value forKey:NO]);
- XCTAssertEqual(value, YES);
- [dict2 release];
- [dict release];
- }
- - (void)testRemove {
- const BOOL kKeys[] = { YES, NO};
- const BOOL kValues[] = { NO, YES };
- GPBBoolBoolDictionary *dict =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- [dict removeBoolForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- BOOL value;
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, NO);
- XCTAssertFalse([dict getBool:NULL forKey:NO]);
- // Remove again does nothing.
- [dict removeBoolForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, NO);
- XCTAssertFalse([dict getBool:NULL forKey:NO]);
- [dict removeAll];
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getBool:NULL forKey:YES]);
- XCTAssertFalse([dict getBool:NULL forKey:NO]);
- [dict release];
- }
- - (void)testInplaceMutation {
- const BOOL kKeys[] = { YES, NO };
- const BOOL kValues[] = { NO, YES };
- GPBBoolBoolDictionary *dict =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- BOOL value;
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, NO);
- XCTAssertTrue([dict getBool:NULL forKey:NO]);
- XCTAssertTrue([dict getBool:&value forKey:NO]);
- XCTAssertEqual(value, YES);
- [dict setBool:YES forKey:YES];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, YES);
- XCTAssertTrue([dict getBool:NULL forKey:NO]);
- XCTAssertTrue([dict getBool:&value forKey:NO]);
- XCTAssertEqual(value, YES);
- [dict setBool:NO forKey:NO];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, YES);
- XCTAssertTrue([dict getBool:NULL forKey:NO]);
- XCTAssertTrue([dict getBool:&value forKey:NO]);
- XCTAssertEqual(value, NO);
- const BOOL kKeys2[] = { NO, YES };
- const BOOL kValues2[] = { YES, NO };
- GPBBoolBoolDictionary *dict2 =
- [[GPBBoolBoolDictionary alloc] initWithBools:kValues2
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getBool:NULL forKey:YES]);
- XCTAssertTrue([dict getBool:&value forKey:YES]);
- XCTAssertEqual(value, NO);
- XCTAssertTrue([dict getBool:NULL forKey:NO]);
- XCTAssertTrue([dict getBool:&value forKey:NO]);
- XCTAssertEqual(value, YES);
- [dict2 release];
- [dict release];
- }
- @end
- //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Float, float, 500.f, 501.f)
- // This block of code is generated, do not edit it directly.
- #pragma mark - Bool -> Float
- @interface GPBBoolFloatDictionaryTests : XCTestCase
- @end
- @implementation GPBBoolFloatDictionaryTests
- - (void)testEmpty {
- GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getFloat:NULL forKey:YES]);
- [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
- #pragma unused(aKey, aValue, stop)
- XCTFail(@"Shouldn't get here!");
- }];
- [dict release];
- }
- - (void)testOne {
- GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
- [dict setFloat:500.f forKey:YES];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 1U);
- float value;
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 500.f);
- XCTAssertFalse([dict getFloat:NULL forKey:NO]);
- [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
- XCTAssertEqual(aKey, YES);
- XCTAssertEqual(aValue, 500.f);
- XCTAssertNotEqual(stop, NULL);
- }];
- [dict release];
- }
- - (void)testBasics {
- const BOOL kKeys[] = { YES, NO };
- const float kValues[] = { 500.f, 501.f };
- GPBBoolFloatDictionary *dict =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- float value;
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 500.f);
- XCTAssertTrue([dict getFloat:NULL forKey:NO]);
- XCTAssertTrue([dict getFloat:&value forKey:NO]);
- XCTAssertEqual(value, 501.f);
- __block NSUInteger idx = 0;
- BOOL *seenKeys = malloc(2 * sizeof(BOOL));
- float *seenValues = malloc(2 * sizeof(float));
- [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
- XCTAssertLessThan(idx, 2U);
- seenKeys[idx] = aKey;
- seenValues[idx] = aValue;
- XCTAssertNotEqual(stop, NULL);
- ++idx;
- }];
- for (int i = 0; i < 2; ++i) {
- BOOL foundKey = NO;
- for (int j = 0; (j < 2) && !foundKey; ++j) {
- if (kKeys[i] == seenKeys[j]) {
- foundKey = YES;
- XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
- }
- }
- XCTAssertTrue(foundKey, @"i = %d", i);
- }
- free(seenKeys);
- free(seenValues);
- // Stopping the enumeration.
- idx = 0;
- [dict enumerateKeysAndFloatsUsingBlock:^(BOOL aKey, float aValue, BOOL *stop) {
- #pragma unused(aKey, aValue)
- if (idx == 0) *stop = YES;
- XCTAssertNotEqual(idx, 2U);
- ++idx;
- }];
- [dict release];
- }
- - (void)testEquality {
- const BOOL kKeys1[] = { YES, NO };
- const BOOL kKeys2[] = { NO, YES };
- const float kValues1[] = { 500.f, 501.f };
- const float kValues2[] = { 501.f, 500.f };
- const float kValues3[] = { 501.f };
- GPBBoolFloatDictionary *dict1 =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1);
- GPBBoolFloatDictionary *dict1prime =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1prime);
- GPBBoolFloatDictionary *dict2 =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues2
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- GPBBoolFloatDictionary *dict3 =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues1
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict3);
- GPBBoolFloatDictionary *dict4 =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues3
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues3)];
- XCTAssertNotNil(dict4);
- // 1/1Prime should be different objects, but equal.
- XCTAssertNotEqual(dict1, dict1prime);
- XCTAssertEqualObjects(dict1, dict1prime);
- // Equal, so they must have same hash.
- XCTAssertEqual([dict1 hash], [dict1prime hash]);
- // 2 is same keys, different values; not equal.
- XCTAssertNotEqualObjects(dict1, dict2);
- // 3 is different keys, same values; not equal.
- XCTAssertNotEqualObjects(dict1, dict3);
- // 4 Fewer pairs; not equal
- XCTAssertNotEqualObjects(dict1, dict4);
- [dict1 release];
- [dict1prime release];
- [dict2 release];
- [dict3 release];
- [dict4 release];
- }
- - (void)testCopy {
- const BOOL kKeys[] = { YES, NO };
- const float kValues[] = { 500.f, 501.f };
- GPBBoolFloatDictionary *dict =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolFloatDictionary *dict2 = [dict copy];
- XCTAssertNotNil(dict2);
- // Should be new object but equal.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- XCTAssertTrue([dict2 isKindOfClass:[GPBBoolFloatDictionary class]]);
- [dict2 release];
- [dict release];
- }
- - (void)testDictionaryFromDictionary {
- const BOOL kKeys[] = { YES, NO };
- const float kValues[] = { 500.f, 501.f };
- GPBBoolFloatDictionary *dict =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolFloatDictionary *dict2 =
- [[GPBBoolFloatDictionary alloc] initWithDictionary:dict];
- XCTAssertNotNil(dict2);
- // Should be new pointer, but equal objects.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- [dict2 release];
- [dict release];
- }
- - (void)testAdds {
- GPBBoolFloatDictionary *dict = [[GPBBoolFloatDictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- [dict setFloat:500.f forKey:YES];
- XCTAssertEqual(dict.count, 1U);
- const BOOL kKeys[] = { NO };
- const float kValues[] = { 501.f };
- GPBBoolFloatDictionary *dict2 =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- float value;
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 500.f);
- XCTAssertTrue([dict getFloat:NULL forKey:NO]);
- XCTAssertTrue([dict getFloat:&value forKey:NO]);
- XCTAssertEqual(value, 501.f);
- [dict2 release];
- [dict release];
- }
- - (void)testRemove {
- const BOOL kKeys[] = { YES, NO};
- const float kValues[] = { 500.f, 501.f };
- GPBBoolFloatDictionary *dict =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- [dict removeFloatForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- float value;
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 500.f);
- XCTAssertFalse([dict getFloat:NULL forKey:NO]);
- // Remove again does nothing.
- [dict removeFloatForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 500.f);
- XCTAssertFalse([dict getFloat:NULL forKey:NO]);
- [dict removeAll];
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getFloat:NULL forKey:YES]);
- XCTAssertFalse([dict getFloat:NULL forKey:NO]);
- [dict release];
- }
- - (void)testInplaceMutation {
- const BOOL kKeys[] = { YES, NO };
- const float kValues[] = { 500.f, 501.f };
- GPBBoolFloatDictionary *dict =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- float value;
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 500.f);
- XCTAssertTrue([dict getFloat:NULL forKey:NO]);
- XCTAssertTrue([dict getFloat:&value forKey:NO]);
- XCTAssertEqual(value, 501.f);
- [dict setFloat:501.f forKey:YES];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 501.f);
- XCTAssertTrue([dict getFloat:NULL forKey:NO]);
- XCTAssertTrue([dict getFloat:&value forKey:NO]);
- XCTAssertEqual(value, 501.f);
- [dict setFloat:500.f forKey:NO];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 501.f);
- XCTAssertTrue([dict getFloat:NULL forKey:NO]);
- XCTAssertTrue([dict getFloat:&value forKey:NO]);
- XCTAssertEqual(value, 500.f);
- const BOOL kKeys2[] = { NO, YES };
- const float kValues2[] = { 501.f, 500.f };
- GPBBoolFloatDictionary *dict2 =
- [[GPBBoolFloatDictionary alloc] initWithFloats:kValues2
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getFloat:NULL forKey:YES]);
- XCTAssertTrue([dict getFloat:&value forKey:YES]);
- XCTAssertEqual(value, 500.f);
- XCTAssertTrue([dict getFloat:NULL forKey:NO]);
- XCTAssertTrue([dict getFloat:&value forKey:NO]);
- XCTAssertEqual(value, 501.f);
- [dict2 release];
- [dict release];
- }
- @end
- //%PDDM-EXPAND BOOL_TESTS_FOR_POD_VALUE(Double, double, 600., 601.)
- // This block of code is generated, do not edit it directly.
- #pragma mark - Bool -> Double
- @interface GPBBoolDoubleDictionaryTests : XCTestCase
- @end
- @implementation GPBBoolDoubleDictionaryTests
- - (void)testEmpty {
- GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getDouble:NULL forKey:YES]);
- [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
- #pragma unused(aKey, aValue, stop)
- XCTFail(@"Shouldn't get here!");
- }];
- [dict release];
- }
- - (void)testOne {
- GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
- [dict setDouble:600. forKey:YES];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 1U);
- double value;
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 600.);
- XCTAssertFalse([dict getDouble:NULL forKey:NO]);
- [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
- XCTAssertEqual(aKey, YES);
- XCTAssertEqual(aValue, 600.);
- XCTAssertNotEqual(stop, NULL);
- }];
- [dict release];
- }
- - (void)testBasics {
- const BOOL kKeys[] = { YES, NO };
- const double kValues[] = { 600., 601. };
- GPBBoolDoubleDictionary *dict =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- double value;
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 600.);
- XCTAssertTrue([dict getDouble:NULL forKey:NO]);
- XCTAssertTrue([dict getDouble:&value forKey:NO]);
- XCTAssertEqual(value, 601.);
- __block NSUInteger idx = 0;
- BOOL *seenKeys = malloc(2 * sizeof(BOOL));
- double *seenValues = malloc(2 * sizeof(double));
- [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
- XCTAssertLessThan(idx, 2U);
- seenKeys[idx] = aKey;
- seenValues[idx] = aValue;
- XCTAssertNotEqual(stop, NULL);
- ++idx;
- }];
- for (int i = 0; i < 2; ++i) {
- BOOL foundKey = NO;
- for (int j = 0; (j < 2) && !foundKey; ++j) {
- if (kKeys[i] == seenKeys[j]) {
- foundKey = YES;
- XCTAssertEqual(kValues[i], seenValues[j], @"i = %d, j = %d", i, j);
- }
- }
- XCTAssertTrue(foundKey, @"i = %d", i);
- }
- free(seenKeys);
- free(seenValues);
- // Stopping the enumeration.
- idx = 0;
- [dict enumerateKeysAndDoublesUsingBlock:^(BOOL aKey, double aValue, BOOL *stop) {
- #pragma unused(aKey, aValue)
- if (idx == 0) *stop = YES;
- XCTAssertNotEqual(idx, 2U);
- ++idx;
- }];
- [dict release];
- }
- - (void)testEquality {
- const BOOL kKeys1[] = { YES, NO };
- const BOOL kKeys2[] = { NO, YES };
- const double kValues1[] = { 600., 601. };
- const double kValues2[] = { 601., 600. };
- const double kValues3[] = { 601. };
- GPBBoolDoubleDictionary *dict1 =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1);
- GPBBoolDoubleDictionary *dict1prime =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict1prime);
- GPBBoolDoubleDictionary *dict2 =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues2
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- GPBBoolDoubleDictionary *dict3 =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues1
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues1)];
- XCTAssertNotNil(dict3);
- GPBBoolDoubleDictionary *dict4 =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues3
- forKeys:kKeys1
- count:GPBARRAYSIZE(kValues3)];
- XCTAssertNotNil(dict4);
- // 1/1Prime should be different objects, but equal.
- XCTAssertNotEqual(dict1, dict1prime);
- XCTAssertEqualObjects(dict1, dict1prime);
- // Equal, so they must have same hash.
- XCTAssertEqual([dict1 hash], [dict1prime hash]);
- // 2 is same keys, different values; not equal.
- XCTAssertNotEqualObjects(dict1, dict2);
- // 3 is different keys, same values; not equal.
- XCTAssertNotEqualObjects(dict1, dict3);
- // 4 Fewer pairs; not equal
- XCTAssertNotEqualObjects(dict1, dict4);
- [dict1 release];
- [dict1prime release];
- [dict2 release];
- [dict3 release];
- [dict4 release];
- }
- - (void)testCopy {
- const BOOL kKeys[] = { YES, NO };
- const double kValues[] = { 600., 601. };
- GPBBoolDoubleDictionary *dict =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolDoubleDictionary *dict2 = [dict copy];
- XCTAssertNotNil(dict2);
- // Should be new object but equal.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- XCTAssertTrue([dict2 isKindOfClass:[GPBBoolDoubleDictionary class]]);
- [dict2 release];
- [dict release];
- }
- - (void)testDictionaryFromDictionary {
- const BOOL kKeys[] = { YES, NO };
- const double kValues[] = { 600., 601. };
- GPBBoolDoubleDictionary *dict =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- GPBBoolDoubleDictionary *dict2 =
- [[GPBBoolDoubleDictionary alloc] initWithDictionary:dict];
- XCTAssertNotNil(dict2);
- // Should be new pointer, but equal objects.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- [dict2 release];
- [dict release];
- }
- - (void)testAdds {
- GPBBoolDoubleDictionary *dict = [[GPBBoolDoubleDictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- [dict setDouble:600. forKey:YES];
- XCTAssertEqual(dict.count, 1U);
- const BOOL kKeys[] = { NO };
- const double kValues[] = { 601. };
- GPBBoolDoubleDictionary *dict2 =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- double value;
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 600.);
- XCTAssertTrue([dict getDouble:NULL forKey:NO]);
- XCTAssertTrue([dict getDouble:&value forKey:NO]);
- XCTAssertEqual(value, 601.);
- [dict2 release];
- [dict release];
- }
- - (void)testRemove {
- const BOOL kKeys[] = { YES, NO};
- const double kValues[] = { 600., 601. };
- GPBBoolDoubleDictionary *dict =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- [dict removeDoubleForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- double value;
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 600.);
- XCTAssertFalse([dict getDouble:NULL forKey:NO]);
- // Remove again does nothing.
- [dict removeDoubleForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 600.);
- XCTAssertFalse([dict getDouble:NULL forKey:NO]);
- [dict removeAll];
- XCTAssertEqual(dict.count, 0U);
- XCTAssertFalse([dict getDouble:NULL forKey:YES]);
- XCTAssertFalse([dict getDouble:NULL forKey:NO]);
- [dict release];
- }
- - (void)testInplaceMutation {
- const BOOL kKeys[] = { YES, NO };
- const double kValues[] = { 600., 601. };
- GPBBoolDoubleDictionary *dict =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues
- forKeys:kKeys
- count:GPBARRAYSIZE(kValues)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- double value;
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 600.);
- XCTAssertTrue([dict getDouble:NULL forKey:NO]);
- XCTAssertTrue([dict getDouble:&value forKey:NO]);
- XCTAssertEqual(value, 601.);
- [dict setDouble:601. forKey:YES];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 601.);
- XCTAssertTrue([dict getDouble:NULL forKey:NO]);
- XCTAssertTrue([dict getDouble:&value forKey:NO]);
- XCTAssertEqual(value, 601.);
- [dict setDouble:600. forKey:NO];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 601.);
- XCTAssertTrue([dict getDouble:NULL forKey:NO]);
- XCTAssertTrue([dict getDouble:&value forKey:NO]);
- XCTAssertEqual(value, 600.);
- const BOOL kKeys2[] = { NO, YES };
- const double kValues2[] = { 601., 600. };
- GPBBoolDoubleDictionary *dict2 =
- [[GPBBoolDoubleDictionary alloc] initWithDoubles:kValues2
- forKeys:kKeys2
- count:GPBARRAYSIZE(kValues2)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertTrue([dict getDouble:NULL forKey:YES]);
- XCTAssertTrue([dict getDouble:&value forKey:YES]);
- XCTAssertEqual(value, 600.);
- XCTAssertTrue([dict getDouble:NULL forKey:NO]);
- XCTAssertTrue([dict getDouble:&value forKey:NO]);
- XCTAssertEqual(value, 601.);
- [dict2 release];
- [dict release];
- }
- @end
- //%PDDM-EXPAND TESTS_FOR_BOOL_KEY_OBJECT_VALUE(Object, NSString*, @"abc", @"def")
- // This block of code is generated, do not edit it directly.
- #pragma mark - Bool -> Object
- @interface GPBBoolObjectDictionaryTests : XCTestCase
- @end
- @implementation GPBBoolObjectDictionaryTests
- - (void)testEmpty {
- GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- XCTAssertNil([dict objectForKey:YES]);
- [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
- #pragma unused(aKey, aObject, stop)
- XCTFail(@"Shouldn't get here!");
- }];
- [dict release];
- }
- - (void)testOne {
- GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
- [dict setObject:@"abc" forKey:YES];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 1U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
- XCTAssertNil([dict objectForKey:NO]);
- [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
- XCTAssertEqual(aKey, YES);
- XCTAssertEqualObjects(aObject, @"abc");
- XCTAssertNotEqual(stop, NULL);
- }];
- [dict release];
- }
- - (void)testBasics {
- const BOOL kKeys[] = { YES, NO };
- const NSString* kObjects[] = { @"abc", @"def" };
- GPBBoolObjectDictionary<NSString*> *dict =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
- forKeys:kKeys
- count:GPBARRAYSIZE(kObjects)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
- XCTAssertEqualObjects([dict objectForKey:NO], @"def");
- __block NSUInteger idx = 0;
- BOOL *seenKeys = malloc(2 * sizeof(BOOL));
- NSString* *seenObjects = malloc(2 * sizeof(NSString*));
- [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
- XCTAssertLessThan(idx, 2U);
- seenKeys[idx] = aKey;
- seenObjects[idx] = aObject;
- XCTAssertNotEqual(stop, NULL);
- ++idx;
- }];
- for (int i = 0; i < 2; ++i) {
- BOOL foundKey = NO;
- for (int j = 0; (j < 2) && !foundKey; ++j) {
- if (kKeys[i] == seenKeys[j]) {
- foundKey = YES;
- XCTAssertEqualObjects(kObjects[i], seenObjects[j], @"i = %d, j = %d", i, j);
- }
- }
- XCTAssertTrue(foundKey, @"i = %d", i);
- }
- free(seenKeys);
- free(seenObjects);
- // Stopping the enumeration.
- idx = 0;
- [dict enumerateKeysAndObjectsUsingBlock:^(BOOL aKey, NSString* aObject, BOOL *stop) {
- #pragma unused(aKey, aObject)
- if (idx == 0) *stop = YES;
- XCTAssertNotEqual(idx, 2U);
- ++idx;
- }];
- [dict release];
- }
- - (void)testEquality {
- const BOOL kKeys1[] = { YES, NO };
- const BOOL kKeys2[] = { NO, YES };
- const NSString* kObjects1[] = { @"abc", @"def" };
- const NSString* kObjects2[] = { @"def", @"abc" };
- const NSString* kObjects3[] = { @"def" };
- GPBBoolObjectDictionary<NSString*> *dict1 =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kObjects1)];
- XCTAssertNotNil(dict1);
- GPBBoolObjectDictionary<NSString*> *dict1prime =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
- forKeys:kKeys1
- count:GPBARRAYSIZE(kObjects1)];
- XCTAssertNotNil(dict1prime);
- GPBBoolObjectDictionary<NSString*> *dict2 =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
- forKeys:kKeys1
- count:GPBARRAYSIZE(kObjects2)];
- XCTAssertNotNil(dict2);
- GPBBoolObjectDictionary<NSString*> *dict3 =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects1
- forKeys:kKeys2
- count:GPBARRAYSIZE(kObjects1)];
- XCTAssertNotNil(dict3);
- GPBBoolObjectDictionary<NSString*> *dict4 =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects3
- forKeys:kKeys1
- count:GPBARRAYSIZE(kObjects3)];
- XCTAssertNotNil(dict4);
- // 1/1Prime should be different objects, but equal.
- XCTAssertNotEqual(dict1, dict1prime);
- XCTAssertEqualObjects(dict1, dict1prime);
- // Equal, so they must have same hash.
- XCTAssertEqual([dict1 hash], [dict1prime hash]);
- // 2 is same keys, different objects; not equal.
- XCTAssertNotEqualObjects(dict1, dict2);
- // 3 is different keys, same objects; not equal.
- XCTAssertNotEqualObjects(dict1, dict3);
- // 4 Fewer pairs; not equal
- XCTAssertNotEqualObjects(dict1, dict4);
- [dict1 release];
- [dict1prime release];
- [dict2 release];
- [dict3 release];
- [dict4 release];
- }
- - (void)testCopy {
- const BOOL kKeys[] = { YES, NO };
- const NSString* kObjects[] = { @"abc", @"def" };
- GPBBoolObjectDictionary<NSString*> *dict =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
- forKeys:kKeys
- count:GPBARRAYSIZE(kObjects)];
- XCTAssertNotNil(dict);
- GPBBoolObjectDictionary<NSString*> *dict2 = [dict copy];
- XCTAssertNotNil(dict2);
- // Should be new object but equal.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- XCTAssertTrue([dict2 isKindOfClass:[GPBBoolObjectDictionary class]]);
- [dict2 release];
- [dict release];
- }
- - (void)testDictionaryFromDictionary {
- const BOOL kKeys[] = { YES, NO };
- const NSString* kObjects[] = { @"abc", @"def" };
- GPBBoolObjectDictionary<NSString*> *dict =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
- forKeys:kKeys
- count:GPBARRAYSIZE(kObjects)];
- XCTAssertNotNil(dict);
- GPBBoolObjectDictionary<NSString*> *dict2 =
- [[GPBBoolObjectDictionary alloc] initWithDictionary:dict];
- XCTAssertNotNil(dict2);
- // Should be new pointer, but equal objects.
- XCTAssertNotEqual(dict, dict2);
- XCTAssertEqualObjects(dict, dict2);
- [dict2 release];
- [dict release];
- }
- - (void)testAdds {
- GPBBoolObjectDictionary<NSString*> *dict = [[GPBBoolObjectDictionary alloc] init];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 0U);
- [dict setObject:@"abc" forKey:YES];
- XCTAssertEqual(dict.count, 1U);
- const BOOL kKeys[] = { NO };
- const NSString* kObjects[] = { @"def" };
- GPBBoolObjectDictionary<NSString*> *dict2 =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
- forKeys:kKeys
- count:GPBARRAYSIZE(kObjects)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
- XCTAssertEqualObjects([dict objectForKey:NO], @"def");
- [dict2 release];
- [dict release];
- }
- - (void)testRemove {
- const BOOL kKeys[] = { YES, NO};
- const NSString* kObjects[] = { @"abc", @"def" };
- GPBBoolObjectDictionary<NSString*> *dict =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
- forKeys:kKeys
- count:GPBARRAYSIZE(kObjects)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- [dict removeObjectForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
- XCTAssertNil([dict objectForKey:NO]);
- // Remove again does nothing.
- [dict removeObjectForKey:NO];
- XCTAssertEqual(dict.count, 1U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
- XCTAssertNil([dict objectForKey:NO]);
- [dict removeAll];
- XCTAssertEqual(dict.count, 0U);
- XCTAssertNil([dict objectForKey:YES]);
- XCTAssertNil([dict objectForKey:NO]);
- [dict release];
- }
- - (void)testInplaceMutation {
- const BOOL kKeys[] = { YES, NO };
- const NSString* kObjects[] = { @"abc", @"def" };
- GPBBoolObjectDictionary<NSString*> *dict =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects
- forKeys:kKeys
- count:GPBARRAYSIZE(kObjects)];
- XCTAssertNotNil(dict);
- XCTAssertEqual(dict.count, 2U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
- XCTAssertEqualObjects([dict objectForKey:NO], @"def");
- [dict setObject:@"def" forKey:YES];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"def");
- XCTAssertEqualObjects([dict objectForKey:NO], @"def");
- [dict setObject:@"abc" forKey:NO];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"def");
- XCTAssertEqualObjects([dict objectForKey:NO], @"abc");
- const BOOL kKeys2[] = { NO, YES };
- const NSString* kObjects2[] = { @"def", @"abc" };
- GPBBoolObjectDictionary<NSString*> *dict2 =
- [[GPBBoolObjectDictionary alloc] initWithObjects:kObjects2
- forKeys:kKeys2
- count:GPBARRAYSIZE(kObjects2)];
- XCTAssertNotNil(dict2);
- [dict addEntriesFromDictionary:dict2];
- XCTAssertEqual(dict.count, 2U);
- XCTAssertEqualObjects([dict objectForKey:YES], @"abc");
- XCTAssertEqualObjects([dict objectForKey:NO], @"def");
- [dict2 release];
- [dict release];
- }
- @end
- //%PDDM-EXPAND-END (8 expansions)
|