src/test/error_test.cc
changeset 824 157115b5814a
parent 542 69bde1d90c04
child 906 17f31d280385
equal deleted inserted replaced
1:e3491b750861 2:5707243f072d
     1 #include <iostream>
     1 #include <iostream>
     2 
     2 
     3 #include <hugo/error.h>
     3 #include <hugo/error.h>
     4 
     4 #include "test_tools.h"
     5 using namespace hugo;
     5 using namespace hugo;
     6 using std::cout;
     6 using std::cout;
     7 using std::endl;
     7 using std::endl;
     8 
     8 
     9 void faulty_fn() {
     9 void faulty_fn() {
    19   FIXME("unfinished_fn() is unfinished!");
    19   FIXME("unfinished_fn() is unfinished!");
    20 }
    20 }
    21 
    21 
    22 
    22 
    23 int main() {
    23 int main() {
    24   bool no_errors = false;
       
    25 
       
    26   try {
    24   try {
    27     cout << "Trying a faulty function\n";
       
    28     faulty_fn();
    25     faulty_fn();
    29     no_errors = true;
    26     check(false, "A faulty function did not fail.");
    30     cout << "FAILED!\n";
       
    31   }
    27   }
    32   catch(const Exception &e) {
    28   catch(const Exception &e) {
    33     cout << "E: " << e.what() << endl;
    29     cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
    34   }
    30   }
    35 
    31 
    36   try {
    32   try {
    37     cout << "Trying a function throwing Exception\n";
       
    38     exception_fn();
    33     exception_fn();
    39     no_errors = true;
    34     check(false, "The function did not throw Exception.");
    40     cout << "FAILED!\n";
       
    41   }
    35   }
    42   catch(const Exception &e) {
    36   catch(const Exception &e) {
    43     cout << "E: " << e.what() << endl;
    37     cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
    44   }
    38   }
    45 
    39 
    46   try {
    40   try {
    47     cout << "Trying a function using FIXME\n";
       
    48     unfinished_fn();
    41     unfinished_fn();
    49     no_errors = true;
    42     check(false, "FIXME macro does not work.");
    50     cout << "FAILED!\n";
       
    51   }
    43   }
    52   catch(const Exception &e) {
    44   catch(const Exception &e) {
    53     cout << "E: " << e.what() << endl;
    45     cout << "Exeption = \"" << e.what() << "\" (Right behaviour)" << endl;
    54   }
    46   }
    55 
    47 
    56   return no_errors ? 1 : 0;
    48   return 0;
    57 }
    49 }