• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //  Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 //  Distributed under the Boost Software License, Version 1.0. (See
5 //  accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 //
8 
9 #include "test_locale.hpp"
10 #include "../src/shared/ios_prop.hpp"
11 #include <sstream>
12 #include <locale>
13 
14 int counter=0;
15 int imbued=0;
16 struct propery {
properypropery17     propery(int xx=-1) : x(xx) { counter ++; }
properypropery18     propery(propery const &other) { counter++; x=other.x; }
operator =propery19     propery const &operator=(propery const &other) {
20         x=other.x;
21         return *this;
22     };
23     int x;
on_imbuepropery24     void on_imbue() {imbued++; }
~properypropery25     ~propery() { counter--; }
26 };
27 typedef boost::locale::impl::ios_prop<propery> prop_type;
28 
29 struct init {
initinit30     init() { prop_type::global_init(); }
31 };
32 
main()33 int main()
34 {
35     try {
36         {
37             std::stringstream ss;
38             TEST(!prop_type::has(ss));
39             TEST(prop_type::get(ss).x==-1);
40             TEST(prop_type::has(ss));
41             TEST(counter==1);
42         }
43         TEST(counter==0);
44         {
45             std::stringstream ss;
46             prop_type::set(propery(1),ss);
47             TEST(counter==1);
48             TEST(prop_type::get(ss).x==1);
49         }
50         TEST(counter==0);
51         {
52             std::stringstream ss;
53             prop_type::set(propery(1),ss);
54             TEST(counter==1);
55             TEST(prop_type::get(ss).x==1);
56         }
57         TEST(counter==0);
58         {
59             std::stringstream ss,ss2;
60             prop_type::set(propery(2),ss);
61             ss2.copyfmt(ss);
62             TEST(prop_type::get(ss).x==2);
63             TEST(prop_type::has(ss2));
64             TEST(prop_type::has(ss));
65             TEST(prop_type::get(ss2).x==2);
66             prop_type::get(ss2).x=3;
67             TEST(prop_type::get(ss2).x==3);
68             TEST(prop_type::get(ss).x==2);
69             TEST(counter==2);
70             TEST(imbued==0);
71             ss2.imbue(std::locale::classic());
72             TEST(imbued==1);
73         }
74         TEST(counter==0);
75     }catch(std::exception const &e) {
76         std::cerr << "Fail:" << e.what() << std::endl;
77         return EXIT_FAILURE;
78     }
79     FINALIZE();
80     return 0;
81 }
82 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
83 
84 // boostinspect:noascii
85