1 /*
2 
3 Copyright (c) 2002-2008, Yauheni Akhotnikau
4 Copyright (c) 2008-2013, The SObjectizer Project
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 - Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12 
13 - Redistributions in binary form must reproduce the above copyright notice, this
14 list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 - The name of the author may not be used to endorse or promote products derived
18 from this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
23 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
25 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
29 OF SUCH DAMAGE.
30 
31 */
32 
33 #include <iostream>
34 
35 #include <oess_2/io/h/bstring_buf.hpp>
36 #include <oess_2/stdsn/h/inout_templ.hpp>
37 #include <oess_2/stdsn/h/ent_no_markers.hpp>
38 
39 
40 #include <utest_helper_1/h/helper.hpp>
41 
42 #include <test/h/binary_str_proxy.hpp>
43 
44 
45 //
46 // type_t
47 //
48 class type_t :
49 	public oess_2::stdsn::serializable_t
50 {
51 		OESS_SERIALIZER( type_t )
52 	public:
53 
type_t()54 		type_t() {}
55 
type_t(bool flag)56 		type_t( bool flag ): m_flag(flag) {}
57 
58 		bool m_flag;
59 };
60 
61 #include "main.ddl.cpp"
62 
63 template< class C >
64 void
pack_to(const C & what,std::string & to)65 pack_to( const C & what, std::string & to )
66 {
67 	oess_2::io::obstring_t s( to );
68 	oess_2::stdsn::oent_std_t ent( s );
69 	ent << what;
70 }
71 
72 template< class C >
73 void
unpack_from(C & what,const std::string & from)74 unpack_from( C & what, const std::string & from )
75 {
76 	oess_2::io::ibstring_t s( from );
77 	oess_2::stdsn::ient_std_t ent( s );
78 	ent >> what;
79 }
80 
81 template< class C >
82 void
do_tests(const C & value)83 do_tests( const C & value )
84 {
85 	C first( value );
86 
87 	std::string first_image;
88 	pack_to( first, first_image );
89 
90 	C second;
91 	unpack_from( second, first_image );
92 
93 	UT_CHECK_EQ( first.m_flag, second.m_flag );
94 
95 	std::string second_image;
96 	pack_to( second, second_image );
97 
98 	UT_CHECK_EQ( binary_str_proxy(first_image), binary_str_proxy(second_image) );
99 }
100 
UT_UNIT_TEST(true_test)101 UT_UNIT_TEST( true_test )
102 {
103 	do_tests< type_t >( true );
104 }
105 
UT_UNIT_TEST(false_test)106 UT_UNIT_TEST( false_test )
107 {
108 	do_tests< type_t >( false );
109 }
110 
111 int
main()112 main()
113 {
114 	UT_RUN_UNIT_TEST( true_test );
115 	UT_RUN_UNIT_TEST( false_test );
116 }
117