<commit_before>/*
 * Copyright (C) 2011 Collabora Ltd.
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: <NAME> <<EMAIL>>
 */

using DBus;
using TelepathyGLib;
using TpTest;
using Tpf;
using Folks;
using Gee;

public class IndividualPropertiesTests : Folks.TestCase
{
  private TpTest.Backend tp_backend;
  private void* _account_handle;
  private int _test_timeout = 3;
  private HashSet<string> _changes_pending;

  public IndividualPropertiesTests ()
    {
      base ("IndividualProperties");

      this.tp_backend = new TpTest.Backend ();

      this.add_test ("individual properties",
          this.test_individual_properties);
      this.add_test ("individual properties:change alias through tp backend",
          this.test_individual_properties_change_alias_through_tp_backend);
      this.add_test ("individual properties:change alias through test cm",
          this.test_individual_properties_change_alias_through_test_cm);
      this.add_test ("individual properties:change contact info",
          this.test_individual_properties_change_contact_info);

      if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
          this._test_timeout = 10;
    }

  public override void set_up ()
    {
      this.tp_backend.set_up ();
      this._account_handle = this.tp_backend.add_account ("protocol",
          "<EMAIL>", "cm", "account");
      this._changes_pending = new HashSet<string> ();
    }

  public override void tear_down ()
    {
      this.tp_backend.remove_account (this._account_handle);
      this.tp_backend.tear_down ();
    }

  public void test_individual_properties ()
    {
      var main_loop = new GLib.MainLoop (null, false);

      /* Set up the aggregator */
      var aggregator = new IndividualAggregator ();
      aggregator.individuals_changed_detailed.connect ((changes) =>
        {
          var added = changes.get_values ();
          var removed = changes.get_keys ();

          foreach (Individual i in added)
            {
              assert (i != null);

              /* We only check one (singleton Individual containing just
               * <EMAIL>) */
              if (i.id != "0e46c5e74f61908f49550d241f2a1651892a1695")
                {
                  continue;
                }

              /* Check properties */
              assert (i.alias == "Olivier");
              assert (i.presence_message == "");
              assert (i.presence_status == "away");
              assert (i.presence_type == PresenceType.AWAY);
              assert (((PresenceDetails) i).is_online () == true);

              /* Check groups */
              assert (i.groups.size == 2);
              assert (i.groups.contains ("Montreal") == true);
              assert (i.groups.contains ("Francophones") == true);

              /* Check ContactInfo-provided properties */
              assert (new PhoneFieldDetails ("+15142345678")
                  in i.phone_numbers);
            }

          assert (removed.size == 1);

          foreach (var i in removed)
            {<commit_msg>Add assertions about Telepathy writeable properties to our tests.<commit_after>/*
 * Copyright (C) 2011 Collabora Ltd.
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: <NAME> <<EMAIL>>
 */

using DBus;
using TelepathyGLib;
using TpTest;
using Tpf;
using Folks;
using Gee;

public class IndividualPropertiesTests : Folks.TestCase
{
  private TpTest.Backend tp_backend;
  private void* _account_handle;
  private int _test_timeout = 3;
  private HashSet<string> _changes_pending;

  public IndividualPropertiesTests ()
    {
      base ("IndividualProperties");

      this.tp_backend = new TpTest.Backend ();

      this.add_test ("individual properties",
          this.test_individual_properties);
      this.add_test ("individual properties:change alias through tp backend",
          this.test_individual_properties_change_alias_through_tp_backend);
      this.add_test ("individual properties:change alias through test cm",
          this.test_individual_properties_change_alias_through_test_cm);
      this.add_test ("individual properties:change contact info",
          this.test_individual_properties_change_contact_info);

      if (Environment.get_variable ("FOLKS_TEST_VALGRIND") != null)
          this._test_timeout = 10;
    }

  public override void set_up ()
    {
      this.tp_backend.set_up ();
      this._account_handle = this.tp_backend.add_account ("protocol",
          "<EMAIL>", "cm", "account");
      this._changes_pending = new HashSet<string> ();
    }

  public override void tear_down ()
    {
      this.tp_backend.remove_account (this._account_handle);
      this.tp_backend.tear_down ();
    }

  public void test_individual_properties ()
    {
      var main_loop = new GLib.MainLoop (null, false);

      /* Set up the aggregator */
      var aggregator = new IndividualAggregator ();
      aggregator.individuals_changed_detailed.connect ((changes) =>
        {
          var added = changes.get_values ();
          var removed = changes.get_keys ();

          foreach (Individual i in added)
            {
              assert (i != null);

              /* We only check one (singleton Individual containing just
               * <EMAIL>) */
              if (i.id != "0e46c5e74f61908f49550d241f2a1651892a1695")
                {
                  continue;
                }

              /* Check properties */
              assert (i.alias == "Olivier");
              assert (i.presence_message == "");
              assert (i.presence_status == "away");
              assert (i.presence_type == PresenceType.AWAY);
              assert (((PresenceDetails) i).is_online () == true);

              /* Check groups */
              assert (i.groups.size == 2);
              assert (i.groups.contains ("Montreal") == true);
              assert (i.groups.contains ("Francophones") == true);

              /* Check writeability of fields */
              Tpf.Persona tpf_persona = null;
              foreach (var p in i.personas)
                {
                  if (p is Tpf.Persona)
                    {
                      tpf_persona = p as Tpf.Persona;
                      break;
                    }
                }
              assert (tpf_persona != null);
              assert ("alias" in tpf_persona.writeable_properties);
              assert ("is-favourite" in tpf_persona.writeable_properties);
              assert ("groups" in tpf_persona.writeable_properties);
              /* These are only writeable for the user contact */
              assert (!tpf_persona.is_user);
              assert (!("full-name" in tpf_persona.writeable_properties));
              assert (!("phone-numbers" in tpf_persona.writeable_properties));

              /* Check ContactInfo-provided properties */
              assert (new PhoneFieldDetails ("+15142345678")
                  in i.phone_numbers);
            }

          assert (removed.size == 1);

          foreach (var i in removed)
            {
{'fraction_non_alphanumeric': 0.09447393822393822, 'fraction_numerical': 0.01278957528957529, 'mean_word_length': 2.3010752688172045, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3302202', 'n_tokens_mistral': 2337, 'n_tokens_neox': 2185, 'n_words': 648}