1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/tests/TestSTLWrappers.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +#include <stdio.h> 1.5 + 1.6 +#include <algorithm> 1.7 +#ifndef mozilla_algorithm_h 1.8 +# error "failed to wrap <algorithm>" 1.9 +#endif 1.10 + 1.11 +#include <vector> 1.12 +#ifndef mozilla_vector_h 1.13 +# error "failed to wrap <vector>" 1.14 +#endif 1.15 + 1.16 +// gcc errors out if we |try ... catch| with -fno-exceptions, but we 1.17 +// can still test on windows 1.18 +#ifdef _MSC_VER 1.19 + // C4530 will be generated whenever try...catch is used without 1.20 + // enabling exceptions. We know we don't enbale exceptions. 1.21 +# pragma warning( disable : 4530 ) 1.22 +# define TRY try 1.23 +# define CATCH(e) catch (e) 1.24 +#else 1.25 +# define TRY 1.26 +# define CATCH(e) if (0) 1.27 +#endif 1.28 + 1.29 +int main() { 1.30 + std::vector<int> v; 1.31 + int rv = 1; 1.32 + 1.33 + TRY { 1.34 + // v.at(1) on empty v should abort; NOT throw an exception 1.35 + 1.36 + // (Do some arithmetic with result of v.at() to avoid 1.37 + // compiler warnings for unused variable/result.) 1.38 + rv += v.at(1) ? 1 : 2; 1.39 + } CATCH(const std::out_of_range&) { 1.40 + fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n", 1.41 + stderr); 1.42 + return 1; 1.43 + } 1.44 + 1.45 + fputs("TEST-FAIL | TestSTLWrappers.cpp | didn't abort()?\n", 1.46 + stderr); 1.47 + return rv; 1.48 +}