boostorg / nowide

Compare ee17695 ... +6 ... 5114e58


@@ -378,7 +378,7 @@
Loading
378 378
            }
379 379
380 380
            static const int max_width = 2;
381 -
            static int width(code_point u)
381 +
            static int width(code_point u) // LCOV_EXCL_LINE
382 382
            {
383 383
                return u >= 0x10000 ? 2 : 1;
384 384
            }

@@ -367,7 +367,7 @@
Loading
367 367
    else
368 368
        nw::cout << "NOT using Nowide input buffer\n";
369 369
    if(usesNowideRdBufOut)
370 -
        nw::cout << "Using Nowide output buffer\n";
370 +
        nw::cout << "Using Nowide output buffer\n"; // LCOV_EXCL_LINE
371 371
    else
372 372
        nw::cout << "NOT using Nowide output buffer\n";
373 373
    // LCOV_EXCL_STOP

@@ -26,22 +26,13 @@
Loading
26 26
#define BOOST_NOWIDE_REQUIRE_UTF_CHAR_WORKAROUND 0
27 27
#endif
28 28
29 -
#if defined(_MSC_VER) && !BOOST_NOWIDE_REQUIRE_UTF_CHAR_WORKAROUND
30 -
#define BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION 1
31 -
#else
32 -
#define BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION 0
33 -
#endif
34 -
35 29
static const char* utf8_name =
36 30
  "\xf0\x9d\x92\x9e-\xD0\xBF\xD1\x80\xD0\xB8\xD0\xB2\xD0\xB5\xD1\x82-\xE3\x82\x84\xE3\x81\x82.txt";
37 31
static const std::wstring wide_name_str = boost::nowide::widen(utf8_name);
38 32
static const wchar_t* wide_name = wide_name_str.c_str();
39 33
40 34
using cvt_type = std::codecvt<wchar_t, char, std::mbstate_t>;
41 -
#if BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION
42 -
#pragma warning(push)
43 -
#pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char16/32_t, char, ...>
44 -
#endif
35 +
45 36
#if BOOST_NOWIDE_REQUIRE_UTF_CHAR_WORKAROUND
46 37
using utf16_char_t = int16_t;
47 38
using utf32_char_t = int32_t;
@@ -50,42 +41,31 @@
Loading
50 41
using utf32_char_t = char32_t;
51 42
#endif
52 43
44 +
BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_BEGIN
53 45
using cvt_type16 = std::codecvt<utf16_char_t, char, std::mbstate_t>;
54 46
using cvt_type32 = std::codecvt<utf32_char_t, char, std::mbstate_t>;
55 -
#if BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION
56 -
#pragma warning(pop)
57 -
#endif
58 47
using utf8_utf16_codecvt = boost::nowide::utf8_codecvt<utf16_char_t>;
59 48
using utf8_utf32_codecvt = boost::nowide::utf8_codecvt<utf32_char_t>;
49 +
BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_END
60 50
61 51
void test_codecvt_basic()
62 52
{
63 53
    // UTF-16
64 54
    {
65 -
#if BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION
66 -
#pragma warning(push)
67 -
#pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char16, char, ...>
68 -
#endif
55 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_BEGIN
69 56
        std::locale l(std::locale::classic(), new utf8_utf16_codecvt());
70 57
        const cvt_type16& cvt = std::use_facet<cvt_type16>(l);
71 -
#if BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION
72 -
#pragma warning(pop)
73 -
#endif
58 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_END
74 59
        TEST_EQ(cvt.encoding(), 0);   // Characters have a variable width
75 60
        TEST_EQ(cvt.max_length(), 4); // At most 4 UTF-8 code units are one internal char (one or two UTF-16 code units)
76 61
        TEST(!cvt.always_noconv());   // Always convert
77 62
    }
78 63
    // UTF-32
79 64
    {
80 -
#if BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION
81 -
#pragma warning(push)
82 -
#pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char32, char, ...>
83 -
#endif
65 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_BEGIN
84 66
        std::locale l(std::locale::classic(), new utf8_utf32_codecvt());
85 67
        const cvt_type32& cvt = std::use_facet<cvt_type32>(l);
86 -
#if BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION
87 -
#pragma warning(pop)
88 -
#endif
68 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_END
89 69
        TEST_EQ(cvt.encoding(), 0);   // Characters have a variable width
90 70
        TEST_EQ(cvt.max_length(), 4); // At most 4 UTF-8 code units are one internal char (one UTF-32 code unit)
91 71
        TEST(!cvt.always_noconv());   // Always convert
@@ -95,18 +75,17 @@
Loading
95 75
void test_codecvt_unshift()
96 76
{
97 77
    char buf[256];
98 -
    const auto name16 = boost::nowide::utf::convert_string<utf16_char_t>(utf8_name, utf8_name + std::strlen(utf8_name));
99 -
100 -
    utf8_utf16_codecvt cvt16;
78 +
    // UTF-16
101 79
    {
102 -
        const cvt_type16& cvt = cvt16;
80 +
        const auto name16 =
81 +
          boost::nowide::utf::convert_string<utf16_char_t>(utf8_name, utf8_name + std::strlen(utf8_name));
82 +
83 +
        utf8_utf16_codecvt cvt16;
103 84
        // Unshift on initial state does nothing
104 85
        std::mbstate_t mb{};
105 86
        char* to_next;
106 -
#if BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION
107 -
#pragma warning(push)
108 -
#pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char16, char, ...>
109 -
#endif
87 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_BEGIN
88 +
        const cvt_type16& cvt = cvt16;
110 89
        TEST_EQ(cvt.unshift(mb, buf, std::end(buf), to_next), cvt_type16::ok);
111 90
        TEST(to_next == buf);
112 91
        const utf16_char_t* from_next;
@@ -116,9 +95,30 @@
Loading
116 95
        TEST(to_next == buf);
117 96
        // Unshift on non-default state is not possible
118 97
        TEST_EQ(cvt.unshift(mb, buf, std::end(buf), to_next), cvt_type16::error);
119 -
#if BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION
120 -
#pragma warning(pop)
121 -
#endif
98 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_END
99 +
    }
100 +
    // UTF-32
101 +
    {
102 +
        const auto name32 =
103 +
          boost::nowide::utf::convert_string<utf32_char_t>(utf8_name, utf8_name + std::strlen(utf8_name));
104 +
105 +
        utf8_utf32_codecvt cvt32;
106 +
        // Unshift on initial state does nothing
107 +
        std::mbstate_t mb{};
108 +
        char* to_next;
109 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_BEGIN
110 +
        const cvt_type32& cvt = cvt32;
111 +
        TEST_EQ(cvt.unshift(mb, buf, std::end(buf), to_next), cvt_type32::noconv);
112 +
        TEST(to_next == buf);
113 +
        const utf32_char_t* from_next;
114 +
        // Convert into a too small buffer
115 +
        TEST_EQ(cvt.out(mb, &name32.front(), &name32.back(), from_next, buf, buf + 1, to_next), cvt_type32::partial);
116 +
        TEST(from_next == &name32.front()); // Noting consumed
117 +
        TEST(to_next == buf);
118 +
        TEST(std::mbsinit(&mb) != 0); // State unchanged --> Unshift does nothing
119 +
        TEST_EQ(cvt.unshift(mb, buf, std::end(buf), to_next), cvt_type32::noconv);
120 +
        TEST(to_next == buf);
121 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_END
122 122
    }
123 123
}
124 124
@@ -227,7 +227,8 @@
Loading
227 227
    }
228 228
    TEST(nptr == utf8_name + u8len);
229 229
    TEST(from_next == real_from_end);
230 -
    TEST_EQ(cvt.unshift(mb, to, to + n, to_next), cvt_type::ok);
230 +
    const auto expected = (sizeof(wchar_t) == 2) ? cvt_type::ok : cvt_type::noconv; // UTF-32 is not state-dependent
231 +
    TEST_EQ(cvt.unshift(mb, to, to + n, to_next), expected);
231 232
    TEST(to_next == to);
232 233
}
233 234
@@ -250,10 +251,8 @@
Loading
250 251
                test_codecvt_out_n_m(cvt, i, j);
