Skip to content

Commit 1c1ae07

Browse files
committed
add unsigned java tests
1 parent f2f5059 commit 1c1ae07

File tree

8 files changed

+61
-28
lines changed

8 files changed

+61
-28
lines changed

java/fory-core/src/main/java/org/apache/fory/config/ForyBuilder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ public ForyBuilder withLanguage(Language language) {
102102
return this;
103103
}
104104

105+
public ForyBuilder withXlang(boolean xlang) {
106+
this.language = xlang ? Language.XLANG : Language.JAVA;
107+
return this;
108+
}
109+
105110
/** Whether track shared or circular references. */
106111
public ForyBuilder withRefTracking(boolean trackingRef) {
107112
this.trackingRef = trackingRef;
@@ -260,6 +265,11 @@ public ForyBuilder withCompatibleMode(CompatibleMode compatibleMode) {
260265
return this;
261266
}
262267

268+
public ForyBuilder withCompatible(boolean compatible) {
269+
return withCompatibleMode(
270+
compatible ? CompatibleMode.COMPATIBLE : CompatibleMode.SCHEMA_CONSISTENT);
271+
}
272+
263273
/**
264274
* Whether check class schema consistency, will be disabled automatically when {@link
265275
* CompatibleMode#COMPATIBLE} is enabled. Do not disable this option unless you can ensure the

java/fory-core/src/main/java/org/apache/fory/meta/ClassDef.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.ObjectStreamClass;
2525
import java.io.Serializable;
2626
import java.lang.reflect.Field;
27-
import java.math.BigDecimal;
2827
import java.util.ArrayList;
2928
import java.util.Collection;
3029
import java.util.Comparator;

java/fory-core/src/main/java/org/apache/fory/meta/FieldInfo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.io.Serializable;
2323
import java.lang.reflect.Field;
2424
import java.lang.reflect.Modifier;
25-
import java.math.BigDecimal;
2625
import java.util.Objects;
2726
import org.apache.fory.reflect.TypeRef;
2827
import org.apache.fory.resolver.TypeResolver;

java/fory-core/src/main/java/org/apache/fory/meta/FieldTypes.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ public static FieldType xread(
369369
default:
370370
{
371371
if (Types.isPrimitiveType(xtypeId)) {
372-
// unsigned types share same class with signed numeric types, so unsigned types are not registered.
372+
// unsigned types share same class with signed numeric types, so unsigned types are
373+
// not registered.
373374
return new RegisteredFieldType(nullable, trackingRef, xtypeId);
374375
}
375376
if (!Types.isUserDefinedType((byte) xtypeId)) {
@@ -423,7 +424,7 @@ public TypeRef<?> toTypeToken(TypeResolver resolver, TypeRef<?> declared) {
423424
if (TypeUtils.unwrap(declared.getRawType()) == TypeUtils.unwrap(cls)) {
424425
// we still need correct type, the `read/write` should use `nullable` of `Descriptor`
425426
// for serialization
426-
cls = declared.getRawType();
427+
cls = declared.getRawType();
427428
}
428429
}
429430
return TypeRef.of(cls, new TypeExtMeta(classId, nullable, trackingRef));

java/fory-core/src/main/java/org/apache/fory/serializer/NonexistentClassSerializers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.apache.fory.collection.IdentityObjectIntMap;
3030
import org.apache.fory.collection.LongMap;
3131
import org.apache.fory.collection.MapEntry;
32+
import org.apache.fory.logging.Logger;
33+
import org.apache.fory.logging.LoggerFactory;
3234
import org.apache.fory.memory.MemoryBuffer;
3335
import org.apache.fory.meta.ClassDef;
3436
import org.apache.fory.resolver.ClassInfo;
@@ -45,8 +47,6 @@
4547
import org.apache.fory.type.DescriptorGrouper;
4648
import org.apache.fory.type.DispatchId;
4749
import org.apache.fory.type.Generics;
48-
import org.apache.fory.logging.Logger;
49-
import org.apache.fory.logging.LoggerFactory;
5050
import org.apache.fory.util.Preconditions;
5151

5252
@SuppressWarnings({"rawtypes", "unchecked"})

java/fory-core/src/test/java/org/apache/fory/ForyTestBase.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public static Object[][] crossLanguageReferenceTrackingConfig() {
183183

184184
@DataProvider
185185
public static Object[][] language() {
186-
return new Object[][] { {Language.XLANG}};
186+
return new Object[][] {{Language.JAVA}, {Language.XLANG}};
187187
}
188188

189189
@DataProvider(name = "javaFory")
@@ -197,7 +197,34 @@ public static Object[][] javaForyConfig() {
197197
.requireClassRegistration(false)
198198
.suppressClassRegistrationWarnings(true)
199199
.build()
200-
}
200+
},
201+
{
202+
Fory.builder()
203+
.withLanguage(Language.JAVA)
204+
.withRefTracking(false)
205+
.withCodegen(false)
206+
.requireClassRegistration(false)
207+
.suppressClassRegistrationWarnings(true)
208+
.build()
209+
},
210+
{
211+
Fory.builder()
212+
.withLanguage(Language.JAVA)
213+
.withRefTracking(true)
214+
.withCodegen(true)
215+
.requireClassRegistration(false)
216+
.suppressClassRegistrationWarnings(true)
217+
.build()
218+
},
219+
{
220+
Fory.builder()
221+
.withLanguage(Language.JAVA)
222+
.withRefTracking(false)
223+
.withCodegen(true)
224+
.requireClassRegistration(false)
225+
.suppressClassRegistrationWarnings(true)
226+
.build()
227+
},
201228
};
202229
}
203230

java/fory-core/src/test/java/org/apache/fory/serializer/CompatibleFieldConvertTest.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.apache.fory.serializer;
2121

2222
import com.google.common.collect.ImmutableSet;
23+
import java.lang.reflect.Field;
24+
import java.util.List;
2325
import org.apache.fory.Fory;
2426
import org.apache.fory.ForyTestBase;
2527
import org.apache.fory.config.CompatibleMode;
@@ -30,9 +32,6 @@
3032
import org.testng.Assert;
3133
import org.testng.annotations.Test;
3234

33-
import java.lang.reflect.Field;
34-
import java.util.List;
35-
3635
public class CompatibleFieldConvertTest extends ForyTestBase {
3736
public static final class CompatibleFieldConvert1 {
3837
public boolean ftrue;
@@ -49,7 +48,10 @@ public static final class CompatibleFieldConvert1 {
4948
public Float f12;
5049
public double f13;
5150
public Double f14;
52-
public String toString() {return "" + ftrue + ffalse + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14;}
51+
52+
public String toString() {
53+
return "" + ftrue + ffalse + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14;
54+
}
5355
}
5456

5557
public static final class CompatibleFieldConvert2 {
@@ -67,7 +69,10 @@ public static final class CompatibleFieldConvert2 {
6769
public float f12;
6870
public Double f13;
6971
public double f14;
70-
public String toString() {return "" + ftrue + ffalse + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14;}
72+
73+
public String toString() {
74+
return "" + ftrue + ffalse + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14;
75+
}
7176
}
7277

7378
public static final class CompatibleFieldConvert3 {
@@ -85,7 +90,10 @@ public static final class CompatibleFieldConvert3 {
8590
public String f12;
8691
public String f13;
8792
public String f14;
88-
public String toString() {return ftrue + ffalse + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14;}
93+
94+
public String toString() {
95+
return ftrue + ffalse + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14;
96+
}
8997
}
9098

9199
@Test(dataProvider = "language")
@@ -105,21 +113,15 @@ public void testCompatibleFieldConvert(Language language) throws Exception {
105113
field.set(o1, converted);
106114
}
107115
Fory fory =
108-
builder()
109-
.withLanguage(language)
110-
.withCompatibleMode(CompatibleMode.COMPATIBLE)
111-
.build();
116+
builder().withLanguage(language).withCompatibleMode(CompatibleMode.COMPATIBLE).build();
112117
fory.register(cls);
113118
bytes = fory.serialize(o1);
114119
}
115120
{
116121
Class<?> cls = CompatibleFieldConvert2.class;
117122
Assert.assertNotEquals(o1.getClass(), cls);
118123
Fory fory =
119-
builder()
120-
.withLanguage(language)
121-
.withCompatibleMode(CompatibleMode.COMPATIBLE)
122-
.build();
124+
builder().withLanguage(language).withCompatibleMode(CompatibleMode.COMPATIBLE).build();
123125
fory.register(cls);
124126
Object o = fory.deserialize(bytes);
125127
Assert.assertEquals(o.getClass(), cls);
@@ -138,10 +140,7 @@ public void testCompatibleFieldConvert(Language language) throws Exception {
138140
}
139141
{
140142
Fory fory =
141-
builder()
142-
.withLanguage(language)
143-
.withCompatibleMode(CompatibleMode.COMPATIBLE)
144-
.build();
143+
builder().withLanguage(language).withCompatibleMode(CompatibleMode.COMPATIBLE).build();
145144
Class<?> cls = CompatibleFieldConvert3.class;
146145
Assert.assertNotEquals(o1.getClass(), cls);
147146
fory.register(cls);

java/fory-core/src/test/java/org/apache/fory/serializer/MetaSharedCompatibleTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
import org.apache.fory.reflect.ReflectionUtils;
4343
import org.apache.fory.resolver.MetaContext;
4444
import org.apache.fory.serializer.collection.UnmodifiableSerializersTest;
45-
import org.apache.fory.serializer.converter.FieldConverter;
46-
import org.apache.fory.serializer.converter.FieldConverters;
4745
import org.apache.fory.test.bean.BeanA;
4846
import org.apache.fory.test.bean.BeanB;
4947
import org.apache.fory.test.bean.CollectionFields;

0 commit comments

Comments
 (0)