libcxx: Disabling locale-related libc++ tests on Android

This is my first post here so apologies for any silliness about this question. Several tests that I’ve looked at don’t work on Android due to lack of locale support (https://code.google.com/p/android/issues/detail?id=57313#c2). So I’d like to disable tests that rely on this. An example of such a test is http://llvm.org/svn/llvm-project/libcxx/trunk/test/re/re.alg/re.alg.match/basic.pass.cpp, which does something like:

    std::locale::global(std::locale("cs_CZ.ISO8859-2"));
    {
        std::cmatch m;
        const char s[] = "m";
        assert(std::regex_match(s, m, std::regex("[a[=M=]z]",
                                                 std::regex_constants::basic)));
        assert(m.size() == 1);
        assert(!m.prefix().matched);
        assert(m.prefix().first == s);
        assert(m.prefix().second == m[0].first);
        assert(!m.suffix().matched);
        assert(m.suffix().first == m[0].second);
        assert(m.suffix().second == m[0].second);
        assert(m.length(0) == std::char_traits<char>::length(s));
        assert(m.position(0) == 0);
        assert(m.str(0) == s);
    }
    {
        std::cmatch m;
        const char s[] = "Ch";
        assert(std::regex_match(s, m, std::regex("[a[.ch.]z]",
                   std::regex_constants::basic | std::regex_constants::icase)));
        assert(m.size() == 1);
        assert(!m.prefix().matched);
        assert(m.prefix().first == s);
        assert(m.prefix().second == m[0].first);
        assert(!m.suffix().matched);
        assert(m.suffix().first == m[0].second);
        assert(m.suffix().second == m[0].second);
        assert(m.length(0) == std::char_traits<char>::length(s));
        assert(m.position(0) == 0);
        assert(m.str(0) == s);
    }
    std::locale::global(std::locale("C"));

What’s the right way to disable this test for Android? Is there an appropriate #ifdef I can use? Or should I move the tests out to a separate file that’s not built for Android?

Cheers.

You can use

#ifndef ANDROID

around the whole or part of tests that should fail on ANDROID. See here:

http://sourceforge.net/p/predef/wiki/OperatingSystems/

You can use

#ifndef __ANDROID__

around the whole or part of tests that should fail on ANDROID. See here:

Pre-defined Compiler Macros / Wiki / OperatingSystems

2014-05-29 13:26 GMT+03:00 William Chan (陈智昌) <willchan@chromium.org
<mailto:willchan@chromium.org>>:

    This is my first post here so apologies for any silliness about this
    question. Several tests that I've looked at don't work on Android due to
    lack of locale support
    (Google Issue Tracker). So I'd like
    to disable tests that rely on this. An example of such a test is
    http://llvm.org/svn/llvm-project/libcxx/trunk/test/re/re.alg/re.alg.match/basic.pass.cpp,
    which does something like:

         std::locale::global(std::locale("cs_CZ.ISO8859-2"));
         {
             std::cmatch m;
             const char s = "m";
             assert(std::regex_match(s, m, std::regex("[a[=M=]z]",
                                                      std::regex_constants::basic)));
             assert(m.size() == 1);
             assert(!m.prefix().matched);
             assert(m.prefix().first == s);
             assert(m.prefix().second == m[0].first);
             assert(!m.suffix().matched);
             assert(m.suffix().first == m[0].second);
             assert(m.suffix().second == m[0].second);
             assert(m.length(0) == std::char_traits<char>::length(s));
             assert(m.position(0) == 0);
             assert(m.str(0) == s);
         }
         {
             std::cmatch m;
             const char s = "Ch";
             assert(std::regex_match(s, m, std::regex("[a[.ch.]z]",
                        std::regex_constants::basic | std::regex_constants::icase)));
             assert(m.size() == 1);
             assert(!m.prefix().matched);
             assert(m.prefix().first == s);
             assert(m.prefix().second == m[0].first);
             assert(!m.suffix().matched);
             assert(m.suffix().first == m[0].second);
             assert(m.suffix().second == m[0].second);
             assert(m.length(0) == std::char_traits<char>::length(s));
             assert(m.position(0) == 0);
             assert(m.str(0) == s);
         }
         std::locale::global(std::locale("C"));

    What's the right way to disable this test for Android? Is there an
    appropriate #ifdef I can use? Or should I move the tests out to a separate
    file that's not built for Android?

If you move these into separate files, then other platforms should be able to XFAIL them as needed. I'm particularly interested in this because newlib is also lacking these extra locales.

I think that's a cleaner solution than my previous suggestion of creating a LIBCXX_SUPPORT_EXTRA_LOCALES macro and using that.

Some bikeshed name suggestions if we end up going with separate files:
http://llvm.org/svn/llvm-project/libcxx/trunk/test/locale/re/re.alg/re.alg.match/basic.pass.cpp
http://llvm.org/svn/llvm-project/libcxx/trunk/test/re/re.alg/re.alg.match/basic.locale.pass.cpp

Cheers,
Jon