| 163 | const size_t type_count = sizeof(types) / sizeof(types[0]); |
| 164 | |
| 165 | bool testType(const Encoding& encoding, DataTypeBase* type, bool reset = false) |
| 166 | { |
| 167 | ACE_Message_Block mb(1024); |
| 168 | bool ok = true; |
| 169 | // "offset" represents how far out of alignment the stream is before we write: |
| 170 | // 8 and 0 should be the same, but test both anyway. |
| 171 | // "memory" represents how far out of alignment the mb.wr_ptr() is before we |
| 172 | // give the message block to the serializer (which establishes the logical |
| 173 | // start of the stream). |
| 174 | for (size_t memory = 0; memory <= 8; ++memory) { |
| 175 | for (size_t offset = 0; offset <= 8; ++offset) { |
| 176 | mb.reset(); |
| 177 | mb.wr_ptr(memory); |
| 178 | |
| 179 | Serializer s(&mb, encoding); |
| 180 | mb.wr_ptr(offset); |
| 181 | type->write(s); |
| 182 | |
| 183 | const size_t len1 = mb.length() - memory; |
| 184 | const size_t align1 = type->alignment(encoding); |
| 185 | const size_t padding1 = (align1 > 1 && offset % align1) |
| 186 | ? align1 - (offset % align1) : 0; |
| 187 | const size_t expected1 = offset + padding1 + type->space(); |
| 188 | if (len1 != expected1) { |
| 189 | ok = false; |
| 190 | std::cerr << "ERROR: expected length " << expected1 << " != actual " |
| 191 | << len1 << " with offset " << offset << " and type " |
| 192 | << type->name() << " (padding " << padding1 << ")\n"; |
| 193 | continue; |
| 194 | } |
| 195 | |
| 196 | if (reset) { |
| 197 | s.reset_alignment(); |
| 198 | } |
| 199 | |
| 200 | type->write(s); |
| 201 | { |
| 202 | const size_t len = mb.length() - memory; |
| 203 | const size_t align = type->alignment(encoding); |
| 204 | const size_t extraPadding = (reset || !align) ? 0 : (len1 % align); |
| 205 | |
| 206 | const size_t padding = (align > 1 && offset % align) |
| 207 | ? align - (offset % align) : 0; |
| 208 | const size_t expected = offset + extraPadding + |
| 209 | padding + type->space() * 2; |
| 210 | if (len != expected) { |
| 211 | ok = false; |
| 212 | std::cerr << "ERROR: expected length2 " << expected << " != actual " |
| 213 | << len << " with offset " << offset << " and type " |
| 214 | << type->name() << " (padding " << padding << ")\n"; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | mb.rd_ptr(memory); |
| 219 | |
| 220 | Serializer s2(&mb, encoding); |
| 221 | mb.rd_ptr(offset); |
| 222 | type->read(s2); |