File: MaximumLength.cpp

package info (click to toggle)
odil 0.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,476 kB
  • sloc: cpp: 55,982; python: 3,947; javascript: 460; xml: 182; makefile: 99; sh: 36
file content (56 lines) | stat: -rw-r--r-- 1,319 bytes parent folder | download | duplicates (6)
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
#define BOOST_TEST_MODULE MaximumLength
#include <boost/test/unit_test.hpp>

#include <sstream>
#include <string>

#include "odil/Exception.h"
#include "odil/pdu/MaximumLength.h"

BOOST_AUTO_TEST_CASE(ConstructorDefault)
{
    odil::pdu::MaximumLength const maximum_length;
    BOOST_REQUIRE_EQUAL(maximum_length.get_maximum_length(), 0);
}

BOOST_AUTO_TEST_CASE(ConstructorInt)
{
    odil::pdu::MaximumLength const maximum_length(123);
    BOOST_REQUIRE_EQUAL(maximum_length.get_maximum_length(), 123);
}

BOOST_AUTO_TEST_CASE(FromStream)
{
    std::string const data(
        "\x51\x00\x00\x04"
        "\x12\x34\x56\x78",
        8
    );
    std::istringstream stream(data);

    odil::pdu::MaximumLength const maximum_length(stream);

    BOOST_REQUIRE_EQUAL(maximum_length.get_maximum_length(), 0x12345678);
}

BOOST_AUTO_TEST_CASE(MaximumLength)
{
    odil::pdu::MaximumLength maximum_length;
    maximum_length.set_maximum_length(123);
    BOOST_REQUIRE_EQUAL(maximum_length.get_maximum_length(), 123);
}

BOOST_AUTO_TEST_CASE(Write)
{
    odil::pdu::MaximumLength const maximum_length(0x12345678);
    std::ostringstream data;
    data << maximum_length;

    std::string const expected(
        "\x51\x00\x00\x04"
        "\x12\x34\x56\x78",
        8
    );

    BOOST_REQUIRE_EQUAL(data.str(), expected);
}