void GenerateTestData(TestData& testData) { testData.clear(); string key; string val; const size_t longKeyLength = 2048; const size_t longDataLength = 4096; FillString("a", key, longKeyLength); testData.insert(pair<string, string>(key, "i")); FillString("b", key, longKeyLength); testData.insert(pair<string, string>(key, "j")); testData.insert(pair<string, string>(key, "q")); testData.insert(pair<string, string>(key, "r")); testData.insert(pair<string, string>(key, "s")); testData.insert(pair<string, string>(key, "t")); FillString("k", val, longDataLength); testData.insert(pair<string, string>("c", val)); FillString("l", val, longDataLength); testData.insert(pair<string, string>("d", val)); FillString("q", val, longDataLength); testData.insert(pair<string, string>("d", val)); FillString("r", val, longDataLength); testData.insert(pair<string, string>("d", val)); FillString("s", val, longDataLength); testData.insert(pair<string, string>("d", val)); FillString("t", val, longDataLength); testData.insert(pair<string, string>("d", val)); testData.insert(pair<string, string>("e", "m")); testData.insert(pair<string, string>("f", "n")); testData.insert(pair<string, string>("f", "q")); testData.insert(pair<string, string>("f", "r")); testData.insert(pair<string, string>("f", "s")); testData.insert(pair<string, string>("f", "t")); FillString("g", key, longKeyLength); FillString("o", val, longDataLength); testData.insert(pair<string, string>(key, val)); FillString("h", key, longKeyLength); FillString("p", val, longDataLength); testData.insert(pair<string, string>(key, val)); FillString("q", val, longDataLength); testData.insert(pair<string, string>(key, val)); FillString("r", val, longDataLength); testData.insert(pair<string, string>(key, val)); FillString("s", val, longDataLength); testData.insert(pair<string, string>(key, val)); FillString("t", val, longDataLength); testData.insert(pair<string, string>(key, val)); }
void TestDataFile(const std::string &filename, unsigned int &totalTests, unsigned int &failedTests) { std::ifstream file(filename.c_str()); if (!file.good()) throw Exception(Exception::OTHER_ERROR, "Can not open file " + filename + " for reading"); TestData v; s_currentTestData = &v; std::string name, value, lastAlgName; while (file) { while (file.peek() == '#') file.ignore(INT_MAX, '\n'); if (file.peek() == '\n') v.clear(); if (!GetField(file, name, value)) break; v[name] = value; if (name == "Test") { bool failed = true; std::string algType = GetRequiredDatum(v, "AlgorithmType"); if (lastAlgName != GetRequiredDatum(v, "Name")) { lastAlgName = GetRequiredDatum(v, "Name"); cout << "\nTesting " << algType.c_str() << " algorithm " << lastAlgName.c_str() << ".\n"; } try { if (algType == "Signature") TestSignatureScheme(v); else if (algType == "SymmetricCipher") TestSymmetricCipher(v); else if (algType == "AsymmetricCipher") TestAsymmetricCipher(v); else if (algType == "MessageDigest") TestDigestOrMAC(v, true); else if (algType == "MAC") TestDigestOrMAC(v, false); else if (algType == "FileList") TestDataFile(GetRequiredDatum(v, "Test"), totalTests, failedTests); else SignalTestError(); failed = false; } catch (TestFailure &) { cout << "\nTest failed.\n"; } catch (CryptoPP::Exception &e) { cout << "\nCryptoPP::Exception caught: " << e.what() << endl; } catch (std::exception &e) { cout << "\nstd::exception caught: " << e.what() << endl; } if (failed) { cout << "Skipping to next test.\n"; failedTests++; } else cout << "." << flush; totalTests++; } } }