forked from artyom-beilis/cppcms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy_filter_test.cpp
More file actions
74 lines (70 loc) · 1.61 KB
/
copy_filter_test.cpp
File metadata and controls
74 lines (70 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#include "test.h"
#include <iostream>
#include <cppcms/copy_filter.h>
int main()
{
try {
std::cout << "- Normal flow" << std::endl;
std::ostringstream ss;
ss << "a";
{
cppcms::copy_filter flt(ss);
ss << "bc";
TEST(flt.detach()=="bc");
ss << "d";
}
ss << "e";
TEST(ss.str()=="abcde");
std::cout << "- With Flush" << std::endl;
ss.clear();
ss.str("");
ss << "a";
{
cppcms::copy_filter flt(ss);
ss << "b";
ss << std::flush;
ss << "c";
TEST(flt.detach()=="bc");
}
ss << "d";
TEST(ss.str()=="abcd");
std::cout << "- With throw and flush" << std::endl;
ss.clear();
ss.str("");
ss << "a";
try {
cppcms::copy_filter flt(ss);
ss << "b";
ss << std::flush;
throw int(1);
}
catch(int x){}
ss << "c";
TEST(ss.str()=="abc");
std::cout << "- With throw and no flush" << std::endl;
ss.clear();
ss.str("");
ss << "a";
try {
cppcms::copy_filter flt(ss);
ss << "b";
throw int(1);
}
catch(int x){}
ss << "c";
TEST(ss.str()=="ac");
}
catch(std::exception const &e) {
std::cerr << "Fail:" << e.what() << std::endl;
return 1;
}
std::cout << "Ok" << std::endl;
return 0;
}