/src/mozilla-central/xpcom/tests/gtest/TestSTLWrappers.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include <stdio.h> |
2 | | |
3 | | #include <algorithm> |
4 | | #ifndef mozilla_algorithm_h |
5 | | # error "failed to wrap <algorithm>" |
6 | | #endif |
7 | | |
8 | | #include <vector> |
9 | | #ifndef mozilla_vector_h |
10 | | # error "failed to wrap <vector>" |
11 | | #endif |
12 | | |
13 | | #include "nsCOMPtr.h" |
14 | | #include "nsICrashReporter.h" |
15 | | #include "nsServiceManagerUtils.h" |
16 | | |
17 | | // gcc errors out if we |try ... catch| with -fno-exceptions, but we |
18 | | // can still test on windows |
19 | | #ifdef _MSC_VER |
20 | | // C4530 will be generated whenever try...catch is used without |
21 | | // enabling exceptions. We know we don't enbale exceptions. |
22 | | # pragma warning( disable : 4530 ) |
23 | | # define TRY try |
24 | | # define CATCH(e) catch (e) |
25 | | #else |
26 | | # define TRY |
27 | 0 | # define CATCH(e) if (0) |
28 | | #endif |
29 | | |
30 | | #include "gtest/gtest.h" |
31 | | |
32 | | #if defined(XP_UNIX) |
33 | | extern unsigned int _gdb_sleep_duration; |
34 | | #endif |
35 | | |
36 | | void ShouldAbort() |
37 | 0 | { |
38 | 0 | #if defined(XP_UNIX) |
39 | 0 | _gdb_sleep_duration = 0; |
40 | 0 | #endif |
41 | 0 |
|
42 | 0 | nsCOMPtr<nsICrashReporter> crashreporter = |
43 | 0 | do_GetService("@mozilla.org/toolkit/crash-reporter;1"); |
44 | 0 | if (crashreporter) { |
45 | 0 | crashreporter->SetEnabled(false); |
46 | 0 | } |
47 | 0 |
|
48 | 0 | std::vector<int> v; |
49 | 0 | int rv = 1; |
50 | 0 |
|
51 | 0 | TRY { |
52 | 0 | // v.at(1) on empty v should abort; NOT throw an exception |
53 | 0 |
|
54 | 0 | // (Do some arithmetic with result of v.at() to avoid |
55 | 0 | // compiler warnings for unused variable/result.) |
56 | 0 | rv += v.at(1) ? 1 : 2; |
57 | 0 | } CATCH(const std::out_of_range&) { |
58 | 0 | fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n", |
59 | 0 | stderr); |
60 | 0 | return; |
61 | 0 | } |
62 | 0 | |
63 | 0 | fputs("TEST-FAIL | TestSTLWrappers.cpp | didn't abort()?\n", |
64 | 0 | stderr); |
65 | 0 | } |
66 | | |
67 | | #ifdef XP_WIN |
68 | | TEST(STLWrapper, DISABLED_ShouldAbortDeathTest) |
69 | | #else |
70 | | TEST(STLWrapper, ShouldAbortDeathTest) |
71 | | #endif |
72 | 0 | { |
73 | 0 | ASSERT_DEATH_IF_SUPPORTED(ShouldAbort(), "terminate called after throwing an instance of 'std::out_of_range'|vector::_M_range_check"); |
74 | 0 | } |