UFO: Alien Invasion
Toggle main menu visibility
Loading...
Searching...
No Matches
test_webapi.cpp
Go to the documentation of this file.
1
4
5
/*
6
Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8
This program is free software; you can redistribute it and/or
9
modify it under the terms of the GNU General Public License
10
as published by the Free Software Foundation; either version 2
11
of the License, or (at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17
See the GNU General Public License for more details.
18
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23
*/
24
25
#include "
test_shared.h
"
26
#include "
../client/web/web_main.h
"
27
#include "
../client/web/web_cgame.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
35
static
const
char
*
user
;
36
static
const
char
*
password
;
37
38
class
WebApiTest
:
public
::testing::Test {
39
protected
:
40
static
void
SetUpTestCase
() {
41
TEST_Init
();
42
43
Com_ParseScripts
(
true
);
44
45
WEB_InitStartup
();
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
() {
57
TEST_Shutdown
();
58
}
59
};
60
61
TEST_F
(
WebApiTest
, Auth)
62
{
63
if
(
Q_strnull
(
user
) ||
Q_strnull
(
password
))
64
return
;
65
ASSERT_TRUE(
WEB_Auth
(
user
,
password
));
66
}
67
68
TEST_F
(
WebApiTest
, FileManagement)
69
{
70
if
(
Q_strnull
(
user
) ||
Q_strnull
(
password
))
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
);
79
FS_WriteFile
(
buf
,
size
,
FILENAME
);
80
FS_FreeFile
(
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
}
WebApiTest
Definition
test_webapi.cpp:38
WebApiTest::SetUpTestCase
static void SetUpTestCase()
Definition
test_webapi.cpp:40
WebApiTest::TearDownTestCase
static void TearDownTestCase()
Definition
test_webapi.cpp:56
FS_LoadFile
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition
files.cpp:384
FS_FreeFile
void FS_FreeFile(void *buffer)
Definition
files.cpp:411
FS_WriteFile
int FS_WriteFile(const void *buffer, size_t len, const char *filename)
Definition
files.cpp:1546
FS_Gamedir
const char * FS_Gamedir(void)
Called to find where to write a file (savegames, etc).
Definition
files.cpp:68
FS_FileExists
bool FS_FileExists(const char *filename,...)
Checks whether a file exists (not in virtual filesystem).
Definition
files.cpp:1583
password
cvar_t * password
Definition
g_main.cpp:67
size
voidpf void uLong size
Definition
ioapi.h:42
buf
voidpf void * buf
Definition
ioapi.h:42
Com_ParseScripts
void Com_ParseScripts(bool onlyServer)
Definition
scripts.cpp:3619
Q_strnull
bool Q_strnull(const char *string)
Definition
shared.h:138
TEST_Shutdown
void TEST_Shutdown(void)
Definition
test_shared.cpp:34
TEST_GetStringProperty
const char * TEST_GetStringProperty(const char *name)
Definition
test_shared.cpp:185
TEST_Init
void TEST_Init(void)
Definition
test_shared.cpp:72
test_shared.h
CGAME
#define CGAME
Definition
test_webapi.cpp:32
FILE
#define FILE
Definition
test_webapi.cpp:30
TEST_F
TEST_F(WebApiTest, Auth)
Definition
test_webapi.cpp:61
CATEGORY
#define CATEGORY
Definition
test_webapi.cpp:33
user
static const char * user
Definition
test_webapi.cpp:35
FILENAME
#define FILENAME
Definition
test_webapi.cpp:31
password
static const char * password
Definition
test_webapi.cpp:36
WEB_CGameUpload
bool WEB_CGameUpload(const char *cgameId, int category, const char *filename)
Uploads a file to the server.
Definition
web_cgame.cpp:106
WEB_CGameDelete
bool WEB_CGameDelete(const char *cgameId, int category, const char *filename)
Deletes a user owned file on the server.
Definition
web_cgame.cpp:152
WEB_CGameListForUser
int WEB_CGameListForUser(const char *cgameId, int category, int userId)
Shows the uploaded files for the particular cgame category and the given userid.
Definition
web_cgame.cpp:310
WEB_CGameDownloadFromUser
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.
Definition
web_cgame.cpp:187
web_cgame.h
UFOAI web interface management. c(lient)game related stuff.
WEB_Auth
bool WEB_Auth(const char *username, const char *password)
Performs a web auth request.
Definition
web_main.cpp:135
WEB_InitStartup
void WEB_InitStartup(void)
Definition
web_main.cpp:185
web_userid
cvar_t * web_userid
Definition
web_main.cpp:35
web_main.h
UFOAI web interface management. Authentication as well as uploading/downloading stuff to and from you...
src
tests
test_webapi.cpp
Generated on __DATE__ __TIME__ for UFO: Alien Invasion by
1.17.0