<commit_before>/*
 * Package : dartivity
 * Author : <NAME> <<EMAIL>>
 * Date   : 28/09/2015
 * Copyright :  S.Hamblett 2015
 */

library dartivity.test;

import 'dart:async';

import 'package:dartivity/dartivity.dart';

Future main() async {
  // Instantiate a Dartivity client and initialise for
  // messaging only
  Dartivity dartivity = new Dartivity(Mode.messagingOnly);

  // Send before ready
  DartivityMessage noSend = new DartivityMessage();
  var result = dartivity.send(noSend);
  if (result == null) {
    print("Message not sent not ready - OK");
  } else {
    print("Oops message sent when not ready- ERROR");
  }

  // Initialise
  await dartivity.initialise(
      DartivityCfg.MESS_CRED_PATH, DartivityCfg.MESS_PROJECT_ID);

  if (dartivity.initialised) {
    print("Initialse Status is true - OK");
  } else {
    print("Oops Initialse Status is false - ERROR");
  }

  // Send a null message
  var result1 = dartivity.send(null);
  if (result1 == null) {
    print("Null message not sent - OK");
  } else {
    print("Oops null message sent - ERROR");
  }

  // Send a couple of whoHas messages
  DartivityMessage whoHas1 =
  new DartivityMessage.whoHas(dartivity.id, '/core/light');
  dartivity.send(whoHas1);
  DartivityMessage whoHas2 =
  new DartivityMessage.whoHas(dartivity.id, '/core/thermostat');
  dartivity.send(whoHas2);

  // Followed by a I Have
  Map<String, String> myDevice = {'iama': 'thermostat', 'url': 'here.com/ami'};
  DartivityMessage iHave = new DartivityMessage.iHave(
      dartivity.id, dartivity.id, '/core/therm/1', myDevice);
  dartivity.send(iHave);

  // Followed by a I Have but not for us
  Map<String, String> myDevice1 = {'iama': 'thermostat', 'url': 'here.com/ami'};
  DartivityMessage iHave1 = new DartivityMessage.iHave(
      dartivity.id, 'not us', '/core/therm/1', myDevice1);
  dartivity.send(iHave1);

  // And a resource details
  DartivityMessage details = new DartivityMessage.details(
      dartivity.id, dartivity.id, '/core/therm/1', myDevice);
  dartivity.send(details);

  // Listen for our messages until our timer pops
  var subscription;
  int messCount = 0;

  void timerCallback() {
    print("Closing the client");
    if (messCount == 4) {
      print("Message count is 4 - OK");
    } else {
      print("Message count is ${messCount} - ERROR, should be 4");
    }
    subscription.cancel();
    try {
      dartivity.close();
    } catch (e) {
    }
  }
  Timer timer = new Timer(
      new Duration(seconds: (DartivityCfg.MESS_PULL_TIME_INTERVAL * 7 + 2)),
      timerCallback);

  subscription = dartivity.nextMessage.listen((DartivityMessage message) {
    print("Message received ${message.toString()}");
    messCount++;
  });
}
<commit_msg>Add good/bad exit codes<commit_after>/*
 * Package : dartivity
 * Author : <NAME> <<EMAIL>>
 * Date   : 28/09/2015
 * Copyright :  S.Hamblett 2015
 */

library dartivity.test;

import 'dart:async';
import 'dart:io';

import 'package:dartivity/dartivity.dart';

Future main() async {
  final int badExitCode = -1;

  // Instantiate a Dartivity client and initialise for
  // messaging only
  Dartivity dartivity = new Dartivity(Mode.messagingOnly);

  // Send before ready
  DartivityMessage noSend = new DartivityMessage();
  var result = dartivity.send(noSend);
  if (result == null) {
    print("Message not sent not ready - OK");
  } else {
    print("Oops message sent when not ready- ERROR");
    exit(badExitCode);
  }

  // Initialise
  await dartivity.initialise(
      DartivityCfg.MESS_CRED_PATH, DartivityCfg.MESS_PROJECT_ID);

  if (dartivity.initialised) {
    print("Initialse Status is true - OK");
  } else {
    print("Oops Initialse Status is false - ERROR");
    exit(badExitCode);
  }

  // Send a null message
  var result1 = dartivity.send(null);
  if (result1 == null) {
    print("Null message not sent - OK");
  } else {
    print("Oops null message sent - ERROR");
    exit(badExitCode);
  }

  // Send a couple of whoHas messages
  DartivityMessage whoHas1 =
  new DartivityMessage.whoHas(dartivity.id, '/core/light');
  dartivity.send(whoHas1);
  DartivityMessage whoHas2 =
  new DartivityMessage.whoHas(dartivity.id, '/core/thermostat');
  dartivity.send(whoHas2);

  // Followed by a I Have
  Map<String, String> myDevice = {'iama': 'thermostat', 'url': 'here.com/ami'};
  DartivityMessage iHave = new DartivityMessage.iHave(
      dartivity.id, dartivity.id, '/core/therm/1', myDevice);
  dartivity.send(iHave);

  // Followed by a I Have but not for us
  Map<String, String> myDevice1 = {'iama': 'thermostat', 'url': 'here.com/ami'};
  DartivityMessage iHave1 = new DartivityMessage.iHave(
      dartivity.id, 'not us', '/core/therm/1', myDevice1);
  dartivity.send(iHave1);

  // And a resource details
  DartivityMessage details = new DartivityMessage.details(
      dartivity.id, dartivity.id, '/core/therm/1', myDevice);
  dartivity.send(details);

  // Listen for our messages until our timer pops
  var subscription;
  int messCount = 0;

  void timerCallback() {
    print("Closing the client");
    if (messCount == 4) {
      print("Message count is 4 - OK");
    } else {
      print("Message count is ${messCount} - ERROR, should be 4");
      exit(badExitCode);
    }
    subscription.cancel();
    try {
      dartivity.close();
    } catch (e) {
    }
    // Good exit
    exit(0);
  }
  Timer timer = new Timer(
      new Duration(seconds: (DartivityCfg.MESS_PULL_TIME_INTERVAL * 7 + 2)),
      timerCallback);

  subscription = dartivity.nextMessage.listen((DartivityMessage message) {
    print("Message received ${message.toString()}");
    messCount++;
  });
}

{'fraction_non_alphanumeric': 0.13206878213082787, 'fraction_numerical': 0.01134550611593689, 'mean_word_length': 3.3668730650154797, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2213127', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1863, 'n_words': 486}