Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dd_vector_test.cpp « coding_tests « coding - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d6cc16f842de738664397edebc3f482b1ff4e763 (plain)
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
#include "testing/testing.hpp"

#include "coding/dd_vector.hpp"
#include "coding/reader.hpp"


UNIT_TEST(DDVector_Smoke)
{
  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 (size_t i = 0; i < v.size(); ++i, ++it)
    TEST_EQUAL(v[i], *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, ());
}