UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
test_webapi.cpp
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 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 
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 
62 {
64  return;
65  ASSERT_TRUE(WEB_Auth(user, password));
66 }
67 
68 TEST_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);
79  FS_WriteFile(buf, size, FILENAME);
80  FS_FreeFile(buf);
81  }
82  ASSERT_TRUE(WEB_CGameUpload(CGAME, CATEGORY, FILENAME));
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 }
bool Q_strnull(const char *string)
Definition: shared.h:138
static const char * password
Definition: test_webapi.cpp:36
cvar_t * web_userid
Definition: web_main.cpp:35
bool FS_FileExists(const char *filename,...)
Checks whether a file exists (not in virtual filesystem)
Definition: files.cpp:1581
#define FILE
Definition: test_webapi.cpp:30
bool WEB_Auth(const char *username, const char *password)
Performs a web auth request.
Definition: web_main.cpp:135
static const char * user
Definition: test_webapi.cpp:35
void Com_ParseScripts(bool onlyServer)
Definition: scripts.cpp:3641
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition: files.cpp:384
int integer
Definition: cvar.h:81
#define CGAME
Definition: test_webapi.cpp:32
voidpf void * buf
Definition: ioapi.h:42
#define FILENAME
Definition: test_webapi.cpp:31
const char * FS_Gamedir(void)
Called to find where to write a file (savegames, etc)
Definition: files.cpp:68
GLsizei size
Definition: r_gl.h:152
void TEST_Shutdown(void)
Definition: test_shared.cpp:34
int FS_WriteFile(const void *buffer, size_t len, const char *filename)
Definition: files.cpp:1544
#define CATEGORY
Definition: test_webapi.cpp:33
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
void WEB_InitStartup(void)
Definition: web_main.cpp:185
bool WEB_CGameUpload(const char *cgameId, int category, const char *filename)
Uploads a file to the server.
Definition: web_cgame.cpp:106
const char * TEST_GetStringProperty(const char *name)
void TEST_Init(void)
Definition: test_shared.cpp:72
static void SetUpTestCase()
Definition: test_webapi.cpp:40
bool WEB_CGameDelete(const char *cgameId, int category, const char *filename)
Deletes a user owned file on the server.
Definition: web_cgame.cpp:152
static void TearDownTestCase()
Definition: test_webapi.cpp:56
uint8_t byte
Definition: ufotypes.h:34
TEST_F(WebApiTest, Auth)
Definition: test_webapi.cpp:61
void FS_FreeFile(void *buffer)
Definition: files.cpp:411
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