32 #include <gtest/gtest.h>
45 using std::system_error;
46 using std::runtime_error;
57 TEST(secure_vector_test, char_sanity)
60 ASSERT_EQ(v.size(), 0);
62 ASSERT_EQ(v2.size(), 10);
63 SecVecChar v3(10,
'\1');
64 ASSERT_EQ(v3.size(), 10);
66 for (
unsigned i = 0; i < v3.size(); i++) t.push_back(
'\1');
67 for (
unsigned i = 0; i < v3.size(); i++) ASSERT_EQ(v3[i], t[i]);
70 ASSERT_EQ(v3.size(), 5);
72 for (
unsigned i = 0; i < v3.size(); i++) ASSERT_EQ(v3[i], t[i]);
75 ASSERT_EQ(v3.size(), 10);
77 for (
unsigned i = 0; i < v3.size(); i++) ASSERT_EQ(v3[i], t[i]);
80 ASSERT_EQ(v3.size(), 0);
83 TEST(secure_vector_test, uchar_sanity)
86 ASSERT_EQ(v.size(), 0);
88 ASSERT_EQ(v2.size(), 10);
89 SecVecUchar v3(10,
'\1');
90 ASSERT_EQ(v3.size(), 10);
91 vector<unsigned char> t;
92 for (
unsigned i = 0; i < v3.size(); i++) t.push_back(
'\1');
93 for (
unsigned i = 0; i < v3.size(); i++) ASSERT_EQ(v3[i], t[i]);
96 ASSERT_EQ(v3.size(), 5);
98 for (
unsigned i = 0; i < v3.size(); i++) ASSERT_EQ(v3[i], t[i]);
101 ASSERT_EQ(v3.size(), 10);
103 for (
unsigned i = 0; i < v3.size(); i++) ASSERT_EQ(v3[i], t[i]);
106 ASSERT_EQ(v3.size(), 0);
109 static string plaintext =
"\
110 To be, or not to be, that is the question: \n\
111 Whether 'tis nobler in the mind to suffer \n\
112 The slings and arrows of outrageous fortune, \n\
113 Or to take Arms against a Sea of troubles, \n\
114 And by opposing end them: to die, to sleep; \n\
115 No more; and by a sleep, to say we end \n\
116 The heart-ache, and the thousand natural shocks \n\
117 That Flesh is heir to? 'Tis a consummation \n\
118 Devoutly to be wished. To die, to sleep, \n\
119 perchance to Dream; aye, there's the rub...\n";
121 struct SecVecCharTest :
public testing::Test
127 SecVecCharTest() : fname(
"testfile.txt"), tname(
"testfile2.txt")
129 ofstream file(fname, ios::out|ios::trunc);
133 throw runtime_error(
"could not open for writing");
140 for (
auto ch : plaintext)
142 plainsv.push_back(ch);
145 virtual ~SecVecCharTest()
153 TEST_F(SecVecCharTest, read_from_file)
159 string ver(sv.begin(), sv.end());
161 cout <<
"<start plaintext>";
163 cout <<
"<end plaintext>" << endl;
165 ASSERT_EQ(plaintext, ver);
166 ASSERT_EQ(plainsv, sv);
169 TEST_F(SecVecCharTest, write_to_file)
171 ofstream file(tname);
183 ASSERT_EQ(s, plaintext);
186 TEST_F(SecVecCharTest, bad_read)
188 ifstream f(
"nothere");
190 ASSERT_THROW(f >> sv, runtime_error);
193 TEST_F(SecVecCharTest, bad_write)
195 fstream file(fname, ios::in);
198 throw runtime_error(
"could not open test file for reading");
201 ASSERT_THROW(file << plainsv, runtime_error);
Common file system utilities.
static void remove(const std::string &, std::system_error *=nullptr)
Remove the file or directory.
Common file system utilities.
TEST(inet_example, client_server_stream_test)
[Inet client server]