// // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_LOCALE_TEST_H #define BOOST_LOCALE_TEST_H #include #include #include #include #include #include int error_counter=0; int test_counter=0; #ifndef BOOST_LOCALE_ERROR_LIMIT #define BOOST_LOCALE_ERROR_LIMIT 20 #endif #define THROW_IF_TOO_BIG(X) \ do { \ if((X) > BOOST_LOCALE_ERROR_LIMIT) \ throw std::runtime_error("Error limits reached, stopping unit test"); \ }while(0) #define TEST(X) \ do { \ test_counter++; \ if(X) break; \ std::cerr << "Error in line:"<<__LINE__ << " "#X << std::endl; \ THROW_IF_TOO_BIG(error_counter++); \ }while(0) #endif #define TEST_THROWS(X,E) \ do { \ test_counter++; \ try { X; } catch(E const &/*e*/ ) {break;} catch(...){} \ std::cerr << "Error in line:"<<__LINE__ << " "#X << std::endl; \ THROW_IF_TOO_BIG(error_counter++); \ }while(0) #define FINALIZE() \ do { \ int passed=test_counter - error_counter; \ std::cout << std::endl; \ std::cout << "Passed "<0 ) { \ std::cout << "Failed "<= 0x35) return c; unsigned l; if(c < 192) l = 0; else if(c < 224) l = 1; else if(c < 240) l = 2; else l = 3; c&=(1<<(6-l))-1; switch(l) { case 3: c = (c << 6) | (((unsigned char)s[pos++]) & 0x3F); case 2: c = (c << 6) | (((unsigned char)s[pos++]) & 0x3F); case 1: c = (c << 6) | (((unsigned char)s[pos++]) & 0x3F); } return c; } template std::basic_string to(std::string const &utf8) { std::basic_string out; unsigned i=0; while(i 255) { std::ostringstream ss; ss << "Can't convert codepoint U" << std::hex << point <<"(" <0xFFFF) { // Deal with surragates point-=0x10000; out+=static_cast(0xD800 | (point>>10)); out+=static_cast(0xDC00 | (point & 0x3FF)); continue; } out+=static_cast(point); } return out; } // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4