UFO: Alien Invasion
Loading...
Searching...
No Matches
test_webapi.cpp
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#include "test_shared.h"
28
29#define FILEPATH "save/campaign/"
30#define FILE "unittest1.savx"
31#define FILENAME FILEPATH FILE
32#define CGAME "test"
33#define CATEGORY 0
34
35static const char* user;
36static const char* password;
37
38class WebApiTest: public ::testing::Test {
39protected:
40 static void SetUpTestCase() {
41 TEST_Init();
42
43 Com_ParseScripts(true);
44
46
47 user = TEST_GetStringProperty("webapi-user");
48 if (user == nullptr)
49 user = "";
50
51 password = TEST_GetStringProperty("webapi-password");
52 if (password == nullptr)
53 password = "";
54 }
55
56 static void TearDownTestCase() {
58 }
59};
60
62{
64 return;
65 ASSERT_TRUE(WEB_Auth(user, password));
66}
67
68TEST_F(WebApiTest, FileManagement)
69{
71 return;
72
73 /* we can only upload files from within our user directory - so let's copy it there */
74 if (!FS_FileExists("%s/" FILENAME, FS_Gamedir())) {
75 byte* buf;
76 const int size = FS_LoadFile(FILENAME, &buf);
77 ASSERT_TRUE(size > 0);
78 ASSERT_TRUE(nullptr != buf);
81 }
82 ASSERT_TRUE(WEB_CGameUpload(CGAME, CATEGORY, FILENAME));
83 ASSERT_TRUE(WEB_CGameDownloadFromUser(CGAME, CATEGORY, FILE, web_userid->integer));
84 const int countAfterUpload = WEB_CGameListForUser(CGAME, CATEGORY, web_userid->integer);
85 ASSERT_TRUE(countAfterUpload != -1);
86 ASSERT_TRUE(countAfterUpload >= 1);
87 ASSERT_TRUE(WEB_CGameDelete(CGAME, CATEGORY, FILE));
88 const int countAfterDelete = WEB_CGameListForUser(CGAME, CATEGORY, web_userid->integer);
89 ASSERT_TRUE(countAfterDelete != -1);
90 ASSERT_EQ(countAfterDelete, countAfterUpload - 1);
91}
static void SetUpTestCase()
static void TearDownTestCase()
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition files.cpp:384
void FS_FreeFile(void *buffer)
Definition files.cpp:411
int FS_WriteFile(const void *buffer, size_t len, const char *filename)
Definition files.cpp:1546
const char * FS_Gamedir(void)
Called to find where to write a file (savegames, etc).
Definition files.cpp:68
bool FS_FileExists(const char *filename,...)
Checks whether a file exists (not in virtual filesystem).
Definition files.cpp:1583
cvar_t * password
Definition g_main.cpp:67
voidpf void uLong size
Definition ioapi.h:42
voidpf void * buf
Definition ioapi.h:42
void Com_ParseScripts(bool onlyServer)
Definition scripts.cpp:3619
bool Q_strnull(const char *string)
Definition shared.h:138
void TEST_Shutdown(void)
const char * TEST_GetStringProperty(const char *name)
void TEST_Init(void)
#define CGAME
#define FILE
TEST_F(WebApiTest, Auth)
#define CATEGORY
static const char * user
#define FILENAME
static const char * password
bool WEB_CGameUpload(const char *cgameId, int category, const char *filename)
Uploads a file to the server.
bool WEB_CGameDelete(const char *cgameId, int category, const char *filename)
Deletes a user owned file on the server.
int WEB_CGameListForUser(const char *cgameId, int category, int userId)
Shows the uploaded files for the particular cgame category and the given userid.
bool WEB_CGameDownloadFromUser(const char *cgameId, int category, const char *filename, int userId)
Downloads a file from the server and store it in the user directory.
UFOAI web interface management. c(lient)game related stuff.
bool WEB_Auth(const char *username, const char *password)
Performs a web auth request.
Definition web_main.cpp:135
void WEB_InitStartup(void)
Definition web_main.cpp:185
cvar_t * web_userid
Definition web_main.cpp:35
UFOAI web interface management. Authentication as well as uploading/downloading stuff to and from you...