1  /* GLib testing framework examples and tests
       2   *
       3   * Copyright © 2018 Endless Mobile, Inc.
       4   *
       5   * SPDX-License-Identifier: LGPL-2.1-or-later
       6   *
       7   * This library is free software; you can redistribute it and/or
       8   * modify it under the terms of the GNU Lesser General Public
       9   * License as published by the Free Software Foundation; either
      10   * version 2.1 of the License, or (at your option) any later version.
      11   *
      12   * This library is distributed in the hope that it will be useful,
      13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15   * Lesser General Public License for more details.
      16   *
      17   * You should have received a copy of the GNU Lesser General
      18   * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      19   *
      20   * Author: Philip Withnall <withnall@endlessm.com>
      21   */
      22  
      23  #include <gio/gio.h>
      24  #include <locale.h>
      25  
      26  
      27  /* Smoketest for construction of a #GMountOperation. */
      28  static void
      29  test_construction (void)
      30  {
      31    GMountOperation *op = NULL;
      32  
      33    op = g_mount_operation_new ();
      34    g_assert_nonnull (op);
      35    g_assert_true (G_IS_MOUNT_OPERATION (op));
      36    g_object_unref (op);
      37  }
      38  
      39  /* Test the property getters and setters on #GMountOperation work correctly. */
      40  static void
      41  test_properties (void)
      42  {
      43    GMountOperation *op = NULL;
      44    gchar *username = NULL;
      45    gchar *password = NULL;
      46    gboolean anonymous;
      47    gchar *domain = NULL;
      48    GPasswordSave password_save;
      49    int choice;
      50    gboolean hidden_volume;
      51    gboolean system_volume;
      52    guint pim;
      53  
      54    op = g_mount_operation_new ();
      55  
      56    g_object_get (op,
      57                  "username", &username,
      58                  "password", &password,
      59                  "anonymous", &anonymous,
      60                  "domain", &domain,
      61                  "password-save", &password_save,
      62                  "choice", &choice,
      63                  "is-tcrypt-hidden-volume", &hidden_volume,
      64                  "is-tcrypt-system-volume", &system_volume,
      65                  "pim", &pim,
      66                  NULL);
      67  
      68    g_assert_cmpstr (username, ==, g_mount_operation_get_username (op));
      69    g_assert_cmpstr (password, ==, g_mount_operation_get_password (op));
      70    g_assert_cmpint (anonymous, ==, g_mount_operation_get_anonymous (op));
      71    g_assert_cmpstr (domain, ==, g_mount_operation_get_domain (op));
      72    g_assert_cmpint (password_save, ==, g_mount_operation_get_password_save (op));
      73    g_assert_cmpint (choice, ==, g_mount_operation_get_choice (op));
      74    g_assert_cmpint (hidden_volume, ==, g_mount_operation_get_is_tcrypt_hidden_volume (op));
      75    g_assert_cmpint (system_volume, ==, g_mount_operation_get_is_tcrypt_system_volume (op));
      76    g_assert_cmpuint (pim, ==, g_mount_operation_get_pim (op));
      77  
      78    g_mount_operation_set_username (op, "username");
      79    g_assert_cmpstr (g_mount_operation_get_username (op), ==, "username");
      80  
      81    g_mount_operation_set_password (op, "password");
      82    g_assert_cmpstr (g_mount_operation_get_password (op), ==, "password");
      83  
      84    g_mount_operation_set_anonymous (op, !anonymous);
      85    g_assert_cmpint (g_mount_operation_get_anonymous (op), ==, !anonymous);
      86  
      87    g_mount_operation_set_domain (op, "domain");
      88    g_assert_cmpstr (g_mount_operation_get_domain (op), ==, "domain");
      89  
      90    g_mount_operation_set_password_save (op, G_PASSWORD_SAVE_NEVER);
      91    g_assert_cmpint (g_mount_operation_get_password_save (op), ==, G_PASSWORD_SAVE_NEVER);
      92  
      93    g_mount_operation_set_choice (op, 5);
      94    g_assert_cmpint (g_mount_operation_get_choice (op), ==, 5);
      95  
      96    g_mount_operation_set_is_tcrypt_hidden_volume (op, !hidden_volume);
      97    g_assert_cmpint (g_mount_operation_get_is_tcrypt_hidden_volume (op), ==, !hidden_volume);
      98  
      99    g_mount_operation_set_is_tcrypt_system_volume (op, !system_volume);
     100    g_assert_cmpint (g_mount_operation_get_is_tcrypt_system_volume (op), ==, !system_volume);
     101  
     102    g_mount_operation_set_pim (op, 5);
     103    g_assert_cmpuint (g_mount_operation_get_pim (op), ==, 5);
     104  
     105    g_object_set (op,
     106                  "username", "other-username",
     107                  "password", "other-password",
     108                  "anonymous", FALSE,
     109                  "domain", "other-domain",
     110                  "password-save", G_PASSWORD_SAVE_PERMANENTLY,
     111                  "choice", 4,
     112                  "is-tcrypt-hidden-volume", FALSE,
     113                  "is-tcrypt-system-volume", FALSE,
     114                  "pim", 4,
     115                  NULL);
     116  
     117    g_free (domain);
     118    g_free (password);
     119    g_free (username);
     120    g_object_unref (op);
     121  }
     122  
     123  int
     124  main (int   argc,
     125        char *argv[])
     126  {
     127    setlocale (LC_ALL, "");
     128    g_test_init (&argc, &argv, NULL);
     129  
     130    g_test_add_func ("/mount-operation/construction", test_construction);
     131    g_test_add_func ("/mount-operation/properties", test_properties);
     132  
     133    return g_test_run ();
     134  }