test_gnunet_chat_lobby_open.c (3485B)
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 37 struct GNUNET_CHAT_Handle *handle = *( 38 (struct GNUNET_CHAT_Handle**) cls 39 ); 40 41 ck_assert_ptr_nonnull(handle); 42 ck_assert_ptr_null(context); 43 ck_assert_ptr_nonnull(message); 44 45 struct GNUNET_CHAT_Account *account; 46 struct GNUNET_CHAT_Lobby *lobby; 47 48 account = GNUNET_CHAT_message_get_account(message); 49 50 switch (GNUNET_CHAT_message_get_kind(message)) 51 { 52 case GNUNET_CHAT_KIND_WARNING: 53 ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); 54 break; 55 case GNUNET_CHAT_KIND_REFRESH: 56 ck_assert_ptr_null(context); 57 ck_assert_ptr_null(account); 58 59 if (lobby_stage == 0) 60 { 61 account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID); 62 63 ck_assert_ptr_nonnull(account); 64 65 GNUNET_CHAT_connect( 66 handle, 67 account, 68 TEST_OPEN_SECRET, 69 strlen(TEST_OPEN_SECRET) 70 ); 71 72 lobby_stage = 1; 73 } 74 75 break; 76 case GNUNET_CHAT_KIND_LOGIN: 77 ck_assert_ptr_null(context); 78 ck_assert_ptr_nonnull(account); 79 ck_assert_uint_eq(lobby_stage, 1); 80 81 lobby = GNUNET_CHAT_lobby_open( 82 handle, 83 1, 84 NULL, 85 NULL 86 ); 87 88 ck_assert_ptr_nonnull(lobby); 89 90 GNUNET_CHAT_lobby_close(lobby); 91 GNUNET_CHAT_disconnect(handle); 92 lobby_stage = 2; 93 break; 94 case GNUNET_CHAT_KIND_LOGOUT: 95 ck_assert_ptr_null(context); 96 ck_assert_ptr_nonnull(account); 97 ck_assert_uint_eq(lobby_stage, 2); 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 default: 106 ck_abort(); 107 break; 108 } 109 110 return GNUNET_YES; 111 } 112 113 REQUIRE_GNUNET_CHAT_ACCOUNT(gnunet_chat_lobby_open, TEST_OPEN_ID) 114 115 void 116 call_gnunet_chat_lobby_open(const struct GNUNET_CONFIGURATION_Handle *cfg) 117 { 118 static struct GNUNET_CHAT_Handle *handle = NULL; 119 handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_open_msg, &handle); 120 121 ck_assert_ptr_nonnull(handle); 122 } 123 124 CREATE_GNUNET_TEST(test_gnunet_chat_lobby_open, gnunet_chat_lobby_open) 125 126 START_SUITE(lobby_suite, "Lobby") 127 ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_open, "Open/Close") 128 END_SUITE 129 130 MAIN_SUITE(lobby_suite, CK_NORMAL)