File indexing completed on 2024-04-06 12:12:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <Utilities/Testing/interface/CppUnit_testdriver.icpp>
0015 #include <cppunit/extensions/HelperMacros.h>
0016 #include <iostream>
0017 #include <sstream>
0018
0019
0020 #include "FWCore/PluginManager/interface/CacheParser.h"
0021
0022 class TestCacheParser : public CppUnit::TestFixture {
0023 CPPUNIT_TEST_SUITE(TestCacheParser);
0024 CPPUNIT_TEST(testSpace);
0025 CPPUNIT_TEST(testReadWrite);
0026 CPPUNIT_TEST_SUITE_END();
0027
0028 public:
0029 void testSpace();
0030 void testReadWrite();
0031 void setUp() {}
0032 void tearDown() {}
0033 };
0034
0035
0036 CPPUNIT_TEST_SUITE_REGISTRATION(TestCacheParser);
0037
0038 void TestCacheParser::testSpace() {
0039 using namespace edmplugin;
0040
0041 const std::string kNoSpace("abcDefla");
0042 std::string unchanged(kNoSpace);
0043
0044 CPPUNIT_ASSERT(kNoSpace == CacheParser::replaceSpaces(unchanged));
0045 CPPUNIT_ASSERT(kNoSpace == unchanged);
0046 CPPUNIT_ASSERT(kNoSpace == CacheParser::restoreSpaces(unchanged));
0047 CPPUNIT_ASSERT(kNoSpace == unchanged);
0048
0049 const std::string kWithSpace("abc Def");
0050 std::string changed(kWithSpace);
0051
0052 const std::string kSpaceReplaced("abc%Def");
0053 CPPUNIT_ASSERT(kSpaceReplaced == CacheParser::replaceSpaces(changed));
0054 CPPUNIT_ASSERT(kSpaceReplaced == changed);
0055
0056 CPPUNIT_ASSERT(kWithSpace == CacheParser::restoreSpaces(changed));
0057 CPPUNIT_ASSERT(kWithSpace == changed);
0058 }
0059
0060 void TestCacheParser::testReadWrite() {
0061 using namespace edmplugin;
0062 std::map<std::string, std::vector<PluginInfo> > categoryToInfos;
0063 PluginInfo info;
0064 info.loadable_ = "pluginA.so";
0065 info.name_ = "AlphaClass";
0066 categoryToInfos["Cat One"].push_back(info);
0067 info.name_ = "BetaClass<Itl >";
0068 categoryToInfos["Cat Two"].push_back(info);
0069
0070 const std::string match("pluginA.so AlphaClass Cat%One\npluginA.so BetaClass<Itl%> Cat%Two\n");
0071 {
0072 std::stringstream ss;
0073 CacheParser::write(categoryToInfos, ss);
0074 CPPUNIT_ASSERT(match == ss.str());
0075 }
0076
0077
0078 categoryToInfos.clear();
0079
0080 info.loadable_ = "/enee/menee/minee/mo/pluginA.so";
0081 info.name_ = "AlphaClass";
0082 categoryToInfos["Cat One"].push_back(info);
0083 info.name_ = "BetaClass<Itl >";
0084 categoryToInfos["Cat Two"].push_back(info);
0085
0086 {
0087 std::stringstream ss;
0088 CacheParser::write(categoryToInfos, ss);
0089 CPPUNIT_ASSERT(match == ss.str());
0090
0091 std::map<std::string, std::vector<PluginInfo> > readValues;
0092 CacheParser::read(ss, "/enee/menee/minee/mo", readValues);
0093 CPPUNIT_ASSERT(categoryToInfos.size() == readValues.size());
0094
0095 {
0096 std::stringstream ssFinalWrite;
0097 CacheParser::write(readValues, ssFinalWrite);
0098 std::cout << ssFinalWrite.str() << std::endl;
0099 CPPUNIT_ASSERT(match == ssFinalWrite.str());
0100 }
0101 }
0102 }