LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
eithertest.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  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #include "eithertest.h"
10 #include <QtTest>
11 #include <either.h>
12 #include <void.h>
13 #include <functor.h>
14 
15 QTEST_MAIN (LC::Util::EitherTest)
16 
17 namespace LC
18 {
19 namespace Util
20 {
22 
23  void EitherTest::testBasicLeft ()
24  {
25  const SomeEither_t left { Left (1) };
26  QCOMPARE (left.IsLeft (), true);
27  QCOMPARE (left.IsRight (), false);
28  QCOMPARE (left.GetLeft (), 1);
29 
30  bool hadCaught = false;
31  try
32  {
33  left.GetRight ();
34  }
35  catch (const std::exception&)
36  {
37  hadCaught = true;
38  }
39  QCOMPARE (hadCaught, true);
40  }
41 
42  void EitherTest::testBasicRight ()
43  {
44  const SomeEither_t right { "foo" };
45  QCOMPARE (right.IsLeft (), false);
46  QCOMPARE (right.IsRight (), true);
47  QCOMPARE (right.GetRight (), QString { "foo" });
48 
49  bool hadCaught = false;
50  try
51  {
52  right.GetLeft ();
53  }
54  catch (const std::exception&)
55  {
56  hadCaught = true;
57  }
58  QCOMPARE (hadCaught, true);
59  }
60 }
61 }
Either< int, QString > SomeEither_t
Definition: eithertest.cpp:21