コード例 #1
0
 /**
  * Set the bug report for the current test failure. GZip it to save space. This is only called
  * when the --bugreport option is enabled.
  */
 private void setBugReport(InputStreamSource dataStream) throws IOException {
   if (mCurrentIssue != null) {
     // Only one bug report can be stored at a time and they are gzipped to
     // about 0.5 MB so there shoudn't be any memory leak bringing down CTS.
     InputStream input = null;
     try {
       input = dataStream.createInputStream();
       mCurrentIssue.mBugReport = getBytes(input, BUGREPORT_SIZE);
     } finally {
       if (input != null) {
         input.close();
       }
     }
   } else {
     CLog.e("setBugReport is getting called on an empty issue...");
   }
 }
コード例 #2
0
  /**
   * Test logging to a logger.
   *
   * @throws ConfigurationException if unable to create log file
   * @throws IOException if unable to read from the file
   * @throws SecurityException if unable to delete the log file on cleanup
   */
  public void testLogToLogger() throws ConfigurationException, IOException, SecurityException {
    String Text1 = "The quick brown fox jumps over the lazy doggie.";
    String Text2 = "Betty Botter bought some butter, 'But,' she said, 'this butter's bitter.'";
    String Text3 = "Wolf zombies quickly spot the jinxed grave.";
    BufferedReader logFileReader = null;
    FileLogger logger = new FileLogger();
    InputStreamSource logSource = null;

    try {

      logger.init();
      // Write 3 lines of text to the log...
      logger.printLog(LogLevel.INFO, LOG_TAG, Text1);
      String expectedText1 = LogUtil.getLogFormatString(LogLevel.INFO, LOG_TAG, Text1).trim();
      logger.printLog(LogLevel.VERBOSE, LOG_TAG, Text2);
      String expectedText2 = LogUtil.getLogFormatString(LogLevel.VERBOSE, LOG_TAG, Text2).trim();
      logger.printLog(LogLevel.ASSERT, LOG_TAG, Text3);
      String expectedText3 = LogUtil.getLogFormatString(LogLevel.ASSERT, LOG_TAG, Text3).trim();

      // Verify the 3 lines we logged
      logSource = logger.getLog();
      logFileReader = new BufferedReader(new InputStreamReader(logSource.createInputStream()));

      String actualLogString = logFileReader.readLine().trim();
      assertTrue(actualLogString.equals(expectedText1));

      actualLogString = logFileReader.readLine().trim();
      assertTrue(actualLogString.equals(expectedText2));

      actualLogString = logFileReader.readLine().trim();
      assertTrue(actualLogString.equals(expectedText3));

    } finally {
      if (logFileReader != null) {
        logFileReader.close();
      }
      if (logSource != null) {
        logSource.cancel();
      }
      logger.closeLog();
    }
  }