1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package ohos.devtools.views.charts; 17 18 import com.intellij.ui.components.JBPanel; 19 import ohos.devtools.views.charts.model.ChartDataModel; 20 import ohos.devtools.views.common.LayoutConstants; 21 import ohos.devtools.views.layout.chartview.ProfilerChartsView; 22 import ohos.devtools.views.layout.chartview.TaskScenePanelChart; 23 import org.junit.Assert; 24 import org.junit.Before; 25 import org.junit.Test; 26 27 import java.awt.Color; 28 import java.awt.event.MouseEvent; 29 import java.util.ArrayList; 30 import java.util.Collections; 31 import java.util.LinkedHashMap; 32 import java.util.List; 33 34 /** 35 * Test class of the abstract parent class of Chart 36 * 37 * @since 2021/5/19 16:39 38 */ 39 public class ProfilerChartTest { 40 private static final String NAME = "Test"; 41 42 private static final int TEST_START = 0; 43 44 private static final int TEST_END = 1000; 45 46 private static final int TEST_TIME1 = 333; 47 48 private static final int TEST_TIME2 = 666; 49 50 private static final int TEST_INDEX1 = 1; 51 52 private static final int TEST_INDEX2 = 2; 53 54 private static final int TEST_VALUE1 = 10; 55 56 private static final int TEST_VALUE2 = 20; 57 58 private ProfilerChartsView view; 59 60 private LinkedHashMap<Integer, List<ChartDataModel>> dataMap; 61 62 private ProfilerChart chart; 63 64 private List<ChartDataModel> models; 65 66 /** 67 * init 68 * 69 * @tc.name: init 70 * @tc.number: OHOS_JAVA_View_ProfilerChart_init_0001 71 * @tc.desc: init 72 * @tc.type: functional testing 73 * @tc.require: AR000FK5UI 74 */ 75 @Before init()76 public void init() { 77 initView(); 78 initDataMap(); 79 chart = new FilledLineChart(view, NAME, true); 80 ChartDataModel chartDataModel = new ChartDataModel(); 81 chartDataModel.setIndex(1); 82 chartDataModel.setColor(Color.GREEN); 83 chartDataModel.setValue(1); 84 models = new ArrayList<>(); 85 models.add(chartDataModel); 86 } 87 initView()88 private void initView() { 89 view = new ProfilerChartsView(LayoutConstants.NUM_L, true, new TaskScenePanelChart()); 90 view.getPublisher().getStandard().updateDisplayTimeRange(TEST_START, TEST_END); 91 } 92 initDataMap()93 private void initDataMap() { 94 dataMap = new LinkedHashMap<>(); 95 ChartDataModel model1 = new ChartDataModel(); 96 model1.setIndex(TEST_INDEX1); 97 model1.setName("Java"); 98 model1.setColor(Color.GRAY); 99 model1.setValue(TEST_VALUE1); 100 List<ChartDataModel> list1 = Collections.singletonList(model1); 101 dataMap.put(TEST_TIME1, list1); 102 ChartDataModel model2 = new ChartDataModel(); 103 model2.setIndex(TEST_INDEX2); 104 model2.setName("Java"); 105 model2.setColor(Color.GRAY); 106 model2.setValue(TEST_VALUE2); 107 List<ChartDataModel> list2 = Collections.singletonList(model2); 108 dataMap.put(TEST_TIME2, list2); 109 } 110 111 /** 112 * refresh chart test 113 * 114 * @tc.name: refreshChart 115 * @tc.number: OHOS_JAVA_View_ProfilerChart_refreshChart_0001 116 * @tc.desc: refreshChart 117 * @tc.type: functional testing 118 * @tc.require: AR000FK5UI 119 */ 120 @Test refreshChartTest()121 public void refreshChartTest() { 122 chart.refreshChart(TEST_START, TEST_END, dataMap); 123 Assert.assertTrue(true); 124 } 125 126 /** 127 * get bottomPanel test 128 * 129 * @tc.name: getBottomPanel 130 * @tc.number: OHOS_JAVA_View_ProfilerChart_getBottomPanel_0001 131 * @tc.desc: getBottomPanel 132 * @tc.type: functional testing 133 * @tc.require: AR000FK5UI 134 */ 135 @Test getBottomPanelTest()136 public void getBottomPanelTest() { 137 ProfilerChartsView profilerChartsView = new FilledLineChart(view, NAME, true).getBottomPanel(); 138 Assert.assertNotNull(profilerChartsView); 139 } 140 141 /** 142 * functional test 143 * 144 * @tc.name: getEndTime 145 * @tc.number: OHOS_JAVA_View_ProfilerChart_getEndTime_0001 146 * @tc.desc: getEndTime 147 * @tc.type: functional testing 148 * @tc.require: AR000FK5UI 149 */ 150 @Test getEndTimeTest()151 public void getEndTimeTest() { 152 int endTime = new FilledLineChart(view, NAME, true).getEndTime(); 153 Assert.assertNotNull(endTime); 154 } 155 156 /** 157 * functional test 158 * 159 * @tc.name: getStartTime 160 * @tc.number: OHOS_JAVA_View_ProfilerChart_getStartTime_0001 161 * @tc.desc: getStartTime 162 * @tc.type: functional testing 163 * @tc.require: AR000FK5UI 164 */ 165 @Test getStartTimeTest()166 public void getStartTimeTest() { 167 int startTime = new FilledLineChart(view, NAME, true).getStartTime(); 168 Assert.assertNotNull(startTime); 169 } 170 171 /** 172 * functional test 173 * 174 * @tc.name: refreshLegendsTest 175 * @tc.number: OHOS_JAVA_View_ProfilerChart_refreshLegendsTest_0001 176 * @tc.desc: refresh Legends Test 177 * @tc.type: functional testing 178 * @tc.require: AR000FK5UI 179 */ 180 @Test refreshLegendsTest()181 public void refreshLegendsTest() { 182 chart.refreshChart(TEST_START, TEST_END, dataMap); 183 chart.refreshLegends(); 184 Assert.assertTrue(true); 185 } 186 187 /** 188 * paint Component Test 189 * 190 * @tc.name: paintComponentTest 191 * @tc.number: OHOS_JAVA_View_ProfilerChart_paintComponentTest_0001 192 * @tc.desc: paint Component Test 193 * @tc.type: functional testing 194 * @tc.require: AR000FK5UI 195 */ 196 @Test paintComponentTest()197 public void paintComponentTest() { 198 chart.revalidate(); 199 Assert.assertTrue(true); 200 } 201 202 /** 203 * get Yaxis Label Str Test 204 * 205 * @tc.name: getYaxisLabelStrTest 206 * @tc.number: OHOS_JAVA_View_ProfilerChart_getYaxisLabelStrTest_0001 207 * @tc.desc: get Yaxis Label Str Test 208 * @tc.type: functional testing 209 * @tc.require: AR000FK5UI 210 */ 211 @Test getYaxisLabelStrTest()212 public void getYaxisLabelStrTest() { 213 String yaxisLabelStr = chart.getYaxisLabelStr(10); 214 Assert.assertNotNull(yaxisLabelStr); 215 } 216 217 /** 218 * init Point Test 219 * 220 * @tc.name: initPointTest 221 * @tc.number: OHOS_JAVA_View_ProfilerChart_initPointTest_0001 222 * @tc.desc: init Point Test 223 * @tc.type: functional testing 224 * @tc.require: AR000FK5UI 225 */ 226 @Test initPointTest()227 public void initPointTest() { 228 chart.initPoint(); 229 Assert.assertTrue(true); 230 } 231 232 /** 233 * check Mouse For Tool tip Test 234 * 235 * @tc.name: checkMouseForTooltipTest 236 * @tc.number: OHOS_JAVA_View_ProfilerChart_checkMouseForTooltipTest_0001 237 * @tc.desc: check Mouse For Tool tip Test 238 * @tc.type: functional testing 239 * @tc.require: AR000FK5UI 240 */ 241 @Test checkMouseForTooltipTest()242 public void checkMouseForTooltipTest() { 243 JBPanel jBPanel = new JBPanel(); 244 MouseEvent mouseEvent = new MouseEvent(jBPanel, 1, 1, 1, 1, 1, 1, true, 1); 245 chart.checkMouseForTooltip(mouseEvent); 246 Assert.assertTrue(true); 247 } 248 249 /** 250 * get Current Line Color Test 251 * 252 * @tc.name: getCurrentLineColorTest 253 * @tc.number: OHOS_JAVA_View_ProfilerChart_getCurrentLineColorTest_0001 254 * @tc.desc: get Current Line Color Test 255 * @tc.type: functional testing 256 * @tc.require: AR000FK5UI 257 */ 258 @Test getCurrentLineColorTest()259 public void getCurrentLineColorTest() { 260 Color currentLineColor = chart.getCurrentLineColor(1, models); 261 Assert.assertNotNull(currentLineColor); 262 } 263 264 /** 265 * get Next Line Index Test 266 * 267 * @tc.name: getNextLineIndexTest 268 * @tc.number: OHOS_JAVA_View_ProfilerChart_getNextLineIndexTest_0001 269 * @tc.desc: get Next Line Index Test 270 * @tc.type: functional testing 271 * @tc.require: AR000FK5UI 272 */ 273 @Test getNextLineIndexTest()274 public void getNextLineIndexTest() { 275 int nextLineIndex = chart.getNextLineIndex(1, models); 276 Assert.assertNotNull(nextLineIndex); 277 } 278 279 /** 280 * get List Sum Test 281 * 282 * @tc.name: getListSumTest 283 * @tc.number: OHOS_JAVA_View_ProfilerChart_getListSumTest_0001 284 * @tc.desc: get List Sum Test 285 * @tc.type: functional testing 286 * @tc.require: AR000FK5UI 287 */ 288 @Test getListSumTest()289 public void getListSumTest() { 290 int listSum = chart.getListSum(models, 1); 291 Assert.assertNotNull(listSum); 292 } 293 294 /** 295 * get Model Value By Index Test 296 * 297 * @tc.name: getModelValueByIndexTest 298 * @tc.number: OHOS_JAVA_View_ProfilerChart_getModelValueByIndexTest_0001 299 * @tc.desc: get Model Value By Index Test 300 * @tc.type: functional testing 301 * @tc.require: AR000FK5UI 302 */ 303 @Test getModelValueByIndexTest()304 public void getModelValueByIndexTest() { 305 int modelValueByIndex = chart.getModelValueByIndex(models, 1); 306 Assert.assertNotNull(modelValueByIndex); 307 } 308 309 /** 310 * mouse Clicked Test 311 * 312 * @tc.name: mouseClickedTest 313 * @tc.number: OHOS_JAVA_View_ProfilerChart_mouseClickedTest_0001 314 * @tc.desc: mouse Clicked Test 315 * @tc.type: functional testing 316 * @tc.require: AR000FK5UI 317 */ 318 @Test mouseClickedTest()319 public void mouseClickedTest() { 320 JBPanel jBPanel = new JBPanel(); 321 MouseEvent mouseEvent = new MouseEvent(jBPanel, 1, 1, 1, 1, 1, 1, true, 1); 322 chart.mouseClicked(mouseEvent); 323 Assert.assertTrue(true); 324 } 325 326 /** 327 * mouse Pressed Test 328 * 329 * @tc.name: mousePressedTest 330 * @tc.number: OHOS_JAVA_View_ProfilerChart_mousePressedTest_0001 331 * @tc.desc: mouse Pressed Test 332 * @tc.type: functional testing 333 * @tc.require: AR000FK5UI 334 */ 335 @Test mousePressedTest()336 public void mousePressedTest() { 337 JBPanel jBPanel = new JBPanel(); 338 MouseEvent mouseEvent = new MouseEvent(jBPanel, 1, 1, 1, 1, 1, 1, true, 1); 339 chart.mousePressed(mouseEvent); 340 Assert.assertTrue(true); 341 } 342 343 /** 344 * mouse Released Test 345 * 346 * @tc.name: mouseReleasedTest 347 * @tc.number: OHOS_JAVA_View_ProfilerChart_mouseReleasedTest_0001 348 * @tc.desc: mouse Released Test 349 * @tc.type: functional testing 350 * @tc.require: AR000FK5UI 351 */ 352 @Test mouseReleasedTest()353 public void mouseReleasedTest() { 354 JBPanel jBPanel = new JBPanel(); 355 MouseEvent mouseEvent = new MouseEvent(jBPanel, 1, 1, 1, 1, 1, 1, true, 1); 356 chart.mouseReleased(mouseEvent); 357 Assert.assertTrue(true); 358 } 359 360 /** 361 * mouse Entered Test 362 * 363 * @tc.name: mouseEnteredTest 364 * @tc.number: OHOS_JAVA_View_ProfilerChart_mouseEnteredTest_0001 365 * @tc.desc: mouse Entered Test 366 * @tc.type: functional testing 367 * @tc.require: AR000FK5UI 368 */ 369 @Test mouseEnteredTest()370 public void mouseEnteredTest() { 371 JBPanel jBPanel = new JBPanel(); 372 MouseEvent mouseEvent = new MouseEvent(jBPanel, 1, 1, 1, 1, 1, 1, true, 1); 373 chart.mouseEntered(mouseEvent); 374 Assert.assertTrue(true); 375 } 376 377 /** 378 * mouse Exited Test 379 * 380 * @tc.name: mouseExitedTest 381 * @tc.number: OHOS_JAVA_View_ProfilerChart_mouseExitedTest_0001 382 * @tc.desc: mouse Exited Test 383 * @tc.type: functional testing 384 * @tc.require: AR000FK5UI 385 */ 386 @Test mouseExitedTest()387 public void mouseExitedTest() { 388 JBPanel jBPanel = new JBPanel(); 389 MouseEvent mouseEvent = new MouseEvent(jBPanel, 1, 1, 1, 1, 1, 1, true, 1); 390 chart.mouseExited(mouseEvent); 391 Assert.assertTrue(true); 392 } 393 394 /** 395 * mouse Dragged Test 396 * 397 * @tc.name: mouseDraggedTest 398 * @tc.number: OHOS_JAVA_View_ProfilerChart_mouseDraggedTest_0001 399 * @tc.desc: mouse Dragged Test 400 * @tc.type: functional testing 401 * @tc.require: AR000FK5UI 402 */ 403 @Test mouseDraggedTest()404 public void mouseDraggedTest() { 405 JBPanel jBPanel = new JBPanel(); 406 MouseEvent mouseEvent = new MouseEvent(jBPanel, 1, 1, 1, 1, 1, 1, true, 1); 407 chart.mouseDragged(mouseEvent); 408 Assert.assertTrue(true); 409 } 410 411 /** 412 * mouse Moved Test 413 * 414 * @tc.name: mouseMovedTest 415 * @tc.number: OHOS_JAVA_View_ProfilerChart_mouseMovedTest_0001 416 * @tc.desc: mouse Moved Test 417 * @tc.type: functional testing 418 * @tc.require: AR000FK5UI 419 */ 420 @Test mouseMovedTest()421 public void mouseMovedTest() { 422 JBPanel jBPanel = new JBPanel(); 423 MouseEvent mouseEvent = new MouseEvent(jBPanel, 1, 1, 1, 1, 1, 1, true, 1); 424 chart.mouseMoved(mouseEvent); 425 Assert.assertTrue(true); 426 } 427 } 428 429