Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:11

0001 /*
0002  *  format_type_name.cppunit.cc
0003  *  CMSSW
0004  *
0005  *  Created by Chris Jones on 09/12/09.
0006  *
0007  */
0008 
0009 #include <cppunit/extensions/HelperMacros.h>
0010 #include <iostream>
0011 #include "DataFormats/FWLite/interface/format_type_name.h"
0012 
0013 class testFormatTypeName : public CppUnit::TestFixture {
0014   CPPUNIT_TEST_SUITE(testFormatTypeName);
0015 
0016   CPPUNIT_TEST(test);
0017 
0018   CPPUNIT_TEST_SUITE_END();
0019 
0020 public:
0021   void setUp() {}
0022   void tearDown() {}
0023 
0024   void test();
0025 };
0026 
0027 ///registration of the test so that the runner can find it
0028 CPPUNIT_TEST_SUITE_REGISTRATION(testFormatTypeName);
0029 
0030 void testFormatTypeName::test() {
0031   typedef std::pair<std::string, std::string> Values;
0032   std::vector<Values> classToFriendly;
0033   classToFriendly.push_back(Values("Foo", "Foo"));
0034   classToFriendly.push_back(Values("bar::Foo", "bar_1Foo"));
0035   classToFriendly.push_back(Values("std::vector<Foo>", "std_1vector_9Foo_0"));
0036   classToFriendly.push_back(Values("std::vector<bar::Foo>", "std_1vector_9bar_1Foo_0"));
0037   classToFriendly.push_back(Values("V<A,B>", "V_9A_3B_0"));
0038   classToFriendly.push_back(
0039       Values("edm::ExtCollection<std::vector<reco::SuperCluster>,reco::SuperClusterRefProds>",
0040              "edm_1ExtCollection_9std_1vector_9reco_1SuperCluster_0_3reco_1SuperClusterRefProds_0"));
0041   classToFriendly.push_back(Values("A<B<C>, D<E> >", "A_9B_9C_0_3_4D_9E_0_4_0"));
0042   classToFriendly.push_back(Values("A<B<C<D> > >", "A_9B_9C_9D_0_4_0_4_0"));
0043   classToFriendly.push_back(Values("A<B<C,D>, E<F> >", "A_9B_9C_3D_0_3_4E_9F_0_4_0"));
0044   classToFriendly.push_back(Values("Aa<Bb<Cc>, Dd<Ee> >", "Aa_9Bb_9Cc_0_3_4Dd_9Ee_0_4_0"));
0045   classToFriendly.push_back(Values("Aa<Bb<Cc<Dd> > >", "Aa_9Bb_9Cc_9Dd_0_4_0_4_0"));
0046   classToFriendly.push_back(Values("Aa<Bb<Cc,Dd>, Ee<Ff> >", "Aa_9Bb_9Cc_3Dd_0_3_4Ee_9Ff_0_4_0"));
0047   classToFriendly.push_back(Values("Aa<Bb<Cc,Dd>, Ee<Ff,Gg> >", "Aa_9Bb_9Cc_3Dd_0_3_4Ee_9Ff_3Gg_0_4_0"));
0048 
0049   for (auto const& item : classToFriendly) {
0050     //std::cout << item.first << std::endl;
0051     if (item.second != fwlite::format_type_to_mangled(item.first)) {
0052       std::cout << "class name: '" << item.first << "' has wrong mangled name \n"
0053                 << "expect: '" << item.second << "' got: '" << fwlite::format_type_to_mangled(item.first) << "'"
0054                 << std::endl;
0055       CPPUNIT_ASSERT(0 && "expected mangled name does not match actual mangled name");
0056     }
0057     if (item.first != fwlite::unformat_mangled_to_type(item.second)) {
0058       std::cout << "mangled name: '" << item.second << "' has wrong type name \n"
0059                 << "expect: '" << item.first << "' got: '" << fwlite::unformat_mangled_to_type(item.second) << "'"
0060                 << std::endl;
0061       CPPUNIT_ASSERT(0 && "expected type name does not match actual type name");
0062     }
0063   }
0064 }