mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03:36 +00:00
committed by
Konstantin Pastbin
parent
c9cbb64f12
commit
76ffc99abd
45
libs/coding/coding_tests/dd_vector_test.cpp
Normal file
45
libs/coding/coding_tests/dd_vector_test.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "testing/testing.hpp"
|
||||
|
||||
#include "coding/dd_vector.hpp"
|
||||
#include "coding/reader.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
UNIT_TEST(DDVector_Smoke)
|
||||
{
|
||||
std::vector<uint16_t> data;
|
||||
// Push size. Big endian is used.
|
||||
data.push_back(1);
|
||||
data.push_back(2);
|
||||
data.push_back(3);
|
||||
typedef DDVector<uint16_t, MemReader> Vector;
|
||||
MemReader reader(reinterpret_cast<char const *>(&data[0]), data.size() * sizeof(data[0]));
|
||||
Vector v(reader);
|
||||
TEST_EQUAL(3, v.size(), ());
|
||||
TEST_EQUAL(1, v[0], ());
|
||||
TEST_EQUAL(2, v[1], ());
|
||||
TEST_EQUAL(3, v[2], ());
|
||||
Vector::const_iterator it = v.begin();
|
||||
for (auto const value : v)
|
||||
TEST_EQUAL(value, *it++, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(DDVector_IncorrectSize)
|
||||
{
|
||||
typedef DDVector<uint16_t, MemReader> Vector;
|
||||
char const data[] = "ab";
|
||||
MemReader reader(data, ARRAY_SIZE(data));
|
||||
|
||||
bool exceptionCaught = false;
|
||||
try
|
||||
{
|
||||
Vector v(reader);
|
||||
}
|
||||
catch (Vector::OpenException & e)
|
||||
{
|
||||
exceptionCaught = true;
|
||||
}
|
||||
|
||||
TEST(exceptionCaught, ());
|
||||
}
|
||||
Reference in New Issue
Block a user