Skip to content

Commit 655c9c2

Browse files
author
Haydelj
committed
added var buffer tests
1 parent 9fd2521 commit 655c9c2

File tree

2 files changed

+118
-7
lines changed

2 files changed

+118
-7
lines changed

src/Interface/Modules/Render/Tests/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#
22
# For more information, please see: http://software.sci.utah.edu
3-
#
3+
#
44
# The MIT License
5-
#
5+
#
66
# Copyright (c) 2015 Scientific Computing and Imaging Institute,
77
# University of Utah.
8-
#
9-
#
8+
#
9+
#
1010
# Permission is hereby granted, free of charge, to any person obtaining a
1111
# copy of this software and associated documentation files (the "Software"),
1212
# to deal in the Software without restriction, including without limitation
1313
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1414
# and/or sell copies of the Software, and to permit persons to whom the
1515
# Software is furnished to do so, subject to the following conditions:
16-
#
16+
#
1717
# The above copyright notice and this permission notice shall be included
18-
# in all copies or substantial portions of the Software.
19-
#
18+
# in all copies or substantial portions of the Software.
19+
#
2020
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
2121
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2222
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
@@ -28,6 +28,7 @@
2828

2929
SET(Interface_Modules_Render_Tests_SRCS
3030
SRInterfaceTests.cc
31+
VarBufferTests.cc
3132
)
3233

3334
SCIRUN_ADD_UNIT_TEST(Interface_Modules_Render_Tests
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include <spire/var-buffer/VarBuffer.hpp>
2+
#include <bserialize/BSerialize.hpp>
3+
#include <gtest/gtest.h>
4+
#include <memory>
5+
#include <cstring>
6+
7+
using namespace spire;
8+
9+
TEST(VarBufferTest, BasicSerialization)
10+
{
11+
VarBuffer vb;
12+
13+
// Proceed close to 1024 limit.
14+
const size_t emptySize = 1020;
15+
char empty[emptySize];
16+
std::memset(empty, 0, emptySize);
17+
18+
vb.writeBytes(empty, emptySize);
19+
20+
// After this write, we are at 1024.
21+
uint32_t v1 = 3;
22+
double v2 = 5.483;
23+
float v3 = 8293.09;
24+
int32_t v4 = -323;
25+
uint16_t v5 = 8924;
26+
std::string v6 = "This is a test string.";
27+
uint8_t v7 = 98;
28+
29+
vb.write(v1);
30+
31+
// Continue writing.
32+
vb.write(v2);
33+
vb.write(v3);
34+
vb.write(v4);
35+
vb.writeNullTermString("Blah!");
36+
vb.write(v5);
37+
vb.write(v6);
38+
vb.write(v7);
39+
40+
// Now take the buffer and stuff it into BSerialize
41+
BSerialize sin(vb.getBuffer(), vb.getBufferSize());
42+
sin.readBytes(emptySize);
43+
EXPECT_EQ(v1, sin.read<uint32_t>());
44+
EXPECT_EQ(v2, sin.read<double>());
45+
EXPECT_EQ(v3, sin.read<float>());
46+
EXPECT_EQ(v4, sin.read<int32_t>());
47+
EXPECT_EQ(std::string("Blah!"), std::string(sin.readNullTermString()));
48+
EXPECT_EQ(v5, sin.read<uint16_t>());
49+
EXPECT_EQ(v6, sin.read<std::string>());
50+
EXPECT_EQ(v7, sin.read<uint8_t>());
51+
}
52+
53+
TEST(VarBufferTest, TestPreallocatedSize)
54+
{
55+
VarBuffer vb(5000);
56+
57+
EXPECT_EQ(5000, vb.getAllocatedSize());
58+
59+
// Proceed close to 1024 limit.
60+
const size_t emptySize = 1020;
61+
char empty[emptySize];
62+
std::memset(empty, 0, emptySize);
63+
64+
vb.writeBytes(empty, emptySize);
65+
66+
// After this write, we are at 1024.
67+
uint32_t v1 = 3;
68+
double v2 = 5.483;
69+
float v3 = 8293.09;
70+
int32_t v4 = -323;
71+
uint16_t v5 = 8924;
72+
std::string v6 = "This is a test string.";
73+
uint8_t v7 = 98;
74+
75+
vb.write(v1);
76+
77+
// Continue writing.
78+
vb.write(v2);
79+
vb.write(v3);
80+
vb.write(v4);
81+
vb.writeNullTermString("Blah!");
82+
vb.write(v5);
83+
vb.write(v6);
84+
vb.write(v7);
85+
86+
// Now take the buffer and stuff it into BSerialize
87+
BSerialize sin(vb.getBuffer(), vb.getBufferSize());
88+
sin.readBytes(emptySize);
89+
EXPECT_EQ(v1, sin.read<uint32_t>());
90+
EXPECT_EQ(v2, sin.read<double>());
91+
EXPECT_EQ(v3, sin.read<float>());
92+
EXPECT_EQ(v4, sin.read<int32_t>());
93+
EXPECT_EQ(std::string("Blah!"), std::string(sin.readNullTermString()));
94+
EXPECT_EQ(v5, sin.read<uint16_t>());
95+
EXPECT_EQ(v6, sin.read<std::string>());
96+
EXPECT_EQ(v7, sin.read<uint8_t>());
97+
98+
// Check to ensure that we are still at size 5000.
99+
EXPECT_EQ(5000, vb.getAllocatedSize());
100+
}
101+
102+
103+
//takes on the order of 10 second to run becasue of the large allocation size so I dsiabeld it for now
104+
TEST(VarBufferTest, DISABLED_TestLargeAllocation)
105+
{
106+
size_t size = 1ull << 32;
107+
EXPECT_GT(size, static_cast<size_t>(std::numeric_limits<uint32_t>::max()));
108+
VarBuffer vb(size);
109+
EXPECT_EQ(size, vb.getAllocatedSize());
110+
}

0 commit comments

Comments
 (0)