251 252
            } catch(...) // LCOV_EXCL_LINE
252 253
            {
253 -
                // LCOV_EXCL_START
254 -
                std::cerr << "Wlen=" << j << " Nlen=" << i << std::endl;
255 -
                throw;
256 -
                // LCOV_EXCL_STOP
254 +
                std::cerr << "Wlen=" << j << " Nlen=" << i << std::endl; // LCOV_EXCL_LINE
255 +
                throw;                                                   // LCOV_EXCL_LINE
257 256
            }
258 257
        }
259 258
    }

@@ -77,10 +77,11 @@
Loading
77 77
            // LCOV_EXCL_START
78 78
            bool do_read(wchar_t* buffer, std::size_t num_chars_to_read, std::size_t& num_chars_read) override
79 79
            {
80 -
                DWORD size = 0;
81 -
                const bool result = ReadConsoleW(handle_, buffer, static_cast<DWORD>(num_chars_to_read), &size, 0) != 0;
82 -
                num_chars_read = size;
83 -
                return result;
80 +
                DWORD size = 0;                                                                 // LCOV_EXCL_LINE
81 +
                const auto to_read_size = static_cast<DWORD>(num_chars_to_read);                // LCOV_EXCL_LINE
82 +
                const bool result = ReadConsoleW(handle_, buffer, to_read_size, &size, 0) != 0; // LCOV_EXCL_LINE
83 +
                num_chars_read = size;                                                          // LCOV_EXCL_LINE
84 +
                return result;                                                                  // LCOV_EXCL_LINE
84 85
            }
85 86
            // LCOV_EXCL_STOP
86 87
        };

