summaryrefslogtreecommitdiff
path: root/swingp/testSrc
diff options
context:
space:
mode:
authorDavid Herman <davidherman@google.com>2018-08-21 21:23:51 +0000
committerTreeHugger Robot <treehugger-gerrit@google.com>2018-08-21 23:43:00 +0000
commit7f8c687120247dd987656d061b96f280b1c87cc2 (patch)
tree6bde01269b81db80eeceb91ad5951f34665d0748 /swingp/testSrc
parentef12ed7143d59a32ce97c21a19f75f4166e3fb82 (diff)
downloadidea-7f8c687120247dd987656d061b96f280b1c87cc2.tar.gz
Revert "Clean up Swingp JSON deserialization using Gson annotations"
This reverts commit f366e150cef883ce34205b6e98425c59d2b3f0a1. Reason for revert: This somehow broke Swingp. We'll revert for now and investigate. Change-Id: I669cf5456e6157e8ade63bb9fec3a71e185fb5a6
Diffstat (limited to 'swingp/testSrc')
-rw-r--r--swingp/testSrc/com/android/tools/swingp/MethodStatTest.java18
-rw-r--r--swingp/testSrc/com/android/tools/swingp/json/SwingpSerializationTest.java182
2 files changed, 18 insertions, 182 deletions
diff --git a/swingp/testSrc/com/android/tools/swingp/MethodStatTest.java b/swingp/testSrc/com/android/tools/swingp/MethodStatTest.java
index c85f467eaa8..0438d81dc6f 100644
--- a/swingp/testSrc/com/android/tools/swingp/MethodStatTest.java
+++ b/swingp/testSrc/com/android/tools/swingp/MethodStatTest.java
@@ -16,6 +16,8 @@
package com.android.tools.swingp;
import org.jetbrains.annotations.NotNull;
+import com.google.common.truth.Truth;
+import com.google.gson.JsonArray;
import org.junit.Test;
public class MethodStatTest {
@@ -35,6 +37,22 @@ public class MethodStatTest {
RenderStatsManager.setIsEnabled(false);
}
+ @Test
+ public void arraySerializesCorrectly() {
+ int[] intArray = {5, 7};
+ JsonArray jsonIntArray = SerializationHelpers.arrayToJsonArray(intArray);
+ Truth.assertThat(jsonIntArray.size()).isEqualTo(2);
+ Truth.assertThat(jsonIntArray.get(0).getAsInt()).isEqualTo(intArray[0]);
+ Truth.assertThat(jsonIntArray.get(1).getAsInt()).isEqualTo(intArray[1]);
+
+ double[] doubleArray = {3.5, 9.5, 11};
+ JsonArray jsonDoubleArray = SerializationHelpers.arrayToJsonArray(doubleArray);
+ Truth.assertThat(jsonDoubleArray.size()).isEqualTo(3);
+ Truth.assertThat(jsonDoubleArray.get(0).getAsDouble()).isEqualTo(doubleArray[0]);
+ Truth.assertThat(jsonDoubleArray.get(1).getAsDouble()).isEqualTo(doubleArray[1]);
+ Truth.assertThat(jsonDoubleArray.get(2).getAsDouble()).isEqualTo(doubleArray[2]);
+ }
+
/**
* Trivial extension of {@link MethodStat} (since it's abstract) to test its implementation.
*/
diff --git a/swingp/testSrc/com/android/tools/swingp/json/SwingpSerializationTest.java b/swingp/testSrc/com/android/tools/swingp/json/SwingpSerializationTest.java
deleted file mode 100644
index d56921dca90..00000000000
--- a/swingp/testSrc/com/android/tools/swingp/json/SwingpSerializationTest.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed 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.android.tools.swingp.json;
-
-import com.android.tools.swingp.*;
-import com.google.common.collect.Lists;
-import com.google.gson.Gson;
-import com.google.gson.JsonObject;
-import com.intellij.reference.SoftReference;
-import org.junit.Test;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.geom.AffineTransform;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class SwingpSerializationTest {
- @Test
- public void affineTransformCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
- AffineTransform transform = new AffineTransform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f);
-
- assertThat(gson.toJson(transform)).isEqualTo("[1.0,2.0,3.0,4.0,5.0,6.0]");
- }
-
- @Test
- public void pointCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
- Point point = new Point(1, 2);
-
- assertThat(gson.toJson(point)).isEqualTo("[1,2]");
- }
-
- @Test
- public void softReferenceCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
-
- String unusedValue = "DUMMY";
- SoftReference<String> setReference = new SoftReference<>(unusedValue);
- SoftReference<String> unsetReference = new SoftReference<>(null);
-
- assertThat(gson.toJsonTree(setReference).getAsString()).isEqualTo("String");
- assertThat(gson.toJsonTree(unsetReference).getAsString()).isEqualTo("<gc>");
- }
-
- @Test
- public void bufferStrategyPaintMethodStatCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
-
- Object owner = new Object();
- BufferStrategyPaintMethodStat stat = new BufferStrategyPaintMethodStat(owner, true);
-
- JsonObject statObj = gson.toJsonTree(stat).getAsJsonObject();
- assertThat(statObj.keySet()).containsAllIn(Lists.newArrayList(
- "callee",
- "endTime",
- "isBufferStrategy",
- "owner",
- "startTime"
- ));
- }
-
- @Test
- public void paintChildrenMethodStatCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
-
- JLabel dummyLabel = new JLabel("DUMMY");
- AffineTransform transform = new AffineTransform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f);
-
- PaintChildrenMethodStat stat = new PaintChildrenMethodStat(dummyLabel, transform);
- JsonObject statObj = gson.toJsonTree(stat).getAsJsonObject();
- assertThat(statObj.keySet()).containsAllIn(Lists.newArrayList(
- "callee",
- "endTime",
- "owner",
- "startTime",
- "xform"));
- }
-
- @Test
- public void paintComponentMethodStatCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
-
- JLabel dummyLabel = new JLabel("DUMMY");
- AffineTransform transform = new AffineTransform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f);
- Graphics g = mock(Graphics2D.class);
-
- PaintComponentMethodStat stat = new PaintComponentMethodStat(dummyLabel, g, transform, -1, -2, 3, 4);
-
- JsonObject statObj = gson.toJsonTree(stat).getAsJsonObject();
- assertThat(statObj.keySet()).containsAllIn(Lists.newArrayList(
- "callee",
- "clip",
- "endTime",
- "isImage",
- "owner",
- "startTime",
- "xform"));
- }
-
- @Test
- public void paintImmediatelyMethodStatCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
-
- Object owner = new Object();
- JLabel label = new JLabel("DUMMY");
- Graphics g = mock(Graphics2D.class);
- when(((Graphics2D)g).getTransform()).thenReturn(new AffineTransform());
-
- PaintImmediatelyMethodStat stat = new PaintImmediatelyMethodStat(owner, label, g, -1, -2, 3, 4);
-
- JsonObject statObj = gson.toJsonTree(stat).getAsJsonObject();
- assertThat(statObj.keySet()).containsAllIn(Lists.newArrayList(
- "bounds",
- "bufferBounds",
- "bufferId",
- "bufferType",
- "callee",
- "classType",
- "constrain",
- "endTime",
- "owner",
- "startTime",
- "xform"));
- }
-
- @Test
- public void windowPaintMethodStatCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
-
- Window window = mock(Window.class);
-
- WindowPaintMethodStat stat = new WindowPaintMethodStat(window);
-
- JsonObject statObj = gson.toJsonTree(stat).getAsJsonObject();
- assertThat(statObj.keySet()).containsAllIn(Lists.newArrayList(
- "callee",
- "endTime",
- "location",
- "owner",
- "startTime",
- "xform",
- "windowId"));
- }
-
- @Test
- public void threadStatCanBeSerialized() {
- Gson gson = RenderStatsManager.createSwingpGson();
-
- Thread thread = mock(Thread.class);
- when(thread.getId()).thenReturn((long)123);
- thread.setName("DUMMY");
-
- ThreadStat stat = new ThreadStat(thread).setIsRecording(true);
- stat.pushMethod(new MethodStat(new Object()) {
- });
-
- JsonObject statObj = gson.toJsonTree(stat).getAsJsonObject();
- assertThat(statObj.keySet()).containsAllIn(Lists.newArrayList(
- "classType",
- "events",
- "threadId",
- "threadName"
- ));
- }
-}