bool mitk::TestDICOMLoading::CompareImageInformationDumps( const std::string& referenceDump, const std::string& testDump ) { KeyValueMap reference = ParseDump(referenceDump); KeyValueMap test = ParseDump(testDump); bool testResult(true); // verify all expected values for (KeyValueMap::const_iterator refIter = reference.begin(); refIter != reference.end(); ++refIter) { const std::string& refKey = refIter->first; const std::string& refValue = refIter->second; if ( test.find(refKey) != test.end() ) { const std::string& testValue = test[refKey]; bool thisTestResult = CompareSpacedValueFields( refValue, testValue ); testResult &= thisTestResult; MITK_DEBUG << refKey << ": '" << refValue << "' == '" << testValue << "' ? " << (thisTestResult?"YES":"NO"); } else { MITK_ERROR << "Reference dump contains a key'" << refKey << "' (value '" << refValue << "')." ; MITK_ERROR << "This key is expected to be generated for tests (but was not). Most probably you need to update your test data."; return false; } } // now check test dump does not contain any additional keys for (KeyValueMap::const_iterator testIter = test.begin(); testIter != test.end(); ++testIter) { const std::string& key = testIter->first; const std::string& value = testIter->second; if ( reference.find(key) == reference.end() ) { MITK_ERROR << "Test dump contains an unexpected key'" << key << "' (value '" << value << "')." ; MITK_ERROR << "This key is not expected. Most probably you need to update your test data."; return false; } } return testResult; }
void GameSpySupport::DumpKeyValueMapToBuffer(KeyValueMap& theMap, char* outbuf, unsigned int maxlen) { AutoCrit aCrit(mDataCrit); unsigned int pos = 0; unsigned int pairlength = 0; KeyValueMap::iterator anItr = theMap.begin(); for (; anItr != theMap.end(); ++anItr) { pairlength = anItr->first.length() + anItr->second.length() + 2; // add 2 for the seperating '\' if (pairlength < (maxlen-pos)) sprintf(outbuf+pos, "\\%s\\%s", anItr->first.c_str(), anItr->second.c_str()); pos += pairlength; } }
void writeKeyValueMap(KeyValueMap& kv, FILE* file) { for(KeyValueMap::iterator it= kv.begin(); it != kv.end(); ++it) fprintf(file, "%s = %s\n", it->first.c_str(), it->second.first.c_str()); }