OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/wasm/decoder.h" | 7 #include "src/wasm/decoder.h" |
8 #include "src/wasm/leb-helper.h" | 8 #include "src/wasm/leb-helper.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 #define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \ | 90 #define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \ |
91 static void CheckEncodeDecode_##name(ctype val) { \ | 91 static void CheckEncodeDecode_##name(ctype val) { \ |
92 static const int kSize = 16; \ | 92 static const int kSize = 16; \ |
93 static byte buffer[kSize]; \ | 93 static byte buffer[kSize]; \ |
94 byte *ptr = buffer; \ | 94 byte *ptr = buffer; \ |
95 LEBHelper::write_##name(&ptr, val); \ | 95 LEBHelper::write_##name(&ptr, val); \ |
96 EXPECT_EQ(LEBHelper::sizeof_##name(val), \ | 96 EXPECT_EQ(LEBHelper::sizeof_##name(val), \ |
97 static_cast<size_t>(ptr - buffer)); \ | 97 static_cast<size_t>(ptr - buffer)); \ |
98 Decoder decoder(buffer, buffer + kSize); \ | 98 Decoder decoder(buffer, buffer + kSize); \ |
99 int length = 0; \ | 99 unsigned int length = 0; \ |
100 ctype result = decoder.checked_read_##name(buffer, 0, &length); \ | 100 ctype result = decoder.checked_read_##name(buffer, 0, &length); \ |
101 EXPECT_EQ(val, result); \ | 101 EXPECT_EQ(val, result); \ |
102 EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \ | 102 EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \ |
103 } | 103 } |
104 | 104 |
105 DECLARE_ENCODE_DECODE_CHECKER(int32_t, i32v) | 105 DECLARE_ENCODE_DECODE_CHECKER(int32_t, i32v) |
106 DECLARE_ENCODE_DECODE_CHECKER(uint32_t, u32v) | 106 DECLARE_ENCODE_DECODE_CHECKER(uint32_t, u32v) |
107 DECLARE_ENCODE_DECODE_CHECKER(int64_t, i64v) | 107 DECLARE_ENCODE_DECODE_CHECKER(int64_t, i64v) |
108 DECLARE_ENCODE_DECODE_CHECKER(uint64_t, u64v) | 108 DECLARE_ENCODE_DECODE_CHECKER(uint64_t, u64v) |
109 | 109 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 CheckEncodeDecode_i64v(bit_cast<int64_t>(val)); | 181 CheckEncodeDecode_i64v(bit_cast<int64_t>(val)); |
182 } | 182 } |
183 | 183 |
184 for (uint64_t val = 0xFFFFFFFFFFFFFF3B; val != 0; val = val << 1) { | 184 for (uint64_t val = 0xFFFFFFFFFFFFFF3B; val != 0; val = val << 1) { |
185 CheckEncodeDecode_i64v(bit_cast<int64_t>(val)); | 185 CheckEncodeDecode_i64v(bit_cast<int64_t>(val)); |
186 } | 186 } |
187 } | 187 } |
188 } // namespace wasm | 188 } // namespace wasm |
189 } // namespace internal | 189 } // namespace internal |
190 } // namespace v8 | 190 } // namespace v8 |
OLD | NEW |