]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testYesNoNone.cc
SourceLayout: C++11 upgrade for class YesNoNone
[thirdparty/squid.git] / src / tests / testYesNoNone.cc
1 /*
2 * Copyright (C) 1996-2016 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 "tests/testYesNoNone.h"
12 #include "unitTestMain.h"
13
14 #include <stdexcept>
15
16 CPPUNIT_TEST_SUITE_REGISTRATION( testYesNoNone );
17
18 void
19 testYesNoNone::testBasics()
20 {
21 // unconfigured, non-implicit
22 {
23 YesNoNone v;
24 CPPUNIT_ASSERT_EQUAL(false, v.configured());
25 // cannot test the value it is 'undefined' and will assert
26 }
27 // implicit dtor test
28
29 // unconfigured, implicit true
30 {
31 YesNoNone v(true);
32 CPPUNIT_ASSERT_EQUAL(false, v.configured());
33 CPPUNIT_ASSERT(v);
34 CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(v));
35
36 // check explicit setter method
37 v.configure(false);
38 CPPUNIT_ASSERT_EQUAL(true, v.configured());
39 CPPUNIT_ASSERT(!v);
40 CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(v));
41 }
42
43 // unconfigured, implicit false
44 {
45 YesNoNone v(false);
46 CPPUNIT_ASSERT_EQUAL(false, v.configured());
47 CPPUNIT_ASSERT(!v);
48 CPPUNIT_ASSERT_EQUAL(false, static_cast<bool>(v));
49
50 // check assignment operator
51 v = YesNoNone(true);
52 CPPUNIT_ASSERT_EQUAL(false, v.configured());
53 CPPUNIT_ASSERT(v);
54 CPPUNIT_ASSERT_EQUAL(true, static_cast<bool>(v));
55 }
56 }