MCPcopy Create free account
hub / github.com/couchbase/fleece / EncoderTests

Class EncoderTests

Tests/EncoderTests.cc:33–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31 using namespace fleece::impl::internal;
32
33class EncoderTests {
34public:
35 EncoderTests()
36 :enc()
37 { }
38
39 ~EncoderTests() {
40 enc.reset();
41 }
42
43 Encoder enc;
44 alloc_slice result;
45
46 void endEncoding() {
47 enc.end();
48 result = enc.finish();
49 REQUIRE(result);
50 enc.reset();
51 }
52
53 template <bool WIDE>
54 uint32_t pointerOffset(const Value *v) const noexcept {
55 return v->_asPointer()->offset<WIDE>();
56 }
57
58 void checkOutput(const char *expected) {
59 endEncoding();
60 std::string hex;
61 for (size_t i = 0; i < result.size; i++) {
62 char str[4];
63 sprintf(str, "%02X", result[i]);
64 hex.append(str);
65 if (i % 2 && i != result.size-1)
66 hex.append(" ");
67 }
68 REQUIRE(hex == std::string(expected));
69 }
70
71 void checkReadBool(bool b) {
72 auto v = Value::fromData(result);
73 REQUIRE(v != nullptr);
74 REQUIRE(v->type() == kBoolean);
75 REQUIRE(v->asBool() == b);
76 REQUIRE(v->asInt() == (int64_t)b);
77 }
78
79 void checkRead(int64_t i) {
80 auto v = Value::fromData(result);
81 if (!v || v->type() != kNumber || !v->isInteger() || v->isUnsigned() || v->asInt() != i || v->asDouble() != (double)i) {
82 REQUIRE(v != nullptr);
83 REQUIRE(v->type() == kNumber);
84 REQUIRE(v->isInteger());
85 REQUIRE(!v->isUnsigned());
86 REQUIRE(v->asInt() == i);
87 REQUIRE(v->asDouble() == (double)i);
88 }
89 }
90

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected