libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

test_gnunet_chat_group_open.c (4171B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2024 GNUnet e.V.
      4 
      5    GNUnet is free software: you can redistribute it and/or modify it
      6    under the terms of the GNU Affero General Public License as published
      7    by the Free Software Foundation, either version 3 of the License,
      8    or (at your option) any later version.
      9 
     10    GNUnet is distributed in the hope that it will be useful, but
     11    WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13    Affero General Public License for more details.
     14 
     15    You should have received a copy of the GNU Affero General Public License
     16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18    SPDX-License-Identifier: AGPL3.0-or-later
     19  */
     20 /*
     21  * @author Tobias Frisch
     22  * @file test_gnunet_chat_group_open.c
     23  */
     24 
     25 #include "test_gnunet_chat.h"
     26 
     27 #define TEST_OPEN_ID         "gnunet_chat_group_open"
     28 #define TEST_OPEN_GROUP      "gnunet_chat_group_open_group"
     29 
     30 enum GNUNET_GenericReturnValue
     31 on_gnunet_chat_group_open_msg(void *cls,
     32                               struct GNUNET_CHAT_Context *context,
     33                               struct GNUNET_CHAT_Message *message)
     34 {
     35   static unsigned int group_stage = 0;
     36 
     37   struct GNUNET_CHAT_Handle *handle = *(
     38       (struct GNUNET_CHAT_Handle**) cls
     39   );
     40 
     41   ck_assert_ptr_nonnull(handle);
     42   ck_assert_ptr_nonnull(message);
     43 
     44   struct GNUNET_CHAT_Account *account;
     45   account = GNUNET_CHAT_message_get_account(message);
     46 
     47   const char *name = GNUNET_CHAT_get_name(handle);
     48 
     49   struct GNUNET_CHAT_Group *group;
     50   group = GNUNET_CHAT_context_get_group(context);
     51 
     52   switch (GNUNET_CHAT_message_get_kind(message))
     53   {
     54     case GNUNET_CHAT_KIND_WARNING:
     55       ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message));
     56       break;
     57     case GNUNET_CHAT_KIND_REFRESH:
     58       ck_assert_ptr_null(context);
     59       ck_assert_ptr_null(account);
     60 
     61       if (group_stage == 0)
     62       {
     63         account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID);
     64 
     65         ck_assert_ptr_nonnull(account);
     66 
     67         GNUNET_CHAT_connect(handle, account);
     68         group_stage = 1;
     69       }
     70 
     71       break;
     72     case GNUNET_CHAT_KIND_LOGIN:
     73       ck_assert_ptr_null(context);
     74       ck_assert_ptr_nonnull(account);
     75       ck_assert_ptr_nonnull(name);
     76       ck_assert_str_eq(name, TEST_OPEN_ID);
     77       ck_assert_ptr_null(group);
     78       ck_assert_uint_eq(group_stage, 1);
     79 
     80       group = GNUNET_CHAT_group_create(handle, TEST_OPEN_GROUP);
     81 
     82       ck_assert_ptr_nonnull(group);
     83 
     84       group_stage = 2;
     85       break;
     86     case GNUNET_CHAT_KIND_LOGOUT:
     87       ck_assert_ptr_null(context);
     88       ck_assert_ptr_nonnull(account);
     89       ck_assert_ptr_null(group);
     90       ck_assert_uint_eq(group_stage, 4);
     91       
     92       GNUNET_CHAT_stop(handle);
     93       break;
     94     case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
     95       ck_assert_ptr_nonnull(account);
     96       break;
     97     case GNUNET_CHAT_KIND_UPDATE_CONTEXT:
     98       ck_assert_ptr_nonnull(context);
     99       break;
    100     case GNUNET_CHAT_KIND_JOIN:
    101       ck_assert_ptr_nonnull(context);
    102       ck_assert_ptr_nonnull(group);
    103       ck_assert_uint_eq(group_stage, 2);
    104 
    105       ck_assert_int_eq(
    106         GNUNET_CHAT_group_leave(group),
    107         GNUNET_OK
    108       );
    109 
    110       group_stage = 3;
    111       break;
    112     case GNUNET_CHAT_KIND_LEAVE:
    113       ck_assert_ptr_nonnull(context);
    114       ck_assert_ptr_null(group);
    115       ck_assert_uint_eq(group_stage, 3);
    116       
    117       GNUNET_CHAT_disconnect(handle);
    118       group_stage = 4;
    119       break;
    120     case GNUNET_CHAT_KIND_CONTACT:
    121       break;
    122     default:
    123       ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message));
    124       ck_abort();
    125       break;
    126   }
    127 
    128   return GNUNET_YES;
    129 }
    130 
    131 REQUIRE_GNUNET_CHAT_ACCOUNT(gnunet_chat_group_open, TEST_OPEN_ID)
    132 
    133 void
    134 call_gnunet_chat_group_open(const struct GNUNET_CONFIGURATION_Handle *cfg)
    135 {
    136   static struct GNUNET_CHAT_Handle *handle = NULL;
    137   handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_group_open_msg, &handle);
    138 
    139   ck_assert_ptr_nonnull(handle);
    140 }
    141 
    142 CREATE_GNUNET_TEST(test_gnunet_chat_group_open, gnunet_chat_group_open)
    143 
    144 START_SUITE(handle_suite, "Group")
    145 ADD_TEST_TO_SUITE(test_gnunet_chat_group_open, "Open/Close")
    146 END_SUITE
    147 
    148 MAIN_SUITE(handle_suite, CK_NORMAL)