http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/main/java/com/taobao/weex/wson/Wson.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/wson/Wson.java b/android/sdk/src/main/java/com/taobao/weex/wson/Wson.java deleted file mode 100644 index 85d740f..0000000 --- a/android/sdk/src/main/java/com/taobao/weex/wson/Wson.java +++ /dev/null @@ -1,820 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.wson; - - -import android.support.v4.util.LruCache; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.annotation.JSONField; -import com.taobao.weex.utils.WXLogUtils; - -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * fast binary json format for parse map and serialize map - * Created by efurture on 2017/8/16. - */ -public class Wson { - - /** - * skip map null values - * */ - public static final boolean WriteMapNullValue = false; - /** - * wson data type - * */ - private static final byte NULL_TYPE = '0'; - - private static final byte STRING_TYPE = 's'; - - private static final byte BOOLEAN_TYPE_TRUE = 't'; - - private static final byte BOOLEAN_TYPE_FALSE = 'f'; - - private static final byte NUMBER_INT_TYPE = 'i'; - - private static final byte NUMBER_LONG_TYPE = 'l'; - - private static final byte NUMBER_BIG_INTEGER_TYPE = 'g'; - - private static final byte NUMBER_BIG_DECIMAL_TYPE = 'e'; - - private static final byte NUMBER_DOUBLE_TYPE = 'd'; - - private static final byte NUMBER_FLOAT_TYPE = 'F'; - - private static final byte ARRAY_TYPE = '['; - - private static final byte MAP_TYPE = '{'; - - /** - * StringUTF-16, byte order with native byte order - * */ - private static final boolean IS_NATIVE_LITTLE_ENDIAN = (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN); - - - /** - * parse wson data to object, please use WXJsonUtils.parseWson - * @param data byte array - * */ - public static final Object parse(byte[] data){ - if(data == null){ - return null; - } - try{ - Parser parser = new Parser(data); - Object object = parser.parse(); - parser.close(); - return object; - }catch (Exception e){ - WXLogUtils.e("parseWson", e); - return null; - } - } - - - /** - * serialize object to wson data, please use WXJsonUtils.wsonWXJSObject - * */ - public static final byte[] toWson(Object object){ - if(object == null){ - return null; - } - Builder builder = new Builder(); - byte[] bts = builder.toWson(object); - builder.close(); - return bts; - } - - - /** - * wson data parser - * */ - private static final class Parser { - - private int position = 0; - private byte[] buffer; - private char[] charsBuffer; - - private Parser(byte[] buffer) { - this.buffer = buffer; - charsBuffer = localCharsBufferCache.get(); - if(charsBuffer != null){ - localCharsBufferCache.set(null); - }else{ - charsBuffer = new char[512]; - } - } - - - private final Object parse(){ - return readObject(); - } - - private final void close(){ - position = 0; - buffer = null; - if(charsBuffer != null){ - localCharsBufferCache.set(charsBuffer); - } - charsBuffer = null; - } - - private final Object readObject(){ - byte type = readType(); - switch (type){ - case STRING_TYPE: - return readUTF16String(); - case NUMBER_INT_TYPE : - return readVarInt(); - case NUMBER_FLOAT_TYPE : - return readFloat(); - case MAP_TYPE: - return readMap(); - case ARRAY_TYPE: - return readArray(); - case NUMBER_DOUBLE_TYPE : - return readDouble(); - case NUMBER_LONG_TYPE : - return readLong(); - case NUMBER_BIG_INTEGER_TYPE : - return new BigInteger(readUTF16String()); - case NUMBER_BIG_DECIMAL_TYPE : - return new BigDecimal(readUTF16String()); - case BOOLEAN_TYPE_FALSE: - return Boolean.FALSE; - case BOOLEAN_TYPE_TRUE: - return Boolean.TRUE; - case NULL_TYPE: - return null; - default: - throw new RuntimeException("wson unhandled type " + type + " " + - position + " length " + buffer.length); - } - } - - - - private final Object readMap(){ - int size = readUInt(); - Map<String, Object> object = new JSONObject();; - for(int i=0; i<size; i++){ - String key = readMapKeyUTF16(); - Object value = readObject(); - object.put(key, value); - } - return object; - } - - private final Object readArray(){ - int length = readUInt(); - List<Object> array = new JSONArray(length); - for(int i=0; i<length; i++){ - array.add(readObject()); - } - return array; - } - - private final byte readType(){ - byte type = buffer[position]; - position ++; - return type; - } - - - private final String readMapKeyUTF16() { - int length = readUInt(); - length = length/2; - if(charsBuffer.length < length){ - charsBuffer = new char[length]; - } - int hash = 5381; - if(IS_NATIVE_LITTLE_ENDIAN){ - for(int i=0; i<length; i++){ - char ch = (char) ((buffer[position] & 0xFF) + - (buffer[position + 1] << 8)); - charsBuffer[i] = (ch); - hash = ((hash << 5) + hash) + ch; - position+=2; - } - }else{ - for(int i=0; i<length; i++){ - char ch = (char) ((buffer[position + 1] & 0xFF) + - (buffer[position] << 8)); - charsBuffer[i] = (ch); - hash = ((hash << 5) + hash) + ch; - position+=2; - } - } - int globalIndex = (globalStringBytesCache.length - 1)&hash; - String cache = globalStringBytesCache[globalIndex]; - if(cache != null - && cache.length() == length){ - boolean isStringEqual = true; - for(int i=0; i<length; i++){ - if(charsBuffer[i] != cache.charAt(i)){ - isStringEqual = false; - break; - } - } - if(isStringEqual) { - return cache; - } - } - cache = new String(charsBuffer, 0, length); - if(length < 64) { - globalStringBytesCache[globalIndex] = cache; - } - return cache; - } - - private final String readUTF16String(){ - int length = readUInt()/2; - if(charsBuffer.length < length){ - charsBuffer = new char[length]; - } - if(IS_NATIVE_LITTLE_ENDIAN){ - for(int i=0; i<length; i++){ - char ch = (char) ((buffer[position] & 0xFF) + - (buffer[position + 1] << 8)); - charsBuffer[i] = (ch); - position+=2; - } - }else{ - for(int i=0; i<length; i++){ - char ch = (char) ((buffer[position + 1] & 0xFF) + - (buffer[position] << 8)); - charsBuffer[i] = (ch); - position+=2; - } - } - return new String(charsBuffer, 0, length); - } - - - - - - private final int readVarInt(){ - int raw = readUInt(); - // This undoes the trick in putVarInt() - int num = (((raw << 31) >> 31) ^ raw) >> 1; - // This extra step lets us deal with the largest signed values by treating - // negative results from read unsigned methods as like unsigned values. - // Must re-flip the top bit if the original read value had it set. - return num ^ (raw & (1 << 31)); - } - - private final int readUInt(){ - int value = 0; - int i = 0; - int b; - while (((b = buffer[position]) & 0x80) != 0) { - value |= (b & 0x7F) << i; - i += 7; - position+=1; - if (i > 35) { - throw new IllegalArgumentException("Variable length quantity is too long"); - } - } - position+=1; - return value | (b << i); - } - - private final long readLong(){ - long number = (((buffer[position + 7] & 0xFFL) ) + - ((buffer[position + 6] & 0xFFL) << 8) + - ((buffer[position + 5] & 0xFFL) << 16) + - ((buffer[position + 4] & 0xFFL) << 24) + - ((buffer[position + 3] & 0xFFL) << 32) + - ((buffer[position + 2] & 0xFFL) << 40) + - ((buffer[position + 1] & 0xFFL) << 48) + - (((long) buffer[position]) << 56)); - position += 8; - return number; - } - - private final Object readDouble(){ - double number = Double.longBitsToDouble(readLong()); - if(number > Integer.MAX_VALUE){ - long numberLong = (long) number; - double doubleLong = (numberLong); - if(number - doubleLong < Double.MIN_NORMAL){ - return numberLong; - } - } - return number; - } - - private Object readFloat() { - int number = (((buffer[position + 3] & 0xFF) ) + - ((buffer[position + 2] & 0xFF) << 8) + - ((buffer[position + 1] & 0xFF) << 16) + - ((buffer[position ] & 0xFF) << 24)); - position +=4; - return Float.intBitsToFloat(number); - } - } - - /** - * wson builder - * */ - private static final class Builder { - - private byte[] buffer; - private int position; - private ArrayList refs; - private final static ThreadLocal<byte[]> bufLocal = new ThreadLocal<byte[]>(); - private final static ThreadLocal<ArrayList> refsLocal = new ThreadLocal<ArrayList>(); - - - - private Builder(){ - buffer = bufLocal.get(); - if(buffer != null) { - bufLocal.set(null); - }else{ - buffer = new byte[1024]; - } - refs = refsLocal.get(); - if(refs != null){ - refsLocal.set(null); - }else{ - refs = new ArrayList<>(16); - } - } - - - private final byte[] toWson(Object object){ - writeObject(object); - byte[] bts = new byte[position]; - System.arraycopy(buffer, 0, bts, 0, position); - return bts; - } - - private final void close(){ - if(buffer.length <= 1024*16){ - bufLocal.set(buffer); - } - if(refs.isEmpty()){ - refsLocal.set(refs); - }else{ - refs.clear(); - } - refs = null; - buffer = null; - position = 0; - } - - private final void writeObject(Object object) { - if(object instanceof CharSequence){ - ensureCapacity(2); - writeByte(STRING_TYPE); - writeUTF16String((CharSequence) object); - return; - }else if (object instanceof Map){ - if(refs.contains(object)){ - ensureCapacity(2); - writeByte(NULL_TYPE); - return; - } - refs.add(object); - Map map = (Map) object; - writeMap(map); - refs.remove(refs.size()-1); - return; - }else if (object instanceof List){ - if(refs.contains(object)){ - ensureCapacity(2); - writeByte(NULL_TYPE); - return; - } - refs.add(object); - ensureCapacity(8); - List list = (List) object; - writeByte(ARRAY_TYPE); - writeUInt(list.size()); - for(Object value : list){ - writeObject(value); - } - refs.remove(refs.size()-1); - return; - }else if (object instanceof Number){ - Number number = (Number) object; - writeNumber(number); - return; - }else if (object instanceof Boolean){ - ensureCapacity(2); - Boolean value = (Boolean) object; - if(value){ - writeByte(BOOLEAN_TYPE_TRUE); - }else{ - writeByte(BOOLEAN_TYPE_FALSE); - } - return; - }else if(object == null){ - ensureCapacity(2); - writeByte(NULL_TYPE); - return; - }else if (object.getClass().isArray()){ - if(refs.contains(object)){ - ensureCapacity(2); - writeByte(NULL_TYPE); - return; - } - refs.add(object); - ensureCapacity(8); - int length = Array.getLength(object); - writeByte(ARRAY_TYPE); - writeUInt(length); - for(int i=0; i<length; i++){ - Object value = Array.get(object, i); - writeObject(value); - } - refs.remove(refs.size()-1); - return; - }else if(object instanceof Date){ - ensureCapacity(10); - double date = ((Date)object).getTime(); - writeByte(NUMBER_DOUBLE_TYPE); - writeDouble(date); - }else if(object instanceof Calendar){ - ensureCapacity(10); - double date = ((Calendar)object).getTime().getTime(); - writeByte(NUMBER_DOUBLE_TYPE); - writeDouble(date); - }else if(object instanceof Collection){ - if(refs.contains(object)){ - ensureCapacity(2); - writeByte(NULL_TYPE); - return; - } - refs.add(object); - ensureCapacity(8); - Collection list = (Collection) object; - writeByte(ARRAY_TYPE); - writeUInt(list.size()); - for(Object value : list){ - writeObject(value); - } - refs.remove(refs.size()-1); - }else{ - if(refs.contains(object)){ - ensureCapacity(2); - writeByte(NULL_TYPE); - }else { - refs.add(object); - if(object.getClass().isEnum()){ - writeObject(JSON.toJSONString(object)); - }else{ - writeAdapterObject(object); - } - refs.remove(refs.size()-1); - } - return; - } - } - - private final void writeNumber(Number number) { - ensureCapacity(12); - if(number instanceof Integer){ - writeByte(NUMBER_INT_TYPE); - writeVarInt(number.intValue()); - return; - } - - if(number instanceof Float){ - writeByte(NUMBER_FLOAT_TYPE); - writeFloat(number.floatValue()); - return; - } - if(number instanceof Double){ - writeByte(NUMBER_DOUBLE_TYPE); - writeDouble(number.doubleValue()); - return; - } - - if(number instanceof Long){ - writeByte(NUMBER_LONG_TYPE); - writeLong(number.longValue()); - return; - } - - if(number instanceof Short - || number instanceof Byte){ - writeByte(NUMBER_INT_TYPE); - writeVarInt(number.intValue()); - return; - } - - if(number instanceof BigInteger){ - writeByte(NUMBER_BIG_INTEGER_TYPE); - writeUTF16String(number.toString()); - return; - } - - if(number instanceof BigDecimal){ - String value = number.toString(); - double doubleValue = number.doubleValue(); - if(value.equals(Double.toString(doubleValue))){ - writeByte(NUMBER_DOUBLE_TYPE); - writeDouble(doubleValue); - }else { - writeByte(NUMBER_BIG_DECIMAL_TYPE); - writeUTF16String(value); - } - return; - } - writeByte(STRING_TYPE); - writeUTF16String(number.toString()); - - } - - private final void writeMap(Map map) { - if(WriteMapNullValue){ - ensureCapacity(8); - writeByte(MAP_TYPE); - writeUInt(map.size()); - Set<Map.Entry<Object,Object>> entries = map.entrySet(); - for(Map.Entry<Object,Object> entry : entries){ - writeMapKeyUTF16(entry.getKey().toString()); - writeObject(entry.getValue()); - } - }else{ - Set<Map.Entry<Object,Object>> entries = map.entrySet(); - int nullValueSize = 0; - for(Map.Entry<Object,Object> entry : entries){ - if(entry.getValue() == null){ - nullValueSize++; - } - } - - ensureCapacity(8); - writeByte(MAP_TYPE); - writeUInt(map.size()-nullValueSize); - for(Map.Entry<Object,Object> entry : entries){ - if(entry.getValue() == null){ - continue; - } - writeMapKeyUTF16(entry.getKey().toString()); - writeObject(entry.getValue()); - } - } - } - - - private final void writeByte(byte type){ - buffer[position] = type; - position++; - } - - private final void writeAdapterObject(Object object){ - if(specialClass.get(object.getClass().getName()) != null){ - writeObject(JSON.toJSON(object)); - return; - } - try{ - writeMap(toMap(object)); - }catch (Exception e){ - specialClass.put(object.getClass().getName(), true); - writeObject(JSON.toJSON(object)); - } - } - - private final Map toMap(Object object){ - Map map = new JSONObject(); - try { - Class<?> targetClass = object.getClass(); - String key = targetClass.getName(); - List<Method> methods = getBeanMethod(key, targetClass); - for (Method method : methods) { - String methodName = method.getName(); - if (methodName.startsWith(METHOD_PREFIX_GET)) { - Object value = method.invoke(object); - if(value != null){ - StringBuilder builder = new StringBuilder(method.getName().substring(3)); - builder.setCharAt(0, Character.toLowerCase(builder.charAt(0))); - map.put(builder.toString(), (Object) value); - } - }else if(methodName.startsWith(METHOD_PREFIX_IS)){ - Object value = method.invoke(object); - if(value != null){ - StringBuilder builder = new StringBuilder(method.getName().substring(2)); - builder.setCharAt(0, Character.toLowerCase(builder.charAt(0))); - map.put(builder.toString(), value); - } - } - } - List<Field> fields = getBeanFields(key, targetClass); - for(Field field : fields){ - String fieldName = field.getName(); - if(map.containsKey(fieldName)){ - continue; - } - Object value = field.get(object); - if(value == null){ - continue; - } - map.put(fieldName, value); - } - }catch (Exception e){ - if(e instanceof RuntimeException){ - throw (RuntimeException)e; - }else{ - throw new RuntimeException(e); - } - } - return map; - } - - private final void writeMapKeyUTF16(String value){ - writeUTF16String(value); - } - - - - - /** - * writeString UTF-16 - * */ - private final void writeUTF16String(CharSequence value){ - int length = value.length(); - ensureCapacity(length*2 + 8); - writeUInt(length*2); - if(IS_NATIVE_LITTLE_ENDIAN){ - for(int i=0; i<length; i++){ - char ch = value.charAt(i); - buffer[position] = (byte) (ch); - buffer[position+1] = (byte) (ch >>> 8); - position+=2; - } - }else{ - for(int i=0; i<length; i++){ - char ch = value.charAt(i); - buffer[position + 1] = (byte) (ch ); - buffer[position] = (byte) (ch >>> 8); - position+=2; - } - } - } - - - private final void writeDouble(double value){ - writeLong(Double.doubleToLongBits(value)); - } - - private final void writeFloat(float value){ - int val = Float.floatToIntBits(value); - buffer[position + 3] = (byte) (val ); - buffer[position + 2] = (byte) (val >>> 8); - buffer[position + 1] = (byte) (val >>> 16); - buffer[position ] = (byte) (val >>> 24); - position += 4; - } - - private final void writeLong(long val){ - buffer[position + 7] = (byte) (val ); - buffer[position + 6] = (byte) (val >>> 8); - buffer[position + 5] = (byte) (val >>> 16); - buffer[position + 4] = (byte) (val >>> 24); - buffer[position + 3] = (byte) (val >>> 32); - buffer[position + 2] = (byte) (val >>> 40); - buffer[position + 1] = (byte) (val >>> 48); - buffer[position ] = (byte) (val >>> 56); - position += 8; - } - - private final void writeVarInt(int value){ - writeUInt((value << 1) ^ (value >> 31)); - } - - private final void writeUInt(int value){ - while ((value & 0xFFFFFF80) != 0) { - buffer[position] = (byte)((value & 0x7F) | 0x80); - position++; - value >>>= 7; - } - buffer[position] = (byte)(value & 0x7F); - position++; - } - - - private final void ensureCapacity(int minCapacity) { - minCapacity += position; - // overflow-conscious code - if (minCapacity - buffer.length > 0){ - int oldCapacity = buffer.length; - int newCapacity = oldCapacity << 1; - if(newCapacity < 1024*16){ - newCapacity = 1024*16; - } - if (newCapacity - minCapacity < 0) { - newCapacity = minCapacity; - } - buffer = Arrays.copyOf(buffer, newCapacity); - } - } - } - - - /** - * cache json property key, most of them all same - * */ - private static final int GLOBAL_STRING_CACHE_SIZE = 2*1024; - private static final ThreadLocal<char[]> localCharsBufferCache = new ThreadLocal<>(); - private static final String[] globalStringBytesCache = new String[GLOBAL_STRING_CACHE_SIZE]; - - - - - /** - * lru cache, to map helper - * */ - private static final String METHOD_PREFIX_GET = "get"; - private static final String METHOD_PREFIX_IS = "is"; - private static LruCache<String, List<Method>> methodsCache = new LruCache<>(128); - private static LruCache<String, List<Field>> fieldsCache = new LruCache<>(128); - private static LruCache<String, Boolean> specialClass = new LruCache<>(16); - - - private static final List<Method> getBeanMethod(String key, Class targetClass){ - List<Method> methods = methodsCache.get(key); - if(methods == null){ - methods = new ArrayList<>(); - Method[] allMethods = targetClass.getMethods(); - for(Method method : allMethods){ - if(method.getDeclaringClass() == Object.class){ - continue; - } - if( (method.getModifiers() & Modifier.STATIC) != 0){ - continue; - } - String methodName = method.getName(); - if(methodName.startsWith(METHOD_PREFIX_GET) - || methodName.startsWith(METHOD_PREFIX_IS)) { - if(method.getAnnotation(JSONField.class) != null){ - throw new UnsupportedOperationException("getBeanMethod JSONField Annotation Not Handled, Use toJSON"); - } - methods.add(method); - } - } - methodsCache.put(key, methods); - } - return methods; - } - - - - private static final List<Field> getBeanFields(String key, Class targetClass){ - List<Field> fieldList = fieldsCache.get(key); - if(fieldList == null) { - Field[] fields = targetClass.getFields(); - fieldList = new ArrayList<>(fields.length); - for(Field field : fields){ - if((field.getModifiers() & Modifier.STATIC) != 0){ - continue; - } - if(field.getAnnotation(JSONField.class) != null){ - throw new UnsupportedOperationException("getBeanMethod JSONField Annotation Not Handled, Use toJSON"); - } - fieldList.add(field); - } - fieldsCache.put(key, fieldList); - } - return fieldList; - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/WXSDKEngineTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/WXSDKEngineTest.java b/android/sdk/src/test/java/com/taobao/weex/WXSDKEngineTest.java index 3d21b4c..0864653 100644 --- a/android/sdk/src/test/java/com/taobao/weex/WXSDKEngineTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/WXSDKEngineTest.java @@ -18,15 +18,9 @@ */ package com.taobao.weex; -import android.app.Application; -import android.content.pm.ApplicationInfo; -import android.test.mock.MockApplication; -import com.taobao.weex.adapter.IWXHttpAdapter; import com.taobao.weex.bridge.WXBridgeManagerTest; import com.taobao.weex.common.TestModule; import com.taobao.weex.common.TestModuleFactory; -import com.taobao.weex.dom.TestDomObject; -import com.taobao.weex.http.WXStreamModule; import com.taobao.weex.ui.component.TestComponent; import com.taobao.weex.ui.component.WXComponent; @@ -35,7 +29,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; -import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/WXSDKInstanceTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/WXSDKInstanceTest.java b/android/sdk/src/test/java/com/taobao/weex/WXSDKInstanceTest.java index 051ba9e..6be97ae 100644 --- a/android/sdk/src/test/java/com/taobao/weex/WXSDKInstanceTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/WXSDKInstanceTest.java @@ -30,7 +30,6 @@ import com.taobao.weex.bridge.WXBridgeManagerTest; import com.taobao.weex.common.WXPerformance; import com.taobao.weex.common.WXRenderStrategy; import com.taobao.weex.dom.WXDomManagerTest; -import com.taobao.weex.dom.WXDomObject; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXComponentFactory; import com.taobao.weex.ui.component.WXDivTest; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/adapter/DefaultUriAdapterTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/adapter/DefaultUriAdapterTest.java b/android/sdk/src/test/java/com/taobao/weex/adapter/DefaultUriAdapterTest.java index 967199e..3c4d84b 100644 --- a/android/sdk/src/test/java/com/taobao/weex/adapter/DefaultUriAdapterTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/adapter/DefaultUriAdapterTest.java @@ -110,7 +110,7 @@ public class DefaultUriAdapterTest { assertEquals(Uri.parse(host + "/test2"), uri); uri = adapter.rewrite(instance, URIAdapter.IMAGE, Uri.parse("")); - assertEquals(Uri.parse(""), uri); + assertEquals(Uri.parse(bundleUrl), uri); } } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeManagerTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeManagerTest.java b/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeManagerTest.java index 43f0f16..61a3f14 100644 --- a/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeManagerTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeManagerTest.java @@ -19,12 +19,9 @@ package com.taobao.weex.bridge; import static junit.framework.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import android.os.Handler; import android.os.Message; - -import com.alibaba.fastjson.JSON; import com.taobao.weappplus_sdk.BuildConfig; import com.taobao.weex.InitConfig; import com.taobao.weex.WXSDKEngine; @@ -33,7 +30,6 @@ import com.taobao.weex.WXSDKInstanceTest; import com.taobao.weex.WXSDKManagerTest; import com.taobao.weex.common.Constants; import com.taobao.weex.common.WXJSBridgeMsgType; -import com.taobao.weex.dom.WXDomModule; import com.taobao.weex.ui.WXRenderManager; import org.junit.After; import org.junit.Before; @@ -108,12 +104,12 @@ public class WXBridgeManagerTest { public void testCallNative() throws Exception { getInstance() .callNative(instance.getInstanceId(), - JSON.parseArray("[{\"module\":\"testModule\",\"method\":\"test\"}]"), + "[{\"module\":\"testModule\",\"method\":\"test\"}]", null); getInstance() .callNative(instance.getInstanceId(), - JSON.parseArray("[{\"module\":\""+WXDomModule.WXDOM+"\",\"method\":\"test\"}]"), + "[{\"module\":\""+WXDomModule.WXDOM+"\",\"method\":\"test\"}]", null); } @@ -130,7 +126,7 @@ public class WXBridgeManagerTest { @Test public void testCallback() throws Exception { -// getInstance().callbackJavascript(instance.getInstanceId(),"test",null,false); + getInstance().callbackJavascript(instance.getInstanceId(),"test",null,false); } @Test http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeTest.java b/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeTest.java index 198a90d..13feaf6 100644 --- a/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/bridge/WXBridgeTest.java @@ -18,7 +18,6 @@ */ package com.taobao.weex.bridge; -import com.alibaba.fastjson.JSON; import com.taobao.weappplus_sdk.BuildConfig; import org.junit.After; import org.junit.Before; @@ -47,12 +46,12 @@ public class WXBridgeTest { @Test public void testCallNative() throws Exception { - bridge.callNative("1", JSON.parseArray("[]"),"100"); + bridge.callNative("1","{}","100"); } @Test public void testCallAddElement() throws Exception { - bridge.callAddElement("1","1", JSON.parseObject("{}"),"0","100"); + bridge.callAddElement("1","1","{}","0","100"); } http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/dom/TestDomObject.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/dom/TestDomObject.java b/android/sdk/src/test/java/com/taobao/weex/dom/TestDomObject.java deleted file mode 100644 index f290191..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/dom/TestDomObject.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.dom; - -import com.taobao.weex.dom.flex.CSSLayout; - -import static com.taobao.weex.common.Constants.Event; - -/** - * Created by sospartan on 7/27/16. - */ -public class TestDomObject extends WXDomObject { - public static void setRef(WXDomObject dom,String ref){ - dom.mRef = ref; - } - - public static void setAttribute(WXDomObject dom,WXAttr attr){ - dom.mAttributes = attr; - } - - public TestDomObject(){ - mStyles = new WXStyle(); - csslayout.dimensions[0] = 100; - csslayout.dimensions[0] = 50; - csslayout.position[CSSLayout.POSITION_LEFT] = 10; - csslayout.position[CSSLayout.POSITION_RIGHT] = 20; - csslayout.position[CSSLayout.POSITION_TOP] = 20; - csslayout.position[CSSLayout.POSITION_BOTTOM] = 30; - mAttributes = new WXAttr(); - - mEvents = new WXEvent(); - mEvents.add(Event.DISAPPEAR); - mEvents.add(Event.APPEAR); - mEvents.add(Event.CHANGE); - mEvents.add(Event.BLUR); - mEvents.add(Event.INPUT); - mEvents.add(Event.FOCUS); - } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/dom/WXDomModuleTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/dom/WXDomModuleTest.java b/android/sdk/src/test/java/com/taobao/weex/dom/WXDomModuleTest.java deleted file mode 100644 index 0d18a41..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/dom/WXDomModuleTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.dom; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.taobao.weappplus_sdk.BuildConfig; -import com.taobao.weex.WXSDKInstanceTest; -import com.taobao.weex.bridge.WXBridgeManager; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; - -import static com.taobao.weex.dom.WXDomModule.*; - -/** - * Created by sospartan on 7/29/16. - */ -@RunWith(RobolectricTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 19) -@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*","org.json.*" }) -@PrepareForTest() -public class WXDomModuleTest { - - static final String[] METHODS = { - CREATE_BODY, - UPDATE_ATTRS , - UPDATE_STYLE , - REMOVE_ELEMENT, - ADD_ELEMENT , - MOVE_ELEMENT, - ADD_EVENT , - REMOVE_EVENT, - CREATE_FINISH , - REFRESH_FINISH, - UPDATE_FINISH, - SCROLL_TO_ELEMENT, - null, - "unknown_method" - }; - - static JSONObject data; - static{ - data = new JSONObject(); - data.put("a","b"); - } - - static final Object[][] ARGS_CASES = { - null, - {new JSONObject()}, - {"",new JSONObject()}, - {"test",data}, - {"test"}, - {"",new JSONObject(),1}, - {"test",new JSONObject(),1}, - {"","",1}, - {"test","test",1}, - {"","test"}, - {"test","test"}, - }; - - - - WXDomModule module; - - @Before - public void setUp() throws Exception { - module = new WXDomModule(WXSDKInstanceTest.createInstance()); - } - - @After - public void tearDown() throws Exception { - WXDomManagerTest.getLooper().idle(); - } - - @Test - public void testCallDomMethod() throws Exception { - module.callDomMethod(null); - - JSONObject obj = new JSONObject(); - for (String m : - METHODS) { - obj.put(WXBridgeManager.METHOD,m); - module.callDomMethod(obj); - } - - - obj = new JSONObject(); - for (Object[] args:ARGS_CASES - ) { - JSONArray ary = new JSONArray(); - if(args == null){ - ary = null; - }else { - for (Object arg : args - ) { - ary.add(arg); - } - } - obj.put(WXBridgeManager.ARGS,ary); - for (String m : - METHODS) { - obj.put(WXBridgeManager.METHOD,m); - module.callDomMethod(obj); - } - } - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/dom/WXDomObjectTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/dom/WXDomObjectTest.java b/android/sdk/src/test/java/com/taobao/weex/dom/WXDomObjectTest.java deleted file mode 100644 index 7d23d95..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/dom/WXDomObjectTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.dom; - -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.taobao.weappplus_sdk.BuildConfig; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.*; - -/** - * Created by sospartan on 8/29/16. - */ -@RunWith(RobolectricTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 19) -@PowerMockIgnore( {"org.mockito.*", "org.robolectric.*", "android.*"}) -public class WXDomObjectTest { - - WXDomObject dom; - - @Before - public void setUp() throws Exception { - dom = new TestDomObject(); - } - - @After - public void tearDown() throws Exception { - dom.destroy(); - } - - @Test - public void testParseFromJson() throws Exception { - dom.parseFromJson(JSONObject.parseObject("{\"ref\":\"100\",\"type\":\"div\",\"attr\":{},\"style\":{\"backgroundColor\":\"rgb(40,96,144)\",\"fontSize\":40,\"color\":\"#ffffff\",\"paddingRight\":30,\"paddingLeft\":30,\"paddingBottom\":20,\"paddingTop\":20}}")); - assertEquals(dom.getRef(),"100"); - assertEquals(dom.getType(),"div"); - - dom.applyStyleToNode(); - } - - @Test - public void testAdd() throws Exception { - JSONObject obj = new JSONObject(); - obj.put("ref","100"); - obj.put("type","div"); - dom.parseFromJson(obj); - - JSONObject child = new JSONObject(); - child.put("ref","101"); - child.put("type","test"); - WXDomObject childDom = new WXDomObject(); - childDom.parseFromJson(child); - - dom.add(childDom,0); - assertEquals(dom.getChildCount(),1); - assertEquals(dom.getChild(0),childDom); - - dom.removeChildAt(0); - assertEquals(dom.getChildCount(),0); - - dom.add(childDom,0); - assertEquals(dom.getChildCount(),1); - assertEquals(dom.getChild(0),childDom); - - dom.remove(childDom); - - } - - @Test - public void testClone() throws Exception { - JSONObject.parseObject("{\"ref\":\"100\",\"type\":\"div\",\"attr\":{},\"style\":{\"backgroundColor\":\"rgb(40,96,144)\",\"fontSize\":40,\"color\":\"#ffffff\",\"paddingRight\":30,\"paddingLeft\":30,\"paddingBottom\":20,\"paddingTop\":20}}"); - JSONObject obj = new JSONObject(); - obj.put("ref","101"); - obj.put("type","test"); - - JSONArray event = new JSONArray(); - event.add("click"); - obj.put("event",event); - dom.parseFromJson(obj); - - WXDomObject clone = dom.clone(); - assertEquals(clone.getRef(),"101"); - assertEquals(clone.getType(),"test"); - - } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/dom/WXDomStatementTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/dom/WXDomStatementTest.java b/android/sdk/src/test/java/com/taobao/weex/dom/WXDomStatementTest.java index 1cdcf70..4bdd77a 100644 --- a/android/sdk/src/test/java/com/taobao/weex/dom/WXDomStatementTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/dom/WXDomStatementTest.java @@ -27,7 +27,6 @@ import com.taobao.weex.WXSDKInstanceTest; import com.taobao.weex.WXSDKManager; import com.taobao.weex.WXSDKManagerTest; import com.taobao.weex.bridge.WXBridgeManagerTest; -import com.taobao.weex.dom.action.TestActions; import com.taobao.weex.ui.WXRenderManager; import org.junit.After; @@ -269,10 +268,10 @@ public class WXDomStatementTest { @Test public void testCreateFinish() throws Exception { -// createBody(); -// createFinish(); -// -// stmt.batch(); + createBody(); + createFinish(); + + stmt.batch(); } @Test http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/dom/WXTextDomObjectTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/dom/WXTextDomObjectTest.java b/android/sdk/src/test/java/com/taobao/weex/dom/WXTextDomObjectTest.java index fbd00cb..c01259a 100644 --- a/android/sdk/src/test/java/com/taobao/weex/dom/WXTextDomObjectTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/dom/WXTextDomObjectTest.java @@ -19,16 +19,13 @@ package com.taobao.weex.dom; import com.taobao.weappplus_sdk.BuildConfig; -import com.taobao.weex.common.Constants; + import static com.taobao.weex.common.Constants.Name.*; -import com.taobao.weex.dom.flex.MeasureOutput; -import com.taobao.weex.ui.component.WXComponent; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/dom/action/TestActions.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/dom/action/TestActions.java b/android/sdk/src/test/java/com/taobao/weex/dom/action/TestActions.java deleted file mode 100644 index f41bdff..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/dom/action/TestActions.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.dom.action; - -import com.alibaba.fastjson.JSONObject; -import com.taobao.weex.dom.DOMAction; - -/** - * Created by sospartan on 01/03/2017. - */ - -public class TestActions { - public static DOMAction body(JSONObject data){ - return new CreateBodyAction(data); - } - - - public static DOMAction addDom(JSONObject obj, String parentRef, int index) { - return new AddElementAction(obj,parentRef,index); - } - - public static DOMAction remove(String ref) { - return new RemoveElementAction(ref); - } - - public static DOMAction updateAttr(String ref, JSONObject data) { - return new UpdateAttributeAction(ref,data); - } - - public static DOMAction updateStyle(String ref, JSONObject data, boolean byPesudo) { - return new UpdateStyleAction(ref,data,byPesudo); - } - - public static DOMAction moveDom(String ref, String parent, int index) { - return new MoveElementAction(ref,parent,index); - } - - public static DOMAction scrollTo(String ref,JSONObject data){ - return new ScrollToElementAction(ref,data); - } - - public static DOMAction addEvent(String ref,String event){ - return new AddEventAction(ref,event); - } - - public static DOMAction removeEvent(String ref,String event){ - return new RemoveEventAction(ref,event); - } - - public static DOMAction createFinish(){ - return new CreateFinishAction(); - } - - public static DOMAction updateFinish(){ - return new UpdateFinishAction(); - } - - public static DOMAction refreshFinish(){ - return new RefreshFinishAction(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/dom/transition/WXTransitionTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/dom/transition/WXTransitionTest.java b/android/sdk/src/test/java/com/taobao/weex/dom/transition/WXTransitionTest.java deleted file mode 100644 index 7374026..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/dom/transition/WXTransitionTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.dom.transition; - -import android.app.Application; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.taobao.weappplus_sdk.BuildConfig; -import com.taobao.weex.dom.WXDomObject; -import com.taobao.weex.utils.WXViewUtils; - -import junit.framework.Assert; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by furture on 2017/10/18. - */ -@RunWith(RobolectricTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 19) -@PowerMockIgnore( {"org.mockito.*", "org.robolectric.*", "android.*"}) -public class WXTransitionTest extends Application{ - - - - @Test - public void testFrom(){ - WXViewUtils.setScreenWidth(750); - WXDomObject domObject = new WXDomObject(); - domObject.setViewPortWidth(750); - JSONObject map = JSON.parseObject("{\n" + - " \"style\": {\n" + - " \"width\": 600, \n" + - " \"marginLeft\": 75, \n" + - " \"marginTop\": 35, \n" + - " \"marginBottom\": 35, \n" + - " \"flexDirection\": \"column\", \n" + - " \"justifyContent\": \"center\", \n" + - " \"borderWidth\": 2, \n" + - " \"borderStyle\": \"solid\", \n" + - " \"borderColor\": \"rgb(0,180,255)\", \n" + - " \"backgroundColor\": \"rgba(0,180,255,0.2)\", \n" + - " \"transitionProperty\": \"height\", \n" + - " \"transitionDuration\": 300, \n" + - " \"transitionDelay\": 50, \n" + - " \"transitionTimingFunction\": \"ease-in-out\"\n" + - " }\n" + - "}"); - domObject.parseFromJson(map); - Assert.assertNotNull("transition success",domObject.getTransition()); - WXTransition transition = domObject.getTransition(); - Map<String, Object> updates = new HashMap(); - updates.put("height", "1000"); - Assert.assertTrue(transition.hasTransitionProperty(updates)); - transition.startTransition(updates); - - - - } - - @Test - public void testSplit(){ - - Assert.assertTrue(Arrays.equals(new String[]{"height", "width"}, WXTransition.PROPERTY_SPLIT_PATTERN.split("height|width"))); - Assert.assertTrue(Arrays.equals(new String[]{"height", "width"}, WXTransition.PROPERTY_SPLIT_PATTERN.split("height,width"))); - - - System.out.println(Arrays.toString(WXTransition.PROPERTY_SPLIT_PATTERN.split("height|width"))); - System.out.println(Arrays.toString(WXTransition.PROPERTY_SPLIT_PATTERN.split("height,width"))); - } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/el/FailedCaseTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/el/FailedCaseTest.java b/android/sdk/src/test/java/com/taobao/weex/el/FailedCaseTest.java deleted file mode 100644 index f887dca..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/el/FailedCaseTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.el; - -import com.alibaba.fastjson.JSONObject; -import com.taobao.weex.el.parse.ArrayStack; -import com.taobao.weex.el.parse.Parser; -import com.taobao.weex.el.parse.Token; - -import junit.framework.TestCase; - -/** - * Created by furture on 2018/1/25. - */ - -public class FailedCaseTest extends TestCase { - - - public void testVElseIf0(){ - JSONObject data = new JSONObject(); - JSONObject item = new JSONObject(); - item.put("number", 0.0); - data.put("item", item); - ArrayStack stack = new ArrayStack(); - stack.push(data); - - Token token = Parser.parse("!(item.number%3 === 0) && (item.number%3 === 1)"); - - System.out.println(token.toString() + " " + token.execute(stack)); - - Token if2 = Parser.parse("!(!(item.number%3 === 0) && (item.number%3 === 1))"); - System.out.println(if2 + " " + if2.execute(stack)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/el/IfStatementTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/el/IfStatementTest.java b/android/sdk/src/test/java/com/taobao/weex/el/IfStatementTest.java deleted file mode 100644 index 3ba24f9..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/el/IfStatementTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.el; - -import com.alibaba.fastjson.JSONObject; -import com.taobao.weex.el.parse.ArrayStack; -import com.taobao.weex.el.parse.Operators; -import com.taobao.weex.el.parse.Parser; -import com.taobao.weex.el.parse.Token; - -import junit.framework.Assert; -import junit.framework.TestCase; - - -/** - * Created by furture on 2017/8/29. - */ - -public class IfStatementTest extends TestCase { - - public void testVIfFront(){ - Assert.assertTrue(isIfTrue("((true) && 2 > 1) && 1", createContext())); - Assert.assertTrue(isIfTrue("(3 == 3) === (3 === 3)", createContext())); - Assert.assertFalse(isIfTrue("1 ? false : true", createContext())); - Assert.assertTrue(isIfTrue("1 ? true : false", createContext())); - Assert.assertFalse(isIfTrue("!(source)", createContext())); - Assert.assertTrue(isIfTrue("(source)", createContext())); - } - - - public void testVIfMath(){ - Assert.assertFalse(isIfTrue("1 ? false : true", createContext())); - Assert.assertTrue(isIfTrue("1 ? true : false", createContext())); - Assert.assertTrue(isIfTrue("1 >= 1", createContext())); - Assert.assertFalse(isIfTrue("1 >= 2", createContext())); - Assert.assertTrue(isIfTrue("1 && 1 >= 0", createContext())); - Assert.assertFalse(isIfTrue("false && 1 >= 0", createContext())); - Assert.assertTrue(isIfTrue("1 >= '1'", createContext())); - Assert.assertTrue(isIfTrue("0 >= '-1'", createContext())); - Assert.assertTrue(isIfTrue("0 >= '-1", createContext())); - Assert.assertFalse(isIfTrue("!(source)", createContext())); - Assert.assertTrue(isIfTrue("(source)", createContext())); - - - - - - Assert.assertFalse(isIfTrue("1 > 1", createContext())); - Assert.assertFalse(isIfTrue("-1 > 1", createContext())); - Assert.assertTrue(isIfTrue("1 > -1", createContext())); - - - Assert.assertTrue(isIfTrue("1 <= 1", createContext())); - Assert.assertTrue(isIfTrue("1 <= '1'", createContext())); - - Assert.assertFalse(isIfTrue("1 < 1", createContext())); - - Assert.assertFalse(isIfTrue("1 <= -1", createContext())); - Assert.assertFalse(isIfTrue("1 < -2 ", createContext())); - Assert.assertTrue(isIfTrue("1 > 0", createContext())); - Assert.assertTrue(isIfTrue("1 >= 0.1", createContext())); - Assert.assertFalse(isIfTrue("0 >= 1", createContext())); - Assert.assertFalse(isIfTrue(" -1 > 1", createContext())); - Assert.assertTrue(isIfTrue("0 < 1", createContext())); - Assert.assertTrue(isIfTrue(" -1 <= 1", createContext())); - } - - - - public void testVIfAndOr(){ - Assert.assertTrue(isIfTrue("1 && 1", createContext())); - Assert.assertTrue(isIfTrue("1 && true", createContext())); - Assert.assertFalse(isIfTrue("1 && false", createContext())); - - Assert.assertTrue(isIfTrue("true || false", createContext())); - Assert.assertTrue(isIfTrue("1 || false", createContext())); - Assert.assertFalse(isIfTrue("false && false", createContext())); - Assert.assertFalse(isIfTrue("1 && false", createContext())); - Assert.assertFalse(isIfTrue(" && 1", createContext())); - Assert.assertTrue(isIfTrue("1 && 1 && 1 && true && true", createContext())); - Assert.assertFalse(isIfTrue("false && 1 && 1 && true && true", createContext())); - Assert.assertTrue(isIfTrue("1===1 && 1===1", createContext())); - - } - - public void testVIfBracket(){ - Assert.assertTrue(isIfTrue("((true) && 2 > 1) && 1", createContext())); - Assert.assertFalse(isIfTrue("((true) && 2 < 1) && 1", createContext())); - Assert.assertTrue(isIfTrue("((true) && 2 < 1) || 1", createContext())); - Assert.assertTrue(isIfTrue("((true && 2 > 1 && 1", createContext())); - Assert.assertTrue(isIfTrue("true && 2 > 1 && 1", createContext())); - Assert.assertTrue(isIfTrue("(('true') && 2 > 1) && 1", createContext())); - Assert.assertTrue(isIfTrue("(('true') && 2 > 1) && 1 ()()", createContext())); - Assert.assertTrue(isIfTrue("(('true') && 2 > 1) && 1 ( )", createContext())); - - - Assert.assertTrue(isIfTrue("((true) && 2 > 1) && (1)", createContext())); - Assert.assertTrue(isIfTrue("((true) && 2 > 1) && (1) && (1)", createContext())); - Assert.assertTrue(isIfTrue("((true) && 2 > 1) && (1) || (3)", createContext())); - - Assert.assertTrue(isIfTrue("1", createContext())); - Assert.assertTrue(isIfTrue("true && 2 > 1 && 1", createContext())); - } - - public void testDebug(){ - //System.out.println("isIfTrue" + isIfTrue("((true) && 2 > 1) && 1", createContext())); - Assert.assertFalse(isIfTrue("1 <= 0", createContext())); - Assert.assertTrue(isIfTrue("1 > -1 + 1", createContext())); - Assert.assertFalse(isIfTrue("1 < -1", createContext())); - //Assert.assertTrue(isIfTrue("-1", createContext())); - } - - public void testVIf(){ - Assert.assertTrue(isIfTrue("((true) && 2 > 1) && 1", createContext())); - Assert.assertTrue(isIfTrue("'hello' === 'hello'", createContext())); - Assert.assertTrue(isIfTrue("'3 ' === 3", createContext())); - Assert.assertTrue(isIfTrue("'3 ' == 3", createContext())); - Assert.assertFalse(isIfTrue("'3 ' != 3", createContext())); - Assert.assertTrue(isIfTrue("(3 === 3) === true", createContext())); - Assert.assertTrue(isIfTrue("(3 == 3) === (3 === 3)", createContext())); - } - - private boolean isIfTrue(String code, Object context){ - Token block = Parser.parse(code); - System.out.println( code + " ==> " + block); - return Operators.isTrue(block.execute(context)); - } - private ArrayStack createContext(){ - JSONObject data = new JSONObject(); - data.put("item", new JSONObject()); - data.put("index", 20); - data.put("source", true); - data.getJSONObject("item").put("name", "hello world"); - - ArrayStack context = new ArrayStack(); - context.push(data); - return context; - } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/el/ParserTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/el/ParserTest.java b/android/sdk/src/test/java/com/taobao/weex/el/ParserTest.java deleted file mode 100644 index b95e85a..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/el/ParserTest.java +++ /dev/null @@ -1,244 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.el; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.parser.Feature; -import com.taobao.weex.el.parse.ArrayStack; -import com.taobao.weex.el.parse.Operators; -import com.taobao.weex.el.parse.Parser; -import com.taobao.weex.el.parse.Token; - -import junit.framework.Assert; -import junit.framework.TestCase; - - -/** - * Created by furture on 2017/8/28. - */ - -public class ParserTest extends TestCase { - - - - public void testParseString(){ - Assert.assertEquals("hello world", Parser.parse("\"hello world\"").execute(null)); - Assert.assertEquals("hello 'world", Parser.parse("\"hello \'world\"").execute(null)); - Assert.assertEquals("hello \"world", Parser.parse("\"hello \\\"world\"").execute(null)); - Assert.assertEquals("hello world", Parser.parse("'hello world'").execute(null)); - Assert.assertEquals("hello \"world", Parser.parse("'hello \"world'").execute(null)); - Assert.assertEquals("hello 'world", Parser.parse("'hello \\'world'").execute(null)); - } - - public void testMath(){ - Assert.assertEquals(5.0, Parser.parse("1+4").execute(null)); - Assert.assertEquals(4000001.0, Parser.parse("1+4e6").execute(null)); - Assert.assertEquals(400001.0, Parser.parse("1+.4e6").execute(null)); - Assert.assertEquals(1.4, Parser.parse("1+.4").execute(null)); - Assert.assertEquals(11.0, Parser.parse("1+e6").execute(createContext())); - Assert.assertEquals("1e7hello", Parser.parse("1+e7").execute(createContext())); - Assert.assertEquals(9.0, Parser.parse("1+4*2").execute(null)); - Assert.assertEquals(5.0, Parser.parse("1+4*2/2").execute(null)); - Assert.assertEquals(3.0, Parser.parse("1+4/2").execute(null)); - Assert.assertEquals(2.0, Parser.parse("1+4/4").execute(null)); - Assert.assertEquals(2.0, Parser.parse("1+4%3").execute(null)); - Assert.assertEquals(1.0, Parser.parse("1+4%4").execute(null)); - Assert.assertTrue(Double.isInfinite((double)Parser.parse("1+4/0").execute(null))); - Assert.assertTrue(Double.isNaN((double)Parser.parse("4%0").execute(null))); - - Assert.assertEquals(Parser.parse("1").execute(null), Parser.parse("1++*").execute(null)); - Assert.assertEquals(3.0, Parser.parse("1+2+*").execute(null)); - Assert.assertEquals(3.0, Parser.parse("1+(2*+*)").execute(null)); - } - - public void testCondition(){ - Assert.assertEquals(1, Parser.parse("0 ? 2 : 1").execute(null)); - Assert.assertEquals(2, Parser.parse("1 ? 2 : 1").execute(null)); - Assert.assertEquals(3, Parser.parse("0 ? 1 : (2 ? 3 : 4)").execute(null)); - Assert.assertEquals(3, Parser.parse("0 ? 1 : 2 ? 3 : 4").execute(null)); - Assert.assertEquals(4, Parser.parse("0 ? 1 : 0 ? 3 : 4").execute(null)); - Assert.assertEquals(5, Parser.parse("1 ? 5 : (2 ? 3 : 4)").execute(null)); - Assert.assertEquals(1, Parser.parse("0?2:1").execute(null)); - Assert.assertEquals(1, Parser.parse("0?2:1").execute(null)); - Assert.assertEquals(4, Parser.parse("0?1:0?3:4").execute(null)); - Assert.assertEquals(3, Parser.parse("0?1:0+1?3:4").execute(null)); - Assert.assertEquals("hello world", Parser.parse("item.name ? item.name : false").execute(this.createContext())); - Assert.assertEquals(10, Parser.parse("item.name ? item[1] : false").execute(this.createContext())); - Assert.assertEquals("hello world", Parser.parse("item.name == null ? false : item.name").execute(this.createContext())); - Assert.assertEquals(false, Parser.parse("true ? false : item.name").execute(this.createContext())); - Assert.assertEquals(false, Parser.parse("true ? false : item.name.work").execute(this.createContext())); - Assert.assertEquals("hello world", Parser.parse("item.name ? item.name : false").execute(this.createContext())); - Assert.assertEquals(null, Parser.parse("item.name ? item.name.not : false").execute(this.createContext())); - Assert.assertEquals("hello world", Parser.parse("item.name == null ? false : (item.name)").execute(this.createContext())); - - - } - - public void testDebug(){ - System.out.println("execute " + Parser.parse("true ? false : item.name").execute(this.createContext())); - show("true ? false : true xxxx"); - show("true ? false : ((item.name))"); - Parser.parse("item[1]").execute(this.createContext()); - Token block = Parser.parse("{{{item.name}}}"); - show("true ? item.name : false"); - show("((true) && 2 > 1) && (1) && (1)"); - System.out.println(block.execute(createContext()) - + " " + Double.parseDouble(".0e6")); - show("1 > -1"); - - } - - - public void testBracket(){ - // Assert.assertEquals(Parser.parse("(item.name)").toString(), Parser.parse("(((item.name)))").toString()); - // Assert.assertEquals(Parser.parse("((item.name))").toString(), Parser.parse("(((item.name)))").toString()); - Assert.assertEquals("hello world", Parser.parse("(((item.name)))").execute(createContext())); - Assert.assertEquals("hello world", Parser.parse("((item.name))").execute(createContext())); - } - - public void testEl(){ - Assert.assertEquals(true, Parser.parse("${item.name.length == 11}").execute(createContext())); - Assert.assertEquals("hello world", Parser.parse("${{{item.name}}}").execute(createContext())); - Assert.assertEquals("hello world", Parser.parse("${{item.name}}").execute(createContext())); - Assert.assertEquals("hello world", Parser.parse("${{{item.name}}}").execute(createContext())); - Assert.assertEquals("hello world", Parser.parse("{{item.name}}").execute(createContext())); - Assert.assertEquals("hello world", Parser.parse("{{{item.name}}}").execute(createContext())); - Assert.assertEquals("hello world", Parser.parse("{{{{item.name}}}}").execute(createContext())); - Assert.assertEquals(1, Parser.parse("1").execute(createContext())); - Assert.assertEquals(30.0, Parser.parse("item[1] + index").execute(createContext())); - Assert.assertEquals("hello world20", Parser.parse("item.name + index").execute(createContext())); - Assert.assertEquals("hello world20", Parser.parse("item[name] + index").execute(createContext())); - Assert.assertEquals(21.0, Parser.parse("1 + index").execute(createContext())); - Assert.assertEquals(11.0, Parser.parse("1 + index/2").execute(createContext())); - Assert.assertEquals(20.0, Parser.parse("item.name/10 + index").execute(createContext())); - - Assert.assertEquals(31.0, Parser.parse("item.name.length + index").execute(createContext())); - Assert.assertEquals(22.0, Parser.parse("item.length + index").execute(createContext())); - Assert.assertEquals(36.0, Parser.parse("count * ${ratio}").execute(createContext())); - Assert.assertEquals(36.0, Parser.parse("count * ${ratio}").execute(createContext())); - Assert.assertEquals(36.0, Parser.parse("count * ${{ratio}}").execute(createContext())); - Assert.assertEquals(36.0, Parser.parse("count * ${{{ratio}}}").execute(createContext())); - Assert.assertEquals(36.0, Parser.parse("count * $ratio").execute(createContext())); - } - - public void testIf(){ - Assert.assertTrue(Operators.isTrue(Parser.parse("1 ? true : false").execute(createContext()))); - Assert.assertFalse(Operators.isTrue(Parser.parse("1 ? false : true").execute(createContext()))); - Assert.assertFalse(Operators.isTrue(Parser.parse("1 ? null : true").execute(createContext()))); - Assert.assertFalse(Operators.isTrue(Parser.parse("1 ? undefined : true").execute(createContext()))); - Assert.assertFalse(Operators.isTrue(Parser.parse("1 ? \"\" : true").execute(createContext()))); - Assert.assertEquals("hello world", Parser.parse("true ? item.name : false").execute(createContext())); - Assert.assertEquals("hello world", Parser.parse("item.name ? item.name : false").execute(createContext())); - Assert.assertEquals(true, Parser.parse("true").execute(createContext())); - Assert.assertEquals(false, Parser.parse("false").execute(createContext())); - Assert.assertEquals(null, Parser.parse("null").execute(createContext())); - Assert.assertEquals(null, Parser.parse("undefined").execute(createContext())); - - } - - - public void testParse(){ - Assert.assertEquals(1, Parser.parse("0?2:1").execute(null)); - Assert.assertEquals(4, Parser.parse("0?1:0?3:4").execute(null)); - Assert.assertEquals(3, Parser.parse("0?1:0+1?3:4").execute(null)); - Parser.parse("item.code \"string test \" ( item.ddd) .item 1000 ccc ? ddd : 0"); - Parser.parse("1+e6"); - show(null); - - show("()++++"); - - show("item"); - } - - - private void show(String code){ - Token block = Parser.parse(code); - System.out.println( code + " ==> " + block); - } - - public void testArray(){ - int disableDecimalFeature = JSON.DEFAULT_PARSER_FEATURE &= ~Feature.UseBigDecimal.getMask(); - Assert.assertEquals(JSONArray.parse("[2, 3, 3]", disableDecimalFeature), Parser.parse("[2, 3, 3]").execute(null)); - Assert.assertEquals(JSONArray.parse("[2.0, 3, 3]", disableDecimalFeature), Parser.parse("[1+1, 3, 3]").execute(null)); - Assert.assertEquals(JSONArray.parse("[2.0, 3,[3, 3], 3]", disableDecimalFeature), Parser.parse("[1+1, 3, [3, 3], 3]").execute(null)); - Assert.assertEquals(JSONArray.parse("['hello world', 3,[3, 3], 3]", disableDecimalFeature), Parser.parse("[item.name, 3, [3, 3], 3]").execute(this.createContext())); - Assert.assertEquals(JSONArray.parse("[10, 3,[3, 3], 3]", disableDecimalFeature), Parser.parse("[item[1], 3, [3, 3], 3]").execute(this.createContext())); - Assert.assertEquals(JSONArray.parse("[1, 3,[3, 3], 3]", disableDecimalFeature), Parser.parse("[1, 3, [3, 3], 3]").execute(this.createContext())); - Assert.assertEquals(JSONArray.parse("[1, 3,['hello world', 3], 3]", disableDecimalFeature), Parser.parse("[1, 3, [item.name, 3], 3]").execute(this.createContext())); - Assert.assertEquals(JSONArray.parse("[1, [1, 2],[3, 3], 3]", disableDecimalFeature), Parser.parse("[1, [1, 2], [3, 3], 3]").execute(this.createContext())); - Assert.assertEquals(null, Parser.parse("item[name + index]").execute(this.createContext())); - Assert.assertEquals("hello world", Parser.parse("item[name]").execute(this.createContext())); - Assert.assertEquals("hello world", Parser.parse("item['name']").execute(this.createContext())); - Assert.assertEquals(10, Parser.parse("item[1]").execute(this.createContext())); - Assert.assertEquals(JSONArray.parse("[false, [1, 2],[3, 3], 3]", disableDecimalFeature), Parser.parse("[!true, [1, 2], [3, 3], 3]").execute(this.createContext())); - Assert.assertEquals(JSONArray.parse("[2, 3, 3]", disableDecimalFeature), Parser.parse("[(2), 3, 3]").execute(null)); - Assert.assertEquals(JSONArray.parse("[2, 3, 3]", disableDecimalFeature), Parser.parse("([2, 3, 3])").execute(null)); - Assert.assertEquals(JSONArray.parse("[2, 3, 3]", disableDecimalFeature), Parser.parse("([2, 3, (3)])").execute(null)); - - } - - - public void testOperator(){ - Parser parser = new Parser("(1 + 3)/3*3"); - Token block = parser.parse(); - - System.out.println(block.execute(null)); - - System.out.println(block); - - Parser parser2 = new Parser("1 + +++"); - block = parser2.parse(); - - - System.out.println(block); - - - String[] values = {null, null}; - for (Object value : values) { - System.out.println(value + "ddd"); - } - - } - - private ArrayStack createContext(){ - JSONObject data = new JSONObject(); - data.put("item", new JSONObject()); - data.put("index", 20); - data.put("1", 10); - data.put("source", true); - data.put("e6", 10); - data.put("e7", "e7hello"); - data.put("ratio", 6); - data.put("count", 6); - data.getJSONObject("item").put("name", "hello world"); - data.getJSONObject("item").put("1", 10); - - ArrayStack context = new ArrayStack(); - context.push(data); - return context; - } - - - - - - -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/http/WXStreamModuleTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/http/WXStreamModuleTest.java b/android/sdk/src/test/java/com/taobao/weex/http/WXStreamModuleTest.java index f4643ec..e0a2aa3 100644 --- a/android/sdk/src/test/java/com/taobao/weex/http/WXStreamModuleTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/http/WXStreamModuleTest.java @@ -21,7 +21,6 @@ package com.taobao.weex.http; import android.os.Looper; import android.telecom.Call; -import com.alibaba.fastjson.JSON; import com.taobao.weex.WXSDKInstanceTest; import com.taobao.weex.adapter.DefaultWXHttpAdapter; import com.taobao.weex.adapter.IWXHttpAdapter; @@ -95,7 +94,7 @@ public class WXStreamModuleTest { WXStreamModule streamModule = new WXStreamModule(adapter); Callback cb = new Callback(); - streamModule.fetch(JSON.parseObject("{}"),cb,null); + streamModule.fetch("",cb,null); assert !(boolean)cb.mData.get("ok"); } @@ -117,7 +116,7 @@ public class WXStreamModuleTest { WXStreamModule streamModule = createModule(adapter); Callback cb = new Callback(); - streamModule.fetch(JSON.parseObject("{'url':'http://www.taobao.com'}"),cb,null); + streamModule.fetch("{'url':'http://www.taobao.com'}",cb,null); assert (boolean)cb.mData.get("ok"); } @@ -136,7 +135,7 @@ public class WXStreamModuleTest { WXStreamModule streamModule = createModule(adapter); Callback cb = new Callback(); - streamModule.fetch(JSON.parseObject("{'url':'http://www.taobao.com'}"),null,cb); + streamModule.fetch("{'url':'http://www.taobao.com'}",null,cb); assert ((Map<String,String>)cb.mData.get("headers")).get("key").equals("someval"); } @@ -147,7 +146,7 @@ public class WXStreamModuleTest { JSCallback progress = mock(JSCallback.class); JSCallback finish = mock(JSCallback.class); System.out.print("request start "+System.currentTimeMillis()); - streamModule.fetch(JSON.parseObject("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}"),finish,progress); + streamModule.fetch("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}",finish,progress); verify(progress,timeout(10*1000).atLeastOnce()).invokeAndKeepAlive(anyMapOf(String.class, Object.class)); verify(finish,timeout(10*1000).times(1)).invoke(anyMapOf(String.class, Object.class)); System.out.print("\nrequest finish"+System.currentTimeMillis()); @@ -166,10 +165,10 @@ public class WXStreamModuleTest { }); Callback finish = new Callback(); - streamModule.fetch(JSON.parseObject("{}"),finish,null); + streamModule.fetch("",finish,null); assertEquals(finish.mData.get(WXStreamModule.STATUS_TEXT),Status.ERR_INVALID_REQUEST); - streamModule.fetch(JSON.parseObject("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}"),finish,null); + streamModule.fetch("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}",finish,null); assertEquals(finish.mData.get(WXStreamModule.STATUS_TEXT),Status.ERR_CONNECT_FAILED); streamModule = createModule(new IWXHttpAdapter() { @@ -180,7 +179,7 @@ public class WXStreamModuleTest { listener.onHttpFinish(response); } }); - streamModule.fetch(JSON.parseObject("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}"),finish,null); + streamModule.fetch("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}",finish,null); assertEquals(finish.mData.get(WXStreamModule.STATUS),302); assertEquals(finish.mData.get(WXStreamModule.STATUS).getClass(),Integer.class); assertEquals(finish.mData.get(WXStreamModule.STATUS_TEXT),Status.getStatusText("302")); http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/ComponentHolderTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/ComponentHolderTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/ComponentHolderTest.java index fb9e85a..1ddb122 100644 --- a/android/sdk/src/test/java/com/taobao/weex/ui/ComponentHolderTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/ui/ComponentHolderTest.java @@ -20,14 +20,11 @@ package com.taobao.weex.ui; import com.taobao.weex.WXSDKInstance; import com.taobao.weex.bridge.Invoker; -import com.taobao.weex.dom.WXDomObject; import com.taobao.weex.ui.component.WXComponent; import com.taobao.weex.ui.component.WXVContainer; import java.lang.reflect.InvocationTargetException; -import static org.junit.Assert.*; - /** * Created by sospartan on 8/4/16. */ http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/WXRenderStatementTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/WXRenderStatementTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/WXRenderStatementTest.java index 044c92c..1c4fef9 100644 --- a/android/sdk/src/test/java/com/taobao/weex/ui/WXRenderStatementTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/ui/WXRenderStatementTest.java @@ -42,7 +42,7 @@ import org.robolectric.annotation.Config; @PrepareForTest({WXSoInstallMgrSdk.class, TextUtils.class,WXComponentFactory.class}) public class WXRenderStatementTest { - RenderActionContextImpl mWXRenderStatement; + RenderContextImpl mWXRenderStatement; @Before public void setUp() throws Exception { @@ -52,7 +52,7 @@ public class WXRenderStatementTest { PowerMockito.when(TextUtils.isEmpty("124")).thenReturn(true); PowerMockito.when(WXSoInstallMgrSdk.initSo(null, 1, null)).thenReturn(true); WXSDKInstance instance = Mockito.mock(WXSDKInstance.class); - mWXRenderStatement = new RenderActionContextImpl(instance); + mWXRenderStatement = new RenderContextImpl(instance); } public void testCreateBody() throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/animation/TransformParserTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/animation/TransformParserTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/animation/TransformParserTest.java deleted file mode 100644 index 28b94ab..0000000 --- a/android/sdk/src/test/java/com/taobao/weex/ui/animation/TransformParserTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package com.taobao.weex.ui.animation; - -import android.util.Property; -import android.view.View; - -import junit.framework.TestCase; - -import java.util.Map; - -/** - * Created by furture on 2017/10/24. - */ - -public class TransformParserTest extends TestCase { - - public void testParseTransform(){ - Map<Property<View,Float>, Float> transforms = TransformParser.parseTransForm("rotate(7deg) translate(1, 2)", 100, 100, 750); - System.out.println(transforms.size()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/animation/WXAnimationModuleTest.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/animation/WXAnimationModuleTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/animation/WXAnimationModuleTest.java index 52e52fa..7dd4858 100644 --- a/android/sdk/src/test/java/com/taobao/weex/ui/animation/WXAnimationModuleTest.java +++ b/android/sdk/src/test/java/com/taobao/weex/ui/animation/WXAnimationModuleTest.java @@ -18,7 +18,6 @@ */ package com.taobao.weex.ui.animation; -import com.alibaba.fastjson.JSONObject; import com.taobao.weappplus_sdk.BuildConfig; import com.taobao.weex.WXSDKInstanceTest; @@ -51,8 +50,8 @@ public class WXAnimationModuleTest { @Test public void testTransition() throws Exception { - module.transition("", JSONObject.parseObject("{}"),""); - module.transition("test", JSONObject.parseObject("{\"test\":\"test\"}"),""); + module.transition("","",""); + module.transition("test","test",""); } @Test
