forked from OSchip/llvm-project
[libcxx] [test] Fix string type handling in a few fairly trivial class.path tests
Use string() for convenience for testing where possible, but keep using native() for move tests where we want to check that no allocations are made, constructing a reference fs::path::string_type instead. Use the right value_type in a few places. Make the synop test check for the right types and for the expected preferred separator. Differential Revision: https://reviews.llvm.org/D89537
This commit is contained in:
parent
b740899c50
commit
3784bdf217
|
@ -29,8 +29,8 @@ int main(int, char**) {
|
|||
const path p(s);
|
||||
path p2;
|
||||
path& pref = (p2 = p);
|
||||
assert(p.native() == s);
|
||||
assert(p2.native() == s);
|
||||
assert(p.string() == s);
|
||||
assert(p2.string() == s);
|
||||
assert(&pref == &p2);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -29,13 +29,14 @@ int main(int, char**) {
|
|||
const std::string s("we really really really really really really really "
|
||||
"really really long string so that we allocate");
|
||||
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||
const fs::path::string_type ps(s.begin(), s.end());
|
||||
path p(s);
|
||||
{
|
||||
DisableAllocationGuard g;
|
||||
path p2;
|
||||
path& pref = (p2 = std::move(p));
|
||||
assert(p2.native() == s);
|
||||
assert(p.native() != s); // Testing moved from state
|
||||
assert(p2.native() == ps);
|
||||
assert(p.native() != ps); // Testing moved from state
|
||||
assert(&pref == &p2);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ int main(int, char**) {
|
|||
const std::string s("foo");
|
||||
const path p(s);
|
||||
path p2(p);
|
||||
assert(p.native() == s);
|
||||
assert(p2.native() == s);
|
||||
assert(p.string() == s);
|
||||
assert(p2.string() == s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,12 +29,13 @@ int main(int, char**) {
|
|||
const std::string s("we really really really really really really really "
|
||||
"really really long string so that we allocate");
|
||||
assert(globalMemCounter.checkOutstandingNewEq(1));
|
||||
const fs::path::string_type ps(s.begin(), s.end());
|
||||
path p(s);
|
||||
{
|
||||
DisableAllocationGuard g;
|
||||
path p2(std::move(p));
|
||||
assert(p2.native() == s);
|
||||
assert(p.native() != s); // Testing moved from state
|
||||
assert(p2.native() == ps);
|
||||
assert(p.native() != ps); // Testing moved from state
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
template <class CharT, class ...Args>
|
||||
void RunTestCaseImpl(MultiStringType const& MS, Args... args) {
|
||||
using namespace fs;
|
||||
const char* Expect = MS;
|
||||
const fs::path::value_type* Expect = MS;
|
||||
const CharT* TestPath = MS;
|
||||
const CharT* TestPathEnd = StrEnd(TestPath);
|
||||
const std::size_t Size = TestPathEnd - TestPath;
|
||||
|
|
|
@ -28,6 +28,7 @@ int main(int, char**)
|
|||
using namespace fs;
|
||||
const char* const value = "hello world";
|
||||
const std::string str_value = value;
|
||||
const fs::path::string_type pathstr_value(str_value.begin(), str_value.end());
|
||||
{ // Check signature
|
||||
path p(value);
|
||||
ASSERT_SAME_TYPE(path::value_type const*, decltype(p.c_str()));
|
||||
|
@ -35,7 +36,7 @@ int main(int, char**)
|
|||
}
|
||||
{
|
||||
path p(value);
|
||||
assert(p.c_str() == str_value);
|
||||
assert(p.c_str() == pathstr_value);
|
||||
assert(p.native().c_str() == p.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ int main(int, char**)
|
|||
{
|
||||
using namespace fs;
|
||||
const char* const value = "hello world";
|
||||
std::string value_str(value);
|
||||
fs::path::string_type pathstr_value(value_str.begin(), value_str.end());
|
||||
{ // Check signature
|
||||
path p(value);
|
||||
ASSERT_SAME_TYPE(path::string_type const&, decltype(p.native()));
|
||||
|
@ -33,7 +35,7 @@ int main(int, char**)
|
|||
}
|
||||
{ // native() is tested elsewhere
|
||||
path p(value);
|
||||
assert(p.native() == value);
|
||||
assert(p.native() == pathstr_value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -28,6 +28,8 @@ int main(int, char**)
|
|||
using namespace fs;
|
||||
using string_type = path::string_type;
|
||||
const char* const value = "hello world";
|
||||
std::string value_str(value);
|
||||
fs::path::string_type pathstr_value(value_str.begin(), value_str.end());
|
||||
{ // Check signature
|
||||
path p(value);
|
||||
static_assert(std::is_convertible<path, string_type>::value, "");
|
||||
|
@ -37,10 +39,10 @@ int main(int, char**)
|
|||
}
|
||||
{
|
||||
path p(value);
|
||||
assert(p.native() == value);
|
||||
assert(p.native() == pathstr_value);
|
||||
string_type s = p;
|
||||
assert(s == value);
|
||||
assert(p == value);
|
||||
assert(s == pathstr_value);
|
||||
assert(p == pathstr_value);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -53,7 +53,7 @@ void doIOTest() {
|
|||
{ // test input
|
||||
path p_in;
|
||||
auto& ret = ss >> p_in;
|
||||
assert(p_in.native() == (const char*)InStr);
|
||||
assert(p_in.native() == (const path::value_type*)InStr);
|
||||
assert(&ret == &ss);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ int main(int, char**)
|
|||
const char* value2 = "_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG_THIS_IS_LONG";
|
||||
path p1(value1);
|
||||
path p2(value2);
|
||||
fs::path::string_type ps1 = p1.native();
|
||||
fs::path::string_type ps2 = p2.native();
|
||||
{
|
||||
using namespace std; using namespace fs;
|
||||
ASSERT_NOEXCEPT(swap(p1, p2));
|
||||
|
@ -39,11 +41,11 @@ int main(int, char**)
|
|||
using namespace std;
|
||||
using namespace fs;
|
||||
swap(p1, p2);
|
||||
assert(p1.native() == value2);
|
||||
assert(p2.native() == value1);
|
||||
assert(p1.native() == ps2);
|
||||
assert(p2.native() == ps1);
|
||||
swap(p1, p2);
|
||||
assert(p1.native() == value1);
|
||||
assert(p2.native() == value2);
|
||||
assert(p1.native() == ps1);
|
||||
assert(p2.native() == ps2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -25,13 +25,21 @@
|
|||
|
||||
int main(int, char**) {
|
||||
using namespace fs;
|
||||
#ifdef _WIN32
|
||||
ASSERT_SAME_TYPE(path::value_type, wchar_t);
|
||||
#else
|
||||
ASSERT_SAME_TYPE(path::value_type, char);
|
||||
#endif
|
||||
ASSERT_SAME_TYPE(path::string_type, std::basic_string<path::value_type>);
|
||||
{
|
||||
ASSERT_SAME_TYPE(const path::value_type, decltype(path::preferred_separator));
|
||||
#ifdef _WIN32
|
||||
static_assert(path::preferred_separator == '\\', "");
|
||||
#else
|
||||
static_assert(path::preferred_separator == '/', "");
|
||||
#endif
|
||||
// Make preferred_separator ODR used by taking its address.
|
||||
const char* dummy = &path::preferred_separator;
|
||||
const path::value_type* dummy = &path::preferred_separator;
|
||||
((void)dummy);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue