You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2018/04/28 06:53:50 UTC
[22/48] incubator-weex git commit: * [android] Merge WeexCore-master
to master.
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/ComponentTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/ComponentTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/ComponentTest.java
index 876d61a..1e74e7a 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/ComponentTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/ComponentTest.java
@@ -21,9 +21,6 @@ package com.taobao.weex.ui.component;
import android.view.View;
import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.dom.TestDomObject;
-import com.taobao.weex.dom.WXDomObject;
-import junit.framework.TestFailure;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
@@ -52,10 +49,10 @@ public class ComponentTest {
parent.createChildViewAt(-1);
}
- comp.setLayout(domObject);
+ comp.setLayout(comp);
- domObject = new TestDomObject();
- comp.updateDom(domObject);
+// domObject = new TestDomObject();
+// comp.updateDom(domObject);
comp.applyLayoutAndEvent(comp);
addEvent(comp);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/EditComponentTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/EditComponentTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/EditComponentTest.java
index 9d9fd90..8a40791 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/EditComponentTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/EditComponentTest.java
@@ -21,7 +21,6 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import com.taobao.weex.ui.view.WXEditText;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/PriorityQueueTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/PriorityQueueTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/PriorityQueueTest.java
deleted file mode 100644
index 805d13c..0000000
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/PriorityQueueTest.java
+++ /dev/null
@@ -1,56 +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.component;
-
-import junit.framework.TestCase;
-
-import org.junit.Test;
-
-import java.util.Comparator;
-import java.util.PriorityQueue;
-
-/**
- * Created by furture on 2018/1/3.
- */
-
-public class PriorityQueueTest extends TestCase {
-
-
- @Test
- public void testPriority(){
- PriorityQueue<Integer> embeds = new PriorityQueue<>(8, new Comparator<Integer>() {
- @Override
- public int compare(Integer o1, Integer o2) {
- return o1 - o2;
- }
- });
-
-
- embeds.add(10);
- embeds.add(9);
- embeds.offer(1);
-
- embeds.offer(2);
- embeds.add(11);
-
- System.out.println(embeds.peek() + " " + embeds.size());
-
- System.out.println(embeds.poll() + " " + embeds.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/TestComponent.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/TestComponent.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/TestComponent.java
index 283b573..1ac43e6 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/TestComponent.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/TestComponent.java
@@ -18,11 +18,7 @@
*/
package com.taobao.weex.ui.component;
-import android.view.View;
import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.dom.WXDomObject;
-
-import java.lang.reflect.InvocationTargetException;
/**
* Created by sospartan on 7/27/16.
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXComponentTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXComponentTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXComponentTest.java
index 15953a8..8ea91f1 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXComponentTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXComponentTest.java
@@ -20,7 +20,7 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.ui.view.border.BorderDrawable;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXDivTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXDivTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXDivTest.java
index 480d5a6..310af8e 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXDivTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXDivTest.java
@@ -18,16 +18,11 @@
*/
package com.taobao.weex.ui.component;
-import static org.junit.Assert.assertEquals;
-
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKInstanceTest;
-import com.taobao.weex.dom.TestDomObject;
-import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.dom.WXEvent;
-import com.taobao.weex.dom.flex.Spacing;
-import com.taobao.weex.ui.flat.FlatGUIContext;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,6 +31,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import static org.junit.Assert.*;
+
/**
* Created by gulin on 16/2/24.
*/
@@ -61,7 +58,6 @@ public class WXDivTest {
public void setUp() throws Exception {
WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
- Mockito.when(instance.getFlatUIContext()).thenReturn(new FlatGUIContext());
WXDomObject divDom = new WXDomObject();
WXDomObject spy = Mockito.spy(divDom);
@@ -77,7 +73,6 @@ public class WXDivTest {
public void testAddChild(){
WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
- Mockito.when(instance.getFlatUIContext()).thenReturn(new FlatGUIContext());
WXDomObject testDom = Mockito.mock(WXDomObject.class);
Mockito.when(testDom.getPadding()).thenReturn(new Spacing());
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXEmbedTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXEmbedTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXEmbedTest.java
index cb88a66..752b425 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXEmbedTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXEmbedTest.java
@@ -20,20 +20,16 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXEnvironment;
-import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.TestDomObject;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import static org.junit.Assert.*;
-
/**
* Created by sospartan on 26/09/2016.
*/
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXHeaderTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXHeaderTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXHeaderTest.java
index 213119b..740f7c4 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXHeaderTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXHeaderTest.java
@@ -19,14 +19,10 @@
package com.taobao.weex.ui.component;
import com.taobao.weex.WXSDKInstanceTest;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
-import com.taobao.weex.ui.component.list.WXListComponent;
import java.lang.reflect.InvocationTargetException;
-import static org.junit.Assert.*;
-
/**
* Created by sospartan on 8/29/16.
*/
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXImageTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXImageTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXImageTest.java
index 1c05647..9999f71 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXImageTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXImageTest.java
@@ -32,9 +32,7 @@ import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.common.Constants;
import com.taobao.weex.common.WXImageSharpen;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.dom.WXAttr;
-import com.taobao.weex.dom.WXDomObject;
import com.taobao.weex.ui.view.WXImageView;
import com.taobao.weex.ui.view.border.BorderDrawable;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXLoadingTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXLoadingTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXLoadingTest.java
index c244031..59d803e 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXLoadingTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXLoadingTest.java
@@ -21,7 +21,6 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import org.junit.After;
import org.junit.Before;
@@ -33,8 +32,6 @@ import org.robolectric.annotation.Config;
import java.lang.reflect.InvocationTargetException;
-import static org.junit.Assert.*;
-
/**
* Created by sospartan on 28/09/2016.
*/
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXRefreshTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXRefreshTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXRefreshTest.java
index 505c45e..99ca151 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXRefreshTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXRefreshTest.java
@@ -21,7 +21,6 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import org.junit.After;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXScrollerTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXScrollerTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXScrollerTest.java
index bf0bed7..185ab2e 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXScrollerTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXScrollerTest.java
@@ -18,11 +18,8 @@
*/
package com.taobao.weex.ui.component;
-import android.view.ViewGroup;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
-import com.taobao.weex.dom.TestDomObject;
-import com.taobao.weex.dom.WXScrollerDomObject;
import com.taobao.weex.ui.view.WXScrollView;
import org.junit.After;
import org.junit.Before;
@@ -32,8 +29,6 @@ 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/25/16.
*/
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderNeighborTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderNeighborTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderNeighborTest.java
index 30c202d..0f18fa5 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderNeighborTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderNeighborTest.java
@@ -20,7 +20,6 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import org.junit.After;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderTest.java
index 995289f..697d3b4 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSliderTest.java
@@ -20,7 +20,6 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import org.junit.After;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSwitchTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSwitchTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSwitchTest.java
index 178ba55..63f8d6a 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSwitchTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXSwitchTest.java
@@ -21,7 +21,6 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import com.taobao.weex.ui.view.WXSwitchView;
@@ -36,8 +35,6 @@ import org.robolectric.annotation.Config;
import java.lang.reflect.InvocationTargetException;
-import static org.junit.Assert.*;
-
/**
* Created by sospartan on 28/09/2016.
*/
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXTextTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXTextTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXTextTest.java
index 3b6700f..c311ffb 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXTextTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXTextTest.java
@@ -18,23 +18,12 @@
*/
package com.taobao.weex.ui.component;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXEnvironment;
import com.taobao.weex.WXSDKInstance;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.TestDomObject;
-import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.dom.WXTextDomObject;
-import com.taobao.weex.dom.flex.Spacing;
import com.taobao.weex.ui.SimpleComponentHolder;
-import com.taobao.weex.ui.flat.FlatGUIContext;
-import java.util.HashMap;
-import java.util.Map;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,6 +32,14 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
/**
* Created by gulin on 16/2/4.
*/
@@ -59,7 +56,6 @@ public class WXTextTest {
WXEnvironment.sApplication = RuntimeEnvironment.application;
WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
- Mockito.when(instance.getFlatUIContext()).thenReturn(new FlatGUIContext());
mParentDomObj = Mockito.spy(new WXDomObject());
Mockito.when(mParentDomObj.getPadding()).thenReturn(new Spacing());
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXVideoTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXVideoTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXVideoTest.java
index 5f24838..d01caa5 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXVideoTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXVideoTest.java
@@ -21,21 +21,17 @@ package com.taobao.weex.ui.component;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.lang.reflect.InvocationTargetException;
-import static org.junit.Assert.*;
-
/**
* Created by sospartan on 8/10/16.
*/
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java
index 56b0b72..53d1773 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/WXWebTest.java
@@ -22,7 +22,6 @@ import android.view.View;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.TestDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import com.taobao.weex.ui.view.IWebView;
import org.junit.After;
@@ -37,8 +36,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.*;
-
/**
* Created by sospartan on 28/09/2016.
*/
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/binding/BindingValueTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/binding/BindingValueTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/binding/BindingValueTest.java
deleted file mode 100644
index 162877e..0000000
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/binding/BindingValueTest.java
+++ /dev/null
@@ -1,65 +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.component.binding;
-
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weex.el.parse.Parser;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import java.util.Stack;
-
-/**
- * Created by furture on 2017/8/22.
- */
-
-public class BindingValueTest extends TestCase {
-
- public void testBindingValue(){
- System.out.println(Parser.parse("true ? item.name : false").execute(createContext()));
- Assert.assertEquals(getValue("true ? true : false", createContext()), true);
- Assert.assertEquals(getValue("true ? item.name : false", createContext()), "hello world");
- Assert.assertEquals(getValue("false ? item.name : false", createContext()), false);
- Assert.assertEquals(getValue("item.name ? item.name : false", createContext()), "hello world");
- Assert.assertEquals(getValue("item.name > 0 ? item.name : false", createContext()), false);
- Assert.assertEquals(getValue("? item.name : false", createContext()), false);
- }
-
-
- public void testDebug(){
- System.out.println(Parser.parse("true ? item.name : false"));
- Assert.assertTrue(getValue("false ? item.name : false", createContext()).toString().equals("false"));
- }
-
-
- private Object getValue(String expression, Stack context){
- return Parser.parse(expression).execute(context);
- }
-
- private Stack createContext(){
- JSONObject data = new JSONObject();
- data.put("item", new JSONObject());
- data.getJSONObject("item").put("name", "hello world");
-
- Stack context = new Stack();
- 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/ui/component/binding/StatementTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/binding/StatementTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/binding/StatementTest.java
deleted file mode 100644
index 2233acc..0000000
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/binding/StatementTest.java
+++ /dev/null
@@ -1,186 +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.component.binding;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.taobao.weappplus_sdk.BuildConfig;
-import com.taobao.weex.WXSDKInstance;
-import com.taobao.weex.WXSDKInstanceTest;
-import com.taobao.weex.dom.TestDomObject;
-import com.taobao.weex.dom.WXCellDomObject;
-import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.dom.WXEvent;
-import com.taobao.weex.dom.WXTextDomObject;
-import com.taobao.weex.dom.binding.ELUtils;
-import com.taobao.weex.dom.binding.WXStatement;
-import com.taobao.weex.dom.flex.Spacing;
-import com.taobao.weex.el.parse.ArrayStack;
-import com.taobao.weex.ui.component.WXComponent;
-import com.taobao.weex.ui.component.WXComponentFactory;
-import com.taobao.weex.ui.component.WXDiv;
-import com.taobao.weex.ui.component.WXText;
-import com.taobao.weex.ui.component.list.WXCell;
-import com.taobao.weex.ui.component.list.template.CellRenderContext;
-
-import junit.framework.Assert;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.rule.PowerMockRule;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.annotation.Config;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by furture on 2017/8/18.
- */
-@RunWith(RobolectricTestRunner.class)
-@Config(constants = BuildConfig.class, sdk = 19)
-@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*" })
-@PrepareForTest(WXComponentFactory.class)
-public class StatementTest {
-
-
- @Rule
- public PowerMockRule rule = new PowerMockRule();
-
- @Test
- public void testVFor() throws Exception {
- WXCell cell = createVForNode();
- int count = 3;
- Statements.doRender(cell, createContext(count));
- Assert.assertTrue(cell.getChildCount() == 1);
- WXDiv div = (WXDiv) cell.getChild(0);
- Assert.assertEquals(div.getChildCount(), count);
- Assert.assertNotNull(div.getChild(0).getDomObject());
- Assert.assertNotNull(((WXDomObject)div.getChild(0).getDomObject()).getAttrs().getStatement());
- Assert.assertNull(((WXDomObject)div.getChild(1).getDomObject()).getAttrs().getStatement());
- WXComponent childOne = div.getChild(0);
- WXComponent childTwo = div.getChild(1);
- WXComponent childThree = div.getChild(2);
-
- count = 4;
- Statements.doRender(cell, createContext(count));
- Assert.assertTrue(cell.getChildCount() == 1);
- div = (WXDiv) cell.getChild(0);
- Assert.assertTrue(div.getChildCount() == count);
- Assert.assertSame(childOne, div.getChild(0));
- Assert.assertSame(childTwo, div.getChild(1));
- Assert.assertSame(childThree, div.getChild(2));
- WXComponent childFour = div.getChild(3);
-
- count = 5;
- Statements.doRender(cell, createContext(count));
- Assert.assertTrue(cell.getChildCount() == 1);
- div = (WXDiv) cell.getChild(0);
- Assert.assertTrue(div.getChildCount() == count);
- Assert.assertSame(childOne, div.getChild(0));
- Assert.assertSame(childTwo, div.getChild(1));
- Assert.assertSame(childThree, div.getChild(2));
- Assert.assertSame(childFour, div.getChild(3));
-
-
- count = 3;
- Statements.doRender(cell, createContext(count));
- Assert.assertTrue(cell.getChildCount() == 1);
- div = (WXDiv) cell.getChild(0);
- Assert.assertTrue(div.getChildCount() == 5);
- Assert.assertSame(childOne, div.getChild(0));
- Assert.assertSame(childTwo, div.getChild(1));
- Assert.assertSame(childThree, div.getChild(2));
-
- for(int i=count; i<5; i++){
- Assert.assertTrue(div.getChild(i).isWaste());
- }
- }
-
-
-
-
- @Before
- public void setUp() throws Exception {
- WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
- Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
- WXDomObject divDom = new WXDomObject();
- WXDomObject spy = Mockito.spy(divDom);
- Mockito.when(spy.getPadding()).thenReturn(new Spacing());
- Mockito.when(spy.getEvents()).thenReturn(new WXEvent());
- Mockito.when(spy.clone()).thenReturn(divDom);
- TestDomObject.setRef(divDom,"1");
-
- }
-
-
- private WXCell createVForNode() throws Exception {
- WXCell cell = new WXCell(WXSDKInstanceTest.createInstance(),new WXCellDomObject(), null, false);
- final WXDiv div = new WXDiv(WXSDKInstanceTest.createInstance(), new WXDomObject(), cell);
- cell.addChild(div);
- WXText text = new WXText(WXSDKInstanceTest.createInstance(), new WXTextDomObject(), div);
- WXStatement statement = new WXStatement();
- statement.put("[[repeat]]",
- ELUtils.vforBlock(
- JSON.parse("{\n" +
- " '@expression': 'dataList',\n" +
- " '@index': 'index',\n" +
- " '@alias': 'item'\n" +
- " }")));
- WXDomObject domObject = (WXDomObject) text.getDomObject();
- domObject.getAttrs().setStatement(statement);
- div.addChild(text);
-
- PowerMockito.mockStatic(WXComponentFactory.class, new Answer() {
- @Override
- public Object answer(InvocationOnMock invocation) throws Throwable {
- WXText renderNode = new WXText(WXSDKInstanceTest.createInstance(), new WXTextDomObject(), div);
- return renderNode;
- }
- });
- return cell;
- }
-
- private CellRenderContext createContext(int count){
- JSONObject data = new JSONObject();
- data.put("item", new JSONObject());
- data.getJSONObject("item").put("name", "hello world");
- List<String> datas = new ArrayList<>();
- for(int i=0; i<count; i++){
- datas.add("hello" + count);
- }
- data.getJSONObject("item").put("list", datas);
- data.put("dataList", datas);
- ArrayStack context = new ArrayStack();
- context.push(data);
- CellRenderContext cellRenderContext = new CellRenderContext();
- cellRenderContext.stack = context;
- return cellRenderContext;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/list/DefaultDragHelperTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/list/DefaultDragHelperTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/list/DefaultDragHelperTest.java
index 7ffeb99..474bdcf 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/list/DefaultDragHelperTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/list/DefaultDragHelperTest.java
@@ -20,9 +20,6 @@ package com.taobao.weex.ui.component.list;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
-import com.taobao.weex.dom.TestDomObject;
-import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.dom.WXListDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import com.taobao.weex.ui.component.ComponentTest;
import com.taobao.weex.ui.component.WXComponent;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/component/list/WXListComponentTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/component/list/WXListComponentTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/component/list/WXListComponentTest.java
index 82cda73..feb2b05 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/component/list/WXListComponentTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/component/list/WXListComponentTest.java
@@ -20,9 +20,6 @@ package com.taobao.weex.ui.component.list;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
-import com.taobao.weex.common.Constants;
-import com.taobao.weex.dom.WXDomObject;
-import com.taobao.weex.dom.WXListDomObject;
import com.taobao.weex.ui.SimpleComponentHolder;
import com.taobao.weex.ui.component.ComponentTest;
import com.taobao.weex.ui.component.WXComponent;
@@ -114,7 +111,7 @@ public class WXListComponentTest {
ComponentTest.create(div);
WXDomObject dom = new WXListDomObject();
- dom.getAttrs().put(Constants.Name.TRANSFORM,"scale(0.9,0.8);translate(10,20);opacity(0.5);rotate(100)");
+ dom.getAttrs().put(WXListComponent.TRANSFORM,"scale(0.9,0.8);translate(10,20);opacity(0.5);rotate(100)");
component = create(div,dom);
ComponentTest.create(component);
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/module/WXModalUIModuleTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/module/WXModalUIModuleTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/module/WXModalUIModuleTest.java
index a916bb5..17d3fba 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/module/WXModalUIModuleTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/module/WXModalUIModuleTest.java
@@ -18,7 +18,6 @@
*/
package com.taobao.weex.ui.module;
-import com.alibaba.fastjson.JSON;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXSDKInstanceTest;
import com.taobao.weex.bridge.JSCallback;
@@ -57,25 +56,25 @@ public class WXModalUIModuleTest {
@Test
public void testToast() throws Exception {
- module.toast(JSON.parseObject("{}"));
+ module.toast("{}");
}
@Test
public void testAlert() throws Exception {
JSCallback callback = Mockito.mock(JSCallback.class);
- module.alert(JSON.parseObject("{}"),callback);
+ module.alert("{}",callback);
}
@Test
public void testConfirm() throws Exception {
JSCallback callback = Mockito.mock(JSCallback.class);
- module.confirm(JSON.parseObject("{}"),callback);
+ module.confirm("{}",callback);
}
@Test
public void testPrompt() throws Exception {
JSCallback callback = Mockito.mock(JSCallback.class);
- module.prompt(JSON.parseObject("{}"),callback);
+ module.prompt("{}",callback);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/module/WXTimerModuleTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/module/WXTimerModuleTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/module/WXTimerModuleTest.java
index f4331b0..7fe508c 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/module/WXTimerModuleTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/module/WXTimerModuleTest.java
@@ -18,8 +18,6 @@
*/
package com.taobao.weex.ui.module;
-import static android.R.attr.end;
-import static android.R.attr.start;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
@@ -63,7 +61,6 @@ public class WXTimerModuleTest {
public final static int DELAY = 50;
public final static int IMMEDIATELY = 0;
public final static int INVALID_DELAY = -50;
- public final static float FLOAT_DELAY = 20.6f;
@Rule
public PowerMockRule rule = new PowerMockRule();
@@ -87,26 +84,7 @@ public class WXTimerModuleTest {
@Test
public void testSetTimeoutDelay() throws Exception {
module.setTimeout(VALID_FUNC_ID, DELAY);
- long start, end, duration;
- start = mLooper.getScheduler().getCurrentTime();
- mLooper.runOneTask();
- end = mLooper.getScheduler().getCurrentTime();
- duration = end - start;
-
- assertThat(duration, is((long) DELAY));
- Mockito.verify(module, times(1)).handleMessage(any(Message.class));
- }
-
- @Test
- public void testSetTimeoutDelay2() throws Exception {
- module.setTimeout(VALID_FUNC_ID, FLOAT_DELAY);
- long start, end, duration;
- start = mLooper.getScheduler().getCurrentTime();
- mLooper.runOneTask();
- end = mLooper.getScheduler().getCurrentTime();
- duration = end - start;
-
- assertThat(duration, is((long) FLOAT_DELAY));
+ mLooper.idle(DELAY);
Mockito.verify(module, times(1)).handleMessage(any(Message.class));
}
@@ -186,23 +164,6 @@ public class WXTimerModuleTest {
}
@Test
- public void testSetIntervalDelay2() {
- long start, end, duration;
- module.setInterval(VALID_FUNC_ID, FLOAT_DELAY);
-
- start = mLooper.getScheduler().getCurrentTime();
- mLooper.runOneTask();
- end = mLooper.getScheduler().getCurrentTime();
- duration = end - start;
-
- assertThat(duration, is((long) FLOAT_DELAY));
-
- mLooper.runOneTask();
- mLooper.runOneTask();
- Mockito.verify(module, times(3)).handleMessage(any(Message.class));
- }
-
- @Test
public void testClearTimeout() throws Exception {
module.setTimeout(VALID_FUNC_ID, DELAY);
module.clearTimeout(VALID_FUNC_ID);
@@ -219,7 +180,7 @@ public class WXTimerModuleTest {
}
@Test
- public void testClearTimeout2(){
+ public void setClearTimeout2(){
module.setTimeout(NO_CACHING_FUNC_ID, DELAY);
module.clearTimeout(NO_CACHING_FUNC_ID);
mLooper.idle(DELAY, TimeUnit.MILLISECONDS);
@@ -227,7 +188,7 @@ public class WXTimerModuleTest {
}
@Test
- public void testClearInterval2(){
+ public void setClearInterval2(){
module.setInterval(NO_CACHING_FUNC_ID, DELAY);
module.clearInterval(NO_CACHING_FUNC_ID);
mLooper.idle(DELAY, TimeUnit.MILLISECONDS);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/view/border/BorderDrawableTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/view/border/BorderDrawableTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/view/border/BorderDrawableTest.java
index 85089fe..49caafa 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/view/border/BorderDrawableTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/view/border/BorderDrawableTest.java
@@ -24,7 +24,6 @@ import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.Rect;
-import com.taobao.weex.dom.flex.Spacing;
import com.taobao.weex.utils.WXResourceUtils;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/ui/view/gesture/WXGestureTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/ui/view/gesture/WXGestureTest.java b/android/sdk/src/test/java/com/taobao/weex/ui/view/gesture/WXGestureTest.java
index 88c533a..125f9d1 100644
--- a/android/sdk/src/test/java/com/taobao/weex/ui/view/gesture/WXGestureTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/ui/view/gesture/WXGestureTest.java
@@ -18,13 +18,11 @@
*/
package com.taobao.weex.ui.view.gesture;
-import android.provider.Settings;
import android.view.MotionEvent;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.TestActivity;
import com.taobao.weex.ui.component.ComponentTest;
import com.taobao.weex.ui.component.WXComponent;
-import com.taobao.weex.ui.component.WXDiv;
import com.taobao.weex.ui.component.WXDivTest;
import org.junit.Before;
import org.junit.Test;
@@ -32,11 +30,8 @@ import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
-import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
-import static org.junit.Assert.*;
-
/**
* Created by sospartan on 27/09/2016.
*/
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/utils/WXExceptionUtilsTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/utils/WXExceptionUtilsTest.java b/android/sdk/src/test/java/com/taobao/weex/utils/WXExceptionUtilsTest.java
deleted file mode 100644
index 8709304..0000000
--- a/android/sdk/src/test/java/com/taobao/weex/utils/WXExceptionUtilsTest.java
+++ /dev/null
@@ -1,74 +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.utils;
-
-import com.taobao.weappplus_sdk.BuildConfig;
-import com.taobao.weex.WXEnvironment;
-import com.taobao.weex.common.WXErrorCode;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.rule.PowerMockRule;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-/**
- * Created by atomtong on 2017/10/19.
- */
-@RunWith(RobolectricTestRunner.class)
-@Config(constants = BuildConfig.class, sdk = 19)
-@PowerMockIgnore({ "org.mockito.*", "org.robolectric.*", "android.*" })
-@PrepareForTest({WXEnvironment.class})
-
-public class WXExceptionUtilsTest {
- static class Exp extends WXExceptionUtils{};
-
- @Rule
- public PowerMockRule rule = new PowerMockRule();
-
- @Before
- public void setUp() throws Exception {
- PowerMockito.mockStatic(WXEnvironment.class);
- PowerMockito.when(WXEnvironment.isApkDebugable()).thenReturn(true);
- }
-
- @Test
- public void testExpCommitNull(){
- Exp.commitCriticalExceptionRT(null,null,null,null,null);
- }
-
- @Test
- public void testExpCommitString(){
- Map testMap = new HashMap<String, String>();
- testMap.put("weexUrl","weexurltest");
- testMap.put("bundleUrl","bundleUrltest");
- Exp.commitCriticalExceptionRT("1", WXErrorCode.WX_ERR_TEST,"test","test",testMap);
- Exp.commitCriticalExceptionRT("1",WXErrorCode.WX_ERR_TEST,"test","test",null);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/utils/WXFileUtilsTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/utils/WXFileUtilsTest.java b/android/sdk/src/test/java/com/taobao/weex/utils/WXFileUtilsTest.java
index 5a7e9ce..64a0720 100644
--- a/android/sdk/src/test/java/com/taobao/weex/utils/WXFileUtilsTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/utils/WXFileUtilsTest.java
@@ -20,8 +20,6 @@ package com.taobao.weex.utils;
import com.taobao.weappplus_sdk.BuildConfig;
import java.io.File;
-
-import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -64,11 +62,4 @@ public class WXFileUtilsTest {
public void testSaveFile() throws Exception {
WXFileUtils.saveFile("build/test","test".getBytes(),RuntimeEnvironment.application);
}
-
-
- @Test
- public void testMd5(){
- Assert.assertEquals("77963b7a931377ad4ab5ad6a9cd718aa", WXFileUtils.md5("ddd"));
- Assert.assertEquals("d5Y7epMTd61Kta1qnNcYqg==", WXFileUtils.base64Md5("ddd"));
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/utils/WXLogUtilsTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/utils/WXLogUtilsTest.java b/android/sdk/src/test/java/com/taobao/weex/utils/WXLogUtilsTest.java
index e249c1c..ece6e0e 100644
--- a/android/sdk/src/test/java/com/taobao/weex/utils/WXLogUtilsTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/utils/WXLogUtilsTest.java
@@ -20,7 +20,6 @@ package com.taobao.weex.utils;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXEnvironment;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -47,6 +46,7 @@ public class WXLogUtilsTest {
@Before
public void setUp() throws Exception {
+ WXLogUtils.isShowLineNumber = true;
PowerMockito.mockStatic(WXEnvironment.class);
PowerMockito.when(WXEnvironment.isApkDebugable()).thenReturn(true);
}
@@ -92,17 +92,4 @@ public class WXLogUtilsTest {
Log.e("tag",new Throwable("test"));
}
- @Test
- public void testLogLevel() throws Exception {
- WXEnvironment.sLogLevel = LogLevel.DEBUG;
- Log.d("LogLevel.DEBUG", "test debug");
- Log.w("LogLevel.DEBUG", "test warning");
- Log.e("LogLevel.DEBUG", "test error");
-
- WXEnvironment.sLogLevel = LogLevel.WARN;
-
- Log.d("LogLevel.WARN", "test debug");
- Log.w("LogLevel.WARN", "test warning");
- Log.e("LogLevel.WARN", "test error");
- }
- }
+}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/utils/WXReflectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/utils/WXReflectionUtilsTest.java b/android/sdk/src/test/java/com/taobao/weex/utils/WXReflectionUtilsTest.java
index 58cfc46..18df379 100644
--- a/android/sdk/src/test/java/com/taobao/weex/utils/WXReflectionUtilsTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/utils/WXReflectionUtilsTest.java
@@ -47,14 +47,9 @@ public class WXReflectionUtilsTest {
@Test
public void testParseArgument() throws Exception {
-
-
Object value = WXReflectionUtils.parseArgument(String.class,"dkdkdkdk");
assertTrue(value instanceof String);
- value = WXReflectionUtils.parseArgument(int.class,123444);
- assertTrue(value instanceof Integer);
-
value = WXReflectionUtils.parseArgument(long.class,"123444");
assertTrue(value instanceof Long);
@@ -75,10 +70,6 @@ public class WXReflectionUtilsTest {
JSONObject j = new JSONObject();
j.put("a","b");
j.put("c",23);
-
- value = WXReflectionUtils.parseArgument(Map.class,j);
- assertTrue(value == j);
-
value = WXReflectionUtils.parseArgument(String.class,j);
assertTrue(value instanceof String);
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/utils/WXUtilsTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/utils/WXUtilsTest.java b/android/sdk/src/test/java/com/taobao/weex/utils/WXUtilsTest.java
index 5b6d273..e981c69 100644
--- a/android/sdk/src/test/java/com/taobao/weex/utils/WXUtilsTest.java
+++ b/android/sdk/src/test/java/com/taobao/weex/utils/WXUtilsTest.java
@@ -19,7 +19,6 @@
package com.taobao.weex.utils;
import android.text.TextUtils;
-import android.util.Log;
import com.taobao.weappplus_sdk.BuildConfig;
import com.taobao.weex.WXEnvironment;
@@ -50,7 +49,7 @@ import static org.mockito.Matchers.any;
@RunWith(PowerMockRunner.class)
@Config(constants = BuildConfig.class, sdk = 19)
@PowerMockIgnore( {"org.mockito.*", "org.robolectric.*", "android.*"})
-@PrepareForTest( {WXEnvironment.class, WXViewUtils.class, WXSDKInstance.class, TextUtils.class, Log.class, WXUtils.class, WXLogUtils.class})
+@PrepareForTest( {WXEnvironment.class, WXViewUtils.class, WXSDKInstance.class, TextUtils.class})
public class WXUtilsTest extends TestCase {
public static final float TEST_DENSITY = 3.0f;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/wson/AnnoTest.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/wson/AnnoTest.java b/android/sdk/src/test/java/com/taobao/weex/wson/AnnoTest.java
deleted file mode 100644
index 1dce185..0000000
--- a/android/sdk/src/test/java/com/taobao/weex/wson/AnnoTest.java
+++ /dev/null
@@ -1,41 +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 com.alibaba.fastjson.JSON;
-
-import junit.framework.TestCase;
-
-import org.junit.Assert;
-
-/**
- * Created by furture on 2018/3/9.
- */
-
-public class AnnoTest extends TestCase {
-
- public void testAnno(){
- Person person = new Person();
- person.id = "3333";
- for(int i=0; i<10; i++) {
- Assert.assertEquals(JSON.toJSONString(person),
- JSON.toJSONString(Wson.parse(Wson.toWson(person))));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/android/sdk/src/test/java/com/taobao/weex/wson/Person.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/test/java/com/taobao/weex/wson/Person.java b/android/sdk/src/test/java/com/taobao/weex/wson/Person.java
deleted file mode 100644
index 8c9fd7b..0000000
--- a/android/sdk/src/test/java/com/taobao/weex/wson/Person.java
+++ /dev/null
@@ -1,30 +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 com.alibaba.fastjson.annotation.JSONField;
-
-/**
- * Created by furture on 2018/3/9.
- */
-
-public class Person {
- @JSONField(name = "uid")
- public String id = "3333";
-}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/.clang-format
----------------------------------------------------------------------
diff --git a/weex_core/.clang-format b/weex_core/.clang-format
new file mode 100644
index 0000000..0cd3e32
--- /dev/null
+++ b/weex_core/.clang-format
@@ -0,0 +1,2 @@
+{BasedOnStyle: WebKit}
+
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/.gitignore
----------------------------------------------------------------------
diff --git a/weex_core/.gitignore b/weex_core/.gitignore
new file mode 100644
index 0000000..ba15c87
--- /dev/null
+++ b/weex_core/.gitignore
@@ -0,0 +1,5 @@
+*.pyc
+build32/
+build64/
+cmake-build-debug
+cscope.out
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/weex_core/CMakeLists.txt b/weex_core/CMakeLists.txt
new file mode 100644
index 0000000..83d128e
--- /dev/null
+++ b/weex_core/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 3.4.1)
+project(weexv8)
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+#include(Android)
+add_subdirectory(Source)
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/weex_core/Source/CMakeLists.txt b/weex_core/Source/CMakeLists.txt
new file mode 100644
index 0000000..92ce3ae
--- /dev/null
+++ b/weex_core/Source/CMakeLists.txt
@@ -0,0 +1,91 @@
+cmake_minimum_required(VERSION 3.4.1)
+
+add_compile_options(-std=c++11)
+add_compile_options(-fexceptions)
+
+add_definitions(-DOS_ANDROID=1)
+add_definitions(-DGNU_SUPPORT=1)
+add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT=1)
+add_definitions(-DDEBUG=1)
+
+add_definitions(-DRENDER_LOG=0)
+add_definitions(-DPERFORMANCE_LOG=0)
+add_definitions(-DLAYOUT_LOG=0)
+add_definitions(-DJSAPI_LOG=0)
+add_definitions(-DDOM_PARSER_LOG=0)
+
+## add_subdirectory for subdirectory has a CMakeLists.txt
+add_subdirectory(${CMAKE_SOURCE_DIR}/Source/IPC)
+
+## include_directories for include head file
+## include_directories(${CMAKE_SOURCE_DIR}/Source/IPC)
+
+
+add_library(weexjsc SHARED
+
+ ./base/fpconv.cpp
+ ./android/jniprebuild/jni_load.cc
+ ./android/base/jni/android_jni.cpp
+ ./android/base/jni/scoped_java_ref.cpp
+ ./android/base/base64/base64.cpp
+ ./android/base/base64/modp_base64/modp_b64.cc
+ ./android/base/string/scoped_jstring.cpp
+ ./android/base/string/scoped_jstring_utf8.cpp
+ ./android/bridge/impl/bridge_impl_android.cpp
+ ./android/bridge/impl/weexcore_impl_android.cpp
+ ./android/bridge/impl/measure_mode_impl_android.cpp
+ ./android/bridge/impl/content_box_measurement_impl_android.cpp
+
+ ./android/jsengine/multiprocess/WeexJSConnection.cpp
+ ./android/jsengine/multiprocess/WeexProxy.cpp
+ ./android/jsengine/multiprocess/ExtendJSApi.cpp
+
+ ./core/render/manager/render_manager.cpp
+ ./core/render/page/render_page.cpp
+ ./core/render/node/render_object.cpp
+ ./core/render/node/factory/render_creator.cpp
+ ./core/render/action/render_action_add_event.cpp
+ ./core/render/action/render_action_remove_event.cpp
+ ./core/render/action/render_action_add_element.cpp
+ ./core/render/action/render_action_remove_element.cpp
+ ./core/render/action/render_action_move_element.cpp
+ ./core/render/action/render_action_createbody.cpp
+ ./core/render/action/render_action_createfinish.cpp
+ ./core/render/action/render_action_layout.cpp
+ ./core/render/action/render_action_update_attr.cpp
+ ./core/render/action/render_action_update_style.cpp
+
+ ./core/parser/dom_parser.cpp
+
+ ./core/layout/layout.cpp
+ ./core/layout/style.cpp
+
+ ./core/css/css_value_getter.cpp
+
+ ./core/config/core_environment.cpp
+ ./core/moniter/render_performance.cpp
+ )
+
+ # set(weexjsc_LIBRARY_TYPE SHARED)
+
+ # set_target_properties(weexjsc
+ # PROPERTIES
+ # LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}//weexjsc_version_script.txt -Wl,--no-undefined -Wl,-soname,libweexjsc.so"
+ # )
+
+ # add_custom_command(
+ # TARGET weexjsc
+ # POST_BUILD
+ # COMMAND ${CMAKE_STRIP} $<TARGET_FILE:weexjsc> -o ${CMAKE_SOURCE_DIR}/libweexjsc.so
+ # VERBATIM
+ # )
+
+ target_include_directories(weexjsc
+ PUBLIC
+ .)
+
+ target_link_libraries(weexjsc
+ android
+ IPC
+ log
+ z)
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/Buffering/IPCBuffer.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/Buffering/IPCBuffer.h b/weex_core/Source/IPC/Buffering/IPCBuffer.h
new file mode 100644
index 0000000..29b8cc9
--- /dev/null
+++ b/weex_core/Source/IPC/Buffering/IPCBuffer.h
@@ -0,0 +1,13 @@
+#ifndef IPCBUFFER_H
+#define IPCBUFFER_H
+#include <stddef.h>
+
+// A buffer starts with msg.
+class IPCBuffer {
+public:
+ virtual ~IPCBuffer() = default;
+ virtual const void* get() = 0;
+ virtual size_t length() = 0;
+};
+
+#endif /* IPCBUFFER_H */
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/CMakeLists.txt b/weex_core/Source/IPC/CMakeLists.txt
new file mode 100644
index 0000000..6087009
--- /dev/null
+++ b/weex_core/Source/IPC/CMakeLists.txt
@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 2.8.12)
+
+add_library(IPC
+STATIC
+./Serializing/IPCSerializer.cpp
+./IPCResult.cpp
+./IPCSender.cpp
+./IPCException.cpp
+./IPCCommunicator.cpp
+./IPCHandler.cpp
+./IPCListener.cpp
+./IPCFutexPageQueue.cpp
+./IPCFutexPageQueue.cpp
+./ashmem.c
+./IPCCheck.cpp)
+
+#target_link_libraries(IPC
+#JavaScriptCore)
+
+target_include_directories(IPC
+PUBLIC
+.)
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCArguments.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCArguments.h b/weex_core/Source/IPC/IPCArguments.h
new file mode 100644
index 0000000..4c1f9c3
--- /dev/null
+++ b/weex_core/Source/IPC/IPCArguments.h
@@ -0,0 +1,30 @@
+#ifndef IPCARGUMENTS_H
+#define IPCARGUMENTS_H
+#include "IPCType.h"
+
+struct IPCString;
+struct IPCByteArray;
+class IPCArguments {
+public:
+ virtual ~IPCArguments() = default;
+ template <typename T>
+ T get(int index)
+ {
+ return *static_cast<const T*>(getData(index));
+ }
+
+ const IPCString* getString(int index)
+ {
+ return static_cast<const IPCString*>(getData(index));
+ }
+
+ const IPCByteArray* getByteArray(int index)
+ {
+ return static_cast<const IPCByteArray*>(getData(index));
+ }
+
+ virtual const void* getData(int index) = 0;
+ virtual IPCType getType(int index) = 0;
+ virtual size_t getCount() = 0;
+};
+#endif /* IPCARGUMENTS_H */
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCByteArray.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCByteArray.h b/weex_core/Source/IPC/IPCByteArray.h
new file mode 100644
index 0000000..77eaf6f
--- /dev/null
+++ b/weex_core/Source/IPC/IPCByteArray.h
@@ -0,0 +1,8 @@
+#ifndef IPCBYTEARRAY_H
+#define IPCBYTEARRAY_H
+#include <stddef.h>
+struct IPCByteArray {
+ uint32_t length;
+ char content[1];
+};
+#endif /* IPCBYTEARRAY_H */
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCCheck.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCCheck.cpp b/weex_core/Source/IPC/IPCCheck.cpp
new file mode 100644
index 0000000..bb449e4
--- /dev/null
+++ b/weex_core/Source/IPC/IPCCheck.cpp
@@ -0,0 +1,17 @@
+#if !defined(NDEBUG)
+#include "IPCCheck.h"
+#include <android/log.h>
+#define TAG "linzj_IPC"
+
+void reportCheckFailed(const char* msg, const char* file, int line)
+{
+ __android_log_print(ANDROID_LOG_ERROR, TAG, msg, file, line);
+ __builtin_trap();
+}
+
+void reportUnreachable(const char* file, int line)
+{
+ __android_log_print(ANDROID_LOG_ERROR, TAG, "unreachable statement reached %s %d", file, line);
+ __builtin_trap();
+}
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCCheck.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCCheck.h b/weex_core/Source/IPC/IPCCheck.h
new file mode 100644
index 0000000..f3bc54a
--- /dev/null
+++ b/weex_core/Source/IPC/IPCCheck.h
@@ -0,0 +1,16 @@
+#ifndef IPCCHECK_H
+#define IPCCHECK_H
+#include <stdlib.h>
+#if defined(NDEBUG)
+#define IPC_DCHECK(b)
+#define IPC_UNREACHABLE() abort()
+#else
+void reportCheckFailed(const char* msg, const char* file, int line);
+void reportUnreachable(const char* file, int line);
+#define IPC_DCHECK(b) \
+ if (!(b)) { \
+ reportCheckFailed("CHECK FAILED: " #b " at line %s %d", __FILE__, __LINE__); \
+ }
+#define IPC_UNREACHABLE() reportUnreachable(__FILE__, __LINE__);
+#endif
+#endif /* IPCCHECK_H */
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCCommunicator.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCCommunicator.cpp b/weex_core/Source/IPC/IPCCommunicator.cpp
new file mode 100644
index 0000000..dada499
--- /dev/null
+++ b/weex_core/Source/IPC/IPCCommunicator.cpp
@@ -0,0 +1,363 @@
+#include "IPCCommunicator.h"
+
+#include "Buffering/IPCBuffer.h"
+#include "IPCArguments.h"
+#include "IPCByteArray.h"
+#include "IPCCheck.h"
+#include "IPCException.h"
+#include "IPCFutexPageQueue.h"
+#include "IPCLog.h"
+#include "IPCResult.h"
+#include "IPCString.h"
+#include "Serializing/IPCSerializer.h"
+#include "futex.h"
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <vector>
+
+namespace {
+class BufferAssembler
+ : public IPCResult,
+ public IPCArguments {
+public:
+ void readFromBuffer(const char*);
+ void readTypes(const char*&);
+ void readData(const char*&);
+ // IPCResult
+ const void* getData() override;
+ IPCType getType() override;
+ const uint16_t* getStringContent() override;
+ size_t getStringLength() override;
+ const char* getByteArrayContent() override;
+ size_t getByteArrayLength() override;
+
+ // IPCArguments
+ const void* getData(int index) override;
+ IPCType getType(int index) override;
+ size_t getCount() override;
+
+private:
+ std::vector<uint32_t> m_types;
+ std::vector<std::unique_ptr<char[]>> m_datas;
+};
+
+void BufferAssembler::readFromBuffer(const char* blob)
+{
+ readTypes(blob);
+ readData(blob);
+}
+
+void BufferAssembler::readTypes(const char*& blob)
+{
+ while (true) {
+ uint32_t type;
+ type = *reinterpret_cast<const uint32_t*>(blob);
+ blob += sizeof(uint32_t);
+ if (type == static_cast<uint32_t>(IPCType::END))
+ break;
+ m_types.emplace_back(type);
+ }
+}
+
+void BufferAssembler::readData(const char*& blob)
+{
+ for (uint32_t type : m_types) {
+ switch (static_cast<IPCType>(type)) {
+ case IPCType::INT32: {
+ int32_t n;
+ memcpy(&n, blob, sizeof(n));
+ blob += sizeof(n);
+ std::unique_ptr<char[]> data(new char[sizeof(n)]);
+ *reinterpret_cast<int32_t*>(data.get()) = n;
+ m_datas.emplace_back(std::move(data));
+ } break;
+ case IPCType::INT64: {
+ int64_t n;
+ memcpy(&n, blob, sizeof(n));
+ blob += sizeof(n);
+ std::unique_ptr<char[]> data(new char[sizeof(n)]);
+ *reinterpret_cast<int64_t*>(data.get()) = n;
+ m_datas.emplace_back(std::move(data));
+ } break;
+ case IPCType::FLOAT: {
+ float n;
+ memcpy(&n, blob, sizeof(n));
+ blob += sizeof(n);
+ std::unique_ptr<char[]> data(new char[sizeof(n)]);
+ *reinterpret_cast<float*>(data.get()) = n;
+ m_datas.emplace_back(std::move(data));
+ } break;
+ case IPCType::DOUBLE: {
+ double n;
+ memcpy(&n, blob, sizeof(n));
+ blob += sizeof(n);
+ std::unique_ptr<char[]> data(new char[sizeof(n)]);
+ *reinterpret_cast<double*>(data.get()) = n;
+ m_datas.emplace_back(std::move(data));
+ } break;
+ case IPCType::JSONSTRING:
+ case IPCType::STRING: {
+ uint32_t n;
+ memcpy(&n, blob, sizeof(n));
+ blob += sizeof(n);
+ size_t byteLength = n * sizeof(uint16_t);
+ std::unique_ptr<char[]> data(new char[byteLength + sizeof(IPCString)]);
+ IPCString* s = reinterpret_cast<IPCString*>(data.get());
+ s->length = n;
+ memcpy(s->content, blob, byteLength);
+ blob += byteLength;
+ m_datas.emplace_back(std::move(data));
+ } break;
+ case IPCType::BYTEARRAY: {
+ uint32_t n;
+ memcpy(&n, blob, sizeof(n));
+ blob += sizeof(n);
+ size_t byteLength = n;
+ std::unique_ptr<char[]> data(new char[byteLength + sizeof(IPCByteArray)]);
+ IPCByteArray* s = reinterpret_cast<IPCByteArray*>(data.get());
+ s->length = n;
+ memcpy(s->content, blob, byteLength);
+ blob += byteLength;
+ s->content[byteLength] = '\0';
+ m_datas.emplace_back(std::move(data));
+ } break;
+ case IPCType::JSUNDEFINED:
+ case IPCType::VOID:
+ m_datas.emplace_back();
+ break;
+ case IPCType::END:
+ default:
+ IPC_UNREACHABLE();
+ }
+ }
+}
+
+// IPCResult
+const void* BufferAssembler::getData()
+{
+ return getData(0);
+}
+
+IPCType BufferAssembler::getType()
+{
+ return getType(0);
+}
+
+const uint16_t* BufferAssembler::getStringContent()
+{
+ IPC_DCHECK((getType(0) == IPCType::STRING) || (getType(0) == IPCType::JSONSTRING));
+ const IPCString* s = reinterpret_cast<const IPCString*>(getData(0));
+ return s->content;
+}
+
+size_t BufferAssembler::getStringLength()
+{
+ IPC_DCHECK((getType(0) == IPCType::STRING) || (getType(0) == IPCType::JSONSTRING));
+ const IPCString* s = reinterpret_cast<const IPCString*>(getData(0));
+ return s->length;
+}
+
+const char* BufferAssembler::getByteArrayContent()
+{
+ IPC_DCHECK(getType(0) == IPCType::BYTEARRAY);
+ const IPCByteArray* s = reinterpret_cast<const IPCByteArray*>(getData(0));
+ return s->content;
+}
+
+size_t BufferAssembler::getByteArrayLength()
+{
+ IPC_DCHECK(getType(0) == IPCType::BYTEARRAY);
+ const IPCByteArray* s = reinterpret_cast<const IPCByteArray*>(getData(0));
+ return s->length;
+}
+
+// IPCArguments
+const void* BufferAssembler::getData(int index)
+{
+ return m_datas.at(index).get();
+}
+
+IPCType BufferAssembler::getType(int index)
+{
+ return static_cast<IPCType>(m_types.at(index));
+}
+
+size_t BufferAssembler::getCount()
+{
+ return m_types.size();
+}
+}
+
+IPCCommunicator::IPCCommunicator(IPCFutexPageQueue* futexPageQueue)
+ : m_futexPageQueue(futexPageQueue)
+{
+}
+
+IPCCommunicator::~IPCCommunicator()
+{
+}
+
+std::unique_ptr<IPCResult> IPCCommunicator::assembleResult()
+{
+ std::unique_ptr<BufferAssembler> bufferAssembler(new BufferAssembler());
+ bufferAssembler->readFromBuffer(getBlob());
+ return std::unique_ptr<IPCResult>(bufferAssembler.release());
+}
+
+std::unique_ptr<IPCArguments> IPCCommunicator::assembleArguments()
+{
+ std::unique_ptr<BufferAssembler> bufferAssembler(new BufferAssembler());
+ bufferAssembler->readFromBuffer(getBlob());
+ return std::unique_ptr<IPCArguments>(bufferAssembler.release());
+}
+
+std::unique_ptr<IPCBuffer> IPCCommunicator::generateResultBuffer(IPCResult* result)
+{
+ std::unique_ptr<IPCSerializer> serializer = createIPCSerializer();
+ serializer->setMsg(MSG_END);
+ switch (result->getType()) {
+ case IPCType::INT32:
+ serializer->add(result->get<int32_t>());
+ break;
+ case IPCType::INT64:
+ serializer->add(result->get<int64_t>());
+ break;
+ case IPCType::FLOAT:
+ serializer->add(result->get<float>());
+ break;
+ case IPCType::DOUBLE:
+ serializer->add(result->get<double>());
+ break;
+ case IPCType::BYTEARRAY:
+ serializer->add(result->getByteArrayContent(), result->getByteArrayLength());
+ break;
+ case IPCType::CHARARRAY:
+ serializer->add(static_cast<const char*>(result->getData()), result->getStringLength());
+ break;
+ case IPCType::JSONSTRING:
+ serializer->addJSON(result->getStringContent(), result->getStringLength());
+ break;
+ case IPCType::STRING:
+ serializer->add(result->getStringContent(), result->getStringLength());
+ break;
+ case IPCType::JSUNDEFINED:
+ serializer->addJSUndefined();
+ break;
+ case IPCType::VOID:
+ serializer->addVoid();
+ break;
+ default:
+ IPC_UNREACHABLE();
+ }
+ return serializer->finish();
+}
+
+void IPCCommunicator::doSendBufferOnly(IPCBuffer* buffer)
+{
+ const char* data = static_cast<const char*>(buffer->get());
+ uint32_t length = buffer->length();
+ doSendBufferOnly(data, length);
+}
+
+uint32_t IPCCommunicator::doReadPackage()
+{
+ uint32_t msg;
+ uint32_t length;
+ m_futexPageQueue->lockReadPage();
+ void* sharedMemory = m_futexPageQueue->getCurrentReadPage();
+ length = static_cast<uint32_t*>(sharedMemory)[0];
+ uint32_t availableSize = m_futexPageQueue->getPageSize() - sizeof(uint32_t);
+ if (length < 2 * sizeof(uint32_t)) {
+ releaseBlob();
+ throw IPCException("Not a vaild msg");
+ }
+ if (length > availableSize) {
+ m_package.reset(new char[length]);
+ doRecvBufferOnly(m_package.get(), length);
+ return *reinterpret_cast<uint32_t*>(m_package.get());
+ }
+ return static_cast<uint32_t*>(sharedMemory)[1];
+}
+
+void IPCCommunicator::doSendBufferOnly(const void* _data, size_t length)
+{
+ const char* data = static_cast<const char*>(_data);
+ size_t pageSize = m_futexPageQueue->getPageSize();
+ ssize_t byteTransfered;
+ uint32_t* dstLength = static_cast<uint32_t*>(m_futexPageQueue->getCurrentWritePage());
+ // special handle the first part, which need a size
+ // as header.
+ dstLength[0] = length;
+
+ IPC_LOGD("send bytes: length: %zu", length);
+ byteTransfered = std::min(length, pageSize - sizeof(uint32_t));
+ memcpy(dstLength + 1, data, byteTransfered);
+ m_futexPageQueue->stepWrite();
+ // multiple page package
+ if (length > byteTransfered) {
+ data += byteTransfered;
+ length -= byteTransfered;
+ IPC_LOGD("sent bytes: remaining length: %zu, transfered: %zu", length, byteTransfered);
+
+ while (length > 0) {
+ byteTransfered = doSendBufferPage(data, length, pageSize);
+ data += byteTransfered;
+ length -= byteTransfered;
+ IPC_LOGD("sent bytes: remaining length: %zu, transfered: %zu", length, byteTransfered);
+ }
+ }
+}
+
+void IPCCommunicator::doRecvBufferOnly(void* _data, size_t length)
+{
+ char* data = static_cast<char*>(_data);
+ size_t pageSize = m_futexPageQueue->getPageSize();
+ bool firstRun = true;
+ IPC_LOGD("recv bytes: length: %zu", length);
+ while (true) {
+ ssize_t byteTransfered;
+ byteTransfered = std::min(length, pageSize);
+ const void* src = m_futexPageQueue->getCurrentReadPage();
+ // skip the package size.
+ // package starts with msg.
+ if (firstRun) {
+ src = static_cast<const char*>(src) + sizeof(uint32_t);
+ byteTransfered -= sizeof(uint32_t);
+ }
+ memcpy(data, src, byteTransfered);
+ data += byteTransfered;
+ length -= byteTransfered;
+ IPC_LOGD("recv bytes: remaining length: %zu, transfered: %zu", length, byteTransfered);
+ if (length > 0) {
+ firstRun = false;
+ m_futexPageQueue->unlockReadPageAndStep();
+ m_futexPageQueue->lockReadPage();
+ } else {
+ break;
+ }
+ }
+}
+
+const char* IPCCommunicator::getBlob()
+{
+ if (m_package.get())
+ return m_package.get() + sizeof(uint32_t);
+ return static_cast<const char*>(m_futexPageQueue->getCurrentReadPage()) + sizeof(uint32_t) * 2;
+}
+
+void IPCCommunicator::releaseBlob()
+{
+ m_package.reset();
+ m_futexPageQueue->unlockReadPageAndStep();
+}
+
+size_t IPCCommunicator::doSendBufferPage(const void* data, size_t length, size_t pageSize)
+{
+ ssize_t byteTransfered;
+ byteTransfered = std::min(length, pageSize);
+ void* dst = m_futexPageQueue->getCurrentWritePage();
+ memcpy(dst, data, byteTransfered);
+ m_futexPageQueue->stepWrite();
+ return byteTransfered;
+}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCCommunicator.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCCommunicator.h b/weex_core/Source/IPC/IPCCommunicator.h
new file mode 100644
index 0000000..69e63b2
--- /dev/null
+++ b/weex_core/Source/IPC/IPCCommunicator.h
@@ -0,0 +1,30 @@
+#ifndef IPCCOMMUNICATOR_H
+#define IPCCOMMUNICATOR_H
+#include <memory>
+
+class IPCResult;
+class IPCArguments;
+class IPCBuffer;
+class IPCFutexPageQueue;
+class IPCCommunicator {
+protected:
+ explicit IPCCommunicator(IPCFutexPageQueue* futexPageQueue);
+ virtual ~IPCCommunicator();
+
+ std::unique_ptr<IPCResult> assembleResult();
+ std::unique_ptr<IPCArguments> assembleArguments();
+ std::unique_ptr<IPCBuffer> generateResultBuffer(IPCResult*);
+ void doSendBufferOnly(IPCBuffer* buffer);
+ uint32_t doReadPackage();
+ const char* getBlob();
+ void releaseBlob();
+
+private:
+ void doSendBufferOnly(const void* data, size_t s);
+ size_t doSendBufferPage(const void* data, size_t s, size_t pageSize);
+ void doRecvBufferOnly(void* data, size_t s);
+ std::unique_ptr<char[]> m_package;
+ // weakref to a IPCFutexPageQueue object.
+ IPCFutexPageQueue* m_futexPageQueue;
+};
+#endif /* IPCCOMMUNICATOR_H */
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCException.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCException.cpp b/weex_core/Source/IPC/IPCException.cpp
new file mode 100644
index 0000000..a3441b5
--- /dev/null
+++ b/weex_core/Source/IPC/IPCException.cpp
@@ -0,0 +1,32 @@
+#include "IPCException.h"
+#include <stdarg.h>
+#include <string>
+
+struct IPCException::IPCExceptionImpl {
+ std::string str;
+};
+
+IPCException::IPCException(const char* fmt, ...)
+ : m_impl(new IPCExceptionImpl)
+{
+ va_list ap;
+ char buffer[256];
+ va_start(ap, fmt);
+ vsnprintf(buffer, 256, fmt, ap);
+ va_end(ap);
+ m_impl->str.assign(buffer);
+}
+
+IPCException::~IPCException()
+{
+}
+
+IPCException::IPCException(IPCException&& ex)
+{
+ m_impl = std::move(ex.m_impl);
+}
+
+const char* IPCException::msg() const
+{
+ return m_impl->str.c_str();
+}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCException.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCException.h b/weex_core/Source/IPC/IPCException.h
new file mode 100644
index 0000000..8dc633d
--- /dev/null
+++ b/weex_core/Source/IPC/IPCException.h
@@ -0,0 +1,16 @@
+#ifndef IPCEXCEPTION_H
+#define IPCEXCEPTION_H
+#include <memory>
+
+class IPCException {
+public:
+ IPCException(const char* fmt, ...);
+ ~IPCException();
+ IPCException(IPCException&& ex);
+ const char* msg() const;
+
+private:
+ struct IPCExceptionImpl;
+ std::unique_ptr<IPCExceptionImpl> m_impl;
+};
+#endif /* IPCEXCEPTION_H */
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCFutexPageQueue.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCFutexPageQueue.cpp b/weex_core/Source/IPC/IPCFutexPageQueue.cpp
new file mode 100644
index 0000000..f2423fc
--- /dev/null
+++ b/weex_core/Source/IPC/IPCFutexPageQueue.cpp
@@ -0,0 +1,191 @@
+#include "IPCFutexPageQueue.h"
+#include "IPCCheck.h"
+#include "IPCException.h"
+#include "IPCLog.h"
+#include "IPCType.h"
+#include "futex.h"
+#include <errno.h>
+#include <sched.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <time.h>
+#include <unistd.h>
+
+IPCFutexPageQueue::IPCFutexPageQueue(void* sharedMemory, size_t s, size_t id)
+ : m_currentWrite(id)
+ , m_currentRead(id ^ 1)
+ , m_pageSize(s / m_pagesCount)
+ , m_sharedMemory(sharedMemory)
+ , m_tid(gettid())
+{
+ IPC_DCHECK(s == ipc_size);
+ IPC_LOGD("id: %zu", id);
+ for (int i = m_currentWrite; i < m_pagesCount; i += 2) {
+ uint32_t* data = static_cast<uint32_t*>(getPage(i));
+ data[1] |= m_finishTag;
+ }
+ lock(m_currentWrite, true);
+}
+
+IPCFutexPageQueue::~IPCFutexPageQueue()
+{
+ // build a terminate msg.
+ uint32_t* data = static_cast<uint32_t*>(getPage(m_currentWrite));
+ data[1] = sizeof(uint32_t) * 2;
+ data[2] = MSG_TERMINATE;
+ data[3] = static_cast<uint32_t>(IPCType::END);
+ try {
+ unlock(m_currentWrite);
+ } catch (IPCException& e) {
+ IPC_LOGE("%s", e.msg());
+ }
+ munmap(m_sharedMemory, m_pageSize << 2);
+}
+
+void IPCFutexPageQueue::stepWrite()
+{
+ IPC_LOGD("stepWrite");
+ clearFinishedTag();
+ size_t current = m_currentWrite;
+ m_currentWrite = step(m_currentWrite);
+ lock(m_currentWrite, true);
+ unlock(current);
+}
+
+void IPCFutexPageQueue::unlock(size_t id)
+{
+ IPC_LOGD("unlock: %zu", id);
+ volatile uint32_t* pageStart = static_cast<volatile uint32_t*>(getPage(id));
+
+ uint32_t l = m_tid;
+ if (__atomic_compare_exchange_n(pageStart, &l, 0,
+ false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
+ return;
+ }
+ if ((l & FUTEX_WAITERS) != 0) {
+ int futexReturn = __futex(pageStart, FUTEX_UNLOCK_PI, 0, nullptr);
+ if (futexReturn == -1) {
+ throw IPCException("failed to futex unlock %s", strerror(errno));
+ }
+ return;
+ } else if ((l & FUTEX_TID_MASK) != m_tid) {
+ throw IPCException("l is not equal to tid: %d %d", l, m_tid);
+ }
+ throw IPCException("expected lock value");
+}
+
+void IPCFutexPageQueue::lock(size_t id, bool checkFinish)
+{
+ volatile uint32_t* pageStart = static_cast<volatile uint32_t*>(getPage(id));
+ uint32_t l = m_tid;
+ uint32_t expected = 0;
+ IPC_LOGD("lock: %zu", id);
+ // wait for the finished tag;
+ if (checkFinish) {
+ while (true) {
+ uint32_t finishedTag = pageStart[1];
+ if (finishedTag == m_finishTag) {
+ break;
+ }
+ struct timespec waitTime = { m_timeoutSec, 0 };
+ int futexReturn = __futex(pageStart + 1, FUTEX_WAIT, 0, &waitTime);
+ if (futexReturn == -1) {
+ int myerrno = errno;
+ if (myerrno == EINTR)
+ continue;
+ else if (myerrno == ETIMEDOUT) {
+ throw IPCException("IPCFutexPageQueue::lock timeout when waiting for finished");
+ } else if (myerrno == EAGAIN) {
+ // become m_finishTag when enter the linux kernel.
+ break;
+ } else {
+ throw IPCException("IPCException::lock waiting for finished tag %u: %s", pageStart[1], strerror(myerrno));
+ }
+ }
+ break;
+ }
+ }
+ if (__atomic_compare_exchange_n(pageStart, &expected, l,
+ false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
+ return;
+ }
+ errno = 0;
+ while (true) {
+ int futexReturn = __futex(pageStart, FUTEX_LOCK_PI, 1, nullptr);
+ if (futexReturn == -1 && errno != EINTR) {
+
+ volatile uint32_t* pageStart0 = static_cast<volatile uint32_t*>(getPage(0));
+ volatile uint32_t* pageStart1 = static_cast<volatile uint32_t*>(getPage(1));
+ volatile uint32_t* pageStart2 = static_cast<volatile uint32_t*>(getPage(2));
+ volatile uint32_t* pageStart3 = static_cast<volatile uint32_t*>(getPage(3));
+ throw IPCException("futex lock pi failed: %s, %x %x (%x %x %x %x)", strerror(errno), *pageStart, m_tid, *pageStart0, *pageStart1, *pageStart2, *pageStart3);
+ }
+ if (futexReturn == -1)
+ continue;
+ break;
+ }
+ l = *pageStart;
+ if ((l & FUTEX_OWNER_DIED)) {
+ unlock(id);
+ throw IPCException("original owner has die");
+ }
+}
+
+void* IPCFutexPageQueue::getPage(size_t id)
+{
+ size_t offset = id * m_pageSize;
+ return static_cast<char*>(m_sharedMemory) + offset;
+}
+
+void IPCFutexPageQueue::lockReadPage()
+{
+ IPC_LOGD("lockReadPage");
+ uint32_t* pageStart = static_cast<uint32_t*>(getPage(m_currentRead));
+ if (!*pageStart) {
+ // this page should be locked.
+ }
+ lock(m_currentRead, false);
+}
+
+void IPCFutexPageQueue::unlockReadPageAndStep()
+{
+ IPC_LOGD("unlockReadPageAndStep");
+ setFinishedTag();
+ unlock(m_currentRead);
+ m_currentRead = step(m_currentRead);
+}
+
+void IPCFutexPageQueue::spinWaitPeer()
+{
+ volatile uint32_t* pageStart = static_cast<volatile uint32_t*>(getPage(m_currentRead));
+ struct timespec start;
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ while (!*pageStart) {
+ sched_yield();
+ struct timespec now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if ((now.tv_sec - start.tv_sec) > m_timeoutSec)
+ throw IPCException("spinWaitPeer timeout");
+ }
+}
+
+void IPCFutexPageQueue::setFinishedTag()
+{
+ uint32_t* pageStart = static_cast<uint32_t*>(getPage(m_currentRead));
+ uint32_t expected = 0;
+ if (__atomic_compare_exchange_n(pageStart + 1, &expected, m_finishTag,
+ false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
+ IPC_LOGD("setFinishedTag:waking writer");
+ __futex(pageStart + 1, FUTEX_WAKE, 1, nullptr);
+ return;
+ } else {
+ IPC_LOGD("setFinishedTag unexpected value: %u", expected);
+ }
+}
+
+void IPCFutexPageQueue::clearFinishedTag()
+{
+ uint32_t* pageRead = static_cast<uint32_t*>(getPage(m_currentWrite));
+ pageRead[1] = 0;
+ __atomic_thread_fence(__ATOMIC_SEQ_CST);
+}
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCFutexPageQueue.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCFutexPageQueue.h b/weex_core/Source/IPC/IPCFutexPageQueue.h
new file mode 100644
index 0000000..da474eb
--- /dev/null
+++ b/weex_core/Source/IPC/IPCFutexPageQueue.h
@@ -0,0 +1,48 @@
+#ifndef IPCFUTEXPAGEQUEUE_H
+#define IPCFUTEXPAGEQUEUE_H
+
+#include <stdint.h>
+
+// shared memory page layout:
+// futex uint32_t
+// state word uint32_t
+// package size uint32_t
+// msg type uint32_t
+// types[] uint32_t[]
+//
+// data whatever types indicate
+// A page queue is composed of m_pagesCount pages
+// and will use repeatedly.
+class IPCFutexPageQueue {
+public:
+ IPCFutexPageQueue(void* sharedMemory, size_t s, size_t id);
+ ~IPCFutexPageQueue();
+ void stepWrite();
+ void lockReadPage();
+ void unlockReadPageAndStep();
+ void spinWaitPeer();
+ inline void* getCurrentReadPage() { return sizeof(uint32_t) * 2 + static_cast<char*>(getPage(m_currentRead)); }
+ inline void* getCurrentWritePage() { return sizeof(uint32_t) * 2 + static_cast<char*>(getPage(m_currentWrite)); }
+ inline size_t getPageSize() const { return m_pageSize - sizeof(uint32_t) * 2; }
+
+ static const size_t ipc_size = 4 * 1024 * 1024;
+
+private:
+ void unlock(size_t id);
+ void lock(size_t id, bool checkFinish);
+ void* getPage(size_t id);
+ inline size_t step(size_t s) { return (s + 2) & (m_pagesCount - 1); }
+ void setFinishedTag();
+ void clearFinishedTag();
+
+ size_t m_currentWrite;
+ size_t m_currentRead;
+ size_t m_pageSize;
+ void* m_sharedMemory;
+ int m_tid;
+ static const uint32_t m_finishTag = static_cast<uint32_t>(1);
+ static const size_t m_pagesCount = 16;
+ static const int m_timeoutSec = 32;
+};
+
+#endif /* IPCFUTEXPAGEQUEUE_H */
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/2f8caedb/weex_core/Source/IPC/IPCHandler.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/IPC/IPCHandler.cpp b/weex_core/Source/IPC/IPCHandler.cpp
new file mode 100644
index 0000000..6c11b06
--- /dev/null
+++ b/weex_core/Source/IPC/IPCHandler.cpp
@@ -0,0 +1,36 @@
+#include "IPCHandler.h"
+#include "IPCLog.h"
+#include "IPCResult.h"
+#include <unordered_map>
+
+namespace {
+class IPCHandlerImpl : public IPCHandler {
+public:
+ std::unique_ptr<IPCResult> handle(uint32_t msg, IPCArguments*) override;
+ void registerHandler(int msg, const std::function<std::unique_ptr<IPCResult>(IPCArguments*)>& handler) override;
+
+private:
+ typedef std::unordered_map<int, std::function<std::unique_ptr<IPCResult>(IPCArguments*)>> MapType;
+ MapType m_map;
+};
+
+std::unique_ptr<IPCResult> IPCHandlerImpl::handle(uint32_t msg, IPCArguments* arguments)
+{
+ auto it = m_map.find(msg);
+ if (it == m_map.end()) {
+ IPC_LOGE("unable to find msg: %d", msg);
+ return createVoidResult();
+ }
+ return it->second(arguments);
+}
+
+void IPCHandlerImpl::registerHandler(int msg, const std::function<std::unique_ptr<IPCResult>(IPCArguments*)>& handler)
+{
+ m_map.insert(MapType::value_type(msg, handler));
+}
+}
+
+std::unique_ptr<IPCHandler> createIPCHandler()
+{
+ return std::unique_ptr<IPCHandler>(new IPCHandlerImpl);
+}