OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium 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 #ifndef MOJO_PUBLIC_C_TESTS_BINDINGS_TESTING_UTIL_H_ | 5 #ifndef MOJO_PUBLIC_C_TESTS_BINDINGS_TESTING_UTIL_H_ |
6 #define MOJO_PUBLIC_C_TESTS_BINDINGS_TESTING_UTIL_H_ | 6 #define MOJO_PUBLIC_C_TESTS_BINDINGS_TESTING_UTIL_H_ |
7 | 7 |
8 #include <mojo/bindings/buffer.h> | 8 #include <mojo/bindings/buffer.h> |
9 #include <mojo/system/handle.h> | 9 #include <mojo/system/handle.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 #include <string.h> | 12 #include <string.h> |
13 | 13 |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "gtest/gtest.h" |
15 | 15 |
16 // This will copy the supplied |in_struct| and compare it against the new | 16 // This will copy the supplied |in_struct| and compare it against the new |
17 // copy, expecting them to be the same. It compares the encoded version to be | 17 // copy, expecting them to be the same. It compares the encoded version to be |
18 // sure that they are the same, since a unencoded version will have pointers | 18 // sure that they are the same, since a unencoded version will have pointers |
19 // pointing to separate objects in the two copies, whereas encoded versions will | 19 // pointing to separate objects in the two copies, whereas encoded versions will |
20 // only have relative offsets for pointers. The new copy will remain encoded, | 20 // only have relative offsets for pointers. The new copy will remain encoded, |
21 // and the original will be decoded. | 21 // and the original will be decoded. |
22 // This function won't work for structs with handles, and will crash. | 22 // This function won't work for structs with handles, and will crash. |
23 template <typename T> | 23 template <typename T> |
24 void CopyAndCompare( | 24 void CopyAndCompare( |
(...skipping 13 matching lines...) Expand all Loading... |
38 EXPECT_EQ(in_struct_size, buf->num_bytes_used); | 38 EXPECT_EQ(in_struct_size, buf->num_bytes_used); |
39 | 39 |
40 encode_fn(in_struct, in_struct_size, NULL); | 40 encode_fn(in_struct, in_struct_size, NULL); |
41 encode_fn(out_struct, buf->num_bytes_used, NULL); | 41 encode_fn(out_struct, buf->num_bytes_used, NULL); |
42 EXPECT_EQ(0, memcmp(in_struct, out_struct, buf->num_bytes_used)); | 42 EXPECT_EQ(0, memcmp(in_struct, out_struct, buf->num_bytes_used)); |
43 | 43 |
44 decode_fn(in_struct, in_struct_size, NULL, 0); | 44 decode_fn(in_struct, in_struct_size, NULL, 0); |
45 } | 45 } |
46 | 46 |
47 #endif // MOJO_PUBLIC_C_TESTS_BINDINGS_TESTING_UTIL_H_ | 47 #endif // MOJO_PUBLIC_C_TESTS_BINDINGS_TESTING_UTIL_H_ |
OLD | NEW |