LeechCraft  0.6.70-6645-gcd10d7e
Modular cross-platform feature rich live environment.
visitortest.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Boost Software License - Version 1.0 - August 17th, 2003
6  *
7  * Permission is hereby granted, free of charge, to any person or organization
8  * obtaining a copy of the software and accompanying documentation covered by
9  * this license (the "Software") to use, reproduce, display, distribute,
10  * execute, and transmit the Software, and to prepare derivative works of the
11  * Software, and to permit third-parties to whom the Software is furnished to
12  * do so, all subject to the following:
13  *
14  * The copyright notices in the Software and this entire statement, including
15  * the above license grant, this restriction and the following disclaimer,
16  * must be included in all copies of the Software, in whole or in part, and
17  * all derivative works of the Software, unless such copies or derivative
18  * works are solely in the form of machine-executable object code generated by
19  * a source language processor.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  **********************************************************************/
29 
30 #include "visitortest.h"
31 #include <QtTest>
32 #include <visitor.h>
33 
35 
36 namespace LeechCraft
37 {
38 namespace Util
39 {
40  using Variant_t = boost::variant<int, char, std::string, QString, double, float>;
41 
42  void VisitorTest::testBasicVisitor ()
43  {
44  Variant_t v { 'a' };
45  const auto& res = Visit (v,
46  [] (char) { return true; },
47  [] (int) { return false; },
48  [] (std::string) { return false; },
49  [] (QString) { return false; },
50  [] (double) { return false; },
51  [] (float) { return false; });
52  QCOMPARE (res, true);
53  }
54 
55  void VisitorTest::testBasicVisitorGenericFallback ()
56  {
57  Variant_t v { 'a' };
58  const auto& res = Visit (v,
59  [] (char) { return true; },
60  [] (int) { return false; },
61  [] (auto) { return false; });
62  QCOMPARE (res, true);
63  }
64 
65  void VisitorTest::testBasicVisitorCoercion ()
66  {
67  Variant_t v { 'a' };
68  const auto& res = Visit (v,
69  [] (int) { return true; },
70  [] (std::string) { return false; },
71  [] (QString) { return false; },
72  [] (double) { return false; },
73  [] (float) { return false; });
74  QCOMPARE (res, true);
75  }
76 
77  void VisitorTest::testBasicVisitorCoercionGenericFallback ()
78  {
79  Variant_t v { 'a' };
80  const auto& res = Visit (v,
81  [] (int) { return false; },
82  [] (QString) { return false; },
83  [] (auto) { return true; });
84  QCOMPARE (res, true);
85  }
86 
87 #define NC nc = std::unique_ptr<int> {}
88 
89  void VisitorTest::testNonCopyableFunctors ()
90  {
91  Variant_t v { 'a' };
92  const auto& res = Visit (v,
93  [NC] (char) { return true; },
94  [NC] (int) { return false; },
95  [NC] (std::string) { return false; },
96  [NC] (QString) { return false; },
97  [NC] (double) { return false; },
98  [NC] (float) { return false; });
99  QCOMPARE (res, true);
100  }
101 }
102 }
auto Visit(const boost::variant< HeadVar, TailVars... > &v, Args &&...args) -> decltype(detail::VisitorBase< Args... >
Definition: visitor.h:72
#define NC
Definition: visitortest.cpp:87
boost::variant< int, char, std::string, QString, double, float > Variant_t
Definition: visitortest.cpp:40