File indexing completed on 2025-02-16 05:12:10
0001 /* 0002 * test/test.cpp 0003 * Copyright 2013 Google Inc. All Rights Reserved. 0004 * 0005 * Permission is hereby granted, free of charge, to any person obtaining a copy 0006 * of this software and associated documentation files (the "Software"), to deal 0007 * in the Software without restriction, including without limitation the rights 0008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0009 * copies of the Software, and to permit persons to whom the Software is 0010 * furnished to do so, subject to the following conditions: 0011 * 0012 * The above copyright notice and this permission notice shall be included in 0013 * all copies or substantial portions of the Software. 0014 * 0015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0021 * SOFTWARE. 0022 */ 0023 0024 #include "test/test.hpp" 0025 #include <cstdlib> 0026 #include <iostream> 0027 #include <stdexcept> 0028 0029 TEST(empty_test) {} 0030 0031 TEST_FAIL_ASSERT(fail_assert) { ASSERT(1 == 2); } 0032 0033 TEST_FAIL_ASSERT(fail_assert_ge) { ASSERT_GE(4, 5); } 0034 0035 TEST_UNCAUGHT_EXCEPTION(uncaught_exception) { 0036 throw std::runtime_error("some random runtime error"); 0037 } 0038 0039 TEST_UNCAUGHT_EXCEPTION(uncaught_exception_int) { throw 42; } 0040 0041 TEST_SEGFAULT(segfault) { 0042 char *a = 0; 0043 char b = a[42]; 0044 std::cout << "result: " << b << std::endl; 0045 } 0046 0047 TEST_ABORT(abort) { abort(); } 0048 0049 TEST(catch_int) { 0050 ASSERT_THROW({ throw 42; }, int); 0051 } 0052 0053 TEST_FAIL_ASSERT(fail_catch_int) { ASSERT_THROW({}, int); } 0054 0055 TEST_FAIL_ASSERT(fail_no_throw) { 0056 ASSERT_NO_THROW({ throw 42; }); 0057 } 0058 0059 TEST(any_throw) { 0060 ASSERT_ANY_THROW({ throw 42; }); 0061 } 0062 0063 TEST_FAIL_ASSERT(fail_any_throw) { ASSERT_ANY_THROW({}); }