Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-13 23:26:50

0001 // -*- C++ -*-
0002 //
0003 // Package:     Histograms
0004 // Class  :     metoemdformat_t
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Tue Jul 21 11:00:06 CDT 2009
0011 //
0012 
0013 // system include files
0014 
0015 #define CATCH_CONFIG_MAIN
0016 #include "catch.hpp"
0017 
0018 // user include files
0019 #include "DataFormats/Histograms/interface/MonitorElementCollection.h"
0020 
0021 TEST_CASE("MonitorElementData::Path", "[MonitorElementData_Path]") {
0022   MonitorElementData::Path p;
0023 
0024   SECTION("Canonical Paths") {
0025     SECTION("short path") {
0026       std::string pathName = "Foo/";
0027       p.set(pathName, MonitorElementData::Path::Type::DIR);
0028       REQUIRE(p.getDirname() == pathName);
0029       REQUIRE(p.getObjectname().empty());
0030       REQUIRE(p.getFullname() == pathName);
0031     }
0032 
0033     SECTION("2 dirs") {
0034       std::string pathName = "Foo/Bar/";
0035       p.set(pathName, MonitorElementData::Path::Type::DIR);
0036       REQUIRE(p.getDirname() == pathName);
0037       REQUIRE(p.getObjectname().empty());
0038       REQUIRE(p.getFullname() == pathName);
0039     }
0040 
0041     SECTION("long path") {
0042       std::string pathName = "This/Is/A/Very/Long/Path/Name/";
0043       p.set(pathName, MonitorElementData::Path::Type::DIR);
0044       REQUIRE(p.getDirname() == pathName);
0045       REQUIRE(p.getObjectname().empty());
0046       REQUIRE(p.getFullname() == pathName);
0047     }
0048   }
0049   SECTION("extra /") {
0050     SECTION("only /") {
0051       std::string pathName = "/";
0052       std::string canonical = "";
0053       p.set(pathName, MonitorElementData::Path::Type::DIR);
0054       REQUIRE(p.getDirname() == canonical);
0055       REQUIRE(p.getObjectname().empty());
0056       REQUIRE(p.getFullname() == canonical);
0057     }
0058     SECTION("only //") {
0059       std::string pathName = "//";
0060       std::string canonical = "";
0061       p.set(pathName, MonitorElementData::Path::Type::DIR);
0062       REQUIRE(p.getDirname() == canonical);
0063       REQUIRE(p.getObjectname().empty());
0064       REQUIRE(p.getFullname() == canonical);
0065     }
0066     SECTION("leading /") {
0067       std::string pathName = "/Foo/";
0068       std::string canonical = "Foo/";
0069       p.set(pathName, MonitorElementData::Path::Type::DIR);
0070       REQUIRE(p.getDirname() == canonical);
0071       REQUIRE(p.getObjectname().empty());
0072       REQUIRE(p.getFullname() == canonical);
0073     }
0074     SECTION("ending //") {
0075       std::string pathName = "Foo//";
0076       std::string canonical = "Foo/";
0077       p.set(pathName, MonitorElementData::Path::Type::DIR);
0078       REQUIRE(p.getDirname() == canonical);
0079       REQUIRE(p.getObjectname().empty());
0080       REQUIRE(p.getFullname() == canonical);
0081     }
0082     SECTION("middle //") {
0083       std::string pathName = "Foo//Bar/";
0084       std::string canonical = "Foo/Bar/";
0085       p.set(pathName, MonitorElementData::Path::Type::DIR);
0086       REQUIRE(p.getDirname() == canonical);
0087       REQUIRE(p.getObjectname().empty());
0088       REQUIRE(p.getFullname() == canonical);
0089     }
0090   }
0091   SECTION("missing end /") {
0092     SECTION("blank") {
0093       std::string pathName = "";
0094       std::string canonical = "";
0095       p.set(pathName, MonitorElementData::Path::Type::DIR);
0096       REQUIRE(p.getDirname() == canonical);
0097       REQUIRE(p.getObjectname().empty());
0098       REQUIRE(p.getFullname() == canonical);
0099     }
0100     SECTION("one dir") {
0101       std::string pathName = "Foo";
0102       std::string canonical = "Foo/";
0103       p.set(pathName, MonitorElementData::Path::Type::DIR);
0104       REQUIRE(p.getDirname() == canonical);
0105       REQUIRE(p.getObjectname().empty());
0106       REQUIRE(p.getFullname() == canonical);
0107     }
0108     SECTION("two dir") {
0109       std::string pathName = "Foo/Bar";
0110       std::string canonical = "Foo/Bar/";
0111       p.set(pathName, MonitorElementData::Path::Type::DIR);
0112       REQUIRE(p.getDirname() == canonical);
0113       REQUIRE(p.getObjectname().empty());
0114       REQUIRE(p.getFullname() == canonical);
0115     }
0116   }
0117   SECTION("up dir") {
0118     SECTION("to beginning") {
0119       SECTION("end /") {
0120         std::string pathName = "Foo/../";
0121         std::string canonical = "";
0122         p.set(pathName, MonitorElementData::Path::Type::DIR);
0123         REQUIRE(p.getDirname() == canonical);
0124         REQUIRE(p.getObjectname().empty());
0125         REQUIRE(p.getFullname() == canonical);
0126       }
0127       SECTION("missing end /") {
0128         std::string pathName = "Foo/..";
0129         std::string canonical = "";
0130         p.set(pathName, MonitorElementData::Path::Type::DIR);
0131         REQUIRE(p.getDirname() == canonical);
0132         REQUIRE(p.getObjectname().empty());
0133         REQUIRE(p.getFullname() == canonical);
0134       }
0135     }
0136     SECTION("beyond beginning") {
0137       SECTION("end /") {
0138         std::string pathName = "Foo/../..";
0139         std::string canonical = "";
0140         p.set(pathName, MonitorElementData::Path::Type::DIR);
0141         REQUIRE(p.getDirname() == canonical);
0142         REQUIRE(p.getObjectname().empty());
0143         REQUIRE(p.getFullname() == canonical);
0144       }
0145       SECTION("missing end /") {
0146         std::string pathName = "Foo/../..";
0147         std::string canonical = "";
0148         p.set(pathName, MonitorElementData::Path::Type::DIR);
0149         REQUIRE(p.getDirname() == canonical);
0150         REQUIRE(p.getObjectname().empty());
0151         REQUIRE(p.getFullname() == canonical);
0152       }
0153     }
0154     SECTION("middle") {
0155       SECTION("back to beginning") {
0156         std::string pathName = "Foo/../Bar/";
0157         std::string canonical = "Bar/";
0158         p.set(pathName, MonitorElementData::Path::Type::DIR);
0159         REQUIRE(p.getDirname() == canonical);
0160         REQUIRE(p.getObjectname().empty());
0161         REQUIRE(p.getFullname() == canonical);
0162       }
0163       SECTION("midway") {
0164         std::string pathName = "Foo/Bar/../Biz/";
0165         std::string canonical = "Foo/Biz/";
0166         p.set(pathName, MonitorElementData::Path::Type::DIR);
0167         REQUIRE(p.getDirname() == canonical);
0168         REQUIRE(p.getObjectname().empty());
0169         REQUIRE(p.getFullname() == canonical);
0170       }
0171       SECTION("last") {
0172         std::string pathName = "Foo/Bar/../";
0173         std::string canonical = "Foo/";
0174         p.set(pathName, MonitorElementData::Path::Type::DIR);
0175         REQUIRE(p.getDirname() == canonical);
0176         REQUIRE(p.getObjectname().empty());
0177         REQUIRE(p.getFullname() == canonical);
0178       }
0179     }
0180     SECTION("multiple consecutive") {
0181       SECTION("two") {
0182         SECTION("back to beginning") {
0183           std::string pathName = "Foo/Biz/../../Bar/";
0184           std::string canonical = "Bar/";
0185           p.set(pathName, MonitorElementData::Path::Type::DIR);
0186           REQUIRE(p.getDirname() == canonical);
0187           REQUIRE(p.getObjectname().empty());
0188           REQUIRE(p.getFullname() == canonical);
0189         }
0190         SECTION("midway") {
0191           std::string pathName = "Foo/Bar/Blah/../../Biz/";
0192           std::string canonical = "Foo/Biz/";
0193           p.set(pathName, MonitorElementData::Path::Type::DIR);
0194           REQUIRE(p.getDirname() == canonical);
0195           REQUIRE(p.getObjectname().empty());
0196           REQUIRE(p.getFullname() == canonical);
0197         }
0198         SECTION("last") {
0199           std::string pathName = "Foo/Bar/Blah/../../";
0200           std::string canonical = "Foo/";
0201           p.set(pathName, MonitorElementData::Path::Type::DIR);
0202           REQUIRE(p.getDirname() == canonical);
0203           REQUIRE(p.getObjectname().empty());
0204           REQUIRE(p.getFullname() == canonical);
0205         }
0206       }
0207       SECTION("three") {
0208         SECTION("back to beginning") {
0209           std::string pathName = "Foo/Biz/Bleep/../../../Bar/";
0210           std::string canonical = "Bar/";
0211           p.set(pathName, MonitorElementData::Path::Type::DIR);
0212           REQUIRE(p.getDirname() == canonical);
0213           REQUIRE(p.getObjectname().empty());
0214           REQUIRE(p.getFullname() == canonical);
0215         }
0216         SECTION("midway") {
0217           std::string pathName = "Foo/Bar/Blah/Bleep/../../../Biz/";
0218           std::string canonical = "Foo/Biz/";
0219           p.set(pathName, MonitorElementData::Path::Type::DIR);
0220           REQUIRE(p.getDirname() == canonical);
0221           REQUIRE(p.getObjectname().empty());
0222           REQUIRE(p.getFullname() == canonical);
0223         }
0224         SECTION("last") {
0225           std::string pathName = "Foo/Bar/Blah/Bleep/../../../";
0226           std::string canonical = "Foo/";
0227           p.set(pathName, MonitorElementData::Path::Type::DIR);
0228           REQUIRE(p.getDirname() == canonical);
0229           REQUIRE(p.getObjectname().empty());
0230           REQUIRE(p.getFullname() == canonical);
0231         }
0232       }
0233     }
0234   }
0235   SECTION("object") {
0236     SECTION("no dir") {
0237       std::string pathName = "bar";
0238       std::string canonical = "";
0239       std::string objectName = "bar";
0240       p.set(pathName, MonitorElementData::Path::Type::DIR_AND_NAME);
0241       REQUIRE(p.getDirname() == canonical);
0242       REQUIRE(p.getObjectname() == objectName);
0243       REQUIRE(p.getFullname() == canonical + objectName);
0244     }
0245     SECTION("1 dir") {
0246       std::string pathName = "Foo/bar";
0247       std::string canonical = "Foo/";
0248       std::string objectName = "bar";
0249       p.set(pathName, MonitorElementData::Path::Type::DIR_AND_NAME);
0250       REQUIRE(p.getDirname() == canonical);
0251       REQUIRE(p.getObjectname() == objectName);
0252       REQUIRE(p.getFullname() == canonical + objectName);
0253     }
0254     SECTION("2 dir") {
0255       std::string pathName = "Foo/Biz/bar";
0256       std::string canonical = "Foo/Biz/";
0257       std::string objectName = "bar";
0258       p.set(pathName, MonitorElementData::Path::Type::DIR_AND_NAME);
0259       REQUIRE(p.getDirname() == canonical);
0260       REQUIRE(p.getObjectname() == objectName);
0261       REQUIRE(p.getFullname() == canonical + objectName);
0262     }
0263   }
0264 }