Skip to content

Commit

Permalink
add natvis test
Browse files Browse the repository at this point in the history
  • Loading branch information
vinniefalco committed Aug 19, 2022
1 parent dbe84ab commit d365586
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/boost/url/grammar/impl/error.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ make_error_code(
{
struct codes : error_category
{
codes() noexcept
: error_category(
0x0536e50a30f9e9f2)
{
}

const char*
name() const noexcept override
{
Expand Down Expand Up @@ -73,6 +79,12 @@ make_error_condition(
{
struct codes : error_category
{
codes() noexcept
: error_category(
0x809a015e2fe509bd)
{
}

const char*
name() const noexcept override
{
Expand Down
6 changes: 6 additions & 0 deletions include/boost/url/impl/error.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ make_error_code(error e)
{
struct codes : error_category
{
codes() noexcept
: error_category(
0xbc15399d7a4ce829)
{
}

const char*
name() const noexcept override
{
Expand Down
1 change: 1 addition & 0 deletions test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(BOOST_URL_TESTS_FILES
host_type.cpp
ipv4_address.cpp
ipv6_address.cpp
natvis.cpp
optional.cpp
params.cpp
params_encoded.cpp
Expand Down
129 changes: 129 additions & 0 deletions test/unit/natvis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//
// Copyright (c) 2019 Vinnie Falco ([email protected])
// Copyright (c) 2022 Alan Freitas ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/CPPAlliance/url
//

#include <boost/url/error.hpp>
#include <boost/url/string_view.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/core/ignore_unused.hpp>
#include <system_error>
#include "test_suite.hpp"

namespace boost {
namespace urls {

struct natvis_test
{
struct yesexcept
{
int id;
yesexcept()
: id([]
{
static int id_ = 0;
return ++id_;
}())
{
}
yesexcept(yesexcept&& u) { id = u.id; }
yesexcept(yesexcept const& u) { id = u.id; }
yesexcept& operator=(yesexcept&& u) { id = u.id; return *this; }
yesexcept& operator=(yesexcept const& u) { id = u.id; return *this; }
};

struct my_category : error_category
{
my_category() noexcept
: error_category(0xabadfadeadeadfad)
{
}

const char* name() const noexcept override
{
return "boost.url.natvis";
}

std::string message(int) const override
{
return {};
}

error_condition default_error_condition(
int ev) const noexcept override
{
return {ev, *this};
}
};

// these are here to view the results of
// .natvis definitions in the debugger.
void
run()
{
// boost::assert::source_location
{
static auto loc = BOOST_CURRENT_LOCATION;
ignore_unused(loc);
}

// boost::variant2::variant
{
}

// boost::system::error_category
{
auto const& c1 = boost::system::generic_category();
auto const& c2 = boost::system::system_category();
auto const& c3 = error_code(std::error_code()).category();
auto const& c4 = my_category();
auto const& c5 = error_code(error::not_a_base).category();
ignore_unused(c1, c2, c3, c4, c5);
}

// boost::system::error_code
{
static auto loc = BOOST_CURRENT_LOCATION;
auto const e0 = error_code();
auto const e1 = error_code(std::make_error_code(std::errc::address_in_use));
auto const e2 = error_code(error::success);
auto const e3a = error_code(error::not_a_base);
auto const e3b = error_code(make_error_code(errc::bad_address));
auto const e4 = error_code(error_code(error::success), &loc);
auto const e5 = error_code(error_code(error::not_a_base), &loc);
ignore_unused(e0, e1, e2, e3a, e3b, e4, e5);
}

// boost::system::result
{
result<double> rv1;
result<double> rv2 = 3.14;
result<double> rv3 = error::not_a_base;
result<yesexcept> rv4;
result<yesexcept> rv5 = yesexcept{};
result<yesexcept> rv6 = error::not_a_base;
ignore_unused(rv1, rv2, rv3, rv4, rv5, rv6);
}

// boost::core::string_view
{
string_view s1;
string_view s2 = "This is how we do it";
string_view s3 = s2.substr(8, 3);
ignore_unused(s1, s2, s3);
}
}
};

TEST_SUITE(
natvis_test,
"boost.url.natvis");

} // urls
} // boost

0 comments on commit d365586

Please sign in to comment.