brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.9 KiB · 08c33de Raw
142 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// These tests require locale for non-char paths12// UNSUPPORTED: no-localization13 14// <filesystem>15 16// class path17 18// template <class Source>19//      path(const Source& source);20// template <class InputIterator>21//      path(InputIterator first, InputIterator last);22 23#include <filesystem>24#include <type_traits>25#include <cassert>26 27#include "../../path_helper.h"28#include "make_string.h"29#include "min_allocator.h"30#include "test_iterators.h"31#include "test_macros.h"32namespace fs = std::filesystem;33 34template <class CharT, class ...Args>35void RunTestCaseImpl(MultiStringType const& MS, Args... args) {36  using namespace fs;37  const fs::path::value_type* Expect = MS;38  const CharT* TestPath = MS;39  const CharT* TestPathEnd = StrEnd(TestPath);40  const std::size_t Size = TestPathEnd - TestPath;41  const std::size_t SSize = StrEnd(Expect) - Expect;42  assert(Size == SSize);43  // StringTypes44  {45    const std::basic_string<CharT> S(TestPath);46    path p(S, args...);47    assert(p.native() == Expect);48    assert(p.string<CharT>() == TestPath);49    assert(p.string<CharT>() == S);50  }51  {52    const std::basic_string_view<CharT> S(TestPath);53    path p(S, args...);54    assert(p.native() == Expect);55    assert(p.string<CharT>() == TestPath);56    assert(p.string<CharT>() == S);57  }58  // Char* pointers59  {60    path p(TestPath, args...);61    assert(p.native() == Expect);62    assert(p.string<CharT>() == TestPath);63  }64  {65    path p(TestPath, TestPathEnd, args...);66    assert(p.native() == Expect);67    assert(p.string<CharT>() == TestPath);68  }69  // Iterators70  {71    using It = cpp17_input_iterator<const CharT*>;72    path p(It{TestPath}, args...);73    assert(p.native() == Expect);74    assert(p.string<CharT>() == TestPath);75  }76  {77    using It = cpp17_input_iterator<const CharT*>;78    path p(It{TestPath}, It{TestPathEnd}, args...);79    assert(p.native() == Expect);80    assert(p.string<CharT>() == TestPath);81  }82}83 84template <class CharT, class ...Args>85void RunTestCase(MultiStringType const& MS) {86  RunTestCaseImpl<CharT>(MS);87  RunTestCaseImpl<CharT>(MS, fs::path::format::auto_format);88  RunTestCaseImpl<CharT>(MS, fs::path::format::native_format);89  RunTestCaseImpl<CharT>(MS, fs::path::format::generic_format);90  RunTestCaseImpl<CharT>(MS, fs::path::auto_format);91  RunTestCaseImpl<CharT>(MS, fs::path::native_format);92  RunTestCaseImpl<CharT>(MS, fs::path::generic_format);93}94 95void test_sfinae() {96  using namespace fs;97  {98    using It = const char* const;99    static_assert(std::is_constructible<path, It>::value, "");100  }101  {102    using It = cpp17_input_iterator<const char*>;103    static_assert(std::is_constructible<path, It>::value, "");104  }105  {106    struct Traits {107      using iterator_category = std::input_iterator_tag;108      using value_type = const char;109      using pointer = const char*;110      using reference = const char&;111      using difference_type = std::ptrdiff_t;112    };113    using It = cpp17_input_iterator<const char*, Traits>;114    static_assert(std::is_constructible<path, It>::value, "");115  }116  {117    using It = cpp17_output_iterator<const char*>;118    static_assert(!std::is_constructible<path, It>::value, "");119 120  }121  {122    static_assert(!std::is_constructible<path, int*>::value, "");123  }124}125 126int main(int, char**) {127  for (auto const& MS : PathList) {128    RunTestCase<char>(MS);129#if TEST_STD_VER > 17 && defined(__cpp_char8_t)130    RunTestCase<char8_t>(MS);131#endif132#ifndef TEST_HAS_NO_WIDE_CHARACTERS133    RunTestCase<wchar_t>(MS);134#endif135    RunTestCase<char16_t>(MS);136    RunTestCase<char32_t>(MS);137  }138  test_sfinae();139 140  return 0;141}142