// -*- c++ -*- /* * Java-Like C++ Class Library * Copyright (C) 2001 Florian Wolff (florian@donuz.de) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: Test.h,v 1.16 2003/09/27 08:10:28 florian Exp $ */ #define JAKELIB2_INCLUDE_ALL #include "jakelib2.h" #include "jakelib2/lang/System.h" using namespace jakelib::lang; void start(jakelib::lang::String *name); void dumpStringCounter(); void gc(); typedef struct { char* name; char* title; void (*proc)(); } TEST_INFO; #define JTEST_RETURN(type, info, expr, expVal) \ try { \ type val = expr; \ if (val == expVal) { \ jtest_passed(info); \ passedTests ++; \ } else { \ jtest_failed_wrong_return(info, val, expVal); \ failedTests ++; \ } \ } catch(jakelib::lang::Throwable &ex) { \ jtest_failed_exception(info, &ex); \ failedTests ++; \ } catch(...) { \ jtest_failed_exception(info); \ failedTests ++; \ } #define JTEST_RETURN_BOOLEAN(info, expr, expVal) JTEST_RETURN(jboolean, info, expr, expVal) #define JTEST_RETURN_INT(info, expr, expVal) JTEST_RETURN(jint, info, expr, expVal) #define JTEST_RETURN_LONG(info, expr, expVal) JTEST_RETURN(jlong, info, expr, expVal) #define JTEST_RETURN_CHAR(info, expr, expVal) JTEST_RETURN(jchar, info, expr, expVal) #define JTEST_RETURN_FLOAT(info, expr, expVal) JTEST_RETURN(jfloat, info, expr, expVal) #define JTEST_RETURN_DOUBLE(info, expr, expVal) JTEST_RETURN(jdouble, info, expr, expVal) #define JTEST_RETURN_BYTE(info, expr, expVal) JTEST_RETURN(jbyte, info, expr, expVal) #define JTEST_RETURN_SHORT(info, expr, expVal) JTEST_RETURN(jshort, info, expr, expVal) #define JTEST_RETURN_OBJECT(info, expr, expVal) JTEST_RETURN(jboolean, info, (expr)->equals(expVal), true) #define JTEST_EXCEPTION(info, expr, exception) \ { \ jboolean exOk = false; \ try { \ expr; \ } catch(exception &ex) { \ jtest_passed(info); \ exOk = true; \ } catch(jakelib::lang::Throwable &ex) { \ jtest_failed_wrong_exception(info, ""#expr, &ex, ""#exception); \ } catch(...) { \ jtest_failed_wrong_exception(info, ""#expr, ""#exception); \ } \ if (!exOk) { \ jtest_failed_no_exception(info, ""#expr, ""#exception); \ failedTests ++; \ } else { \ passedTests ++; \ } \ } #define JTEST_RETURN_STRING(info, expr, expVal) \ try { \ String *val = expr; \ if (expVal->equals(val)) { \ jtest_passed(info); \ passedTests ++; \ } else { \ jtest_failed_wrong_return(info, val, expVal); \ failedTests ++; \ } \ } catch(jakelib::lang::Throwable &ex) { \ jtest_failed_exception(info, &ex); \ failedTests ++; \ } catch(...) { \ jtest_failed_exception(info); \ failedTests ++; \ } extern int passedTests; extern int failedTests; void jtest_message(String* info); void jtest_passed(String* info); void jtest_failed_wrong_exception(String* info, char* expr, Throwable *ex, char* exceptName); void jtest_failed_wrong_exception(String* info, char* expr, char* exceptName); void jtest_failed_no_exception(String* info, char* expr, char* exceptName); void jtest_failed_wrong_return(String* info, String *val, String *expVal); void jtest_failed_wrong_return(String* info, jint val, jint expVal); void jtest_failed_wrong_return(String* info, jfloat val, jfloat expVal); void jtest_failed_wrong_return(String* info, jdouble val, jdouble expVal); void jtest_failed_wrong_return(String* info, jlong val, jlong expVal); void jtest_failed_wrong_return(String* info, jshort val, jshort expVal); void jtest_failed_wrong_return(String* info, jboolean val, jboolean expVal); void jtest_failed_wrong_return(String* info, jbyte val, jbyte expVal); void jtest_failed_wrong_return(String* info, jchar val, jchar expVal); void jtest_failed_exception(String* info, Throwable *ex); void jtest_failed_exception(String* info); void jtest_summary();