]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/java/test/org/apache/thrift/TestUnsafeBinaries.java
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 package org
.apache
.thrift
;
22 import java
.nio
.ByteBuffer
;
23 import java
.util
.Arrays
;
25 import thrift
.test
.SafeBytes
;
26 import thrift
.test
.UnsafeBytes
;
28 // test generating types with un-copied byte[]/ByteBuffer input/output
30 public class TestUnsafeBinaries
extends TestStruct
{
32 private static byte[] input() {
33 return new byte[]{1, 1};
37 // verify that the unsafe_binaries option modifies behavior
40 // constructor doesn't copy
41 public void testUnsafeConstructor() throws Exception
{
43 byte[] input
= input();
44 UnsafeBytes struct
= new UnsafeBytes(ByteBuffer
.wrap(input
));
48 assertTrue(Arrays
.equals(
55 // getter doesn't copy
56 // note: this behavior is the same with/without the flag, but if this default ever changes, the current behavior
57 // should be retained when using this flag
58 public void testUnsafeGetter(){
59 UnsafeBytes struct
= new UnsafeBytes(ByteBuffer
.wrap(input()));
61 byte[] val
= struct
.getBytes();
64 assertTrue(Arrays
.equals(
71 // setter doesn't copy
72 public void testUnsafeSetter(){
73 UnsafeBytes struct
= new UnsafeBytes();
80 assertTrue(Arrays
.equals(
87 // buffer doens't copy
88 public void testUnsafeBufferFor(){
89 UnsafeBytes struct
= new UnsafeBytes(ByteBuffer
.wrap(input()));
91 ByteBuffer val
= struct
.bufferForBytes();
94 assertTrue(Arrays
.equals(
102 // verify that the default generator does not change behavior
105 public void testSafeConstructor() {
107 byte[] input
= input();
108 SafeBytes struct
= new SafeBytes(ByteBuffer
.wrap(input
));
112 assertTrue(Arrays
.equals(
119 public void testSafeSetter() {
121 byte[] input
= input();
122 SafeBytes struct
= new SafeBytes(ByteBuffer
.wrap(input
));
126 assertTrue(Arrays
.equals(
133 public void testSafeBufferFor(){
134 SafeBytes struct
= new SafeBytes(ByteBuffer
.wrap(input()));
136 ByteBuffer val
= struct
.bufferForBytes();
139 assertTrue(Arrays
.equals(