UFO: Alien Invasion
Loading...
Searching...
No Matches
test_dbuffer.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
26#include "test_shared.h"
27#include "../common/common.h"
28
29class DBufferTest: public ::testing::Test {
30protected:
31 static void SetUpTestCase() {
32 TEST_Init();
33 }
34
35 static void TearDownTestCase() {
37 }
38};
39
40TEST_F(DBufferTest, testDBuffer)
41{
42 int i;
43 const int size = 10000000;
44 dbuffer* buf = new dbuffer();
45 char data[128];
46 size_t dataSize = sizeof(data);
47 for (i = 0; i < size; i++)
48 buf->add("b", 1);
49 ASSERT_EQ(size, buf->length());
50
51 ASSERT_EQ(dataSize, buf->get(data, dataSize));
52 ASSERT_EQ(size, buf->length());
53
54 ASSERT_EQ(dataSize, buf->extract(data, dataSize));
55 ASSERT_EQ(size - dataSize, buf->length());
56
57 delete buf;
58
59 buf = new dbuffer();
60 buf->add("b", 1);
61 ASSERT_EQ(1, buf->length());
62
63 ASSERT_EQ(1, buf->get(data, dataSize));
64 ASSERT_EQ(1, buf->length());
65
66 ASSERT_EQ(1, buf->extract(data, dataSize));
67 ASSERT_EQ(0, buf->length());
68
69 dbuffer* dup = new dbuffer(*buf);
70 delete buf;
71 buf = dup;
72 ASSERT_EQ(0, buf->length());
73
74 for (i = 0; i <= dataSize; i++)
75 buf->add("b", 1);
76 ASSERT_EQ(dataSize + 1, buf->length());
77
78 ASSERT_EQ(dataSize, buf->extract(data, dataSize));
79 ASSERT_EQ(1, buf->length());
80
81 ASSERT_EQ(1, buf->remove(1));
82 ASSERT_EQ(0, buf->length());
83
84 ASSERT_EQ(0, buf->remove(1));
85
86 ASSERT_EQ(0, buf->getAt(1, data, dataSize));
87
88 for (i = 0; i <= dataSize; i++)
89 buf->add("b", 1);
90 ASSERT_EQ(dataSize + 1, buf->length());
91
92 ASSERT_EQ(dataSize, buf->getAt(1, data, dataSize));
93 ASSERT_EQ(dataSize + 1, buf->length());
94}
95
96TEST_F(DBufferTest, testDBufferBigData)
97{
98 int count = 100;
99 byte* data;
100 /* this entity string may not contain any inline models, we don't have the bsp tree loaded here */
101 const int size = FS_LoadFile("game/entity.txt", &data);
102 dbuffer buf;
103
104 for (int i = 0; i < count; i++) {
105 buf.add((char*)data, size);
106 }
107
108 ASSERT_EQ(size * count, buf.length());
110}
111
112TEST_F(DBufferTest, testDBufferNetHandling)
113{
114 dbuffer buf;
115 NET_WriteByte(&buf, 'b');
116 ASSERT_EQ(1, buf.length());
117 NET_WriteShort(&buf, 128);
118 ASSERT_EQ(3, buf.length());
119 NET_WriteLong(&buf, 128);
120 ASSERT_EQ(7, buf.length());
121}
static void TearDownTestCase()
static void SetUpTestCase()
definitions common between client and server, but not game lib
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
voidpf void uLong size
Definition ioapi.h:42
voidpf void * buf
Definition ioapi.h:42
void NET_WriteShort(dbuffer *buf, int c)
Definition netpack.cpp:45
void NET_WriteByte(dbuffer *buf, byte c)
Definition netpack.cpp:39
void NET_WriteLong(dbuffer *buf, int c)
Definition netpack.cpp:52
QGL_EXTERN GLuint count
Definition r_gl.h:99
QGL_EXTERN GLsizei const GLvoid * data
Definition r_gl.h:89
QGL_EXTERN GLint i
Definition r_gl.h:113
TEST_F(DBufferTest, testDBuffer)
void TEST_Shutdown(void)
void TEST_Init(void)