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.

     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 int main() {
    27     std::vector<int> v;
    28     int rv = 1;
    30     TRY {
    31       // v.at(1) on empty v should abort; NOT throw an exception
    33       // (Do some arithmetic with result of v.at() to avoid
    34       // compiler warnings for unused variable/result.)
    35       rv += v.at(1) ? 1 : 2;
    36     } CATCH(const std::out_of_range&) {
    37       fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n",
    38             stderr);
    39       return 1;
    40     }
    42     fputs("TEST-FAIL | TestSTLWrappers.cpp | didn't abort()?\n",
    43           stderr);
    44     return rv;
    45 }

mercurial