<commit_before>var mAccessToken = null;
var mClientId = null;
var mServiceId = null;

function init() {
  dConnect.setExtendedOrigin("http://localhost:4035/");
  if (DEVICE_CONNECT_HOST) {
    dConnect.setHost(DEVICE_CONNECT_HOST);
  }

  if (TEST_TIMEOUT == undefined) {
    TEST_TIMEOUT = 10000;
  }

  if (DEVICE_NAME == undefined) {
    DEVICE_NAME = 'Test Success Device';
  }

  QUnit.config.autostart = false;
  QUnit.config.testTimeout = TEST_TIMEOUT;
}

function checkErrorCode(errorCode) {
  return errorCode == dConnect.constants.ErrorCode.NOT_SUPPORT_ATTRIBUTE
      || errorCode == dConnect.constants.ErrorCode.NOT_SUPPORT_ACTION
      || errorCode == dConnect.constants.ErrorCode.NOT_SUPPORT_PROFILE;
}

function searchTestDevice(services) {
  var re = new RegExp(DEVICE_NAME, 'i');

  for (var i = 0; i < services.length; i++) {
    var service = services[i];
    console.log('services: ' + services + ', name: ' + service.name);
    if (service.name.match(re)) {
      return service.id;
    }
  }
  return null;
}

function getAccessToken(func) {
  var scopes = Array(
      // core profile
      'authorization',
      'battery',
      'canvas',
      'connect',
      'deviceorientation',
      'file_descriptor',
      'file',
      'keyevent',
      'media_player',
      'mediastream_recording',
      'serviceinformation',
      'servicediscovery',
      'notification',
      'phone',
      'proximity',
      'settings',
      'system',
      'touch',
      'vibration',

      // extra profile
      'camera',
      'dice',
      'drive_controller',
      'light',
      'remote_controller',
      'sphero',
      'temperature',
      'health',
      'humandetect',
      'videochat',
      'omnidirectional_image',
      'humidity',
      'illuminance',
      'powermeter',
      'tv',
      'airconditioner'
  );

  dConnect.authorization(scopes,
      'Device Connect Javascript Test',
      function(clientId, accessToken) {
        mAccessToken = accessToken;
        mClientId = clientId;
        getTestServiceId(func);
      },
      function(errorCode, errorMessage) {
        func(null, null);
      }
  );
}

function getTestServiceId(func) {
  if (mAccessToken == null) {
    getAccessToken(func);
  } else if (mServiceId == null) {
    dConnect.discoverDevices(mAccessToken, function(json) {
        mServiceId = searchTestDevice(json.services);
        func(mAccessToken, mServiceId);
      },
      function(errorCode, errorMessage) {<commit_msg>Add gpio profile.<commit_after>var mAccessToken = null;
var mClientId = null;
var mServiceId = null;

function init() {
  dConnect.setExtendedOrigin("http://localhost:4035/");
  if (DEVICE_CONNECT_HOST) {
    dConnect.setHost(DEVICE_CONNECT_HOST);
  }

  if (TEST_TIMEOUT == undefined) {
    TEST_TIMEOUT = 10000;
  }

  if (DEVICE_NAME == undefined) {
    DEVICE_NAME = 'Test Success Device';
  }

  QUnit.config.autostart = false;
  QUnit.config.testTimeout = TEST_TIMEOUT;
}

function checkErrorCode(errorCode) {
  return errorCode == dConnect.constants.ErrorCode.NOT_SUPPORT_ATTRIBUTE
      || errorCode == dConnect.constants.ErrorCode.NOT_SUPPORT_ACTION
      || errorCode == dConnect.constants.ErrorCode.NOT_SUPPORT_PROFILE;
}

function searchTestDevice(services) {
  var re = new RegExp(DEVICE_NAME, 'i');

  for (var i = 0; i < services.length; i++) {
    var service = services[i];
    console.log('services: ' + services + ', name: ' + service.name);
    if (service.name.match(re)) {
      return service.id;
    }
  }
  return null;
}

function getAccessToken(func) {
  var scopes = Array(
      // core profile
      'authorization',
      'battery',
      'canvas',
      'connect',
      'deviceorientation',
      'file_descriptor',
      'file',
      'keyevent',
      'media_player',
      'mediastream_recording',
      'serviceinformation',
      'servicediscovery',
      'notification',
      'phone',
      'proximity',
      'settings',
      'system',
      'touch',
      'vibration',

      // extra profile
      'camera',
      'dice',
      'drive_controller',
      'light',
      'remote_controller',
      'sphero',
      'temperature',
      'health',
      'humandetect',
      'videochat',
      'omnidirectional_image',
      'humidity',
      'illuminance',
      'powermeter',
      'tv',
      'airconditioner',
      'gpio'
  );

  dConnect.authorization(scopes,
      'Device Connect Javascript Test',
      function(clientId, accessToken) {
        mAccessToken = accessToken;
        mClientId = clientId;
        getTestServiceId(func);
      },
      function(errorCode, errorMessage) {
        func(null, null);
      }
  );
}

function getTestServiceId(func) {
  if (mAccessToken == null) {
    getAccessToken(func);
  } else if (mServiceId == null) {
    dConnect.discoverDevices(mAccessToken, function(json) {
        mServiceId = searchTestDevice(json.services);
        func(mAccessToken, mServiceId);
      },
      function(errorCode, errorMessage) {
{'fraction_non_alphanumeric': 0.1282051282051282, 'fraction_numerical': 0.004006410256410256, 'mean_word_length': 2.7797123391370175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7481093', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1578, 'n_words': 293}