mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-14 15:05:37 +02:00
Modernize codebase
- Enhance CMakeLists.txt files. - Move to Boost Test from Google Test to support pre-C++11 compilers. - Add more configurations on CI matrix builds. - Other minor fixes
This commit is contained in:
@@ -1,22 +1,12 @@
|
||||
#include <msgpack.hpp>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#endif //defined(__GNUC__)
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif //defined(__GNUC__)
|
||||
#define BOOST_TEST_MODULE iterator
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
#include <iterator>
|
||||
|
||||
@@ -25,13 +15,13 @@ using namespace std;
|
||||
constexpr unsigned int VECTOR_SIZE = 100;
|
||||
constexpr unsigned int MAP_SIZE = 100;
|
||||
|
||||
TEST(iterator, vector)
|
||||
BOOST_AUTO_TEST_CASE(vector)
|
||||
{
|
||||
using vec_type = vector<unsigned int>;
|
||||
using vec_type = std::vector<unsigned>;
|
||||
vec_type vec;
|
||||
vec.reserve(VECTOR_SIZE);
|
||||
for (unsigned int i = 0; i < VECTOR_SIZE; i++) {
|
||||
vec.push_back(static_cast<unsigned int>(rand()));
|
||||
vec.push_back(static_cast<unsigned>(rand()));
|
||||
}
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, vec);
|
||||
@@ -42,22 +32,22 @@ TEST(iterator, vector)
|
||||
auto const& msgarr = oh.get().via.array;
|
||||
auto dist = std::distance(begin(msgarr), end(msgarr));
|
||||
auto vecSize = vec.size();
|
||||
EXPECT_EQ(static_cast<size_t>(dist), vecSize);
|
||||
BOOST_CHECK_EQUAL(static_cast<size_t>(dist), vecSize);
|
||||
|
||||
vec_type::const_iterator correct = std::begin(vec);
|
||||
for (auto const& obj : msgarr) {
|
||||
auto u64 = *correct;
|
||||
EXPECT_EQ(obj.as<unsigned int>(), u64);
|
||||
BOOST_CHECK_EQUAL(obj.as<unsigned>(), u64);
|
||||
++correct;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(iterator, map)
|
||||
BOOST_AUTO_TEST_CASE(map)
|
||||
{
|
||||
using map_type = map<unsigned int, unsigned int>;
|
||||
using map_type = std::map<unsigned, unsigned>;
|
||||
map_type map;
|
||||
for (unsigned int i = 0; i < MAP_SIZE; i++) {
|
||||
map[static_cast<unsigned int>(rand())] = static_cast<unsigned int>(rand());
|
||||
for (unsigned i = 0; i < MAP_SIZE; i++) {
|
||||
map[static_cast<unsigned>(rand())] = static_cast<unsigned>(rand());
|
||||
}
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, map);
|
||||
@@ -68,13 +58,13 @@ TEST(iterator, map)
|
||||
auto const& msgmap = oh.get().via.map;
|
||||
auto dist = std::distance(begin(msgmap), end(msgmap));
|
||||
auto mapSize = map.size();
|
||||
EXPECT_EQ(static_cast<size_t>(dist), mapSize);
|
||||
BOOST_CHECK_EQUAL(static_cast<size_t>(dist), mapSize);
|
||||
|
||||
for (auto const& kv : msgmap) {
|
||||
auto key = kv.key.as<unsigned int>();
|
||||
auto val = kv.val.as<unsigned int>();
|
||||
auto key = kv.key.as<unsigned>();
|
||||
auto val = kv.val.as<unsigned>();
|
||||
auto correct = map[key];
|
||||
EXPECT_EQ(val, correct);
|
||||
BOOST_CHECK_EQUAL(val, correct);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user