[go: up one dir, main page]

File: test_traits.cpp

package info (click to toggle)
toml11 3.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,120 kB
  • sloc: cpp: 17,500; sh: 6; makefile: 4
file content (84 lines) | stat: -rw-r--r-- 3,691 bytes parent folder | download | duplicates (2)
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
#define BOOST_TEST_MODULE "test_traits"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/types.hpp>

#include <list>
#include <forward_list>
#include <deque>
#include <array>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>

struct dummy_type{};

template<typename T>
struct dummy_container
{
    typedef T value_type;
    typedef value_type* pointer;
    typedef value_type& reference;
    typedef value_type const* const_pointer;
    typedef value_type const& const_reference;
    typedef pointer       iterator;
    typedef const_pointer const_iterator;
};

typedef std::array<dummy_type, 10> std_array_type;
typedef std::map<std::string, dummy_type> std_map_type;
typedef std::unordered_map<std::string, dummy_type> std_unordered_map_type;

BOOST_AUTO_TEST_CASE(test_has_xxx)
{
    BOOST_TEST(toml::detail::has_iterator<std::list<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_iterator<std::forward_list<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_iterator<std::deque<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_iterator<std::vector<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_iterator<std::set<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_iterator<std::unordered_set<std::string>>::value);
    BOOST_TEST(toml::detail::has_iterator<std_array_type>::value);
    BOOST_TEST(toml::detail::has_iterator<std_map_type>::value);
    BOOST_TEST(toml::detail::has_iterator<std_unordered_map_type>::value);
    BOOST_TEST(toml::detail::has_iterator<dummy_container<dummy_type>>::value);

    BOOST_TEST(toml::detail::has_value_type<std::list<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_value_type<std::forward_list<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_value_type<std::deque<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_value_type<std::vector<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_value_type<std_array_type>::value);
    BOOST_TEST(toml::detail::has_value_type<std::set<dummy_type>>::value);
    BOOST_TEST(toml::detail::has_value_type<std::unordered_set<std::string>>::value);
    BOOST_TEST(toml::detail::has_value_type<std_map_type>::value);
    BOOST_TEST(toml::detail::has_value_type<std_unordered_map_type>::value);
    BOOST_TEST(toml::detail::has_value_type<dummy_container<dummy_type>>::value);

    BOOST_TEST(toml::detail::has_key_type<std_map_type>::value);
    BOOST_TEST(toml::detail::has_key_type<std_unordered_map_type>::value);
    BOOST_TEST(toml::detail::has_mapped_type<std_map_type>::value);
    BOOST_TEST(toml::detail::has_mapped_type<std_unordered_map_type>::value);
}

BOOST_AUTO_TEST_CASE(test_is_xxx)
{
    BOOST_TEST(toml::detail::is_container<std::list<dummy_type>>::value);
    BOOST_TEST(toml::detail::is_container<std::forward_list<dummy_type>>::value);
    BOOST_TEST(toml::detail::is_container<std::deque<dummy_type>>::value);
    BOOST_TEST(toml::detail::is_container<std::vector<dummy_type>>::value);
    BOOST_TEST(toml::detail::is_container<std_array_type>::value);
    BOOST_TEST(toml::detail::is_container<std::set<dummy_type>>::value);
    BOOST_TEST(toml::detail::is_container<std::unordered_set<std::string>>::value);
    BOOST_TEST(toml::detail::is_container<dummy_container<dummy_type>>::value);

    BOOST_TEST(!toml::detail::is_container<std_map_type>::value);
    BOOST_TEST(!toml::detail::is_container<std_unordered_map_type>::value);

    BOOST_TEST(toml::detail::is_map<std_map_type>::value);
    BOOST_TEST(toml::detail::is_map<std_unordered_map_type>::value);
}