xpcom/tests/TestSTLWrappers.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 #include <stdio.h>
michael@0 2
michael@0 3 #include <algorithm>
michael@0 4 #ifndef mozilla_algorithm_h
michael@0 5 # error "failed to wrap <algorithm>"
michael@0 6 #endif
michael@0 7
michael@0 8 #include <vector>
michael@0 9 #ifndef mozilla_vector_h
michael@0 10 # error "failed to wrap <vector>"
michael@0 11 #endif
michael@0 12
michael@0 13 // gcc errors out if we |try ... catch| with -fno-exceptions, but we
michael@0 14 // can still test on windows
michael@0 15 #ifdef _MSC_VER
michael@0 16 // C4530 will be generated whenever try...catch is used without
michael@0 17 // enabling exceptions. We know we don't enbale exceptions.
michael@0 18 # pragma warning( disable : 4530 )
michael@0 19 # define TRY try
michael@0 20 # define CATCH(e) catch (e)
michael@0 21 #else
michael@0 22 # define TRY
michael@0 23 # define CATCH(e) if (0)
michael@0 24 #endif
michael@0 25
michael@0 26 int main() {
michael@0 27 std::vector<int> v;
michael@0 28 int rv = 1;
michael@0 29
michael@0 30 TRY {
michael@0 31 // v.at(1) on empty v should abort; NOT throw an exception
michael@0 32
michael@0 33 // (Do some arithmetic with result of v.at() to avoid
michael@0 34 // compiler warnings for unused variable/result.)
michael@0 35 rv += v.at(1) ? 1 : 2;
michael@0 36 } CATCH(const std::out_of_range&) {
michael@0 37 fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n",
michael@0 38 stderr);
michael@0 39 return 1;
michael@0 40 }
michael@0 41
michael@0 42 fputs("TEST-FAIL | TestSTLWrappers.cpp | didn't abort()?\n",
michael@0 43 stderr);
michael@0 44 return rv;
michael@0 45 }

mercurial