com.tencent.wstt.apt.util.TestSenceUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.tencent.wstt.apt.util.TestSenceUtil.java

Source

/**
 * Tencent is pleased to support the open source community by making APT available.
 * Copyright (C) 2014 THL A29 Limited, a Tencent company. All rights reserved.
 * 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.tencent.wstt.apt.util;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.PlatformUI;

import com.tencent.wstt.apt.console.APTConsoleFactory;
import com.tencent.wstt.apt.data.Constant;
import com.tencent.wstt.apt.data.TestSence;
import com.tencent.wstt.apt.ui.views.DevicesView;
import com.tencent.wstt.apt.ui.views.SettingView;

/**
 * @Description * ? 1?? 2????
 * @date 20131110 ?6:23:11
 * 
 */
public class TestSenceUtil {
    /**
    * @Description ?? 
    * @param @return   
    * @return boolean 
    * @throws
     */
    public static boolean update() {
        DevicesView dvPart = (DevicesView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .findView(DevicesView.ID);
        SettingView svPart = (SettingView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .findView(SettingView.ID);

        if (dvPart == null || svPart == null) {
            return false;
        }
        /**
         * ?????
         * ?settings??
         * 
         * ????xml
         */
        dvPart.getTargetPkgInfoList();
        svPart.getTestArgs();
        return true;
    }

    /**
    * @Description ?? 
    * @param @return   
    * @return boolean 
    * @throws
     */
    public static boolean verifyTestSence() {
        //
        if (TestSence.getInstance().pkgInfos.size() == 0) {
            String info = "";
            APTConsoleFactory.getInstance().APTPrint(info);
            MessageDialog.openWarning(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "??", info);
            return false;
        }

        //?
        int testItemCount = 0;
        for (int i = 0; i < Constant.TEST_ITEM_COUNT; i++) {
            if (TestSence.getInstance().itemTestSwitch[i]) {
                testItemCount++;
            }
        }

        if (testItemCount == 0) {
            String info = "";
            APTConsoleFactory.getInstance().APTPrint(info);
            MessageDialog.openWarning(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "??", info);
            return false;
        }

        if (TestSence.getInstance().itemTestSwitch[Constant.MEM_INDEX] && testItemCount > 1) {
            String info = "?CPU?CPU";
            APTConsoleFactory.getInstance().APTPrint(info);
            if (!MessageDialog.openConfirm(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "??",
                    info)) {
                return false;
            }
        }

        if (TestSence.getInstance().itemTestPeriod[Constant.CPU_INDEX] < Constant.TOP_UPDATE_PERIOD * 1000) {
            String info = "CPU3";
            APTConsoleFactory.getInstance().APTPrint(info);
            MessageDialog.openWarning(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "??", info);
            return false;
        }

        return true;
    }

}