Пример #1
0
static int
run_test (int, char*[])
{
    test_mismatch (0);

    if (rw_opt_no_predicate) {
        rw_note (0, __FILE__, __LINE__, "Predicate test disabled");
    }
    else {
        test_mismatch ("std::equal_to<UserClass>");
    }

    return 0;
}
Пример #2
0
static int
run_test (int, char*[])
{
    test_adjacent_find (0);

    if (rw_opt_no_predicate) {
        rw_note (0, __FILE__, __LINE__, "Predicate test disabled");
    }
    else {
        test_adjacent_find ("std::equal_to<X>");
    }
                
    return 0;
}
Пример #3
0
static int
run_test (int /* argc */, char** /* argv */)
{
    rw_info (0, 0, 0, "std::vector<UserClass>::capacity() const");
    rw_info (0, 0, 0, "std::vector<UserClass>::reserve(size_type)");

    const Vector::size_type max_elems = Vector::size_type (rw_opt_nloops);

    rw_note (0 == rw_opt_no_exceptions, 0, 0, "exception test disabled");

    for (Vector::size_type i = 0; i < max_elems; ++i) {
        test_capacity (i);
    }

    return 0;
}
Пример #4
0
static int
run_test (int, char**)
{
    //////////////////////////////////////////////////////////////////
    rw_info (0, 0, 0, "checking for the absence of masking macros");

    // verify the shadow macros are not #defined (explicitly
    // disallowed by 17.4.1.2, p6 and Footnote 159 of C++ '03)
    for (unsigned i = 0; cctype_macros [i]; ++i) {
        rw_assert ('\0' == cctype_macros [i][0], 0, 0,
                   "macro %s unexpectedly #defined", cctype_macros [i]);
    }

    //////////////////////////////////////////////////////////////////
    // verify that each function is defined
#define TEST(function)                                          \
    do {                                                        \
        rw_info (0, 0, 0, "%s(int) definition", #function);     \
        function (function_called = 1);                         \
        rw_assert (1 == function_called, 0, __LINE__,           \
                   "%s (int) not defined", #function);          \
    } while (0)

    TEST (std::isalnum);
    TEST (std::isalpha);
    TEST (std::iscntrl);
    TEST (std::isdigit);
    TEST (std::isgraph);
    TEST (std::islower);
    TEST (std::isprint);
    TEST (std::ispunct);
    TEST (std::isupper);
    TEST (std::isxdigit);
    TEST (std::tolower);
    TEST (std::toupper);

    //////////////////////////////////////////////////////////////////
    if (rw_opt_no_behavior)
        rw_note (0, 0, 0, "behavior test disabled (use --test-behavior)");
    else
        test_behavior ();

    return 0;
}
Пример #5
0
LifetimeChecker::~LifetimeChecker ()
{
    if (rw_opt_no_global_dtors) {
        rw_note (0, 0, __LINE__, "test of global dtors disabled");
    }
    else {
        // objects must not be destroyed during program lifetime
        // try to use them in the destructor of a global object...
        std::cout << "[output from the dtor of a global object]";

        std::cout << "[cout]";
        std::cerr << "[cerr]";
        std::clog << "[clog]";

#ifndef _RWSTD_NO_WCHAR_T

        std::wcout << "[wcout]";
        std::wcerr << "[wcerr]";
        std::wclog << "[wclog]";

#endif   // _RWSTD_NO_WCHAR_T

    }
}
Пример #6
0
static int
run_test (int, char**)
{
    for (std::size_t i = 0; i != opt_nfacets; ++i) {
        if (0 < opt_facets [i]) {
            for (std::size_t j = 0; j != opt_nfacets; ++j) {
                if (opt_facets [j] == 0)
                    opt_facets [j] = -1;
            }
            break;
        }
    }

    rw_note (0 <= opt_facets [opt_inx_codecvt], 0, __LINE__,
             "std::codecvt tests disabled");

    rw_note (0 <= opt_facets [opt_inx_collate], 0, __LINE__,
             "std::collate tests disabled");

    rw_note (0 <= opt_facets [opt_inx_ctype], 0, __LINE__,
             "std::ctype tests disabled");

    rw_note (0 <= opt_facets [opt_inx_messages], 0, __LINE__,
             "std::messages tests disabled");

    rw_note (0 <= opt_facets [opt_inx_moneypunct], 0, __LINE__,
             "std::moneypunct<charT, false> tests disabled");

    rw_note (0 <= opt_facets [opt_inx_moneypunct_intl], 0, __LINE__,
             "std::moneypunct<charT, true> tests disabled");

    rw_note (0 <= opt_facets [opt_inx_money_get], 0, __LINE__,
             "std::money_get tests disabled");

    rw_note (0 <= opt_facets [opt_inx_money_put], 0, __LINE__,
             "std::money_put tests disabled");

    rw_note (0 <= opt_facets [opt_inx_numpunct], 0, __LINE__,
             "std::numpunct tests disabled");

    rw_note (0 <= opt_facets [opt_inx_num_get], 0, __LINE__,
             "std::num_get tests disabled");

    rw_note (0 <= opt_facets [opt_inx_num_put], 0, __LINE__,
             "std::num_put tests disabled");

    rw_note (0 <= opt_facets [opt_inx_time_get], 0, __LINE__,
             "std::time_get tests disabled");

    rw_note (0 <= opt_facets [opt_inx_time_put], 0, __LINE__,
             "std::time_put tests disabled");

    rw_note (0 == opt_no_exceptions, 0, __LINE__,
             "tests involving exceptions disabled");

    // find all installed locales for which setlocale(LC_ALL) succeeds
    const char* const locale_list =
        rw_opt_locales ? rw_opt_locales : rw_locales (_RWSTD_LC_ALL);

    const std::size_t maxinx = sizeof locales / sizeof *locales;

    // set to true if the classic "C" locale is on the lost
    bool has_classic = false;

    for (const char *name = locale_list; *name; name += std::strlen (name) +1) {

        locales [nlocales++] = name;

        if (!has_classic && 0 == std::strcmp ("C", name))
            has_classic = true;

        if (nlocales == maxinx)
            break;
    }

    // when the classic "C" locale isn't on the list put it there
    // unless the list was explicitly specified on the command line
    if (1 < nlocales && !has_classic && 0 == rw_opt_locales)
        locales [0] = "C";

    int result;

    rw_info (0, 0, 0,
             "testing std::locale globals with %d thread%{?}s%{;}, "
             "%d iteration%{?}s%{;} each, in %zu locales { %{ .*A@} }",
             opt_nthreads, 1 != opt_nthreads,
             opt_nloops, 1 != opt_nloops,
             nlocales, int (nlocales), "%#s", locales);

    if (opt_has_facet >= 0) {
        rw_info (0, 0, 0,
                 "template <class T> bool std::has_facet (const locale&)");

        // create and start a pool of threads and wait for them to finish
        result = rw_thread_pool (0, std::size_t (opt_nthreads), 0,
                                 test_has_facet, 0);

        rw_error (result == 0, 0, __LINE__,
                  "rw_thread_pool(0, %d, 0, %{#f}, 0) failed",
                  opt_nthreads, test_has_facet);
    }
    else {
        rw_note (0, 0, 0, "std::has_facet test disabled");
    }

    if (opt_use_facet >= 0) {
        rw_info (0, 0, 0,
                 "template <class T> const T& std::use_facet (const locale&)");

#ifdef _RWSTD_NO_DYNAMIC_CAST

        // if dynamic_cast isn't supported, then [has,use]_facet()
        // can't reliably detect if a facet is installed or not.
        rw_warn (0 != opt_no_exceptions, 0, __LINE__,
                 "dynamic_cast not supported "
                 "(macro _RWSTD_NO_DYNAMIC_CAST is #defined), "
                 "disabling exceptions tests");

        opt_no_exceptions = 1;

#endif   // _RWSTD_NO_DYNAMIC_CAST


#ifdef _RWSTD_NO_THREAD_SAFE_EXCEPTIONS

        // avoid exercising exceptions (triggered by use_facet) if
        // their implementation in the runtime isn't thread-safe
        rw_warn (0, 0, 0,
                 "exceptions not thread safe (macro "
                 "_RWSTD_NO_THREAD_SAFE_EXCEPTIONS is #defined), "
                 "disabling exceptions tests");

        opt_no_exceptions = 1;

#endif   // _RWSTD_NO_THREAD_SAFE_EXCEPTIONS


        // create and start a pool of threads and wait for them to finish
        result = rw_thread_pool (0, std::size_t (opt_nthreads), 0,
                                 test_use_facet, 0);

        rw_error (result == 0, 0, __LINE__,
                  "rw_thread_pool(0, %d, 0, %{#f}, 0) failed",
                  opt_nthreads, test_use_facet);
    }
    else {
        rw_note (0, 0, 0, "std::use_facet test disabled");
    }

    return result;
}
Пример #7
0
void do_test (bool        intl,    // international?
              charT       which,   // which overload to exercise
              const char *cname,   // the name of the charT type
              const char *tname,   // the name of the floating point type
              int         lineno,  // line number
              LongDouble  val,     // the expected extracted value
              const char *str,     // the sequence to extract from
              int         consumed = -1,   // expected number extractions
              int         flags = 0,       // initial ios flags
              int         err_expect = -1, // expected final state
              int         frac_digits = 0, // fractional digits
              const char *fmat = 0,        // money_base::pattern
              const char *cursym = 0,      // currency symbol
              const char *grouping = "")   // grouping string
{
    if (!rw_enabled (lineno)) {
        rw_note (0, __FILE__, __LINE__, "test on line %d disabled", lineno);
        return;
    }

    if (!fmat) {
        // if fmat isn't set, use the default pattern
        static const std::money_base::pattern pat = { {
            std::money_base::symbol, std::money_base::sign,
            std::money_base::none,   std::money_base::value
        } };

        fmat = pat.field;
    }
    else
        fmat = set_pattern (fmat).field;

    // local format? (the opposite of interantional)
    const bool locl = !intl;

    // take care to initialize Punct static data before installing
    // the facet in case locale or the base facet calls the overridden
    // virtuals early to cache the results
    PunctData<charT>::format_ [intl][1].field [0] = fmat [0];
    PunctData<charT>::format_ [intl][1].field [1] = fmat [1];
    PunctData<charT>::format_ [intl][1].field [2] = fmat [2];
    PunctData<charT>::format_ [intl][1].field [3] = fmat [3];

    PunctData<charT>::format_ [locl][1].field [0] = fmat [3];
    PunctData<charT>::format_ [locl][1].field [1] = fmat [2];
    PunctData<charT>::format_ [locl][1].field [2] = fmat [1];
    PunctData<charT>::format_ [locl][1].field [3] = fmat [0];

    // zero out positive format (not used by money_get)
    PunctData<charT>::format_ [intl][0] = std::money_base::pattern ();
    PunctData<charT>::format_ [locl][0] = std::money_base::pattern ();

    // expand (widen) currency symbol
    PunctData<charT>::curr_symbol_ [intl] = rw_expand ((charT*)0, cursym);
    PunctData<charT>::curr_symbol_ [locl] = 0;
    
    PunctData<charT>::grouping_ [intl] = grouping;
    PunctData<charT>::grouping_ [locl] = 0;

    PunctData<charT>::frac_digits_ [intl] = frac_digits;
    PunctData<charT>::frac_digits_ [locl] = frac_digits + 1;

    Ios<charT> io;
    MoneyGet<charT> mg;

    // create distinct punctuation facets for each iteration to make sure
    // any data cached in between successive calls to the facet's public
    // member functions are flushed
    if (intl) {
        const std::moneypunct<charT, true> *pf = new Punct<charT, true>(0);
        io.imbue (std::locale (io.getloc (), pf));
    }
    else {
        const std::moneypunct<charT, false> *pf = new Punct<charT, false>(0);
        io.imbue (std::locale (io.getloc (), pf));
    }

    io.flags (std::ios_base::fmtflags (flags));

    // expand (widen) input sequence
    const charT* const next = rw_expand ((charT*)0, str);

    std::ios_base::iostate err = std::ios_base::goodbit;

    const charT *last;

    if (0 == which) {   // exercise get (..., long double)

        last = next + std::char_traits<charT>::length (next);

        LongDouble x = 0;

        last = mg.get (next, last, intl, io, err, x);

        if (-1 == err_expect)
            err_expect = err;

        const int success =
            !(-1 != consumed && last - next != consumed || err != err_expect);

        rw_assert (success, __FILE__, lineno,
                   "money_get<%s>::get (%{*Ac}, ..., %b, ..., %s&), "
                   "ate %d, expected %d, frac_digits = %d, "
                   "flags = %{If}, grouping = %#s, pattern = %{LM}, "
                   "state = %{Is}, expected %{Is}",
                   cname, int (sizeof *next), next, intl, tname,
                   last - next, consumed, frac_digits,
                   flags, grouping, fmat,
                   err, err_expect);

        rw_assert (2 > rw_ldblcmp (x, val), __FILE__, lineno,
                   "money_get<%s>::get (%{*Ac}, ..., %b, ..., %s&), "
                   "got %Lg, expected %Lg, frac_digits = %d, "
                   "flags = %{If}s, grouping = %#s, pattern = %{LM}, "
                   "state = %{Is}, expected %{Is}",
                   cname, int (sizeof *next), next, intl, tname,
                   x, val, frac_digits,
                   flags, grouping, fmat,
                   err, err_expect);
    }
    else {   // exercise get (..., string_type)

        static const charT initial[] = { '*', '*', '*', '\0' };
        typename std::money_get<charT, const charT*>::string_type bs (initial);

        last = next + std::char_traits<charT>::length (next);

        last = mg.get (next, last, intl, io, err, bs);

        int success =
            !(-1 != consumed && last - next != consumed || err != err_expect);

        rw_assert (success, __FILE__, lineno,
                   "money_get<%s>::get (%{*Ac}, ..., %b, ..., "
                   "basic_string<%s>&), ate %d, expected %d, "
                   "frac_digits = %d, flags = %{If}, grouping = %#s"
                   ", format = %{LM}, state = %{Is}, expected %{Is}",
                   cname, int (sizeof *next), next, intl,
                   cname, last - next, consumed,
                   frac_digits, flags, grouping,
                   fmat, err, err_expect);

        if (success) {

            char narrow_buf [4096];
            rw_narrow (narrow_buf, bs.c_str ());

            LongDouble x = 0;

            // prevent gcc warning: ANSI C does not support
            // the `L' length modifier
            const char fmt[] = "%" _RWSTD_LDBL_PRINTF_PREFIX "g";
            int n = std::sscanf (narrow_buf, fmt, &x);

            success = 
                !(   err_expect & std::ios::failbit && !*grouping
                  && (1 == n || bs != initial)
                  || !(err_expect & std::ios::failbit)
                  && 1 < rw_ldblcmp (x, val));

            rw_assert (success, __FILE__, lineno,
                       "money_get<%s>::get (%{*Ac}, ..., %b, ..., "
                       "basic_string<%s>&), got %s, expected %Lg, "
                       "frac_digits = %d, flags = %{If}, grouping = %#s,"
                       " pattern = %{LM}, iostate = %{Is}, expected %{Is}",
                       cname, int (sizeof *next), next, intl,
                       cname, bs.c_str (), val,
                       frac_digits, flags, grouping,
                       fmat, err, err_expect);
        }
    }

    delete[] PunctData<charT>::curr_symbol_ [intl];
    delete[] next;
}
Пример #8
0
void run_test (intT, thr_args_base::tag_t tag)
{
    static const char* const tname = rw_any_t (intT ()).type_name ();

    if (!rw_enabled (tname)) {
        rw_note (0, 0, 0, "%s test disabled", tname);
        return;
    }

#ifdef _RWSTD_REENTRANT

    static const char* const fun = "__rw_atomic_exchange";

    rw_info (0, 0, 0, "__rw::%s (%s&, %2$s): %d iterations in %d threads",
             fun, tname, rw_opt_nloops, rw_opt_nthreads);

    rw_thread_t tid [MAX_THREADS];

    typedef thr_args<intT> Args;

    Args::nthreads_   = unsigned (rw_opt_nthreads);
    Args::type_tag_   = tag;
    Args::nincr_      = unsigned (rw_opt_nloops);
    Args::shared_ [0] = intT (1);
    Args::shared_ [1] = intT (1);

    _RWSTD_ASSERT (Args::nthreads_ < sizeof tid / sizeof *tid);

    Args args [sizeof tid / sizeof *tid];

    for (unsigned long i = 0; i != Args::nthreads_; ++i) {

        args [i].threadno_ = i;
        args [i].niter_    = 0;
        args [i].nxchg_    = 0;

        rw_fatal (0 == rw_thread_create (tid + i, 0, thread_routine, args + i),
                  0, __LINE__, "thread_create() failed");
    }
            
    for (unsigned long i = 0; i != Args::nthreads_; ++i) {

        rw_error (0 == rw_thread_join (tid [i], 0), 0, __LINE__,
                  "thread_join() failed");

        if (args [i].niter_) {
            // compute the percantage of thread iterations that resulted
            // in increments of one of the shared variables
            const unsigned long incrpcnt =
                (100U * Args::nincr_) / args [i].niter_;

            printf ("thread %lu performed %lu exchanges in %lu iterations "
                    "(%lu%% increments)\n",
                    args [i].threadno_, args [i].nxchg_,
                    args [i].niter_, incrpcnt);
        }
    }

    // compute the expected result, "skipping" zeros by incrementing
    // expect twice when it overflows and wraps around to 0 (zero is
    // used as the lock variable in thread_routine() above)
    intT expect = intT (1);

    const unsigned long nincr = (Args::nthreads_ * Args::nincr_) / 2U;
        
    for (unsigned long i = 0; i != nincr; ++i) {
        if (intT () == ++expect)
            ++expect;
    }

    // verify that the final value of the variables shared among all
    // threads equals the number of increments performed by the threads
    rw_assert (Args::shared_ [0] == expect, 0, __LINE__,
               "1. %s (%s&, %2$s); %s == %s failed",
               fun, tname, TOSTR (Args::shared_ [0]), TOSTR (expect));

    rw_assert (Args::shared_ [1] == expect, 0, __LINE__,
               "2. %s (%s&, %2$s); %s == %s failed",
               fun, tname, TOSTR (Args::shared_ [1]), TOSTR (expect));

#else   // if !defined (_RWSTD_REENTRANT)

    _RWSTD_UNUSED (tag);

#endif   // _RWSTD_REENTRANT
}