diff --git a/CMakeLists.txt b/CMakeLists.txt index 3748187..9d5219e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,7 @@ if (UPA_BUILD_TESTS) test/test-url.cpp test/test-url-port.cpp test/test-url-setters.cpp + test/test-url_for_.cpp test/test-url_host.cpp test/test-url_percent_encode.cpp test/test-url_search_params.cpp diff --git a/include/upa/url_for_atl.h b/include/upa/url_for_atl.h index f3a1979..206e6b5 100644 --- a/include/upa/url_for_atl.h +++ b/include/upa/url_for_atl.h @@ -5,20 +5,55 @@ #ifndef UPA_URL_FOR_ATL_H #define UPA_URL_FOR_ATL_H +#include "config.h" #include "url.h" // IWYU pragma: export -#include +#include +#ifdef UPA_CPP_20 +# include +#else +# include +#endif namespace upa { -template -struct str_arg_char> { - using type = CharT; +template +struct str_arg_char_for_atl { + using type = typename StrT::XCHAR; - static str_arg to_str_arg(const ATL::CStringT& str) { + static str_arg to_str_arg(const StrT& str) { return { str.GetString(), static_cast(str.GetLength()) }; } }; +#ifdef UPA_CPP_20 + +// CStringT and CFixedStringT are derived from CSimpleStringT +template +concept derived_from_CSimpleString = + std::derived_from> || + std::derived_from> || + std::derived_from> || + std::derived_from>; + +template +struct str_arg_char : public str_arg_char_for_atl {}; + +#else // UPA_CPP_20 + +template +struct str_arg_char> : + public str_arg_char_for_atl> {}; + +template +struct str_arg_char> : + public str_arg_char_for_atl> {}; + +template +struct str_arg_char> : + public str_arg_char_for_atl> {}; + +#endif // UPA_CPP_20 + } // namespace upa #endif // UPA_URL_FOR_ATL_H diff --git a/test/test-url_for_.cpp b/test/test-url_for_.cpp new file mode 100644 index 0000000..8be19bb --- /dev/null +++ b/test/test-url_for_.cpp @@ -0,0 +1,44 @@ +// Copyright 2024 Rimas Misevičius +// Distributed under the BSD-style license that can be +// found in the LICENSE file. +// + +#include "doctest-main.h" + +#ifdef _MSC_VER +# define UPA_TEST_URL_FOR_ATL +# include "upa/url_for_atl.h" +# include +# include +# include +#endif + +#ifdef UPA_TEST_URL_FOR_ATL + +TEST_CASE("ATL::CSimpleStringA input") { + ATL::CStringA basestr; + + ATL::CSimpleStringA str_input("http://host/", basestr.GetManager()); + upa::url url{ str_input }; + CHECK(url.href() == "http://host/"); +} + +TEST_CASE("ATL::CSimpleStringW input") { + ATL::CStringW basestr; + + ATL::CSimpleStringW str_input(L"http://host/", basestr.GetManager()); + upa::url url{ str_input }; + CHECK(url.href() == "http://host/"); +} + +TEST_CASE_TEMPLATE_DEFINE("ATL string input", StrT, test_url_for_atl) { + StrT str_input("http://host/"); + upa::url url{ str_input }; + CHECK(url.href() == "http://host/"); +} + +TEST_CASE_TEMPLATE_INVOKE(test_url_for_atl, + ATL::CStringA, ATL::CFixedStringT, + ATL::CStringW, ATL::CFixedStringT); + +#endif // UPA_TEST_URL_FOR_ATL