File: test_traits.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (146 lines) | stat: -rw-r--r-- 7,553 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
// Copyright (c) 2020 Alexander Grund
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/nowide/detail/is_path.hpp>
#include <boost/nowide/detail/is_string_container.hpp>
#include <boost/nowide/fstream.hpp>
#include "test.hpp"
#include <iostream>
#include <string>

#ifdef __has_include
#if __has_include(<version>)
#include <version>
#endif
#endif

#ifdef __cpp_lib_string_view
#include <string_view>
#define BOOST_NOWIDE_TEST_STD_STRINGVIEW
#endif

// Exclude apple as support there is target level specific -.-
#if defined(__cpp_lib_filesystem) && !defined(__APPLE__)
#include <filesystem>
#define BOOST_NOWIDE_TEST_STD_PATH
#endif
#if defined(__cpp_lib_experimental_filesystem)
#ifndef _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#endif
#include <experimental/filesystem>
#define BOOST_NOWIDE_TEST_STD_EXPERIMENTAL_PATH
#endif

#ifdef BOOST_NOWIDE_TEST_BFS_PATH
#if defined(__GNUC__) && __GNUC__ >= 7
#pragma GCC diagnostic ignored "-Wattributes"
#endif
#if defined(_MSC_VER)
#pragma warning(disable : 4714) // function marked as __forceinline not inlined
#endif
#include <boost/filesystem/path.hpp>
#endif

template<class T_Class, class T_Arg, typename = void>
struct has_open : std::false_type
{};
using boost::nowide::detail::void_t;
template<class T_Class, class T_Arg>
struct has_open<T_Class,
                T_Arg,
                void_t<decltype(std::declval<T_Class>().open(std::declval<T_Arg>(), std::ios_base::openmode{}))>>
    : std::true_type
{};

using boost::nowide::detail::is_string_container;
static_assert(is_string_container<std::string, true>::value, "!");
static_assert(is_string_container<std::wstring, false>::value, "!");
static_assert(is_string_container<std::u16string, false>::value, "!");
static_assert(is_string_container<std::u32string, false>::value, "!");
static_assert(!is_string_container<int, true>::value, "!");
static_assert(!is_string_container<int, false>::value, "!");

using boost::nowide::detail::get_data_width;
static_assert(get_data_width<std::string>::value == sizeof(char), "!");
static_assert(get_data_width<std::wstring>::value == sizeof(wchar_t), "!");
static_assert(get_data_width<std::u16string>::value == sizeof(char16_t), "!");
static_assert(get_data_width<std::u32string>::value == sizeof(char32_t), "!");

// coverity[root_function]
void test_main(int, char**, char**)
{
#ifdef BOOST_NOWIDE_TEST_STD_STRINGVIEW
    std::cout << "Testing string_view" << std::endl;
    static_assert(is_string_container<std::string_view, true>::value, "!");
    static_assert(is_string_container<std::wstring_view, false>::value, "!");
    static_assert(is_string_container<std::u16string_view, false>::value, "!");
    static_assert(is_string_container<std::u32string_view, false>::value, "!");
#endif
#ifdef BOOST_NOWIDE_TEST_STD_PATH
    std::cout << "Testing std::filesystem::path" << std::endl;
    using fs_path = std::filesystem::path;
    static_assert(boost::nowide::detail::is_path<fs_path>::value, "!");
#if BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT
    static_assert(has_open<boost::nowide::filebuf, fs_path>::value, "!");
#endif
    static_assert(has_open<boost::nowide::ifstream, fs_path>::value, "!");
    static_assert(has_open<boost::nowide::ofstream, fs_path>::value, "!");
    static_assert(has_open<boost::nowide::fstream, fs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ifstream, fs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ofstream, fs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::fstream, fs_path>::value, "!");
    static_assert(has_open<boost::nowide::filebuf, const fs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::ifstream, const fs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::ofstream, const fs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::fstream, const fs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ifstream, const fs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ofstream, const fs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::fstream, const fs_path::value_type*>::value, "!");
#endif
#ifdef BOOST_NOWIDE_TEST_STD_EXPERIMENTAL_PATH
    std::cout << "Testing std::experimental::filesystem::path" << std::endl;
    using exfs_path = std::experimental::filesystem::path;
    static_assert(boost::nowide::detail::is_path<exfs_path>::value, "!");
#if BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT
    static_assert(has_open<boost::nowide::filebuf, exfs_path>::value, "!");
#endif
    static_assert(has_open<boost::nowide::ifstream, exfs_path>::value, "!");
    static_assert(has_open<boost::nowide::ofstream, exfs_path>::value, "!");
    static_assert(has_open<boost::nowide::fstream, exfs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ifstream, exfs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ofstream, exfs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::fstream, exfs_path>::value, "!");
    static_assert(has_open<boost::nowide::filebuf, const exfs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::ifstream, const exfs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::ofstream, const exfs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::fstream, const exfs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ifstream, const exfs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ofstream, const exfs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::fstream, const exfs_path::value_type*>::value, "!");
#endif
#ifdef BOOST_NOWIDE_TEST_BFS_PATH
    std::cout << "Testing boost::filesystem::path" << std::endl;
    using bfs_path = boost::filesystem::path;
    static_assert(boost::nowide::detail::is_path<bfs_path>::value, "!");
#if BOOST_NOWIDE_USE_FILEBUF_REPLACEMENT
    static_assert(has_open<boost::nowide::filebuf, bfs_path>::value, "!");
#endif
    static_assert(has_open<boost::nowide::ifstream, bfs_path>::value, "!");
    static_assert(has_open<boost::nowide::ofstream, bfs_path>::value, "!");
    static_assert(has_open<boost::nowide::fstream, bfs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ifstream, bfs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ofstream, bfs_path>::value, "!");
    static_assert(std::is_constructible<boost::nowide::fstream, bfs_path>::value, "!");
    static_assert(has_open<boost::nowide::filebuf, const bfs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::ifstream, const bfs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::ofstream, const bfs_path::value_type*>::value, "!");
    static_assert(has_open<boost::nowide::fstream, const bfs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ifstream, const bfs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::ofstream, const bfs_path::value_type*>::value, "!");
    static_assert(std::is_constructible<boost::nowide::fstream, const bfs_path::value_type*>::value, "!");
#endif
}