diff options
author | Benjamin Segovia <segovia.benjamin@gmail.com> | 2012-05-03 15:14:53 +0000 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-08-10 16:16:57 -0700 |
commit | 1a9bcd8ff623a0b96cb034df711e4b02bfab8c6e (patch) | |
tree | bb3085d39b10c5ca759466675f7c648cafd6fc4d /utests/utest.hpp | |
parent | 97c10d0a80665562cd4980fa9a8b4e5a52750f3a (diff) | |
download | beignet-1a9bcd8ff623a0b96cb034df711e4b02bfab8c6e.tar.gz |
tests -> utests
Diffstat (limited to 'utests/utest.hpp')
-rw-r--r-- | utests/utest.hpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/utests/utest.hpp b/utests/utest.hpp new file mode 100644 index 00000000..e444c721 --- /dev/null +++ b/utests/utest.hpp @@ -0,0 +1,82 @@ +/* + * Copyright © 2012 Intel Corporation + * + * 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 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, see <http://www.gnu.org/licenses/>. + * + * Author: Benjamin Segovia <benjamin.segovia@intel.com> + */ + +/** + * \file utest.hpp + * \author Benjamin Segovia <benjamin.segovia@intel.com> + * + * Provides all unit test capabilites. It is rather rudimentary but it should + * do the job + */ +#ifndef __UTEST_UTEST_HPP__ +#define __UTEST_UTEST_HPP__ + +#include <vector> +#include <exception> + +/*! Quick and dirty unit test system with registration */ +struct UTest +{ + /*! A unit test function to run */ + typedef void (*Function) (void); + /*! Empty test */ + UTest(void); + /*! Build a new unit test and append it to the unit test list */ + UTest(Function fn, const char *name); + /*! Function to execute */ + Function fn; + /*! Name of the test */ + const char *name; + /*! The tests that are registered */ + static std::vector<UTest> *utestList; + /*! Run the test with the given name */ + static void run(const char *name); + /*! Run all the tests */ + static void runAll(void); +}; + +/*! RegisterData a new unit test */ +#define UTEST_REGISTER(FN) static const UTest __##FN##__(FN, #FN); + +/*! No assert is expected */ +#define UTEST_EXPECT_SUCCESS(EXPR) \ + do { \ + try { \ + EXPR; \ + std::cout << " " << #EXPR << " [SUCCESS]" << std::endl; \ + } \ + catch (gbe::Exception e) { \ + std::cout << " " << #EXPR << " [FAILED]" << std::endl; \ + std::cout << " " << e.what() << std::endl; \ + } \ + } while (0) + +#define UTEST_EXPECT_FAILED(EXPR) \ + do { \ + try { \ + EXPR; \ + std::cout << " " << #EXPR << " [FAILED]" << std::endl; \ + } \ + catch (gbe::Exception e) { \ + std::cout << " " << #EXPR << " [SUCCESS]" << std::endl; \ + } \ + } while (0) + +#endif /* __UTEST_UTEST_HPP__ */ + |