Bug 1883861 - Part 1: Move visitMemoryBarrier into the common CodeGenerator file...
[gecko.git] / xpcom / tests / gtest / TestSTLWrappers.cpp
blob31b658f76434f5095eaa46a63a669b2b16ed5e9d
1 #include <stdio.h>
3 #include <algorithm>
4 #ifndef mozilla_algorithm_h
5 # error "failed to wrap <algorithm>"
6 #endif
8 #include <vector>
9 #ifndef mozilla_vector_h
10 # error "failed to wrap <vector>"
11 #endif
13 // gcc errors out if we |try ... catch| with -fno-exceptions, but we
14 // can still test on windows
15 #ifdef _MSC_VER
16 // C4530 will be generated whenever try...catch is used without
17 // enabling exceptions. We know we don't enbale exceptions.
18 # pragma warning(disable : 4530)
19 # define TRY try
20 # define CATCH(e) catch (e)
21 #else
22 # define TRY
23 # define CATCH(e) if (0)
24 #endif
26 #include "gtest/gtest.h"
28 #include "mozilla/gtest/MozHelpers.h"
30 void ShouldAbort() {
31 ZERO_GDB_SLEEP();
33 mozilla::gtest::DisableCrashReporter();
35 std::vector<int> v;
37 TRY {
38 // v.at(1) on empty v should abort; NOT throw an exception
40 (void)v.at(1);
42 CATCH(const std::out_of_range&) {
43 fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n", stderr);
44 return;
47 fputs("TEST-FAIL | TestSTLWrappers.cpp | didn't abort()?\n", stderr);
50 #if defined(XP_WIN) || (defined(XP_MACOSX) && !defined(MOZ_DEBUG))
51 TEST(STLWrapper, DISABLED_ShouldAbortDeathTest)
52 #else
53 TEST(STLWrapper, ShouldAbortDeathTest)
54 #endif
56 ASSERT_DEATH_IF_SUPPORTED(ShouldAbort(),
57 #ifdef __GLIBCXX__
58 // Only libstdc++ will print this message.
59 "terminate called after throwing an instance of "
60 "'std::out_of_range'|vector::_M_range_check"
61 #else
63 #endif