libgnunetchat

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

test_gnunet_chat_lobby_open.c (4289B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2022--2026 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_lobby_open.c
     23  */
     24 
     25 #include "test_gnunet_chat.h"
     26 
     27 #define TEST_OPEN_ID     "gnunet_chat_lobby_open"
     28 #define TEST_OPEN_SECRET "test_secret_lobby_open"
     29 
     30 enum GNUNET_GenericReturnValue
     31 on_gnunet_chat_lobby_open_msg(void *cls,
     32                               struct GNUNET_CHAT_Context *context,
     33                               struct GNUNET_CHAT_Message *message)
     34 {
     35   static unsigned int lobby_stage = 0;
     36   static struct GNUNET_CHAT_Lobby *lobby = NULL;
     37 
     38   struct GNUNET_CHAT_Handle *handle = *(
     39       (struct GNUNET_CHAT_Handle**) cls
     40   );
     41 
     42   ck_assert_ptr_nonnull(handle);
     43   ck_assert_ptr_nonnull(message);
     44 
     45   struct GNUNET_CHAT_Account *account;
     46 
     47   account = GNUNET_CHAT_message_get_account(message);
     48 
     49   switch (GNUNET_CHAT_message_get_kind(message))
     50   {
     51     case GNUNET_CHAT_KIND_WARNING:
     52       ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message));
     53       break;
     54     case GNUNET_CHAT_KIND_REFRESH:
     55       ck_assert_ptr_null(context);
     56       ck_assert_ptr_null(account);
     57 
     58       if (lobby_stage == 0)
     59       {
     60         account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID);
     61 
     62         ck_assert_ptr_nonnull(account);
     63 
     64         GNUNET_CHAT_connect(
     65           handle,
     66           account,
     67           TEST_OPEN_SECRET,
     68           strlen(TEST_OPEN_SECRET)
     69         );
     70 
     71         lobby_stage = 1;
     72       }
     73 
     74       break;
     75     case GNUNET_CHAT_KIND_LOGIN:
     76       ck_assert_ptr_null(context);
     77       ck_assert_ptr_nonnull(account);
     78       ck_assert_ptr_null(lobby);
     79       ck_assert_uint_eq(lobby_stage, 1);
     80 
     81       lobby = GNUNET_CHAT_lobby_open(
     82           handle,
     83           GNUNET_CHAT_LOBBY_TYPE_CONTACT,
     84           1,
     85           NULL,
     86           NULL
     87       );
     88 
     89       ck_assert_ptr_nonnull(lobby);
     90 
     91       lobby_stage = 2;
     92       break;
     93     case GNUNET_CHAT_KIND_LOGOUT:
     94       ck_assert_ptr_null(context);
     95       ck_assert_ptr_nonnull(account);
     96       ck_assert_ptr_null(lobby);
     97       ck_assert_uint_eq(lobby_stage, 4);
     98 
     99       GNUNET_CHAT_stop(handle);
    100       break;
    101     case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
    102       ck_assert_ptr_null(context);
    103       ck_assert_ptr_nonnull(account);
    104       break;
    105     case GNUNET_CHAT_KIND_UPDATE_CONTEXT:
    106       ck_assert_ptr_nonnull(context);
    107       ck_assert_ptr_nonnull(account);
    108       break;
    109     case GNUNET_CHAT_KIND_JOIN:
    110       ck_assert_ptr_nonnull(context);
    111       ck_assert_ptr_nonnull(account);
    112       ck_assert_ptr_nonnull(lobby);
    113       ck_assert_uint_eq(lobby_stage, 2);
    114 
    115       GNUNET_CHAT_lobby_close(lobby);
    116       lobby = NULL;
    117 
    118       lobby_stage = 3;
    119       break;
    120     case GNUNET_CHAT_KIND_LEAVE:
    121       ck_assert_ptr_nonnull(context);
    122       ck_assert_ptr_nonnull(account);
    123       ck_assert_ptr_null(lobby);
    124       ck_assert_uint_eq(lobby_stage, 3);
    125 
    126       GNUNET_CHAT_disconnect(handle);
    127 
    128       lobby_stage = 4;
    129       break;
    130     case GNUNET_CHAT_KIND_CONTACT:
    131       ck_assert_ptr_nonnull(context);
    132       ck_assert_ptr_nonnull(account);
    133       break;
    134     default:
    135       ck_abort();
    136       break;
    137   }
    138 
    139   return GNUNET_YES;
    140 }
    141 
    142 REQUIRE_GNUNET_CHAT_ACCOUNT(gnunet_chat_lobby_open, TEST_OPEN_ID)
    143 
    144 void
    145 call_gnunet_chat_lobby_open(const struct GNUNET_CONFIGURATION_Handle *cfg)
    146 {
    147   static struct GNUNET_CHAT_Handle *handle = NULL;
    148   handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_open_msg, &handle);
    149 
    150   ck_assert_ptr_nonnull(handle);
    151 }
    152 
    153 CREATE_GNUNET_TEST(test_gnunet_chat_lobby_open, gnunet_chat_lobby_open)
    154 
    155 START_SUITE(lobby_suite, "Lobby")
    156 ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_open, "Open/Close")
    157 END_SUITE
    158 
    159 MAIN_SUITE(lobby_suite, CK_NORMAL)