File: test_integers.cpp

package info (click to toggle)
reflect-cpp 0.21.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,128 kB
  • sloc: cpp: 50,336; python: 139; makefile: 30; sh: 3
file content (43 lines) | stat: -rw-r--r-- 947 bytes parent folder | download
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 <gtest/gtest.h>

#include <rfl/cbor.hpp>
#include "write_and_read.hpp"

namespace test_integers {

TEST(cbor, test_integers_signedness) {

    static constexpr uint64_t BIG_INT = 0xffffffffffffffff;

    struct Unsigned {
        uint64_t u64;
    };

    struct Signed {
        int64_t i64;
    };

    write_and_read(
        Unsigned{BIG_INT},
        // From https://cbor.me/?diag={_%20%22u64%22:%200xffffffffffffffff}
        R"(
BF                     # map(*)
   63                  # text(3)
      753634           # "u64"
   1B FFFFFFFFFFFFFFFF # unsigned(18446744073709551615)
   FF                  # primitive(*)
    )");

    write_and_read(
        Signed{static_cast<int64_t>(BIG_INT)},
        // From https://cbor.me/?diag={_%20%22i64%22:%20-1}
        R"(
BF           # map(*)
   63        # text(3)
      693634 # "i64"
   20        # negative(0)
   FF        # primitive(*)
    )");
}

}  // namespace test_integers