testYesNoNone.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "base/YesNoNone.h"
11 #include "compat/cppunit.h"
12 #include "unitTestMain.h"
13 
14 #include <stdexcept>
15 
16 /*
17  * demonstration test file, as new idioms are made they will
18  * be shown in the TestYesNoNone source.
19  */
20 
21 class TestYesNoNone : public CPPUNIT_NS::TestFixture
22 {
24  /* note the statement here and then the actual prototype below */
27 
28 public:
29 protected:
30  void testBasics();
31 };
33 
34 void
36 {
37  // unconfigured, non-implicit
38  {
39  YesNoNone v;
40  CPPUNIT_ASSERT_EQUAL(false, v.configured());
41  // cannot test the value it is 'undefined' and will assert
42  }
43  // implicit dtor test
44 
45  // unconfigured, implicit true
46  {
47  YesNoNone v(true);
48  CPPUNIT_ASSERT_EQUAL(false, v.configured());
49  CPPUNIT_ASSERT(v);
50  CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(v));
51 
52  // check explicit setter method
53  v.configure(false);
54  CPPUNIT_ASSERT_EQUAL(true, v.configured());
55  CPPUNIT_ASSERT(!v);
56  CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(v));
57  }
58 
59  // unconfigured, implicit false
60  {
61  YesNoNone v(false);
62  CPPUNIT_ASSERT_EQUAL(false, v.configured());
63  CPPUNIT_ASSERT(!v);
64  CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(v));
65 
66  // check assignment operator
67  v = YesNoNone(true);
68  CPPUNIT_ASSERT_EQUAL(false, v.configured());
69  CPPUNIT_ASSERT(v);
70  CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(v));
71  }
72 }
73 
74 int
75 main(int argc, char *argv[])
76 {
77  return TestProgram().run(argc, argv);
78 }
79 
int main(int argc, char *argv[])
implements test program's main() function while enabling customization
Definition: unitTestMain.h:25
int run(int argc, char *argv[])
Definition: unitTestMain.h:44
CPPUNIT_TEST_SUITE(TestYesNoNone)
CPPUNIT_TEST_SUITE_REGISTRATION(TestYesNoNone)
void configure(bool beSet)
enables or disables the option; updating to 'configured' state
Definition: YesNoNone.h:53
CPPUNIT_TEST(testBasics)
bool configured() const
Definition: YesNoNone.h:67

 

Introduction

Documentation

Support

Miscellaneous