本文整理汇总了C++中Stream::CanWrite方法的典型用法代码示例。如果您正苦于以下问题:C++ Stream::CanWrite方法的具体用法?C++ Stream::CanWrite怎么用?C++ Stream::CanWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream::CanWrite方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Write_Validation_Tests
void Write_Validation_Tests(Stream & S)
{
char s_buf[4000];
char r_buf[4000];
for (int i = 0; i < 4000; i++)
{
s_buf[i] = 'a';
}
s_buf[3999] = '\0';
//cout << s_buf << endl;
if (S.CanWrite())
{
cout << "Can write" << endl;
}
else
{
cout << "Can't write Unit test passed" << endl;
return;
}
S.Write(s_buf, 4000);
S.Read(r_buf, 4000);
if (memcmp(r_buf, s_buf, 4000) == 0)
{
cout << "T1). PASS: Write all in one write works" << endl;
}
else
{
cout << "T1). FAILED: Write all in one write does not match" << endl;
}
char k_buf[1024];
char o_buf[1801];
for (int i = 0; i < 4000; i++)
{
s_buf[i] = 'b';
}
s_buf[3999] = '\0';
S.SetPosition(S.GetLength());
int k = 4000;
for (int i = 0; i <= 3; i++)
{
int l;
if ((k - 1024) >= 0)
{
l = 1024;
k = k - 1024;
}
else
{
l = k;
}
for (int j = 0; j < l; j++)
{
k_buf[j] = s_buf[i * 1024 + j];
}
S.Write(k_buf, l);
S.SetPosition(S.GetLength());
}
S.SetPosition(4000);
k = 4000;
for (int i = 0; i <= 3; i++)
{
if (k - 1024 >= 0)
{
S.Read(k_buf, 1024);
k = k - 1024;
memcpy(&r_buf[i * 1024], k_buf, 1024);
}
else
{
S.Read(k_buf, k);
memcpy(&r_buf[i * 1024], k_buf, k);
}
S.SetPosition(4000 + (i*1024));
}
r_buf[3999] = '\0';
if (memcmp(r_buf, s_buf, 4000) == 0)
{
cout << "T2). PASS: Write by block works" << endl;
}
else
{
cout << "T2). FAILED: Write all in one write does not match" << endl;
}
for (int i = 0; i < 4000; i++)
{
s_buf[i] = 'c';
}
s_buf[3999] = '\0';
//.........这里部分代码省略.........