Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-04-04 01:26:38

0001 #include "catch.hpp"
0002 #include "FWCore/Utilities/interface/OftenEmptyCString.h"
0003 #include <cstring>
0004 
0005 TEST_CASE("test edm::OftenEmptyCString", "[OftenEmptyCString]") {
0006   SECTION("Constructors") {
0007     SECTION("default") {
0008       edm::OftenEmptyCString s;
0009       REQUIRE(s.c_str() != nullptr);
0010       REQUIRE(s.c_str()[0] == '\0');
0011     }
0012     SECTION("from const *") {
0013       SECTION("nullptr") {
0014         edm::OftenEmptyCString s(nullptr);
0015         REQUIRE(s.c_str() != nullptr);
0016         REQUIRE(s.c_str()[0] == '\0');
0017       }
0018       SECTION("empty") {
0019         const char* kEmpty = "";
0020         edm::OftenEmptyCString s(kEmpty);
0021         REQUIRE(s.c_str() != nullptr);
0022         REQUIRE(s.c_str() != kEmpty);
0023         REQUIRE(s.c_str()[0] == '\0');
0024       }
0025       SECTION("non empty string") {
0026         const char* kValue = "something";
0027         edm::OftenEmptyCString s(kValue);
0028         REQUIRE(s.c_str() != nullptr);
0029         REQUIRE(s.c_str() != kValue);
0030         REQUIRE(strncmp(kValue, s.c_str(), 9) == 0);
0031         REQUIRE(strlen(kValue) == strlen(s.c_str()));
0032       }
0033     }
0034     SECTION("Copy") {
0035       SECTION("from non empty") {
0036         edm::OftenEmptyCString s("something");
0037         edm::OftenEmptyCString copy(s);
0038         REQUIRE(s.c_str() != copy.c_str());
0039         REQUIRE(strcmp(s.c_str(), copy.c_str()) == 0);
0040       }
0041       SECTION("from default") {
0042         edm::OftenEmptyCString s;
0043         edm::OftenEmptyCString copy(s);
0044         REQUIRE(s.c_str() == copy.c_str());
0045         REQUIRE(s.c_str() != nullptr);
0046         REQUIRE(strlen(s.c_str()) == 0);
0047       }
0048     }
0049     SECTION("Move") {
0050       SECTION("from non empty") {
0051         edm::OftenEmptyCString s("something");
0052         edm::OftenEmptyCString copy(std::move(s));
0053         REQUIRE(s.c_str() != copy.c_str());
0054         REQUIRE(s.c_str() == nullptr);
0055         REQUIRE(strcmp("something", copy.c_str()) == 0);
0056       }
0057       SECTION("from default") {
0058         edm::OftenEmptyCString s;
0059         edm::OftenEmptyCString copy(std::move(s));
0060         REQUIRE(s.c_str() == nullptr);
0061         REQUIRE(copy.c_str() == edm::OftenEmptyCString().c_str());
0062       }
0063     }
0064   }
0065   SECTION("operator=") {
0066     SECTION("copy version") {
0067       SECTION("from non empty to non empty") {
0068         edm::OftenEmptyCString s("something");
0069         edm::OftenEmptyCString copy("else");
0070         copy = s;
0071         REQUIRE(s.c_str() != copy.c_str());
0072         REQUIRE(strcmp("something", copy.c_str()) == 0);
0073         REQUIRE(strcmp(s.c_str(), copy.c_str()) == 0);
0074       }
0075       SECTION("from default to non empty") {
0076         edm::OftenEmptyCString s;
0077         edm::OftenEmptyCString copy("original");
0078         copy = s;
0079         REQUIRE(strcmp(s.c_str(), copy.c_str()) == 0);
0080       }
0081       SECTION("from non empty to empty") {
0082         edm::OftenEmptyCString s("something");
0083         edm::OftenEmptyCString copy;
0084         copy = s;
0085         REQUIRE(s.c_str() != copy.c_str());
0086         REQUIRE(strcmp("something", copy.c_str()) == 0);
0087         REQUIRE(strcmp(s.c_str(), copy.c_str()) == 0);
0088       }
0089     }
0090     SECTION("move version") {
0091       SECTION("from non empty to non empty") {
0092         edm::OftenEmptyCString s("something");
0093         edm::OftenEmptyCString copy("else");
0094         copy = std::move(s);
0095         REQUIRE(s.c_str() != copy.c_str());
0096         REQUIRE(s.c_str() == nullptr);
0097         REQUIRE(strcmp("something", copy.c_str()) == 0);
0098       }
0099       SECTION("from default to non empty") {
0100         edm::OftenEmptyCString s;
0101         edm::OftenEmptyCString copy("original");
0102         copy = std::move(s);
0103         REQUIRE(copy.c_str() != nullptr);
0104         REQUIRE(copy.c_str()[0] == '\0');
0105         REQUIRE(s.c_str() == nullptr);
0106       }
0107       SECTION("from non empty to empty") {
0108         edm::OftenEmptyCString s("something");
0109         edm::OftenEmptyCString copy;
0110         copy = std::move(s);
0111         REQUIRE(s.c_str() != copy.c_str());
0112         REQUIRE(s.c_str() == nullptr);
0113         REQUIRE(strcmp("something", copy.c_str()) == 0);
0114       }
0115     }
0116   }
0117 }