test/error_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Mon, 17 Mar 2008 19:21:27 +0000
changeset 93 f857981306ea
child 108 889d0c289d19
permissions -rw-r--r--
Merge
kpeter@66
     1
/* -*- C++ -*-
kpeter@66
     2
 *
kpeter@66
     3
 * This file is a part of LEMON, a generic C++ optimization library
kpeter@66
     4
 *
kpeter@66
     5
 * Copyright (C) 2003-2008
kpeter@66
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
kpeter@66
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
kpeter@66
     8
 *
kpeter@66
     9
 * Permission to use, modify and distribute this software is granted
kpeter@66
    10
 * provided that this copyright notice appears in all copies. For
kpeter@66
    11
 * precise terms see the accompanying LICENSE file.
kpeter@66
    12
 *
kpeter@66
    13
 * This software is provided "AS IS" with no warranty of any kind,
kpeter@66
    14
 * express or implied, and with no claim as to its suitability for any
kpeter@66
    15
 * purpose.
kpeter@66
    16
 *
kpeter@66
    17
 */
kpeter@66
    18
kpeter@66
    19
#include <iostream>
kpeter@66
    20
kpeter@66
    21
#include <lemon/error.h>
kpeter@66
    22
#include "test_tools.h"
kpeter@66
    23
kpeter@66
    24
using namespace lemon;
kpeter@66
    25
using std::cout;
kpeter@66
    26
using std::endl;
kpeter@66
    27
kpeter@66
    28
void faulty_fn() {
kpeter@66
    29
  fault("This is a fault message");
kpeter@66
    30
}
kpeter@66
    31
kpeter@66
    32
void exception_fn() {
kpeter@66
    33
  throw Exception("This is a function throwing exception with some args: ")
kpeter@66
    34
    << 5 << ", " << 18;
kpeter@66
    35
}
kpeter@66
    36
kpeter@66
    37
void unfinished_fn() {
kpeter@66
    38
  LEMON_FIXME("unfinished_fn() is unfinished!");
kpeter@66
    39
}
kpeter@66
    40
kpeter@66
    41
kpeter@66
    42
int main() {
kpeter@66
    43
  try {
kpeter@66
    44
    faulty_fn();
kpeter@66
    45
    check(false, "A faulty function did not fail.");
kpeter@66
    46
  }
kpeter@66
    47
  catch(const Exception &e) {
kpeter@66
    48
    cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
kpeter@66
    49
  }
kpeter@66
    50
kpeter@66
    51
  try {
kpeter@66
    52
    exception_fn();
kpeter@66
    53
    check(false, "The function did not throw Exception.");
kpeter@66
    54
  }
kpeter@66
    55
  catch(const Exception &e) {
kpeter@66
    56
    cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
kpeter@66
    57
  }
kpeter@66
    58
kpeter@66
    59
  try {
kpeter@66
    60
    unfinished_fn();
kpeter@66
    61
    check(false, "FIXME macro does not work.");
kpeter@66
    62
  }
kpeter@66
    63
  catch(const Exception &e) {
kpeter@66
    64
    cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
kpeter@66
    65
  }
kpeter@66
    66
kpeter@66
    67
  return 0;
kpeter@66
    68
}