@@ -49,11 +49,7 @@
Loading
49 49
    template<typename CharType, int CharSize = sizeof(CharType)>
50 50
    class utf8_codecvt;
51 51
52 -
#ifdef BOOST_MSVC
53 -
#pragma warning(push)
54 -
#pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char16_t, char, ...>
55 -
#endif
56 -
52 +
    BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_BEGIN
57 53
    /// Specialization for the UTF-8 <-> UTF-16 variant of the std::codecvt implementation
58 54
    template<typename CharType>
59 55
    class BOOST_SYMBOL_VISIBLE utf8_codecvt<CharType, 2> : public std::codecvt<CharType, char, std::mbstate_t>
@@ -63,10 +59,7 @@
Loading
63 59
64 60
        utf8_codecvt(size_t refs = 0) : std::codecvt<CharType, char, std::mbstate_t>(refs)
65 61
        {}
66 -
67 -
#ifdef BOOST_MSVC
68 -
#pragma warning(pop)
69 -
#endif
62 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_END
70 63
71 64
    protected:
72 65
        using uchar = CharType;
@@ -132,7 +125,7 @@
Loading
132 125
            return static_cast<int>(from - save_from);
133 126
        }
134 127
135 -
        std::codecvt_base::result do_in(std::mbstate_t& std_state,
128 +
        std::codecvt_base::result do_in(std::mbstate_t& std_state, // LCOV_EXCL_LINE
136 129
                                        const char* from,
137 130
                                        const char* from_end,
138 131
                                        const char*& from_next,
@@ -256,22 +249,15 @@
Loading
256 249
        }
257 250
    };
258 251
259 -
#ifdef BOOST_MSVC
260 -
#pragma warning(push)
261 -
#pragma warning(disable : 4996) // Disable deprecation warning for std::codecvt<char32_t, char, ...>
262 -
#endif
263 -
252 +
    BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_BEGIN
264 253
    /// Specialization for the UTF-8 <-> UTF-32 variant of the std::codecvt implementation
265 254
    template<typename CharType>
266 255
    class BOOST_SYMBOL_VISIBLE utf8_codecvt<CharType, 4> : public std::codecvt<CharType, char, std::mbstate_t>
267 256
    {
268 257
    public:
269 258
        utf8_codecvt(size_t refs = 0) : std::codecvt<CharType, char, std::mbstate_t>(refs)
270 259
        {}
271 -
272 -
#ifdef BOOST_MSVC
273 -
#pragma warning(pop)
274 -
#endif
260 +
        BOOST_NOWIDE_SUPPRESS_UTF_CODECVT_DEPRECATION_END
275 261
276 262
    protected:
277 263
        using uchar = CharType;
@@ -280,7 +266,7 @@
Loading
280 266
        do_unshift(std::mbstate_t& /*s*/, char* from, char* /*to*/, char*& next) const override
281 267
        {
282 268
            next = from;
283 -
            return std::codecvt_base::ok;
269 +
            return std::codecvt_base::noconv;
284 270
        }
285 271
        int do_encoding() const noexcept override
286 272
        {

Learn more Showing 25 files with coverage changes found.

Changes in include/boost/nowide/args.hpp
-1
Loading file...
Changes in test/file_test_helpers.hpp
+3
Loading file...
Changes in test/test_system.cpp
+5
Loading file...
Changes in test/test_ofstream.cpp
+4
Loading file...
Changes in test/test_env.cpp
+1
Loading file...
Changes in test/test_ifstream.cpp
+4
Loading file...
Changes in test/test_convert.cpp
+1
Loading file...
Changes in test/test_stackstring.cpp
+1
Loading file...
Changes in include/boost/nowide/fstream.hpp
+27
Loading file...
Changes in test/test_stdio.cpp
+2
Loading file...
Changes in test/test_fstream.cpp
+8
Loading file...
Changes in test/test_sets.hpp
New
Loading file...
Changes in test/test_fs.cpp
+1
Loading file...
Changes in test/test_stat.cpp
+1
Loading file...
Changes in test/test_traits.cpp
+1
Loading file...
Changes in include/boost/nowide/stackstring.hpp
+5
Loading file...
Changes in test/test_fstream_special.cpp
+7
Loading file...
Changes in include/boost/nowide/filebuf.hpp
+5
Loading file...
Changes in test/test_codecvt.cpp
-1
+2
Loading file...
Changes in test/test_iostream.cpp
-1
+14
Loading file...
Changes in test/test_filebuf.cpp
-1
+7
Loading file...
Changes in include/boost/nowide/utf8_codecvt.hpp
-2
-1
Loading file...
Changes in include/boost/nowide/utf/utf.hpp
-2
-1
Loading file...
Changes in src/iostream.cpp
-3
-2
Loading file...
Changes in src/filebuf.cpp
-1
+1
Loading file...
Files Coverage
include/boost/nowide 0.57% 98.05%
src +1.33% 94.50%
test 0.16% 100.00%
Project Totals (33 files) 99.08%
Loading