1+ #include " catch.hpp"
2+ #include " FWCore/Utilities/interface/OftenEmptyCString.h"
3+ #include < cstring>
4+
5+ TEST_CASE (" test edm::OftenEmptyCString" , " [OftenEmptyCString]" ) {
6+ SECTION (" Constructors" ) {
7+ SECTION (" default" ) {
8+ edm::OftenEmptyCString s;
9+ REQUIRE (s.c_str () != nullptr );
10+ REQUIRE (s.c_str ()[0 ] == ' \0 ' );
11+ }
12+ SECTION (" from const *" ) {
13+ SECTION (" nullptr" ) {
14+ edm::OftenEmptyCString s (nullptr );
15+ REQUIRE (s.c_str () != nullptr );
16+ REQUIRE (s.c_str ()[0 ] == ' \0 ' );
17+ }
18+ SECTION (" empty" ) {
19+ const char * kEmpty = " " ;
20+ edm::OftenEmptyCString s (kEmpty );
21+ REQUIRE (s.c_str () != nullptr );
22+ REQUIRE (s.c_str () != kEmpty );
23+ REQUIRE (s.c_str ()[0 ] == ' \0 ' );
24+ }
25+ SECTION (" non empty string" ) {
26+ const char * kValue = " something" ;
27+ edm::OftenEmptyCString s (kValue );
28+ REQUIRE (s.c_str () != nullptr );
29+ REQUIRE (s.c_str () != kValue );
30+ REQUIRE (strncmp (kValue , s.c_str (), 9 ) == 0 );
31+ REQUIRE (strlen (kValue ) == strlen (s.c_str ()));
32+ }
33+ }
34+ SECTION (" Copy" ) {
35+ SECTION (" from non empty" ) {
36+ edm::OftenEmptyCString s (" something" );
37+ edm::OftenEmptyCString copy (s);
38+ REQUIRE (s.c_str () != copy.c_str ());
39+ REQUIRE (strcmp (s.c_str (), copy.c_str ()) == 0 );
40+ }
41+ SECTION (" from default" ) {
42+ edm::OftenEmptyCString s;
43+ edm::OftenEmptyCString copy (s);
44+ REQUIRE (s.c_str () == copy.c_str ());
45+ REQUIRE (s.c_str () != nullptr );
46+ REQUIRE (strlen (s.c_str ()) == 0 );
47+ }
48+ }
49+ SECTION (" Move" ) {
50+ SECTION (" from non empty" ) {
51+ edm::OftenEmptyCString s (" something" );
52+ edm::OftenEmptyCString copy (std::move (s));
53+ REQUIRE (s.c_str () != copy.c_str ());
54+ REQUIRE (s.c_str () == nullptr );
55+ REQUIRE (strcmp (" something" , copy.c_str ()) == 0 );
56+ }
57+ SECTION (" from default" ) {
58+ edm::OftenEmptyCString s;
59+ edm::OftenEmptyCString copy (std::move (s));
60+ REQUIRE (s.c_str () == nullptr );
61+ REQUIRE (copy.c_str () == edm::OftenEmptyCString ().c_str ());
62+ }
63+ }
64+ }
65+ SECTION (" operator=" ) {
66+ SECTION (" copy version" ) {
67+ SECTION (" from non empty to non empty" ) {
68+ edm::OftenEmptyCString s (" something" );
69+ edm::OftenEmptyCString copy (" else" );
70+ copy = s;
71+ REQUIRE (s.c_str () != copy.c_str ());
72+ REQUIRE (strcmp (" something" , copy.c_str ()) == 0 );
73+ REQUIRE (strcmp (s.c_str (), copy.c_str ()) == 0 );
74+ }
75+ SECTION (" from default to non empty" ) {
76+ edm::OftenEmptyCString s;
77+ edm::OftenEmptyCString copy (" original" );
78+ copy = s;
79+ REQUIRE (strcmp (s.c_str (), copy.c_str ()) == 0 );
80+ }
81+ SECTION (" from non empty to empty" ) {
82+ edm::OftenEmptyCString s (" something" );
83+ edm::OftenEmptyCString copy;
84+ copy = s;
85+ REQUIRE (s.c_str () != copy.c_str ());
86+ REQUIRE (strcmp (" something" , copy.c_str ()) == 0 );
87+ REQUIRE (strcmp (s.c_str (), copy.c_str ()) == 0 );
88+ }
89+ }
90+ SECTION (" move version" ) {
91+ SECTION (" from non empty to non empty" ) {
92+ edm::OftenEmptyCString s (" something" );
93+ edm::OftenEmptyCString copy (" else" );
94+ copy = std::move (s);
95+ REQUIRE (s.c_str () != copy.c_str ());
96+ REQUIRE (s.c_str () == nullptr );
97+ REQUIRE (strcmp (" something" , copy.c_str ()) == 0 );
98+ }
99+ SECTION (" from default to non empty" ) {
100+ edm::OftenEmptyCString s;
101+ edm::OftenEmptyCString copy (" original" );
102+ copy = std::move (s);
103+ REQUIRE (copy.c_str () != nullptr );
104+ REQUIRE (copy.c_str ()[0 ] == ' \0 ' );
105+ REQUIRE (s.c_str () == nullptr );
106+ }
107+ SECTION (" from non empty to empty" ) {
108+ edm::OftenEmptyCString s (" something" );
109+ edm::OftenEmptyCString copy;
110+ copy = std::move (s);
111+ REQUIRE (s.c_str () != copy.c_str ());
112+ REQUIRE (s.c_str () == nullptr );
113+ REQUIRE (strcmp (" something" , copy.c_str ()) == 0 );
114+ }
115+ }
116+ }
117+ }
0 commit comments