alpar@906: /* -*- C++ -*-
ladanyi@1435:  * test/error_test.cc - Part of LEMON, a generic C++ optimization library
alpar@906:  *
alpar@1875:  * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359:  * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906:  *
alpar@906:  * Permission to use, modify and distribute this software is granted
alpar@906:  * provided that this copyright notice appears in all copies. For
alpar@906:  * precise terms see the accompanying LICENSE file.
alpar@906:  *
alpar@906:  * This software is provided "AS IS" with no warranty of any kind,
alpar@906:  * express or implied, and with no claim as to its suitability for any
alpar@906:  * purpose.
alpar@906:  *
alpar@906:  */
alpar@906: 
klao@489: #include <iostream>
klao@489: 
alpar@921: #include <lemon/error.h>
alpar@727: #include "test_tools.h"
alpar@921: using namespace lemon;
klao@489: using std::cout;
klao@489: using std::endl;
klao@489: 
klao@489: void faulty_fn() {
klao@489:   fault("This is a fault message");
klao@489: }
klao@489: 
klao@489: void exception_fn() {
klao@489:   throw Exception("This is a fn throwing excpt with some args: ") 
klao@489:     << 5 << ", " << 18;
klao@489: }
klao@489: 
klao@489: void unfinished_fn() {
klao@489:   FIXME("unfinished_fn() is unfinished!");
klao@489: }
klao@489: 
klao@489: 
klao@489: int main() {
klao@489:   try {
klao@489:     faulty_fn();
alpar@727:     check(false, "A faulty function did not fail.");
klao@489:   }
klao@489:   catch(const Exception &e) {
alpar@727:     cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
klao@489:   }
klao@489: 
klao@489:   try {
klao@489:     exception_fn();
alpar@727:     check(false, "The function did not throw Exception.");
klao@489:   }
klao@489:   catch(const Exception &e) {
alpar@727:     cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
klao@489:   }
klao@489: 
klao@489:   try {
klao@489:     unfinished_fn();
alpar@727:     check(false, "FIXME macro does not work.");
klao@489:   }
klao@489:   catch(const Exception &e) {
alpar@727:     cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
klao@489:   }
klao@489: 
alpar@727:   return 0;
klao@489: }