libgnunetchat

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

test_gnunet_chat_lobby_open.c (3336B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2022--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_lobby_open.c
     23  */
     24 
     25 #include "test_gnunet_chat.h"
     26 
     27 #define TEST_OPEN_ID "gnunet_chat_lobby_open"
     28 
     29 enum GNUNET_GenericReturnValue
     30 on_gnunet_chat_lobby_open_msg(void *cls,
     31                               struct GNUNET_CHAT_Context *context,
     32                               struct GNUNET_CHAT_Message *message)
     33 {
     34   static unsigned int lobby_stage = 0;
     35 
     36   struct GNUNET_CHAT_Handle *handle = *(
     37       (struct GNUNET_CHAT_Handle**) cls
     38   );
     39 
     40   ck_assert_ptr_nonnull(handle);
     41   ck_assert_ptr_null(context);
     42   ck_assert_ptr_nonnull(message);
     43 
     44   struct GNUNET_CHAT_Account *account;
     45   struct GNUNET_CHAT_Lobby *lobby;
     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(handle, account);
     65         lobby_stage = 1;
     66       }
     67       
     68       break;
     69     case GNUNET_CHAT_KIND_LOGIN:
     70       ck_assert_ptr_null(context);
     71       ck_assert_ptr_nonnull(account);
     72       ck_assert_uint_eq(lobby_stage, 1);
     73 
     74       lobby = GNUNET_CHAT_lobby_open(
     75           handle,
     76           1,
     77           NULL,
     78           NULL
     79       );
     80 
     81       ck_assert_ptr_nonnull(lobby);
     82 
     83       GNUNET_CHAT_lobby_close(lobby);
     84       GNUNET_CHAT_disconnect(handle);
     85       lobby_stage = 2;
     86       break;
     87     case GNUNET_CHAT_KIND_LOGOUT:
     88       ck_assert_ptr_null(context);
     89       ck_assert_ptr_nonnull(account);
     90       ck_assert_uint_eq(lobby_stage, 2);
     91 
     92       GNUNET_CHAT_stop(handle);
     93       break;
     94     case GNUNET_CHAT_KIND_UPDATE_ACCOUNT:
     95       ck_assert_ptr_null(context);
     96       ck_assert_ptr_nonnull(account);
     97       break;
     98     default:
     99       ck_abort();
    100       break;
    101   }
    102 
    103   return GNUNET_YES;
    104 }
    105 
    106 REQUIRE_GNUNET_CHAT_ACCOUNT(gnunet_chat_lobby_open, TEST_OPEN_ID)
    107 
    108 void
    109 call_gnunet_chat_lobby_open(const struct GNUNET_CONFIGURATION_Handle *cfg)
    110 {
    111   static struct GNUNET_CHAT_Handle *handle = NULL;
    112   handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_open_msg, &handle);
    113 
    114   ck_assert_ptr_nonnull(handle);
    115 }
    116 
    117 CREATE_GNUNET_TEST(test_gnunet_chat_lobby_open, gnunet_chat_lobby_open)
    118 
    119 START_SUITE(lobby_suite, "Lobby")
    120 ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_open, "Open/Close")
    121 END_SUITE
    122 
    123 MAIN_SUITE(lobby_suite, CK_NORMAL)