From 962eca59e6ce8ed8b9dc673a9afad3a225377732 Mon Sep 17 00:00:00 2001 From: upstream svn Date: Sun, 20 Nov 2011 23:51:54 +0000 Subject: [PATCH] Remove references to CUInt128 member functions in favor of operator calls These will allow for more optimizations. Also added a missing testcase. --- .svn-revision | 2 +- src/ClientList.cpp | 2 +- src/ClientTCPSocket.cpp | 4 +- src/kademlia/kademlia/Entry.cpp | 4 +- src/kademlia/kademlia/Indexed.cpp | 28 ++-- src/kademlia/kademlia/Search.cpp | 4 +- src/kademlia/net/KademliaUDPListener.cpp | 22 ++-- unittests/tests/CUInt128Test.cpp | 213 +++++++++---------------------- 8 files changed, 96 insertions(+), 183 deletions(-) diff --git a/.svn-revision b/.svn-revision index 406756f2..458d3c57 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10682 +10683 diff --git a/src/ClientList.cpp b/src/ClientList.cpp index 72547b32..00534a81 100644 --- a/src/ClientList.cpp +++ b/src/ClientList.cpp @@ -694,7 +694,7 @@ void CClientList::Process() AddDebugLogLineN(logKadMain, wxT("Starting BuddySearch")); //We are a firewalled client with no buddy. We have also waited a set time //to try to avoid a false firewalled status.. So lets look for a buddy.. - if (!Kademlia::CSearchManager::PrepareLookup(Kademlia::CSearch::FINDBUDDY, true, Kademlia::CUInt128(true).XOR(Kademlia::CKademlia::GetPrefs()->GetKadID()))) { + if (!Kademlia::CSearchManager::PrepareLookup(Kademlia::CSearch::FINDBUDDY, true, Kademlia::CUInt128(true) ^ (Kademlia::CKademlia::GetPrefs()->GetKadID()))) { //This search ID was already going. Most likely reason is that //we found and lost our buddy very quickly and the last search hadn't //had time to be removed yet. Go ahead and set this to happen again diff --git a/src/ClientTCPSocket.cpp b/src/ClientTCPSocket.cpp index e52467bc..55ac40ae 100644 --- a/src/ClientTCPSocket.cpp +++ b/src/ClientTCPSocket.cpp @@ -1637,8 +1637,8 @@ bool CClientTCPSocket::ProcessExtPacket(const byte* buffer, uint32 size, uint8 o } CMemFile data(buffer, size); CUInt128 check = data.ReadUInt128(); - check.XOR(Kademlia::CUInt128(true)); - if( check.CompareTo(Kademlia::CKademlia::GetPrefs()->GetKadID())) { + check ^= Kademlia::CUInt128(true); + if (check != Kademlia::CKademlia::GetPrefs()->GetKadID()) { break; } CUInt128 fileid = data.ReadUInt128(); diff --git a/src/kademlia/kademlia/Entry.cpp b/src/kademlia/kademlia/Entry.cpp index cf760a40..975d470c 100644 --- a/src/kademlia/kademlia/Entry.cpp +++ b/src/kademlia/kademlia/Entry.cpp @@ -65,11 +65,11 @@ CEntry* CEntry::Copy() const entry->m_filenames.push_back(*it); } entry->m_uIP = m_uIP; - entry->m_uKeyID.SetValue(m_uKeyID); + entry->m_uKeyID = m_uKeyID; entry->m_tLifeTime = m_tLifeTime; entry->m_uSize = m_uSize; entry->m_bSource = m_bSource; - entry->m_uSourceID.SetValue(m_uSourceID); + entry->m_uSourceID = m_uSourceID; entry->m_uTCPport = m_uTCPport; entry->m_uUDPport = m_uUDPport; for (TagPtrList::const_iterator it = m_taglist.begin(); it != m_taglist.end(); ++it) { diff --git a/src/kademlia/kademlia/Indexed.cpp b/src/kademlia/kademlia/Indexed.cpp index 12803790..69900c74 100644 --- a/src/kademlia/kademlia/Indexed.cpp +++ b/src/kademlia/kademlia/Indexed.cpp @@ -213,8 +213,8 @@ void CIndexed::ReadFile() } tagList--; } - toAdd->m_uKeyID.SetValue(keyID); - toAdd->m_uSourceID.SetValue(sourceID); + toAdd->m_uKeyID = keyID; + toAdd->m_uSourceID = sourceID; uint8_t load; if (AddSources(keyID, sourceID, toAdd, load)) { totalSource++; @@ -493,11 +493,11 @@ bool CIndexed::AddKeyword(const CUInt128& keyID, const CUInt128& sourceID, Kadem KeyHash* currKeyHash = NULL; if (itKeyHash == m_Keyword_map.end()) { Source* currSource = new Source; - currSource->sourceID.SetValue(sourceID); + currSource->sourceID = sourceID; entry->MergeIPsAndFilenames(NULL); // IpTracking init currSource->entryList.push_front(entry); currKeyHash = new KeyHash; - currKeyHash->keyID.SetValue(keyID); + currKeyHash->keyID = keyID; currKeyHash->m_Source_map[currSource->sourceID] = currSource; m_Keyword_map[currKeyHash->keyID] = currKeyHash; load = 1; @@ -549,7 +549,7 @@ bool CIndexed::AddKeyword(const CUInt128& keyID, const CUInt128& sourceID, Kadem return true; } else { currSource = new Source; - currSource->sourceID.SetValue(sourceID); + currSource->sourceID = sourceID; entry->MergeIPsAndFilenames(NULL); // IpTracking init currSource->entryList.push_front(entry); currKeyHash->m_Source_map[currSource->sourceID] = currSource; @@ -575,10 +575,10 @@ bool CIndexed::AddSources(const CUInt128& keyID, const CUInt128& sourceID, Kadem SrcHashMap::iterator itSrcHash = m_Sources_map.find(keyID); if (itSrcHash == m_Sources_map.end()) { Source* currSource = new Source; - currSource->sourceID.SetValue(sourceID); + currSource->sourceID = sourceID; currSource->entryList.push_front(entry); currSrcHash = new SrcHash; - currSrcHash->keyID.SetValue(keyID); + currSrcHash->keyID = keyID; currSrcHash->m_Source_map.push_front(currSource); m_Sources_map[currSrcHash->keyID] = currSrcHash; m_totalIndexSource++; @@ -617,14 +617,14 @@ bool CIndexed::AddSources(const CUInt128& keyID, const CUInt128& sourceID, Kadem currSource->entryList.pop_back(); wxASSERT(currName != NULL); delete currName; - currSource->sourceID.SetValue(sourceID); + currSource->sourceID = sourceID; currSource->entryList.push_front(entry); currSrcHash->m_Source_map.push_front(currSource); load = 100; return true; } else { Source* currSource = new Source; - currSource->sourceID.SetValue(sourceID); + currSource->sourceID = sourceID; currSource->entryList.push_front(entry); currSrcHash->m_Source_map.push_front(currSource); m_totalIndexSource++; @@ -650,10 +650,10 @@ bool CIndexed::AddNotes(const CUInt128& keyID, const CUInt128& sourceID, Kademli SrcHashMap::iterator itNoteHash = m_Notes_map.find(keyID); if (itNoteHash == m_Notes_map.end()) { Source* currNote = new Source; - currNote->sourceID.SetValue(sourceID); + currNote->sourceID = sourceID; currNote->entryList.push_front(entry); currNoteHash = new SrcHash; - currNoteHash->keyID.SetValue(keyID); + currNoteHash->keyID = keyID; currNoteHash->m_Source_map.push_front(currNote); m_Notes_map[currNoteHash->keyID] = currNoteHash; load = 1; @@ -693,14 +693,14 @@ bool CIndexed::AddNotes(const CUInt128& keyID, const CUInt128& sourceID, Kademli currNote->entryList.pop_back(); wxASSERT(currName != NULL); delete currName; - currNote->sourceID.SetValue(sourceID); + currNote->sourceID = sourceID; currNote->entryList.push_front(entry); currNoteHash->m_Source_map.push_front(currNote); load = 100; return true; } else { Source* currNote = new Source; - currNote->sourceID.SetValue(sourceID); + currNote->sourceID = sourceID; currNote->entryList.push_front(entry); currNoteHash->m_Source_map.push_front(currNote); load = (size * 100) / KADEMLIAMAXNOTESPERFILE; @@ -725,7 +725,7 @@ bool CIndexed::AddLoad(const CUInt128& keyID, uint32_t timet) } load = new Load(); - load->keyID.SetValue(keyID); + load->keyID = keyID; load->time = timet; m_Load_map[load->keyID] = load; m_totalIndexLoad++; diff --git a/src/kademlia/kademlia/Search.cpp b/src/kademlia/kademlia/Search.cpp index 45b48612..dc5d1a58 100644 --- a/src/kademlia/kademlia/Search.cpp +++ b/src/kademlia/kademlia/Search.cpp @@ -927,8 +927,8 @@ void CSearch::ProcessResultNotes(const CUInt128& answer, TagPtrList *info) // Process a received Note to a file. // Create a Note and set the IDs. CEntry* entry = new CEntry(); - entry->m_uKeyID.SetValue(m_target); - entry->m_uSourceID.SetValue(answer); + entry->m_uKeyID = m_target; + entry->m_uSourceID = answer; bool bFilterComment = false; diff --git a/src/kademlia/net/KademliaUDPListener.cpp b/src/kademlia/net/KademliaUDPListener.cpp index 0e4773e4..63fa9661 100644 --- a/src/kademlia/net/KademliaUDPListener.cpp +++ b/src/kademlia/net/KademliaUDPListener.cpp @@ -653,7 +653,7 @@ void CKademliaUDPListener::ProcessKademlia2Request(const uint8_t *packetData, ui CUInt128 target = bio.ReadUInt128(); // Convert Target to Distance as this is how we store contacts. CUInt128 distance(CKademlia::GetPrefs()->GetKadID()); - distance.XOR(target); + distance ^= target; // This makes sure we are not mistaken identify. Some client may have fresh installed and have a new KadID. CUInt128 check = bio.ReadUInt128(); @@ -1013,7 +1013,7 @@ void CKademliaUDPListener::Process2PublishKeyRequest(const uint8_t *packetData, CUInt128 file = bio.ReadUInt128(); CUInt128 distance(CKademlia::GetPrefs()->GetKadID()); - distance.XOR(file); + distance ^= file; if (distance.Get32BitChunk(0) > SEARCHTOLERANCE && !::IsLanIP(wxUINT32_SWAP_ALWAYS(ip))) { return; @@ -1032,8 +1032,8 @@ void CKademliaUDPListener::Process2PublishKeyRequest(const uint8_t *packetData, { entry->m_uIP = ip; entry->m_uUDPport = port; - entry->m_uKeyID.SetValue(file); - entry->m_uSourceID.SetValue(target); + entry->m_uKeyID = file; + entry->m_uSourceID = target; entry->m_tLifeTime = (uint32_t)time(NULL) + KADEMLIAREPUBLISHTIMEK; entry->m_bSource = false; uint32_t tags = bio.ReadUInt8(); @@ -1111,7 +1111,7 @@ void CKademliaUDPListener::Process2PublishSourceRequest(const uint8_t *packetDat CUInt128 file = bio.ReadUInt128(); CUInt128 distance(CKademlia::GetPrefs()->GetKadID()); - distance.XOR(file); + distance ^= file; if (distance.Get32BitChunk(0) > SEARCHTOLERANCE && !::IsLanIP(wxUINT32_SWAP_ALWAYS(ip))) { return; @@ -1125,8 +1125,8 @@ void CKademliaUDPListener::Process2PublishSourceRequest(const uint8_t *packetDat try { entry->m_uIP = ip; entry->m_uUDPport = port; - entry->m_uKeyID.SetValue(file); - entry->m_uSourceID.SetValue(target); + entry->m_uKeyID = file; + entry->m_uSourceID = target; entry->m_bSource = false; entry->m_tLifeTime = (uint32_t)time(NULL) + KADEMLIAREPUBLISHTIMES; bool addUDPPortTag = true; @@ -1291,7 +1291,7 @@ void CKademliaUDPListener::Process2PublishNotesRequest(const uint8_t *packetData CUInt128 target = bio.ReadUInt128(); CUInt128 distance(CKademlia::GetPrefs()->GetKadID()); - distance.XOR(target); + distance ^= target; if (distance.Get32BitChunk(0) > SEARCHTOLERANCE && !::IsLanIP(wxUINT32_SWAP_ALWAYS(ip))) { return; @@ -1303,8 +1303,8 @@ void CKademliaUDPListener::Process2PublishNotesRequest(const uint8_t *packetData try { entry->m_uIP = ip; entry->m_uUDPport = port; - entry->m_uKeyID.SetValue(target); - entry->m_uSourceID.SetValue(source); + entry->m_uKeyID = target; + entry->m_uSourceID = source; entry->m_bSource = false; uint32_t tags = bio.ReadUInt8(); while (tags > 0) { @@ -1477,7 +1477,7 @@ void CKademliaUDPListener::ProcessFindBuddyResponse(const uint8_t *packetData, u CMemFile bio(packetData, lenPacket); CUInt128 check = bio.ReadUInt128(); - check.XOR(CUInt128(true)); + check ^= CUInt128(true); if (CKademlia::GetPrefs()->GetKadID() == check) { CUInt128 userID = bio.ReadUInt128(); uint16_t tcpport = bio.ReadUInt16(); diff --git a/unittests/tests/CUInt128Test.cpp b/unittests/tests/CUInt128Test.cpp index 73c3a10a..ef08a9a7 100644 --- a/unittests/tests/CUInt128Test.cpp +++ b/unittests/tests/CUInt128Test.cpp @@ -175,6 +175,62 @@ TEST_M(CUInt128, ConstructFromUint32, wxT("CUInt128(uint32_t)")) ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::uintValue), CUInt128(0x12345678u)); } +TEST_M(CUInt128, ConstructWithBits, wxT("CUInt128(const CUInt128&, unsigned)")) +{ + CUInt128 a((uint8_t *)&TestData::sequence); + CUInt128 b((uint8_t *)&TestData::minusOne); + + { + CUInt128 testa(a, 1); + ASSERT_EQUALS(0u, testa.Get32BitChunk(0) & 0x80000000); + + CUInt128 testb(b, 1); + ASSERT_EQUALS(0x80000000u, testb.Get32BitChunk(0) & 0x80000000); + } + { + CUInt128 testa(a, 2); + ASSERT_EQUALS(0u, testa.Get32BitChunk(0) & 0xc0000000); + + CUInt128 testb(b, 2); + ASSERT_EQUALS(0xc0000000u, testb.Get32BitChunk(0) & 0xc0000000); + } + { + CUInt128 testa(a, 8); + ASSERT_EQUALS(0u, testa.Get32BitChunk(0) & 0xff000000); + + CUInt128 testb(b, 8); + ASSERT_EQUALS(0xff000000u, testb.Get32BitChunk(0) & 0xff000000); + } + { + CUInt128 testa(a, 31); + ASSERT_EQUALS(0x00010202u, testa.Get32BitChunk(0) & 0xfffffffe); + + CUInt128 testb(b, 31); + ASSERT_EQUALS(0xfffffffeu, testb.Get32BitChunk(0) & 0xfffffffe); + } + { + CUInt128 testa(a, 32); + ASSERT_EQUALS(0x00010203u, testa.Get32BitChunk(0)); + + CUInt128 testb(b, 32); + ASSERT_EQUALS(0xffffffffu, testb.Get32BitChunk(0)); + } + { + CUInt128 testa(a, 33); + ASSERT_EQUALS(0u, testa.Get32BitChunk(1) & 0x80000000); + + CUInt128 testb(b, 33); + ASSERT_EQUALS(0x80000000u, testb.Get32BitChunk(1) & 0x80000000); + } + { + CUInt128 testa(a, 128); + ASSERT_EQUALS(a, testa); + + CUInt128 testb(b, 128); + ASSERT_EQUALS(b, testb); + } +} + TEST_M(CUInt128, AssignCUInt128, wxT("operator=(const CUInt128&)")) { CUInt128 a((uint8_t *)&TestData::sequence); @@ -217,24 +273,6 @@ TEST(CUInt128, Set32BitChunk) ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::sequence), test); } -TEST_M(CUInt128, SetValueCUInt128, wxT("SetValue(const CUInt128&)")) -{ - CUInt128 a((uint8_t *)&TestData::sequence); - CUInt128 b; - - b.SetValue(a); - ASSERT_EQUALS(a, b); -} - -TEST_M(CUInt128, SetValueUint32, wxT("SetValue(uint32_t)")) -{ - CUInt128 a((uint8_t *)&TestData::uintValue); - CUInt128 b; - - b.SetValue(0x12345678u); - ASSERT_EQUALS(a, b); -} - TEST(CUInt128, SetValueBE) { CUInt128 a((uint8_t *)&TestData::sequence); @@ -256,131 +294,6 @@ TEST(CUInt128, StoreCryptValue) ASSERT_EQUALS(CUInt128((uint8_t *)&ref), CUInt128((uint8_t *)&tmp)); } -TEST(CUInt128, ShiftLeft) -{ - CUInt128 test((uint8_t *)&TestData::one); - uint8_t r1[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }; - uint8_t r2[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0 }; - uint8_t r3[16] = { 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - uint8_t r4[16] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - test.ShiftLeft(0); - ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::one), test); - test.ShiftLeft(1); - ASSERT_EQUALS(CUInt128((uint8_t *)&r1), test); - test.ShiftLeft(32); - ASSERT_EQUALS(CUInt128((uint8_t *)&r2), test); - test.ShiftLeft(58); - ASSERT_EQUALS(CUInt128((uint8_t *)&r3), test); - test.SetValueBE((uint8_t *)&TestData::one); - test.ShiftLeft(127); - ASSERT_EQUALS(CUInt128((uint8_t *)&r4), test); - test.SetValueBE((uint8_t *)&TestData::one); - test.ShiftLeft(128); - ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::zero), test); -} - -TEST_M(CUInt128, AddCUInt128, wxT("Add(const CUInt128&)")) -{ - uint8_t d0[16] = { 0xfc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; - uint8_t r1[16] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xd, 0x30, 0x53, 0x76 }; - uint8_t r2[16] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xc, 0xc, 0x30, 0x53, 0x76 }; - uint8_t r3[16] = { 0xfc, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xc, 0xc, 0x30, 0x53, 0x76 }; - uint8_t r4[16] = { 0xf8, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xc, 0xc, 0x30, 0x53, 0x76 }; - CUInt128 a((uint8_t *)&TestData::sequence); - CUInt128 d((uint8_t *)&d0); - - a.Add(CUInt128(0x01234567u)); - ASSERT_EQUALS(CUInt128((uint8_t *)&r1), a); - a.Add(CUInt128(0xff000000u)); - ASSERT_EQUALS(CUInt128((uint8_t *)&r2), a); - a.Add(d); - ASSERT_EQUALS(CUInt128((uint8_t *)&r3), a); - ASSERT_EQUALS(CUInt128((uint8_t *)&d0), d); - a.Add(d); - ASSERT_EQUALS(CUInt128((uint8_t *)&r4), a); - a.SetValueBE((uint8_t *)&TestData::minusOne); - a.Add(CUInt128((uint8_t *)&TestData::one)); - ASSERT_EQUALS(CUInt128(), a); -} - -TEST_M(CUInt128, AddUint32, wxT("Add(uint32_t)")) -{ - uint8_t r1[16] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xd, 0x30, 0x53, 0x76 }; - uint8_t r2[16] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xc, 0xc, 0x30, 0x53, 0x76 }; - CUInt128 a((uint8_t *)&TestData::sequence); - - a.Add(0x01234567u); - ASSERT_EQUALS(CUInt128((uint8_t *)&r1), a); - a.Add(0xff000000u); - ASSERT_EQUALS(CUInt128((uint8_t *)&r2), a); - a.SetValueBE((uint8_t *)&TestData::minusOne); - a.Add(1u); - ASSERT_EQUALS(0, a); -} - -TEST_M(CUInt128, SubtractCUInt128, wxT("Subtract(const CUInt128&)")) -{ - uint8_t d0[16] = { 0xfc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; - uint8_t r1[16] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xd, 0x30, 0x53, 0x76 }; - uint8_t r2[16] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xc, 0xc, 0x30, 0x53, 0x76 }; - uint8_t r3[16] = { 0xfc, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xc, 0xc, 0x30, 0x53, 0x76 }; - uint8_t r4[16] = { 0xf8, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xc, 0xc, 0x30, 0x53, 0x76 }; - CUInt128 a((uint8_t *)&r4); - CUInt128 d((uint8_t *)&d0); - - a.Subtract(d); - ASSERT_EQUALS(CUInt128((uint8_t *)&r3), a); - ASSERT_EQUALS(CUInt128((uint8_t *)&d0), d); - a.Subtract(d); - ASSERT_EQUALS(CUInt128((uint8_t *)&r2), a); - a.Subtract(CUInt128(0xff000000u)); - ASSERT_EQUALS(CUInt128((uint8_t *)&r1), a); - a.Subtract(CUInt128(0x01234567u)); - ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::sequence), a); - a.SetValue(0u); - a.Subtract(CUInt128((uint8_t *)&TestData::one)); - ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::minusOne), a); -} - -TEST_M(CUInt128, SubtractUint32, wxT("Subtract(uint32_t)")) -{ - uint8_t r1[16] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xd, 0x30, 0x53, 0x76 }; - uint8_t r2[16] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xc, 0xc, 0x30, 0x53, 0x76 }; - CUInt128 a((uint8_t *)&r2); - - a.Subtract(0xff000000u); - ASSERT_EQUALS(CUInt128((uint8_t *)&r1), a); - a.Subtract(0x01234567u); - ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::sequence), a); - a.SetValue(0u); - a.Subtract(1u); - ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::minusOne), a); -} - -TEST_M(CUInt128, XorCUInt128, wxT("XOR(const CUInt128&)")) -{ - uint8_t xd[16] = { 0xff, 0x00, 0xee, 0x11, 0xdd, 0x22, 0xcc, 0x33, 0xbb, 0x44, 0xaa, 0x55, 0x99, 0x66, 0x88, 0x77 }; - uint8_t xr[16] = { 0xff, 0x01, 0xec, 0x12, 0xd9, 0x27, 0xca, 0x34, 0xb3, 0x4d, 0xa0, 0x5e, 0x95, 0x6b, 0x86, 0x78 }; - CUInt128 a((uint8_t *)&TestData::sequence); - CUInt128 x((uint8_t *)&xd); - - a.XOR(x); - ASSERT_EQUALS(CUInt128((uint8_t *)&xr), a); - ASSERT_EQUALS(CUInt128((uint8_t *)&xd), x); -} - -// Not yet implemented -#if 0 -TEST_M(CUInt128, XorUint32, wxT("XOR(uint32_t)")) -{ - CUInt128 a(0x12345678u); - - a.XOR(0x76543210u); - ASSERT_EQUALS(0x64606468, a); -} -#endif - TEST_M(CUInt128, OperatorShiftLeftAssign, wxT("operator<<=(unsigned)")) { CUInt128 test((uint8_t *)&TestData::one); @@ -463,7 +376,7 @@ TEST_M(CUInt128, OperatorSubtractAssignCUInt128, wxT("operator-=(const CUInt128& ASSERT_EQUALS(CUInt128((uint8_t *)&r1), a); a -= CUInt128(0x01234567u); ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::sequence), a); - a.SetValue(0u); + a = 0; a -= CUInt128((uint8_t *)&TestData::one); ASSERT_EQUALS(CUInt128((uint8_t *)&TestData::minusOne), a); } @@ -719,7 +632,7 @@ TEST_M(CUInt128, OperatorAddCUInt128, wxT("operator+(const CUInt128&)")) CUInt128 check(a); CUInt128 result(a + a); - check.Add(ref); + check += ref; ASSERT_EQUALS(check, result); ASSERT_EQUALS(ref, a); @@ -743,7 +656,7 @@ TEST_M(CUInt128, OperatorSubtractCUInt128, wxT("operator-(const CUInt128&)")) CUInt128 result(a - b); ASSERT_EQUALS(refa, a); ASSERT_EQUALS(refb, b); - check.Subtract(b); + check -= b; ASSERT_EQUALS(check, result); result = b - a; @@ -778,7 +691,7 @@ TEST_M(CUInt128, OperatorAddUint32, wxT("operator+(uint32_t)")) CUInt128 check(a); CUInt128 result(a + b); - check.Add(b); + check += b; ASSERT_EQUALS(check, result); ASSERT_EQUALS(ref, a); @@ -801,7 +714,7 @@ TEST_M(CUInt128, OperatorSubtractUint32, wxT("operator-(uint32_t)")) CUInt128 result(a - b); ASSERT_EQUALS(ref, a); - check.Subtract(b); + check -= b; ASSERT_EQUALS(check, result); result = a - ~b; @@ -834,7 +747,7 @@ TEST_M(CUInt128, OperatorAddUint32CUInt128, wxT("operator+(uint32_t, const CUInt CUInt128 check(b); CUInt128 result(b + a); - check.Add(a); + check += a; ASSERT_EQUALS(check, result); ASSERT_EQUALS(ref, a); @@ -857,7 +770,7 @@ TEST_M(CUInt128, OperatorSubtractUint32CUInt128, wxT("operator-(uint32_t, const CUInt128 result(b - a); ASSERT_EQUALS(ref, a); - check.Subtract(a); + check -= a; ASSERT_EQUALS(check, result); } -- 2.11.4.GIT