Files
firefox/xpcom/tests/gtest/TestSTLWrappers.cpp
T
Eric Rahm c6756f1edb Bug 1380154 - Part 1: Add the Chromium DAFSA generator. r=njn
This imports Chromium's `make_dafsa.py` script [1]. It takes in a gperf
formatted file (note: gperf is *not* required) and converts that to a compact
binary representation of the string data in the form of a deterministic
acyclic finite state automaton (DAFSA) [2].

The only change made to the script was to make it handle the arguments our
file generation script passes in to the `main` function.

It also imports the logic for traversing the DAFSA [3] almost verbatim in
`Dafsa.cpp`. A thin wrapper was added so that we can reuse the DAFSA structure
for multiple tables.

The only change made to the original logic was to swap in mozilla style
assertions and rename the not found constant from `kNotFound` to
`Dafsa::kKeyNotFound` in order to avoid a collision with `kNotFound` defined in
our nsString code.

[1] https://chromium.googlesource.com/chromium/src/net/+/6ba04a90565e236b5a420c3a5039718183ad35bd/tools/dafsa/make_dafsa.py
[2] https://en.wikipedia.org/wiki/Deterministic_acyclic_finite_state_automaton
[3] https://chromium.googlesource.com/chromium/chromium/+/a2a90a35aa5b7178e219668bde5889595c710451/net/base/registry_controlled_domains/registry_controlled_domain.cc#72

MozReview-Commit-ID: Eion9POHZm5
2017-07-17 16:09:42 -07:00

79 lines
1.8 KiB
C++

#include <stdio.h>
#include <algorithm>
#ifndef mozilla_algorithm_h
# error "failed to wrap <algorithm>"
#endif
#include <vector>
#ifndef mozilla_vector_h
# error "failed to wrap <vector>"
#endif
#ifdef MOZ_CRASHREPORTER
#include "nsCOMPtr.h"
#include "nsICrashReporter.h"
#include "nsServiceManagerUtils.h"
#endif
// gcc errors out if we |try ... catch| with -fno-exceptions, but we
// can still test on windows
#ifdef _MSC_VER
// C4530 will be generated whenever try...catch is used without
// enabling exceptions. We know we don't enbale exceptions.
# pragma warning( disable : 4530 )
# define TRY try
# define CATCH(e) catch (e)
#else
# define TRY
# define CATCH(e) if (0)
#endif
#include "gtest/gtest.h"
#if defined(XP_UNIX)
extern unsigned int _gdb_sleep_duration;
#endif
void ShouldAbort()
{
#if defined(XP_UNIX)
_gdb_sleep_duration = 0;
#endif
#ifdef MOZ_CRASHREPORTER
nsCOMPtr<nsICrashReporter> crashreporter =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
#endif
std::vector<int> v;
int rv = 1;
TRY {
// v.at(1) on empty v should abort; NOT throw an exception
// (Do some arithmetic with result of v.at() to avoid
// compiler warnings for unused variable/result.)
rv += v.at(1) ? 1 : 2;
} CATCH(const std::out_of_range&) {
fputs("TEST-FAIL | TestSTLWrappers.cpp | caught an exception?\n",
stderr);
return;
}
fputs("TEST-FAIL | TestSTLWrappers.cpp | didn't abort()?\n",
stderr);
}
#ifdef XP_WIN
TEST(STLWrapper, DISABLED_ShouldAbortDeathTest)
#else
TEST(STLWrapper, ShouldAbortDeathTest)
#endif
{
ASSERT_DEATH_IF_SUPPORTED(ShouldAbort(), "terminate called after throwing an instance of 'std::out_of_range'|vector::_M_range_check");
}