You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ka...@apache.org on 2016/05/11 22:24:38 UTC
[16/50] [abbrv] mesos git commit: Moved stout from
libprocess/3rdparty/ to 3rdparty/.
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/m4/ax_cxx_compile_stdcxx.m4
----------------------------------------------------------------------
diff --git a/3rdparty/stout/m4/ax_cxx_compile_stdcxx.m4 b/3rdparty/stout/m4/ax_cxx_compile_stdcxx.m4
new file mode 100644
index 0000000..0460bcd
--- /dev/null
+++ b/3rdparty/stout/m4/ax_cxx_compile_stdcxx.m4
@@ -0,0 +1,560 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional])
+#
+# DESCRIPTION
+#
+# Check for baseline language coverage in the compiler for the specified
+# version of the C++ standard. If necessary, add switches to CXX to
+# enable support. VERSION may be '11' (for the C++11 standard) or '14'
+# (for the C++14 standard).
+#
+# The second argument, if specified, indicates whether you insist on an
+# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
+# -std=c++11). If neither is specified, you get whatever works, with
+# preference for an extended mode.
+#
+# The third argument, if specified 'mandatory' or if left unspecified,
+# indicates that baseline support for the specified C++ standard is
+# required and that the macro should error out if no mode with that
+# support is found. If specified 'optional', then configuration proceeds
+# regardless, after defining HAVE_CXX${VERSION} if and only if a
+# supporting mode is found.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Benjamin Kosnik <bk...@redhat.com>
+# Copyright (c) 2012 Zack Weinberg <za...@panix.com>
+# Copyright (c) 2013 Roy Stogner <ro...@ices.utexas.edu>
+# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <so...@google.com>
+# Copyright (c) 2015 Paul Norman <pe...@mac.com>
+# Copyright (c) 2015 Moritz Klammler <mo...@klammler.eu>
+#
+# Copying and distribution of this file, with or without modification, are
+# permitted in any medium without royalty provided the copyright notice
+# and this notice are preserved. This file is offered as-is, without any
+# warranty.
+
+#serial 3
+
+dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
+dnl (serial version number 13).
+
+AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
+ m4_if([$1], [11], [],
+ [$1], [14], [],
+ [$1], [17], [m4_fatal([support for C++17 not yet implemented in AX_CXX_COMPILE_STDCXX])],
+ [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl
+ m4_if([$2], [], [],
+ [$2], [ext], [],
+ [$2], [noext], [],
+ [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl
+ m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true],
+ [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true],
+ [$3], [optional], [ax_cxx_compile_cxx$1_required=false],
+ [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])])
+ AC_LANG_PUSH([C++])dnl
+ ac_success=no
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
+ ax_cv_cxx_compile_cxx$1,
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [ax_cv_cxx_compile_cxx$1=yes],
+ [ax_cv_cxx_compile_cxx$1=no])])
+ if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
+ ac_success=yes
+ fi
+
+ m4_if([$2], [noext], [], [dnl
+ if test x$ac_success = xno; then
+ for switch in -std=gnu++$1 -std=gnu++0x; do
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
+ $cachevar,
+ [ac_save_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXXFLAGS="$ac_save_CXXFLAGS"])
+ if eval test x\$$cachevar = xyes; then
+ CXXFLAGS="$CXXFLAGS $switch"
+ ac_success=yes
+ break
+ fi
+ done
+ fi])
+
+ m4_if([$2], [ext], [], [dnl
+ dnl Note that in "noext" mode, we still want to specify a "-std" flag
+ dnl if the compiler accepts it (even if the compiler supports the
+ dnl desired C++ dialect without any flags), because the default compiler
+ dnl dialect might include support for extensions.
+ dnl HP's aCC needs +std=c++11 according to:
+ dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf
+ dnl Cray's crayCC needs "-h std=c++11"
+ for switch in -std=c++$1 -std=c++0x +std=c++$1 "-h std=c++$1"; do
+ cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch])
+ AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch,
+ $cachevar,
+ [ac_save_CXXFLAGS="$CXXFLAGS"
+ CXXFLAGS="$CXXFLAGS $switch"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
+ [eval $cachevar=yes],
+ [eval $cachevar=no])
+ CXXFLAGS="$ac_save_CXXFLAGS"])
+ if eval test x\$$cachevar = xyes; then
+ CXXFLAGS="$CXXFLAGS $switch"
+ ac_success=yes
+ break
+ fi
+ done
+ ])
+
+ AC_LANG_POP([C++])
+ if test x$ax_cxx_compile_cxx$1_required = xtrue; then
+ if test x$ac_success = xno; then
+ AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.])
+ fi
+ fi
+ if test x$ac_success = xno; then
+ HAVE_CXX$1=0
+ AC_MSG_NOTICE([No compiler with C++$1 support was found])
+ else
+ HAVE_CXX$1=1
+ AC_DEFINE(HAVE_CXX$1,1,
+ [define if the compiler supports basic C++$1 syntax])
+ fi
+ AC_SUBST(HAVE_CXX$1)
+])
+
+
+dnl Test body for checking C++11 support
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11],
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+)
+
+
+dnl Test body for checking C++14 support
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14],
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_11
+ _AX_CXX_COMPILE_STDCXX_testbody_new_in_14
+)
+
+
+dnl Tests for new features in C++11
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[
+
+// If the compiler admits that it is not ready for C++11, why torture it?
+// Hopefully, this will speed up the test.
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus < 201103L
+
+#error "This is not a C++11 compiler"
+
+#else
+
+namespace cxx11
+{
+
+ namespace test_static_assert
+ {
+
+ template <typename T>
+ struct check
+ {
+ static_assert(sizeof(int) <= sizeof(T), "not big enough");
+ };
+
+ }
+
+ namespace test_final_override
+ {
+
+ struct Base
+ {
+ virtual void f() {}
+ };
+
+ struct Derived : public Base
+ {
+ virtual void f() override {}
+ };
+
+ }
+
+ namespace test_double_right_angle_brackets
+ {
+
+ template < typename T >
+ struct check {};
+
+ typedef check<void> single_type;
+ typedef check<check<void>> double_type;
+ typedef check<check<check<void>>> triple_type;
+ typedef check<check<check<check<void>>>> quadruple_type;
+
+ }
+
+ namespace test_decltype
+ {
+
+ int
+ f()
+ {
+ int a = 1;
+ decltype(a) b = 2;
+ return a + b;
+ }
+
+ }
+
+ namespace test_type_deduction
+ {
+
+ template < typename T1, typename T2 >
+ struct is_same
+ {
+ static const bool value = false;
+ };
+
+ template < typename T >
+ struct is_same<T, T>
+ {
+ static const bool value = true;
+ };
+
+ template < typename T1, typename T2 >
+ auto
+ add(T1 a1, T2 a2) -> decltype(a1 + a2)
+ {
+ return a1 + a2;
+ }
+
+ int
+ test(const int c, volatile int v)
+ {
+ static_assert(is_same<int, decltype(0)>::value == true, "");
+ static_assert(is_same<int, decltype(c)>::value == false, "");
+ static_assert(is_same<int, decltype(v)>::value == false, "");
+ auto ac = c;
+ auto av = v;
+ auto sumi = ac + av + 'x';
+ auto sumf = ac + av + 1.0;
+ static_assert(is_same<int, decltype(ac)>::value == true, "");
+ static_assert(is_same<int, decltype(av)>::value == true, "");
+ static_assert(is_same<int, decltype(sumi)>::value == true, "");
+ static_assert(is_same<int, decltype(sumf)>::value == false, "");
+ static_assert(is_same<int, decltype(add(c, v))>::value == true, "");
+ return (sumf > 0.0) ? sumi : add(c, v);
+ }
+
+ }
+
+ namespace test_noexcept
+ {
+
+ int f() { return 0; }
+ int g() noexcept { return 0; }
+
+ static_assert(noexcept(f()) == false, "");
+ static_assert(noexcept(g()) == true, "");
+
+ }
+
+ namespace test_constexpr
+ {
+
+ template < typename CharT >
+ unsigned long constexpr
+ strlen_c_r(const CharT *const s, const unsigned long acc) noexcept
+ {
+ return *s ? strlen_c_r(s + 1, acc + 1) : acc;
+ }
+
+ template < typename CharT >
+ unsigned long constexpr
+ strlen_c(const CharT *const s) noexcept
+ {
+ return strlen_c_r(s, 0UL);
+ }
+
+ static_assert(strlen_c("") == 0UL, "");
+ static_assert(strlen_c("1") == 1UL, "");
+ static_assert(strlen_c("example") == 7UL, "");
+ static_assert(strlen_c("another\0example") == 7UL, "");
+
+ }
+
+ namespace test_rvalue_references
+ {
+
+ template < int N >
+ struct answer
+ {
+ static constexpr int value = N;
+ };
+
+ answer<1> f(int&) { return answer<1>(); }
+ answer<2> f(const int&) { return answer<2>(); }
+ answer<3> f(int&&) { return answer<3>(); }
+
+ void
+ test()
+ {
+ int i = 0;
+ const int c = 0;
+ static_assert(decltype(f(i))::value == 1, "");
+ static_assert(decltype(f(c))::value == 2, "");
+ static_assert(decltype(f(0))::value == 3, "");
+ }
+
+ }
+
+ namespace test_uniform_initialization
+ {
+
+ struct test
+ {
+ static const int zero {};
+ static const int one {1};
+ };
+
+ static_assert(test::zero == 0, "");
+ static_assert(test::one == 1, "");
+
+ }
+
+ namespace test_lambdas
+ {
+
+ void
+ test1()
+ {
+ auto lambda1 = [](){};
+ auto lambda2 = lambda1;
+ lambda1();
+ lambda2();
+ }
+
+ int
+ test2()
+ {
+ auto a = [](int i, int j){ return i + j; }(1, 2);
+ auto b = []() -> int { return '0'; }();
+ auto c = [=](){ return a + b; }();
+ auto d = [&](){ return c; }();
+ auto e = [a, &b](int x) mutable {
+ const auto identity = [](int y){ return y; };
+ for (auto i = 0; i < a; ++i)
+ a += b--;
+ return x + identity(a + b);
+ }(0);
+ return a + b + c + d + e;
+ }
+
+ int
+ test3()
+ {
+ const auto nullary = [](){ return 0; };
+ const auto unary = [](int x){ return x; };
+ using nullary_t = decltype(nullary);
+ using unary_t = decltype(unary);
+ const auto higher1st = [](nullary_t f){ return f(); };
+ const auto higher2nd = [unary](nullary_t f1){
+ return [unary, f1](unary_t f2){ return f2(unary(f1())); };
+ };
+ return higher1st(nullary) + higher2nd(nullary)(unary);
+ }
+
+ }
+
+ namespace test_variadic_templates
+ {
+
+ template <int...>
+ struct sum;
+
+ template <int N0, int... N1toN>
+ struct sum<N0, N1toN...>
+ {
+ static constexpr auto value = N0 + sum<N1toN...>::value;
+ };
+
+ template <>
+ struct sum<>
+ {
+ static constexpr auto value = 0;
+ };
+
+ static_assert(sum<>::value == 0, "");
+ static_assert(sum<1>::value == 1, "");
+ static_assert(sum<23>::value == 23, "");
+ static_assert(sum<1, 2>::value == 3, "");
+ static_assert(sum<5, 5, 11>::value == 21, "");
+ static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, "");
+
+ }
+
+ // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae
+ // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function
+ // because of this.
+ namespace test_template_alias_sfinae
+ {
+
+ struct foo {};
+
+ template<typename T>
+ using member = typename T::member_type;
+
+ template<typename T>
+ void func(...) {}
+
+ template<typename T>
+ void func(member<T>*) {}
+
+ void test();
+
+ void test() { func<foo>(0); }
+
+ }
+
+} // namespace cxx11
+
+#endif // __cplusplus >= 201103L
+
+]])
+
+
+dnl Tests for new features in C++14
+
+m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[
+
+// If the compiler admits that it is not ready for C++14, why torture it?
+// Hopefully, this will speed up the test.
+
+#ifndef __cplusplus
+
+#error "This is not a C++ compiler"
+
+#elif __cplusplus < 201402L
+
+#error "This is not a C++14 compiler"
+
+#else
+
+namespace cxx14
+{
+
+ namespace test_polymorphic_lambdas
+ {
+
+ int
+ test()
+ {
+ const auto lambda = [](auto&&... args){
+ const auto istiny = [](auto x){
+ return (sizeof(x) == 1UL) ? 1 : 0;
+ };
+ const int aretiny[] = { istiny(args)... };
+ return aretiny[0];
+ };
+ return lambda(1, 1L, 1.0f, '1');
+ }
+
+ }
+
+ namespace test_binary_literals
+ {
+
+ constexpr auto ivii = 0b0000000000101010;
+ static_assert(ivii == 42, "wrong value");
+
+ }
+
+ namespace test_generalized_constexpr
+ {
+
+ template < typename CharT >
+ constexpr unsigned long
+ strlen_c(const CharT *const s) noexcept
+ {
+ auto length = 0UL;
+ for (auto p = s; *p; ++p)
+ ++length;
+ return length;
+ }
+
+ static_assert(strlen_c("") == 0UL, "");
+ static_assert(strlen_c("x") == 1UL, "");
+ static_assert(strlen_c("test") == 4UL, "");
+ static_assert(strlen_c("another\0test") == 7UL, "");
+
+ }
+
+ namespace test_lambda_init_capture
+ {
+
+ int
+ test()
+ {
+ auto x = 0;
+ const auto lambda1 = [a = x](int b){ return a + b; };
+ const auto lambda2 = [a = lambda1(x)](){ return a; };
+ return lambda2();
+ }
+
+ }
+
+ namespace test_digit_seperators
+ {
+
+ constexpr auto ten_million = 100'000'000;
+ static_assert(ten_million == 100000000, "");
+
+ }
+
+ namespace test_return_type_deduction
+ {
+
+ auto f(int& x) { return x; }
+ decltype(auto) g(int& x) { return x; }
+
+ template < typename T1, typename T2 >
+ struct is_same
+ {
+ static constexpr auto value = false;
+ };
+
+ template < typename T >
+ struct is_same<T, T>
+ {
+ static constexpr auto value = true;
+ };
+
+ int
+ test()
+ {
+ auto x = 0;
+ static_assert(is_same<int, decltype(f(x))>::value, "");
+ static_assert(is_same<int&, decltype(g(x))>::value, "");
+ return x;
+ }
+
+ }
+
+} // namespace cxx14
+
+#endif // __cplusplus >= 201402L
+
+]])
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/m4/ax_pthread.m4
----------------------------------------------------------------------
diff --git a/3rdparty/stout/m4/ax_pthread.m4 b/3rdparty/stout/m4/ax_pthread.m4
new file mode 100644
index 0000000..0b2071d
--- /dev/null
+++ b/3rdparty/stout/m4/ax_pthread.m4
@@ -0,0 +1,332 @@
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_pthread.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+#
+# DESCRIPTION
+#
+# This macro figures out how to build C programs using POSIX threads. It
+# sets the PTHREAD_LIBS output variable to the threads library and linker
+# flags, and the PTHREAD_CFLAGS output variable to any special C compiler
+# flags that are needed. (The user can also force certain compiler
+# flags/libs to be tested by setting these environment variables.)
+#
+# Also sets PTHREAD_CC to any special C compiler that is needed for
+# multi-threaded programs (defaults to the value of CC otherwise). (This
+# is necessary on AIX to use the special cc_r compiler alias.)
+#
+# NOTE: You are assumed to not only compile your program with these flags,
+# but also link it with them as well. e.g. you should link with
+# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
+#
+# If you are only building threads programs, you may wish to use these
+# variables in your default LIBS, CFLAGS, and CC:
+#
+# LIBS="$PTHREAD_LIBS $LIBS"
+# CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+# CC="$PTHREAD_CC"
+#
+# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
+# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
+# (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
+#
+# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
+# PTHREAD_PRIO_INHERIT symbol is defined when compiling with
+# PTHREAD_CFLAGS.
+#
+# ACTION-IF-FOUND is a list of shell commands to run if a threads library
+# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
+# is not found. If ACTION-IF-FOUND is not specified, the default action
+# will define HAVE_PTHREAD.
+#
+# Please let the authors know if this macro fails on any platform, or if
+# you have any other suggestions or comments. This macro was based on work
+# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
+# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
+# Alejandro Forero Cuervo to the autoconf macro repository. We are also
+# grateful for the helpful feedback of numerous users.
+#
+# Updated for Autoconf 2.68 by Daniel Richard G.
+#
+# LICENSE
+#
+# Copyright (c) 2008 Steven G. Johnson <st...@alum.mit.edu>
+# Copyright (c) 2011 Daniel Richard G. <sk...@iSKUNK.ORG>
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+# Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the respective Autoconf Macro's copyright owner
+# gives unlimited permission to copy, distribute and modify the configure
+# scripts that are the output of Autoconf when processing the Macro. You
+# need not follow the terms of the GNU General Public License when using
+# or distributing such scripts, even though portions of the text of the
+# Macro appear in them. The GNU General Public License (GPL) does govern
+# all other use of the material that constitutes the Autoconf Macro.
+#
+# This special exception to the GPL applies to versions of the Autoconf
+# Macro released by the Autoconf Archive. When you make and distribute a
+# modified version of the Autoconf Macro, you may extend this special
+# exception to the GPL to apply to your modified version as well.
+
+#serial 21
+
+AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
+AC_DEFUN([AX_PTHREAD], [
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_LANG_PUSH([C])
+ax_pthread_ok=no
+
+# We used to check for pthread.h first, but this fails if pthread.h
+# requires special compiler flags (e.g. on True64 or Sequent).
+# It gets checked for in the link test anyway.
+
+# First of all, check if the user has set any of the PTHREAD_LIBS,
+# etcetera environment variables, and if threads linking works using
+# them:
+if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
+ AC_TRY_LINK_FUNC([pthread_join], [ax_pthread_ok=yes])
+ AC_MSG_RESULT([$ax_pthread_ok])
+ if test x"$ax_pthread_ok" = xno; then
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+ fi
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+fi
+
+# We must check for the threads library under a number of different
+# names; the ordering is very important because some systems
+# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
+# libraries is broken (non-POSIX).
+
+# Create a list of thread flags to try. Items starting with a "-" are
+# C compiler flags, and other items are library names, except for "none"
+# which indicates that we try without any flags at all, and "pthread-config"
+# which is a program returning the flags for the Pth emulation library.
+
+ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
+
+# The ordering *is* (sometimes) important. Some notes on the
+# individual items follow:
+
+# pthreads: AIX (must check this before -lpthread)
+# none: in case threads are in libc; should be tried before -Kthread and
+# other compiler flags to prevent continual compiler warnings
+# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
+# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
+# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
+# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
+# -pthreads: Solaris/gcc
+# -mthreads: Mingw32/gcc, Lynx/gcc
+# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
+# doesn't hurt to check since this sometimes defines pthreads too;
+# also defines -D_REENTRANT)
+# ... -mt is also the pthreads flag for HP/aCC
+# pthread: Linux, etcetera
+# --thread-safe: KAI C++
+# pthread-config: use pthread-config program (for GNU Pth library)
+
+case ${host_os} in
+ solaris*)
+
+ # On Solaris (at least, for some versions), libc contains stubbed
+ # (non-functional) versions of the pthreads routines, so link-based
+ # tests will erroneously succeed. (We need to link with -pthreads/-mt/
+ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
+ # a function called by this macro, so we could check for that, but
+ # who knows whether they'll stub that too in a future libc.) So,
+ # we'll just look for -pthreads and -lpthread first:
+
+ ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
+ ;;
+
+ darwin*)
+ ax_pthread_flags="-pthread $ax_pthread_flags"
+ ;;
+esac
+
+# Clang doesn't consider unrecognized options an error unless we specify
+# -Werror. We throw in some extra Clang-specific options to ensure that
+# this doesn't happen for GCC, which also accepts -Werror.
+
+AC_MSG_CHECKING([if compiler needs -Werror to reject unknown flags])
+save_CFLAGS="$CFLAGS"
+ax_pthread_extra_flags="-Werror"
+CFLAGS="$CFLAGS $ax_pthread_extra_flags -Wunknown-warning-option -Wsizeof-array-argument"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int foo();],[foo()])],
+ [AC_MSG_RESULT([yes])],
+ [ax_pthread_extra_flags=
+ AC_MSG_RESULT([no])])
+CFLAGS="$save_CFLAGS"
+
+if test x"$ax_pthread_ok" = xno; then
+for flag in $ax_pthread_flags; do
+
+ case $flag in
+ none)
+ AC_MSG_CHECKING([whether pthreads work without any flags])
+ ;;
+
+ -*)
+ AC_MSG_CHECKING([whether pthreads work with $flag])
+ PTHREAD_CFLAGS="$flag"
+ ;;
+
+ pthread-config)
+ AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
+ if test x"$ax_pthread_config" = xno; then continue; fi
+ PTHREAD_CFLAGS="`pthread-config --cflags`"
+ PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
+ ;;
+
+ *)
+ AC_MSG_CHECKING([for the pthreads library -l$flag])
+ PTHREAD_LIBS="-l$flag"
+ ;;
+ esac
+
+ save_LIBS="$LIBS"
+ save_CFLAGS="$CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS $ax_pthread_extra_flags"
+
+ # Check for various functions. We must include pthread.h,
+ # since some functions may be macros. (On the Sequent, we
+ # need a special flag -Kthread to make this header compile.)
+ # We check for pthread_join because it is in -lpthread on IRIX
+ # while pthread_create is in libc. We check for pthread_attr_init
+ # due to DEC craziness with -lpthreads. We check for
+ # pthread_cleanup_push because it is one of the few pthread
+ # functions on Solaris that doesn't have a non-functional libc stub.
+ # We try pthread_create on general principles.
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
+ static void routine(void *a) { a = 0; }
+ static void *start_routine(void *a) { return a; }],
+ [pthread_t th; pthread_attr_t attr;
+ pthread_create(&th, 0, start_routine, 0);
+ pthread_join(th, 0);
+ pthread_attr_init(&attr);
+ pthread_cleanup_push(routine, 0);
+ pthread_cleanup_pop(0) /* ; */])],
+ [ax_pthread_ok=yes],
+ [])
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ AC_MSG_RESULT([$ax_pthread_ok])
+ if test "x$ax_pthread_ok" = xyes; then
+ break;
+ fi
+
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+done
+fi
+
+# Various other checks:
+if test "x$ax_pthread_ok" = xyes; then
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+ # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
+ AC_MSG_CHECKING([for joinable pthread attribute])
+ attr_name=unknown
+ for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
+ [int attr = $attr; return attr /* ; */])],
+ [attr_name=$attr; break],
+ [])
+ done
+ AC_MSG_RESULT([$attr_name])
+ if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
+ AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], [$attr_name],
+ [Define to necessary symbol if this constant
+ uses a non-standard name on your system.])
+ fi
+
+ AC_MSG_CHECKING([if more special flags are required for pthreads])
+ flag=no
+ case ${host_os} in
+ aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";;
+ osf* | hpux*) flag="-D_REENTRANT";;
+ solaris*)
+ if test "$GCC" = "yes"; then
+ flag="-D_REENTRANT"
+ else
+ # TODO: What about Clang on Solaris?
+ flag="-mt -D_REENTRANT"
+ fi
+ ;;
+ esac
+ AC_MSG_RESULT([$flag])
+ if test "x$flag" != xno; then
+ PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
+ fi
+
+ AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
+ [ax_cv_PTHREAD_PRIO_INHERIT], [
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
+ [[int i = PTHREAD_PRIO_INHERIT;]])],
+ [ax_cv_PTHREAD_PRIO_INHERIT=yes],
+ [ax_cv_PTHREAD_PRIO_INHERIT=no])
+ ])
+ AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"],
+ [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.])])
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ # More AIX lossage: compile with *_r variant
+ if test "x$GCC" != xyes; then
+ case $host_os in
+ aix*)
+ AS_CASE(["x/$CC"],
+ [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
+ [#handle absolute path differently from PATH based program lookup
+ AS_CASE(["x$CC"],
+ [x/*],
+ [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
+ [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
+ ;;
+ esac
+ fi
+fi
+
+test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
+
+AC_SUBST([PTHREAD_LIBS])
+AC_SUBST([PTHREAD_CFLAGS])
+AC_SUBST([PTHREAD_CC])
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test x"$ax_pthread_ok" = xyes; then
+ ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1])
+ :
+else
+ ax_pthread_ok=no
+ $2
+fi
+AC_LANG_POP
+])dnl AX_PTHREAD
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/CMakeLists.txt b/3rdparty/stout/tests/CMakeLists.txt
new file mode 100644
index 0000000..f85dc99
--- /dev/null
+++ b/3rdparty/stout/tests/CMakeLists.txt
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# STOUT TESTS.
+##############
+set(STOUT_TESTS_SRC
+ ${STOUT_TESTS_SRC}
+ base64_tests.cpp
+ bits_tests.cpp
+ bytes_tests.cpp
+ cache_tests.cpp
+ duration_tests.cpp
+ dynamiclibrary_tests.cpp
+ error_tests.cpp
+ gzip_tests.cpp
+ hashmap_tests.cpp
+ hashset_tests.cpp
+ interval_tests.cpp
+ ip_tests.cpp
+ json_tests.cpp
+ jsonify_tests.cpp
+ linkedhashmap_tests.cpp
+ main.cpp
+ multimap_tests.cpp
+ none_tests.cpp
+ numify_tests.cpp
+ option_tests.cpp
+ os/env_tests.cpp
+ os/filesystem_tests.cpp
+ os/process_tests.cpp
+ os/rmdir_tests.cpp
+ os/socket_tests.cpp
+ os/strerror_tests.cpp
+ os/systems_tests.cpp
+ protobuf_tests.pb.h
+ protobuf_tests.proto
+ result_tests.cpp
+ set_tests.cpp
+ some_tests.cpp
+ strings_tests.cpp
+ uuid_tests.cpp
+ version_tests.cpp
+ )
+
+if (NOT WIN32)
+ set(STOUT_TESTS_SRC
+ ${STOUT_TESTS_SRC}
+ flags_tests.cpp
+ mac_tests.cpp
+ os_tests.cpp
+ path_tests.cpp
+ protobuf_tests.cpp
+ protobuf_tests.pb.cc
+ recordio_tests.cpp
+ subcommand_tests.cpp
+ svn_tests.cpp
+ try_tests.cpp
+ os/sendfile_tests.cpp
+ os/signals_tests.cpp
+ )
+endif (NOT WIN32)
+
+if (LINUX)
+ set(STOUT_TESTS_SRC ${STOUT_TESTS_SRC} proc_tests.cpp)
+endif (LINUX)
+
+# INCLUDE DIRECTIVES FOR STOUT TEST BINARY (generates, e.g., -I/path/to/thing
+# on Linux).
+#############################################################################
+include_directories(${STOUT_TEST_INCLUDE_DIRS})
+
+# LINKING LIBRARIES BY DIRECTORY (might generate, e.g., -L/path/to/thing on
+# Linux).
+###########################################################################
+link_directories(${STOUT_TEST_LIB_DIRS})
+
+# THE STOUT TEST EXECUTABLE (generates, e.g., stout_tests, etc., on Linux).
+###########################################################################
+add_executable(${STOUT_TESTS_TARGET} ${STOUT_TESTS_SRC})
+
+# ADD LINKER FLAGS (generates, e.g., -lglog on Linux).
+######################################################
+target_link_libraries(${STOUT_TESTS_TARGET} ${STOUT_TEST_LIBS})
+
+# ADD BINARY DEPENDENCIES (tells CMake what to compile/build first).
+####################################################################
+add_dependencies(${STOUT_TESTS_TARGET} ${STOUT_TEST_DEPENDENCIES})
+
+# ADD TEST TARGET (runs when you do, e.g., `make check`).
+#########################################################
+add_test(NAME StoutTests COMMAND ./${STOUT_TESTS_TARGET})
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/adaptor_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/adaptor_tests.cpp b/3rdparty/stout/tests/adaptor_tests.cpp
new file mode 100644
index 0000000..534b505
--- /dev/null
+++ b/3rdparty/stout/tests/adaptor_tests.cpp
@@ -0,0 +1,36 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include <stout/adaptor.hpp>
+#include <stout/foreach.hpp>
+
+using std::vector;
+
+
+TEST(AdaptorTest, Reversed)
+{
+ vector<int> input = {1, 2, 3};
+ vector<int> output;
+
+ foreach (int i, adaptor::reverse(input)) {
+ output.push_back(i);
+ }
+
+ ASSERT_EQ(3u, output.size());
+ EXPECT_EQ(3, output[0]);
+ EXPECT_EQ(2, output[1]);
+ EXPECT_EQ(1, output[2]);
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/base64_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/base64_tests.cpp b/3rdparty/stout/tests/base64_tests.cpp
new file mode 100644
index 0000000..32e5168
--- /dev/null
+++ b/3rdparty/stout/tests/base64_tests.cpp
@@ -0,0 +1,45 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <gtest/gtest.h>
+
+#include <stout/base64.hpp>
+#include <stout/gtest.hpp>
+
+
+TEST(Base64Test, Encode)
+{
+ EXPECT_EQ("dXNlcjpwYXNzd29yZA==", base64::encode("user:password"));
+}
+
+
+TEST(Base64Test, Decode)
+{
+ // We're able to parse without padding.
+ EXPECT_SOME_EQ("user:password", base64::decode("dXNlcjpwYXNzd29yZA=="));
+ EXPECT_SOME_EQ("user:password", base64::decode("dXNlcjpwYXNzd29yZA="));
+ EXPECT_SOME_EQ("user:password", base64::decode("dXNlcjpwYXNzd29yZA"));
+
+ // Whitespace is not allowed.
+ EXPECT_ERROR(base64::decode("d XNlcjpwYXNzd29yZA=="));
+ EXPECT_ERROR(base64::decode("d\r\nXNlcjpwYXNzd29yZA=="));
+
+ // Invalid characters.
+ EXPECT_ERROR(base64::decode("abc("));
+ EXPECT_ERROR(base64::decode(">abc"));
+ EXPECT_ERROR(base64::decode("ab,="));
+
+ // These cases are not currently validated!
+ // EXPECT_ERROR(base64::decode("ab="));
+ // EXPECT_ERROR(base64::decode("ab=,"));
+ // EXPECT_ERROR(base64::decode("ab==="));
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/bits_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/bits_tests.cpp b/3rdparty/stout/tests/bits_tests.cpp
new file mode 100644
index 0000000..7dfe4c3
--- /dev/null
+++ b/3rdparty/stout/tests/bits_tests.cpp
@@ -0,0 +1,25 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <gtest/gtest.h>
+
+#include <stout/bits.hpp>
+
+TEST(BitsTest, CountSetBits)
+{
+ EXPECT_EQ(0, bits::countSetBits(0));
+ EXPECT_EQ(6, bits::countSetBits(0xf3));
+ EXPECT_EQ(15, bits::countSetBits(0xffbf));
+ EXPECT_EQ(22, bits::countSetBits(0xfffffc));
+ EXPECT_EQ(26, bits::countSetBits(0xfffffcf));
+ EXPECT_EQ(32, bits::countSetBits(0xffffffff));
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/bytes_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/bytes_tests.cpp b/3rdparty/stout/tests/bytes_tests.cpp
new file mode 100644
index 0000000..9d32ea1
--- /dev/null
+++ b/3rdparty/stout/tests/bytes_tests.cpp
@@ -0,0 +1,81 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <stout/bytes.hpp>
+#include <stout/gtest.hpp>
+#include <stout/stringify.hpp>
+#include <stout/try.hpp>
+
+
+TEST(BytesTest, Parse)
+{
+ EXPECT_SOME_EQ(Terabytes(1), Bytes::parse("1TB"));
+ EXPECT_SOME_EQ(Gigabytes(1), Bytes::parse("1GB"));
+ EXPECT_SOME_EQ(Megabytes(1), Bytes::parse("1MB"));
+ EXPECT_SOME_EQ(Kilobytes(1), Bytes::parse("1KB"));
+ EXPECT_SOME_EQ(Bytes(1), Bytes::parse("1B"));
+
+ // Cannot have fractional bytes.
+ EXPECT_ERROR(Bytes::parse("1.5B"));
+
+ // Parsing fractions is unsupported.
+ EXPECT_ERROR(Bytes::parse("1.5GB"));
+
+ // Unknown unit.
+ EXPECT_ERROR(Bytes::parse("1PB"));
+}
+
+
+TEST(BytesTest, Arithmetic)
+{
+ EXPECT_EQ(Terabytes(1), Gigabytes(512) + Gigabytes(512));
+ EXPECT_EQ(Terabytes(1), Terabytes(2) - Terabytes(1));
+
+ EXPECT_EQ(Terabytes(1), Gigabytes(1) * 1024);
+
+ EXPECT_EQ(Gigabytes(1), Terabytes(1) / 1024);
+}
+
+
+TEST(BytesTest, Comparison)
+{
+ EXPECT_GT(Terabytes(1), Gigabytes(1));
+ EXPECT_GT(Gigabytes(1), Megabytes(1));
+ EXPECT_GT(Megabytes(1), Kilobytes(1));
+ EXPECT_GT(Kilobytes(1), Bytes(1));
+
+ EXPECT_EQ(Bytes(1024), Kilobytes(1));
+ EXPECT_LT(Bytes(1023), Kilobytes(1));
+ EXPECT_GT(Bytes(1025), Kilobytes(1));
+}
+
+
+TEST(BytesTest, Stringify)
+{
+ EXPECT_NE(Megabytes(1023), Gigabytes(1));
+
+ EXPECT_EQ("0B", stringify(Bytes()));
+
+ EXPECT_EQ("1KB", stringify(Kilobytes(1)));
+ EXPECT_EQ("1MB", stringify(Megabytes(1)));
+ EXPECT_EQ("1GB", stringify(Gigabytes(1)));
+ EXPECT_EQ("1TB", stringify(Terabytes(1)));
+
+ EXPECT_EQ("1023B", stringify(Bytes(1023)));
+ EXPECT_EQ("1023KB", stringify(Kilobytes(1023)));
+ EXPECT_EQ("1023MB", stringify(Megabytes(1023)));
+ EXPECT_EQ("1023GB", stringify(Gigabytes(1023)));
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/cache_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/cache_tests.cpp b/3rdparty/stout/tests/cache_tests.cpp
new file mode 100644
index 0000000..0950c85
--- /dev/null
+++ b/3rdparty/stout/tests/cache_tests.cpp
@@ -0,0 +1,88 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include <stout/cache.hpp>
+#include <stout/gtest.hpp>
+
+
+TEST(CacheTest, Insert)
+{
+ Cache<int, std::string> cache(1);
+ EXPECT_EQ(0, cache.size());
+ cache.put(1, "a");
+ EXPECT_SOME_EQ("a", cache.get(1));
+ EXPECT_EQ(1, cache.size());
+}
+
+
+TEST(CacheTest, Update)
+{
+ Cache<int, std::string> cache(1);
+ cache.put(1, "a");
+ cache.put(1, "b");
+ EXPECT_SOME_EQ("b", cache.get(1));
+ EXPECT_EQ(1, cache.size());
+}
+
+
+TEST(CacheTest, Erase)
+{
+ Cache<int, std::string> cache(2);
+ cache.put(1, "a");
+ cache.put(2, "b");
+
+ EXPECT_NONE(cache.erase(44));
+
+ EXPECT_SOME_EQ("b", cache.erase(2));
+ EXPECT_EQ(1, cache.size());
+
+ EXPECT_NONE(cache.erase(2));
+ EXPECT_EQ(1, cache.size());
+
+ EXPECT_SOME_EQ("a", cache.erase(1));
+ EXPECT_EQ(0, cache.size());
+}
+
+
+TEST(CacheTest, LRUEviction)
+{
+ Cache<int, std::string> cache(2);
+ cache.put(1, "a");
+ cache.put(2, "b");
+ cache.put(3, "c");
+
+ EXPECT_NONE(cache.get(1));
+
+ // 'Get' makes '2' the most-recently used (MRU) item.
+ cache.get(2);
+ cache.put(4, "d");
+ EXPECT_NONE(cache.get(3));
+ EXPECT_SOME_EQ("b", cache.get(2));
+ EXPECT_SOME_EQ("d", cache.get(4));
+
+ // 'Put' also makes '2' MRU.
+ cache.put(2, "x");
+ cache.put(5, "e");
+ EXPECT_NONE(cache.get(4));
+ EXPECT_SOME_EQ("x", cache.get(2));
+ EXPECT_SOME_EQ("e", cache.get(5));
+
+ // 'Erase' the LRU.
+ cache.erase(2);
+ cache.put(6, "f");
+ cache.put(7, "g");
+ EXPECT_NONE(cache.get(5));
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/duration_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/duration_tests.cpp b/3rdparty/stout/tests/duration_tests.cpp
new file mode 100644
index 0000000..c2f82fb
--- /dev/null
+++ b/3rdparty/stout/tests/duration_tests.cpp
@@ -0,0 +1,146 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <stout/duration.hpp>
+#include <stout/gtest.hpp>
+#include <stout/stringify.hpp>
+#include <stout/try.hpp>
+
+
+TEST(DurationTest, Comparison)
+{
+ EXPECT_EQ(Duration::zero(), Seconds(0));
+ EXPECT_EQ(Minutes(180), Hours(3));
+ EXPECT_EQ(Seconds(10800), Hours(3));
+ EXPECT_EQ(Milliseconds(10800000), Hours(3));
+
+ EXPECT_EQ(Milliseconds(1), Microseconds(1000));
+ EXPECT_EQ(Milliseconds(1000), Seconds(1));
+
+ EXPECT_GT(Weeks(1), Days(6));
+
+ EXPECT_LT(Hours(23), Days(1));
+
+ EXPECT_LE(Hours(24), Days(1));
+ EXPECT_GE(Hours(24), Days(1));
+
+ EXPECT_NE(Minutes(59), Hours(1));
+
+ // Maintains precision for a 100 year duration.
+ EXPECT_GT(Weeks(5217) + Nanoseconds(1), Weeks(5217));
+ EXPECT_LT(Weeks(5217) - Nanoseconds(1), Weeks(5217));
+}
+
+TEST(DurationTest, ParseAndTry)
+{
+ EXPECT_SOME_EQ(Hours(3), Duration::parse("3hrs"));
+ EXPECT_SOME_EQ(Hours(3) + Minutes(30), Duration::parse("3.5hrs"));
+
+ EXPECT_SOME_EQ(Nanoseconds(3141592653), Duration::create(3.141592653));
+ // Duration can hold only 9.22337e9 seconds.
+ EXPECT_ERROR(Duration::create(10 * 1e9));
+ EXPECT_ERROR(Duration::create(-10 * 1e9));
+}
+
+TEST(DurationTest, Arithmetic)
+{
+ Duration d = Seconds(11);
+ d += Seconds(9);
+ EXPECT_EQ(Seconds(20), d);
+
+ d = Seconds(11);
+ d -= Seconds(21);
+ EXPECT_EQ(Seconds(-10), d);
+
+ d = Seconds(10);
+ d *= 2;
+ EXPECT_EQ(Seconds(20), d);
+
+ d = Seconds(10);
+ d /= 2.5;
+ EXPECT_EQ(Seconds(4), d);
+
+ EXPECT_EQ(Seconds(20), Seconds(11) + Seconds(9));
+ EXPECT_EQ(Seconds(-10), Seconds(11) - Seconds(21));
+ EXPECT_EQ(Duration::create(2.5).get(), Seconds(10) * 0.25);
+ EXPECT_EQ(Duration::create(1.25).get(), Seconds(10) / 8);
+
+ EXPECT_EQ(Duration::create(Days(11).secs() + 9).get(), Days(11) + Seconds(9));
+}
+
+
+TEST(DurationTest, OutputFormat)
+{
+ EXPECT_EQ("1ns", stringify(Nanoseconds(1)));
+ EXPECT_EQ("2ns", stringify(Nanoseconds(2)));
+
+ // Truncated. Seconds in 15 digits of precision, max of double
+ // type's precise digits.
+ EXPECT_EQ("3.141592653secs",
+ stringify(Duration::create(3.14159265358979).get()));
+ EXPECT_EQ("3140ms", stringify(Duration::create(3.14).get()));
+ EXPECT_EQ("10hrs", stringify(Hours(10)));
+ EXPECT_EQ("-10hrs", stringify(Hours(-10)));
+
+ // "10days" reads better than "1.42857142857143weeks" so it is
+ // printed out in the lower unit.
+ EXPECT_EQ("10days", stringify(Days(10)));
+ // We go one-level down and it is still not a whole number so we
+ // print it out using the higher unit.
+ EXPECT_EQ("1.1875days", stringify(Days(1) + Hours(4) + Minutes(30)));
+ // "2weeks" reads better than "14days" so we use the higher unit
+ // here.
+ EXPECT_EQ("2weeks", stringify(Days(14)));
+
+ // Boundary cases.
+ EXPECT_EQ("0ns", stringify(Duration::zero()));
+ EXPECT_EQ("15250.2844524715weeks", stringify(Duration::max()));
+ EXPECT_EQ("-15250.2844524715weeks", stringify(Duration::min()));
+}
+
+TEST(DurationTest, Timeval)
+{
+ EXPECT_EQ(Duration(timeval{10, 0}), Seconds(10));
+ EXPECT_EQ(Duration(timeval{0, 7}), Microseconds(7));
+ EXPECT_EQ(Duration(timeval{2, 123}), Seconds(2) + Microseconds(123));
+
+ timeval t{2, 123};
+ Duration d(t);
+ EXPECT_EQ(d.timeval().tv_sec, t.tv_sec);
+ EXPECT_EQ(d.timeval().tv_usec, t.tv_usec);
+
+ t.tv_usec = 0;
+ d = Duration(t);
+ EXPECT_EQ(d.timeval().tv_sec, t.tv_sec);
+ EXPECT_EQ(d.timeval().tv_usec, t.tv_usec);
+
+ // Negative times.
+ t.tv_sec = 0;
+ t.tv_usec = -1;
+ d = Duration(t);
+ EXPECT_EQ(d.timeval().tv_sec, t.tv_sec);
+ EXPECT_EQ(d.timeval().tv_usec, t.tv_usec);
+
+ d = Microseconds(-1);
+ EXPECT_EQ(d.timeval().tv_sec, t.tv_sec);
+ EXPECT_EQ(d.timeval().tv_usec, t.tv_usec);
+
+ t.tv_sec = -1;
+ t.tv_usec = -30;
+ d = Duration(t);
+ EXPECT_EQ(d.timeval().tv_sec, t.tv_sec);
+ EXPECT_EQ(d.timeval().tv_usec, t.tv_usec);
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/dynamiclibrary_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/dynamiclibrary_tests.cpp b/3rdparty/stout/tests/dynamiclibrary_tests.cpp
new file mode 100644
index 0000000..ac7352c
--- /dev/null
+++ b/3rdparty/stout/tests/dynamiclibrary_tests.cpp
@@ -0,0 +1,169 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <stout/dynamiclibrary.hpp>
+#include <stout/gtest.hpp>
+#include <stout/some.hpp>
+
+using std::string;
+
+#ifdef __linux__
+static const string valid_library_path = "libdl.so";
+#elif defined(__FreeBSD__)
+static const string valid_library_path = "libc.so.7";
+#elif defined(__WINDOWS__)
+static const string valid_library_path = "ntdll.dll";
+#else
+static const string valid_library_path = "libdl.dylib";
+#endif
+
+#ifdef __WINDOWS__
+static const string valid_symbol = "NtOpenProcess";
+#else
+static const string valid_symbol = "dlopen";
+#endif
+
+static const string invalid_symbol = "InvalidSymbol";
+static const string invalid_library_path = "InvalidLibraryPath";
+
+
+// Successful `open`, load symbol, `close`.
+TEST(DynamicLibraryTest, LoadKnownSymbol)
+{
+ DynamicLibrary dltest;
+
+ EXPECT_SOME(dltest.open(valid_library_path));
+ EXPECT_SOME(dltest.loadSymbol(valid_symbol));
+ EXPECT_SOME(dltest.close());
+}
+
+
+// Successful `open`, fail to load nonsense symbol, `close`.
+TEST(DynamicLibraryTest, FailToLoadInvalidSymbol)
+{
+ DynamicLibrary dltest;
+
+ EXPECT_SOME(dltest.open(valid_library_path));
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+ EXPECT_SOME(dltest.close());
+}
+
+
+// Verify that `loadSymbol` and `close` fail if we don't call `open` first.
+TEST(DynamicLibraryTest, CloseAndLoadSymbolFailWithoutOpeningLib)
+{
+ DynamicLibrary dltest;
+
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+ EXPECT_ERROR(dltest.close());
+}
+
+
+// Verify we can open a library and load a symbol. Then close, verify that we
+// can't load the symbol. Then open and verify we can load symbol again, just
+// to be safe.
+TEST(DynamicLibraryTest, VerifyClose)
+{
+ DynamicLibrary dltest;
+
+ EXPECT_SOME(dltest.open(valid_library_path));
+ EXPECT_SOME(dltest.loadSymbol(valid_symbol));
+ EXPECT_SOME(dltest.close());
+
+ EXPECT_ERROR(dltest.loadSymbol(valid_symbol));
+
+ EXPECT_SOME(dltest.open(valid_library_path));
+ EXPECT_SOME(dltest.loadSymbol(valid_symbol));
+ EXPECT_SOME(dltest.close());
+}
+
+
+// Attempt to load invalid lib path, verify failure, as well as failures when
+// we try to call `loadSymbol` and `close`.
+TEST(DynamicLibraryTest, FailToLoadInvalidLibPath)
+{
+ DynamicLibrary dltest;
+
+ EXPECT_ERROR(dltest.open(invalid_library_path));
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+ EXPECT_ERROR(dltest.close());
+}
+
+
+// Attempt to `open` invalid lib path _twice_, verify failure, then verify
+// failure when we call `loadSymbol` and `close`.
+TEST(DynamicLibraryTest, DoubleFailOpen)
+{
+ DynamicLibrary dltest;
+
+ EXPECT_ERROR(dltest.open(invalid_library_path));
+ EXPECT_ERROR(dltest.open(invalid_library_path));
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+ EXPECT_ERROR(dltest.close());
+}
+
+
+// `open` valid library, load symbol, then verify we fail when we try to open
+// the library again; verify we can still load symbols from, and `close`, the
+// original library.
+TEST(DynamicLibraryTest, OpenSuccessThenOpenFail)
+{
+ DynamicLibrary dltest;
+
+ // `open`, successfully load symbol.
+ EXPECT_SOME(dltest.open(valid_library_path));
+ EXPECT_SOME(dltest.loadSymbol(valid_symbol));
+
+ // `open` same path again, fail, but successfully load known symbol; fail to
+ // load nonsense symbol.
+ EXPECT_ERROR(dltest.open(valid_library_path));
+ EXPECT_SOME(dltest.loadSymbol(valid_symbol));
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+
+ // `open` different (invalid) path, fail, but successfully load known symbol;
+ // fail to load nonsense symbol.
+ EXPECT_ERROR(dltest.open(invalid_library_path));
+ EXPECT_SOME(dltest.loadSymbol(valid_symbol));
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+
+ // Finally, successfully `close`.
+ EXPECT_SOME(dltest.close());
+}
+
+
+// Attempt to `open` invalid lib, verify we can't load symbols from it, then
+// open valid lib, and verify we can load symbols from, and `close` it.
+TEST(DynamicLibraryTest, OpenFailThenOpenSuccess)
+{
+ DynamicLibrary dltest;
+
+ // Fail to `open`, then fail load nonsense symbols.
+ EXPECT_ERROR(dltest.open(invalid_library_path));
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+
+ // `open` valid path, succeed, then successfully load known symbol; fail to
+ // load nonsense symbol.
+ EXPECT_SOME(dltest.open(valid_library_path));
+ EXPECT_SOME(dltest.loadSymbol(valid_symbol));
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+
+ // `open` different (invalid) path, fail, but successfully load known symbol;
+ // fail to load nonsense symbol.
+ EXPECT_ERROR(dltest.open(invalid_library_path));
+ EXPECT_SOME(dltest.loadSymbol(valid_symbol));
+ EXPECT_ERROR(dltest.loadSymbol(invalid_symbol));
+
+ // Finally, successfully `close`.
+ EXPECT_SOME(dltest.close());
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/error_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/error_tests.cpp b/3rdparty/stout/tests/error_tests.cpp
new file mode 100644
index 0000000..25b5014
--- /dev/null
+++ b/3rdparty/stout/tests/error_tests.cpp
@@ -0,0 +1,73 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <stout/error.hpp>
+#include <stout/gtest.hpp>
+#include <stout/option.hpp>
+#include <stout/result.hpp>
+#include <stout/try.hpp>
+
+using std::string;
+
+
+Error error1()
+{
+ return Error("Failed to ...");
+}
+
+
+Try<string> error2()
+{
+ return Error("Failed to ...");
+}
+
+
+Try<string> error3(const Try<string>& t)
+{
+ return t;
+}
+
+
+Result<string> error4()
+{
+ return Error("Failed to ...");
+}
+
+
+Result<string> error5(const Result<string>& r)
+{
+ return r;
+}
+
+
+TEST(ErrorTest, Test)
+{
+ Try<string> t = error1();
+ EXPECT_ERROR(t);
+ t = error2();
+ EXPECT_ERROR(t);
+ t = error3(error1());
+ EXPECT_ERROR(t);
+
+ Result<string> r = error1();
+ EXPECT_ERROR(r);
+ r = error4();
+ EXPECT_ERROR(r);
+ r = error5(error1());
+ EXPECT_ERROR(r);
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/flags_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/flags_tests.cpp b/3rdparty/stout/tests/flags_tests.cpp
new file mode 100644
index 0000000..66e16ab
--- /dev/null
+++ b/3rdparty/stout/tests/flags_tests.cpp
@@ -0,0 +1,753 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <map>
+#include <string>
+
+#include <gmock/gmock.h>
+
+#include <stout/duration.hpp>
+#include <stout/flags.hpp>
+#include <stout/foreach.hpp>
+#include <stout/gtest.hpp>
+#include <stout/json.hpp>
+#include <stout/none.hpp>
+#include <stout/nothing.hpp>
+#include <stout/option.hpp>
+#include <stout/os.hpp>
+#include <stout/path.hpp>
+#include <stout/some.hpp>
+#include <stout/utils.hpp>
+
+#include <stout/tests/utils.hpp>
+
+using flags::Flag;
+using flags::Flags;
+using flags::FlagsBase;
+
+using std::cout;
+using std::endl;
+using std::string;
+using std::map;
+
+using utils::arraySize;
+
+// Just used to test that the default implementation
+// of --help and 'usage()' works as intended.
+class EmptyFlags : public FlagsBase {};
+
+
+class TestFlags : public virtual FlagsBase
+{
+public:
+ TestFlags()
+ {
+ add(&TestFlags::name1,
+ "name1",
+ "Set name1",
+ "ben folds");
+
+ add(&TestFlags::name2,
+ "name2",
+ "Set name2",
+ 42);
+
+ add(&TestFlags::name3,
+ "name3",
+ "Set name3",
+ false);
+
+ add(&TestFlags::name4,
+ "name4",
+ "Set name4");
+
+ add(&TestFlags::name5,
+ "name5",
+ "Set name5");
+ }
+
+ string name1;
+ int name2;
+ bool name3;
+ Option<bool> name4;
+ Option<bool> name5;
+};
+
+
+TEST(FlagsTest, Load)
+{
+ TestFlags flags;
+
+ const map<string, Option<string> > values = {
+ {"name1", Some("billy joel")},
+ {"name2", Some("43")},
+ {"name3", Some("false")},
+ {"no-name4", None()},
+ {"name5", None()}
+ };
+
+ flags.load(values);
+
+ EXPECT_EQ("billy joel", flags.name1);
+ EXPECT_EQ(43, flags.name2);
+ EXPECT_FALSE(flags.name3);
+ ASSERT_SOME(flags.name4);
+ EXPECT_FALSE(flags.name4.get());
+ ASSERT_SOME(flags.name5);
+ EXPECT_TRUE(flags.name5.get());
+}
+
+
+TEST(FlagsTest, Add)
+{
+ Flags<TestFlags> flags;
+
+ Option<string> name6;
+
+ flags.add(&name6,
+ "name6",
+ "Also set name6");
+
+ bool name7;
+
+ flags.add(&name7,
+ "name7",
+ "Also set name7",
+ true);
+
+ Option<string> name8;
+
+ flags.add(&name8,
+ "name8",
+ "Also set name8");
+
+ Option<string> name9;
+
+ flags.add(&name9,
+ "name9",
+ "Also set name9");
+
+ const map<string, Option<string> > values = {
+ {"name6", Some("ben folds")},
+ {"no-name7", None()},
+ {"name9", Some("")}
+ };
+
+ flags.load(values);
+
+ ASSERT_SOME(name6);
+ EXPECT_EQ("ben folds", name6.get());
+
+ EXPECT_FALSE(name7);
+
+ EXPECT_NONE(name8);
+
+ ASSERT_SOME(name9);
+ EXPECT_EQ("", name9.get());
+}
+
+
+TEST(FlagsTest, Flags)
+{
+ TestFlags flags;
+
+ const map<string, Option<string> > values = {
+ {"name1", Some("billy joel")},
+ {"name2", Some("43")},
+ {"name3", Some("false")},
+ {"no-name4", None()},
+ {"name5", None()}
+ };
+
+ flags.load(values);
+
+ EXPECT_EQ("billy joel", flags.name1);
+ EXPECT_EQ(43, flags.name2);
+ EXPECT_FALSE(flags.name3);
+ ASSERT_SOME(flags.name4);
+ EXPECT_FALSE(flags.name4.get());
+ ASSERT_SOME(flags.name5);
+ EXPECT_TRUE(flags.name5.get());
+}
+
+
+TEST(FlagsTest, LoadFromEnvironment)
+{
+ TestFlags flags;
+
+ os::setenv("FLAGSTEST_name1", "billy joel");
+ os::setenv("FLAGSTEST_name2", "43");
+ os::setenv("FLAGSTEST_no-name3", "");
+ os::setenv("FLAGSTEST_no-name4", "");
+ os::setenv("FLAGSTEST_name5", "");
+
+ Try<Nothing> load = flags.load("FLAGSTEST_");
+ EXPECT_SOME(load);
+
+ EXPECT_EQ("billy joel", flags.name1);
+ EXPECT_EQ(43, flags.name2);
+ EXPECT_FALSE(flags.name3);
+ ASSERT_SOME(flags.name4);
+ EXPECT_FALSE(flags.name4.get());
+ ASSERT_SOME(flags.name5);
+ EXPECT_TRUE(flags.name5.get());
+
+ os::unsetenv("FLAGSTEST_name1");
+ os::unsetenv("FLAGSTEST_name2");
+ os::unsetenv("FLAGSTEST_no-name3");
+ os::unsetenv("FLAGSTEST_no-name4");
+ os::unsetenv("FLAGSTEST_name5");
+}
+
+
+TEST(FlagsTest, LoadFromCommandLine)
+{
+ TestFlags flags;
+
+ const char* argv[] = {
+ "/path/to/program",
+ "--name1=billy joel",
+ "--name2=43",
+ "--no-name3",
+ "--no-name4",
+ "--name5"
+ };
+
+ Try<Nothing> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
+ EXPECT_SOME(load);
+
+ EXPECT_EQ("billy joel", flags.name1);
+ EXPECT_EQ(43, flags.name2);
+ EXPECT_FALSE(flags.name3);
+ ASSERT_SOME(flags.name4);
+ EXPECT_FALSE(flags.name4.get());
+ ASSERT_SOME(flags.name5);
+ EXPECT_TRUE(flags.name5.get());
+}
+
+
+TEST(FlagsTest, LoadFromCommandLineWithNonFlags)
+{
+ TestFlags flags;
+
+ const char* argv[] = {
+ "/path/to/program",
+ "more",
+ "--name1=billy joel",
+ "stuff",
+ "at",
+ "--name2=43",
+ "--no-name3",
+ "--no-name4",
+ "--name5",
+ "the",
+ "end"
+ };
+
+ Try<Nothing> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
+ EXPECT_SOME(load);
+
+ EXPECT_EQ("billy joel", flags.name1);
+ EXPECT_EQ(43, flags.name2);
+ EXPECT_FALSE(flags.name3);
+ ASSERT_SOME(flags.name4);
+ EXPECT_FALSE(flags.name4.get());
+ ASSERT_SOME(flags.name5);
+ EXPECT_TRUE(flags.name5.get());
+}
+
+
+TEST(FlagsTest, LoadFromCommandLineWithDashDash)
+{
+ TestFlags flags;
+
+ const char* argv[] = {
+ "/path/to/program",
+ "more",
+ "--name1=billy joel",
+ "stuff",
+ "at",
+ "--name2=43",
+ "--no-name3",
+ "--",
+ "--no-name4",
+ "--name5",
+ "the"
+ };
+
+ Try<Nothing> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
+ EXPECT_SOME(load);
+
+ EXPECT_EQ("billy joel", flags.name1);
+ EXPECT_EQ(43, flags.name2);
+ EXPECT_FALSE(flags.name3);
+ ASSERT_NONE(flags.name4);
+ ASSERT_NONE(flags.name5);
+}
+
+
+TEST(FlagsTest, LoadFromCommandLineAndUpdateArgcArgv)
+{
+ TestFlags flags;
+
+ char* argv[] = {
+ (char*)"/path/to/program",
+ (char*)"more",
+ (char*)"--name1=billy joel",
+ (char*)"stuff",
+ (char*)"at",
+ (char*)"--name2=43",
+ (char*)"--no-name3",
+ (char*)"--",
+ (char*)"--no-name4",
+ (char*)"--name5",
+ (char*)"the"
+ };
+ int argc = arraySize(argv);
+
+ // Need a temporary since some compilers want to treat the type of
+ // 'argv' as 'char *(*)[argc]' since the size of the array is known.
+ char** _argv = argv;
+
+ Try<Nothing> load = flags.load("FLAGSTEST_", &argc, &_argv);
+ EXPECT_SOME(load);
+
+ EXPECT_EQ("billy joel", flags.name1);
+ EXPECT_EQ(43, flags.name2);
+ EXPECT_FALSE(flags.name3);
+ ASSERT_NONE(flags.name4);
+ ASSERT_NONE(flags.name5);
+
+ EXPECT_EQ(7, argc);
+ EXPECT_STREQ("/path/to/program", argv[0]);
+ EXPECT_STREQ("more", argv[1]);
+ EXPECT_STREQ("stuff", argv[2]);
+ EXPECT_STREQ("at", argv[3]);
+ EXPECT_STREQ("--no-name4", argv[4]);
+ EXPECT_STREQ("--name5", argv[5]);
+ EXPECT_STREQ("the", argv[6]);
+ EXPECT_EQ(NULL, argv[7]);
+}
+
+
+TEST(FlagsTest, Stringification)
+{
+ TestFlags flags;
+
+ Duration name6;
+
+ flags.add(&name6,
+ "name6",
+ "Also set name6",
+ Milliseconds(42));
+
+ Option<bool> name7;
+
+ flags.add(&name7,
+ "name7",
+ "Optional name7");
+
+ Option<bool> name8;
+
+ flags.add(&name8,
+ "name8",
+ "Optional name8");
+
+ const map<string, Option<string> > values = {
+ {"name2", Some("43")},
+ {"no-name4", None()},
+ {"name5", None()}
+ };
+
+ flags.load(values);
+
+ foreachpair (const string& name, const Flag& flag, flags) {
+ Option<string> value = flag.stringify(flags);
+ if (name == "name1") {
+ ASSERT_SOME(value);
+ EXPECT_EQ("ben folds", value.get());
+ } else if (name == "name2") {
+ ASSERT_SOME(value);
+ EXPECT_EQ("43", value.get());
+ } else if (name == "name3") {
+ ASSERT_SOME(value);
+ EXPECT_EQ("false", value.get());
+ } else if (name == "name4") {
+ ASSERT_SOME(value);
+ EXPECT_EQ("false", value.get());
+ } else if (name == "name5") {
+ ASSERT_SOME(value);
+ EXPECT_EQ("true", value.get());
+ } else if (name == "name6") {
+ ASSERT_SOME(value);
+ EXPECT_EQ("42ms", value.get());
+ } else if (name == "name7") {
+ ASSERT_NONE(value);
+ } else if (name == "name8") {
+ ASSERT_NONE(value);
+ }
+ }
+}
+
+
+TEST(FlagsTest, DuplicatesFromEnvironment)
+{
+ TestFlags flags;
+
+ os::setenv("FLAGSTEST_name1", "ben folds");
+
+ const char* argv[] = {
+ "/path/to/program",
+ "--name1=billy joel"
+ };
+
+ Try<Nothing> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
+ EXPECT_SOME(load);
+
+ // The environment variables are overwritten by command line flags.
+ EXPECT_EQ(flags.name1, "billy joel");
+
+ os::unsetenv("FLAGSTEST_name1");
+}
+
+
+TEST(FlagsTest, DuplicatesFromCommandLine)
+{
+ TestFlags flags;
+
+ const char* argv[] = {
+ "/path/to/program",
+ "--name1=billy joel",
+ "--name1=ben folds"
+ };
+
+ // TODO(klaus1982): Simply checking for the error. Once typed errors are
+ // introduced, capture it within the type system.
+ Try<Nothing> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
+ EXPECT_ERROR(load);
+}
+
+
+TEST(FlagsTest, Errors)
+{
+ TestFlags flags;
+
+ int argc = 2;
+ char* argv[argc];
+
+ argv[0] = (char*) "/path/to/program";
+
+ // Test an unknown flag.
+ argv[1] = (char*) "--foo";
+
+ Try<Nothing> load = flags.load("FLAGSTEST_", argc, argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Failed to load unknown flag 'foo'", load.error());
+
+ // Now try an unknown flag with a value.
+ argv[1] = (char*) "--foo=value";
+
+ load = flags.load("FLAGSTEST_", argc, argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Failed to load unknown flag 'foo'", load.error());
+
+ // Now try an unknown flag with a 'no-' prefix.
+ argv[1] = (char*) "--no-foo";
+
+ load = flags.load("FLAGSTEST_", argc, argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Failed to load unknown flag 'foo' via 'no-foo'", load.error());
+
+ // Now test a boolean flag using the 'no-' prefix _and_ a value.
+ argv[1] = (char*) "--no-name3=value";
+
+ load = flags.load("FLAGSTEST_", argc, argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Failed to load boolean flag 'name3' via "
+ "'no-name3' with value 'value'", load.error());
+
+ // Now test a boolean flag that couldn't be parsed.
+ argv[1] = (char*) "--name3=value";
+
+ load = flags.load("FLAGSTEST_", argc, argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Failed to load flag 'name3': Failed to load value 'value': "
+ "Expecting a boolean (e.g., true or false)", load.error());
+
+ // Now test a non-boolean flag without a value.
+ argv[1] = (char*) "--name1";
+
+ load = flags.load("FLAGSTEST_", argc, argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Failed to load non-boolean flag 'name1': "
+ "Missing value", load.error());
+
+ // Now test a non-boolean flag using the 'no-' prefix.
+ argv[1] = (char*) "--no-name2";
+
+ load = flags.load("FLAGSTEST_", argc, argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Failed to load non-boolean flag 'name2' "
+ "via 'no-name2'", load.error());
+
+ Option<int> name6;
+ flags.add(&name6, "name6", "Also set name6");
+
+ // Now test a non-boolean flag using empty string value.
+ argv[1] = (char*) "--name6=";
+
+ load = flags.load("FLAGSTEST_", argc, argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Failed to load flag 'name6': Failed to load value '': "
+ "Failed to convert into required type", load.error());
+}
+
+
+TEST(FlagsTest, Validate)
+{
+ // To provide validation functions.
+ class ValidatingTestFlags : public TestFlags
+ {
+ public:
+ ValidatingTestFlags()
+ {
+ add(&duration,
+ "duration",
+ "Duration to test validation",
+ Seconds(10),
+ [](const Duration& value) -> Option<Error> {
+ if (value > Hours(1)) {
+ return Error("Expected --duration to be less than 1 hour");
+ }
+ return None();
+ });
+ }
+
+ Duration duration;
+ };
+
+ ValidatingTestFlags flags;
+
+ const char* argv[] = {
+ "/path/to/program",
+ "--duration=2hrs"
+ };
+
+ Try<Nothing> load = flags.load("FLAGSTEST_", arraySize(argv), argv);
+ EXPECT_ERROR(load);
+
+ EXPECT_EQ("Expected --duration to be less than 1 hour", load.error());
+}
+
+
+TEST(FlagsTest, UsageMessage)
+{
+ TestFlags flags;
+ flags.setUsageMessage("This is a test");
+
+ EXPECT_EQ(
+ "This is a test\n"
+ "\n"
+ " --[no-]help Prints this help message (default: false)\n"
+ " --name1=VALUE Set name1 (default: ben folds)\n"
+ " --name2=VALUE Set name2 (default: 42)\n"
+ " --[no-]name3 Set name3 (default: false)\n"
+ " --[no-]name4 Set name4\n"
+ " --[no-]name5 Set name5\n",
+ flags.usage());
+}
+
+
+TEST(FlagsTest, EmptyUsage)
+{
+ EmptyFlags flags;
+
+ EXPECT_EQ(
+ "Usage: [options]\n"
+ "\n"
+ " --[no-]help Prints this help message (default: false)\n",
+ flags.usage());
+}
+
+
+TEST(FlagsTest, ProgramName)
+{
+ // To test with a custom program name.
+ class MyTestFlags : public TestFlags
+ {
+ public:
+ MyTestFlags() { programName_ = "TestProgram"; }
+ };
+
+
+ MyTestFlags flags;
+
+ EXPECT_EQ(
+ "Usage: TestProgram [options]\n"
+ "\n"
+ " --[no-]help Prints this help message (default: false)\n"
+ " --name1=VALUE Set name1 (default: ben folds)\n"
+ " --name2=VALUE Set name2 (default: 42)\n"
+ " --[no-]name3 Set name3 (default: false)\n"
+ " --[no-]name4 Set name4\n"
+ " --[no-]name5 Set name5\n",
+ flags.usage());
+}
+
+
+TEST(FlagsTest, OptionalMessage)
+{
+ TestFlags flags;
+
+ EXPECT_EQ(
+ "Good news: this test passed!\n"
+ "\n"
+ "Usage: [options]\n"
+ "\n"
+ " --[no-]help Prints this help message (default: false)\n"
+ " --name1=VALUE Set name1 (default: ben folds)\n"
+ " --name2=VALUE Set name2 (default: 42)\n"
+ " --[no-]name3 Set name3 (default: false)\n"
+ " --[no-]name4 Set name4\n"
+ " --[no-]name5 Set name5\n",
+ flags.usage("Good news: this test passed!"));
+}
+
+
+TEST(FlagsTest, Duration)
+{
+ Flags<TestFlags> flags;
+
+ Duration name6;
+
+ flags.add(&name6,
+ "name6",
+ "Amount of time",
+ Milliseconds(100));
+
+ Option<Duration> name7;
+
+ flags.add(&name7,
+ "name7",
+ "Also some amount of time");
+
+ const map<string, Option<string> > values = {
+ {"name6", Some("2mins")},
+ {"name7", Some("3hrs")}
+ };
+
+ ASSERT_SOME(flags.load(values));
+
+ EXPECT_EQ(Minutes(2), name6);
+
+ EXPECT_SOME_EQ(Hours(3), name7);
+}
+
+
+TEST(FlagsTest, JSON)
+{
+ Flags<TestFlags> flags;
+
+ Option<JSON::Object> json;
+
+ flags.add(&json,
+ "json",
+ "JSON string");
+
+ JSON::Object object;
+
+ object.values["strings"] = "string";
+ object.values["integer"] = 1;
+ object.values["double"] = -1.42;
+
+ JSON::Object nested;
+ nested.values["string"] = "string";
+
+ object.values["nested"] = nested;
+
+ map<string, Option<string> > values;
+ values["json"] = Some(stringify(object));
+
+ ASSERT_SOME(flags.load(values));
+
+ ASSERT_SOME_EQ(object, json);
+}
+
+
+class FlagsFileTest : public TemporaryDirectoryTest {};
+
+
+TEST_F(FlagsFileTest, JSONFile)
+{
+ Flags<TestFlags> flags;
+
+ Option<JSON::Object> json;
+
+ flags.add(&json,
+ "json",
+ "JSON string");
+
+ JSON::Object object;
+
+ object.values["strings"] = "string";
+ object.values["integer"] = 1;
+ object.values["double"] = -1.42;
+
+ JSON::Object nested;
+ nested.values["string"] = "string";
+
+ object.values["nested"] = nested;
+
+ // Write the JSON to a file.
+ const string file = path::join(os::getcwd(), "file.json");
+ ASSERT_SOME(os::write(file, stringify(object)));
+
+ // Read the JSON from the file.
+ map<string, Option<string> > values;
+ values["json"] = Some(file);
+
+ ASSERT_SOME(flags.load(values));
+
+ ASSERT_SOME_EQ(object, json);
+}
+
+
+TEST_F(FlagsFileTest, FilePrefix)
+{
+ Flags<TestFlags> flags;
+
+ Option<string> something;
+
+ flags.add(&something,
+ "something",
+ "arg to be loaded from file");
+
+ // Write the JSON to a file.
+ const string file = path::join(os::getcwd(), "file");
+ ASSERT_SOME(os::write(file, "testing"));
+
+ // Read the JSON from the file.
+ map<string, Option<string> > values;
+ values["something"] = Some("file://" + file);
+
+ ASSERT_SOME(flags.load(values));
+
+ ASSERT_SOME_EQ("testing", something);
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/gzip_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/gzip_tests.cpp b/3rdparty/stout/tests/gzip_tests.cpp
new file mode 100644
index 0000000..814fb99
--- /dev/null
+++ b/3rdparty/stout/tests/gzip_tests.cpp
@@ -0,0 +1,65 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <string>
+
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+#include <stout/gtest.hpp>
+#include <stout/gzip.hpp>
+
+using std::string;
+
+
+#ifdef HAVE_LIBZ
+TEST(GzipTest, CompressDecompressString)
+{
+ // Test bad compression levels, outside of [-1, Z_BEST_COMPRESSION].
+ ASSERT_ERROR(gzip::compress("", -2));
+ ASSERT_ERROR(gzip::compress("", Z_BEST_COMPRESSION + 1));
+
+ string s =
+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
+ "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad "
+ "minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
+ "aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit "
+ "in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "
+ "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui "
+ "officia deserunt mollit anim id est laborum.";
+
+ Try<string> compressed = gzip::compress(s);
+ ASSERT_SOME(compressed);
+ Try<string> decompressed = gzip::decompress(compressed.get());
+ ASSERT_SOME(decompressed);
+ ASSERT_EQ(s, decompressed.get());
+
+ // Test with a 1MB random string!
+ s = "";
+ while (s.length() < (1024 * 1024)) {
+ s.append(1, ' ' + (rand() % ('~' - ' ')));
+ }
+ compressed = gzip::compress(s);
+ ASSERT_SOME(compressed);
+ decompressed = gzip::decompress(compressed.get());
+ ASSERT_SOME(decompressed);
+ ASSERT_EQ(s, decompressed.get());
+
+ s = "";
+ compressed = gzip::compress(s);
+ ASSERT_SOME(compressed);
+ decompressed = gzip::decompress(compressed.get());
+ ASSERT_SOME(decompressed);
+ ASSERT_EQ(s, decompressed.get());
+}
+#endif // HAVE_LIBZ
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/hashmap_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/hashmap_tests.cpp b/3rdparty/stout/tests/hashmap_tests.cpp
new file mode 100644
index 0000000..2626d67
--- /dev/null
+++ b/3rdparty/stout/tests/hashmap_tests.cpp
@@ -0,0 +1,149 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <ctype.h>
+
+#include <map>
+#include <string>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <boost/functional/hash.hpp>
+
+#include <stout/gtest.hpp>
+#include <stout/hashmap.hpp>
+
+using std::string;
+
+
+TEST(HashMapTest, InitializerList)
+{
+ hashmap<string, int> map{{"hello", 1}};
+ EXPECT_EQ(1, map.size());
+
+ EXPECT_TRUE((hashmap<int, int>{}.empty()));
+
+ hashmap<int, int> map2{{1, 2}, {2, 3}, {3, 4}};
+ EXPECT_EQ(3, map2.size());
+ EXPECT_SOME_EQ(2, map2.get(1));
+ EXPECT_SOME_EQ(3, map2.get(2));
+ EXPECT_SOME_EQ(4, map2.get(3));
+ EXPECT_NONE(map2.get(4));
+}
+
+
+TEST(HashMapTest, FromStdMap)
+{
+ std::map<int, int> map1{{1, 2}, {2, 3}};
+
+ hashmap<int, int> map2(map1);
+
+ EXPECT_EQ(2, map1.size());
+ EXPECT_EQ(2, map2.size());
+
+ EXPECT_EQ(2, map1[1]);
+ EXPECT_SOME_EQ(2, map2.get(1));
+
+ EXPECT_EQ(3, map1[2]);
+ EXPECT_SOME_EQ(3, map2.get(2));
+}
+
+
+TEST(HashMapTest, FromRValueStdMap)
+{
+ std::map<int, int> map1{{1, 2}, {2, 3}};
+
+ hashmap<int, int> map2(std::move(map1));
+
+ EXPECT_EQ(2, map1.size());
+
+ EXPECT_EQ(2, map1[1]);
+
+ EXPECT_EQ(3, map1[2]);
+}
+
+
+TEST(HashMapTest, Insert)
+{
+ hashmap<string, int> map;
+ map["abc"] = 1;
+ map.put("def", 2);
+
+ ASSERT_SOME_EQ(1, map.get("abc"));
+ ASSERT_SOME_EQ(2, map.get("def"));
+
+ map.put("def", 4);
+ ASSERT_SOME_EQ(4, map.get("def"));
+ ASSERT_EQ(2, map.size());
+}
+
+
+TEST(HashMapTest, Contains)
+{
+ hashmap<string, int> map;
+ map["abc"] = 1;
+
+ ASSERT_TRUE(map.contains("abc"));
+ ASSERT_TRUE(map.containsValue(1));
+
+ ASSERT_FALSE(map.contains("def"));
+ ASSERT_FALSE(map.containsValue(2));
+}
+
+
+TEST(HashMapTest, CustomHashAndEqual)
+{
+ struct CaseInsensitiveHash
+ {
+ size_t operator()(const string& key) const
+ {
+ size_t seed = 0;
+ foreach (const char c, key) {
+ boost::hash_combine(seed, ::tolower(c));
+ }
+ return seed;
+ }
+ };
+
+ struct CaseInsensitiveEqual
+ {
+ bool operator()(const string& left, const string& right) const
+ {
+ if (left.size() != right.size()) {
+ return false;
+ }
+ for (size_t i = 0; i < left.size(); ++i) {
+ if (::tolower(left[i]) != ::tolower(right[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+ };
+
+ hashmap<string, int, CaseInsensitiveHash, CaseInsensitiveEqual> map;
+
+ map["abc"] = 1;
+ map.put("def", 2);
+ EXPECT_SOME_EQ(1, map.get("Abc"));
+ EXPECT_SOME_EQ(2, map.get("dEf"));
+
+ map.put("Abc", 3);
+ map["DEF"] = 4;
+ EXPECT_SOME_EQ(3, map.get("abc"));
+ EXPECT_SOME_EQ(4, map.get("def"));
+
+ EXPECT_EQ(2, map.size());
+ EXPECT_TRUE(map.contains("abc"));
+ EXPECT_TRUE(map.contains("aBc"));
+}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c235f7c1/3rdparty/stout/tests/hashset_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/hashset_tests.cpp b/3rdparty/stout/tests/hashset_tests.cpp
new file mode 100644
index 0000000..66e59db
--- /dev/null
+++ b/3rdparty/stout/tests/hashset_tests.cpp
@@ -0,0 +1,158 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License
+
+#include <string>
+#include <utility>
+
+#include <boost/functional/hash.hpp>
+
+#include <stout/hashset.hpp>
+
+#include <gtest/gtest.h>
+
+#include <gmock/gmock.h>
+
+using std::string;
+
+
+TEST(HashsetTest, InitializerList)
+{
+ hashset<string> set{"hello"};
+ EXPECT_EQ(1, set.size());
+
+ EXPECT_TRUE((hashset<int>{}.empty()));
+
+ hashset<int> set1{1, 3, 5, 7, 11};
+ EXPECT_EQ(5, set1.size());
+ EXPECT_TRUE(set1.contains(1));
+ EXPECT_TRUE(set1.contains(3));
+ EXPECT_TRUE(set1.contains(5));
+ EXPECT_TRUE(set1.contains(7));
+ EXPECT_TRUE(set1.contains(11));
+
+ EXPECT_FALSE(set1.contains(2));
+}
+
+
+TEST(HashsetTest, FromStdSet)
+{
+ std::set<int> set1{1, 3, 5, 7};
+
+ hashset<int> set2(set1);
+
+ EXPECT_EQ(set1.size(), set2.size());
+ EXPECT_EQ(4, set2.size());
+
+ foreach (const auto set1_entry, set1) {
+ EXPECT_TRUE(set2.contains(set1_entry));
+ }
+}
+
+
+TEST(HashsetTest, FromRValueStdSet)
+{
+ std::set<int> set1{1, 3};
+
+ hashset<int> set2(std::move(set1));
+
+ EXPECT_EQ(2, set2.size());
+
+ EXPECT_TRUE(set2.contains(1));
+ EXPECT_TRUE(set2.contains(3));
+
+ EXPECT_FALSE(set2.contains(2));
+}
+
+
+TEST(HashsetTest, CustomHashAndEqual)
+{
+ struct CaseInsensitiveHash
+ {
+ size_t operator()(const string& key) const
+ {
+ size_t seed = 0;
+ foreach (const char c, key) {
+ boost::hash_combine(seed, ::tolower(c));
+ }
+ return seed;
+ }
+ };
+
+ struct CaseInsensitiveEqual
+ {
+ bool operator()(const string& left, const string& right) const
+ {
+ if (left.size() != right.size()) {
+ return false;
+ }
+ for (size_t i = 0; i < left.size(); ++i) {
+ if (::tolower(left[i]) != ::tolower(right[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+ };
+
+ hashset<string, CaseInsensitiveHash, CaseInsensitiveEqual> set;
+
+ set.insert("abc");
+ set.insert("def");
+ EXPECT_TRUE(set.contains("Abc"));
+ EXPECT_TRUE(set.contains("dEf"));
+
+ EXPECT_EQ(2, set.size());
+ set.insert("Abc");
+ set.insert("DEF");
+ EXPECT_EQ(2, set.size());
+ EXPECT_TRUE(set.contains("abc"));
+ EXPECT_TRUE(set.contains("def"));
+}
+
+
+TEST(HashsetTest, Insert)
+{
+ hashset<string> hs1;
+ hs1.insert(string("HS1"));
+ hs1.insert(string("HS3"));
+
+ hashset<string> hs2;
+ hs2.insert(string("HS2"));
+
+ hs1 = hs2;
+ ASSERT_EQ(1u, hs1.size());
+ ASSERT_TRUE(hs1.contains("HS2"));
+ ASSERT_TRUE(hs1 == hs2);
+}
+
+
+TEST(HashsetTest, Union)
+{
+ hashset<int> hs1;
+ hs1.insert(1);
+ hs1.insert(2);
+ hs1.insert(3);
+
+ hashset<int> hs2;
+ hs2.insert(3);
+ hs2.insert(4);
+ hs2.insert(5);
+
+ hashset<int> hs3 = hs1 | hs2;
+
+ ASSERT_EQ(5u, hs3.size());
+ ASSERT_TRUE(hs3.contains(1));
+ ASSERT_TRUE(hs3.contains(2));
+ ASSERT_TRUE(hs3.contains(3));
+ ASSERT_TRUE(hs3.contains(4));
+ ASSERT_TRUE(hs3.contains(5));
+}