1 /*
2 Copyright (c) 2014, Randolph Voorhies, Shane Grant
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of cereal nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 #ifndef CEREAL_TEST_CHRONO_H_
28 #define CEREAL_TEST_CHRONO_H_
29
30 #include "common.hpp"
31
32 template <class IArchive, class OArchive> inline
test_chrono()33 void test_chrono()
34 {
35 for(int ii=0; ii<100; ++ii)
36 {
37 auto o_timePoint1 = std::chrono::system_clock::now();
38 #ifndef CEREAL_OLDER_GCC
39 auto o_timePoint2 = std::chrono::steady_clock::now();
40 #endif // CEREAL_OLDER_GCC
41 auto o_timePoint3 = std::chrono::high_resolution_clock::now();
42
43 auto o_duration1 = std::chrono::system_clock::now() - o_timePoint1;
44 #ifndef CEREAL_OLDER_GCC
45 auto o_duration2 = std::chrono::steady_clock::now() - o_timePoint2;
46 #endif // CEREAL_OLDER_GCC
47 auto o_duration3 = std::chrono::high_resolution_clock::now() - o_timePoint3;
48
49 std::ostringstream os;
50 {
51 OArchive oar(os);
52
53 oar(o_timePoint1);
54 #ifndef CEREAL_OLDER_GCC
55 oar(o_timePoint2);
56 #endif // CEREAL_OLDER_GCC
57 oar(o_timePoint3);
58 oar(o_duration1);
59 #ifndef CEREAL_OLDER_GCC
60 oar(o_duration2);
61 #endif // CEREAL_OLDER_GCC
62 oar(o_duration3);
63 }
64
65 decltype(o_timePoint1) i_timePoint1;
66 #ifndef CEREAL_OLDER_GCC
67 decltype(o_timePoint2) i_timePoint2;
68 #endif // CEREAL_OLDER_GCC
69 decltype(o_timePoint3) i_timePoint3;
70 decltype(o_duration1) i_duration1;
71 #ifndef CEREAL_OLDER_GCC
72 decltype(o_duration2) i_duration2;
73 #endif // CEREAL_OLDER_GCC
74 decltype(o_duration3) i_duration3;
75
76 std::istringstream is(os.str());
77 {
78 IArchive iar(is);
79
80 iar(i_timePoint1);
81 #ifndef CEREAL_OLDER_GCC
82 iar(i_timePoint2);
83 #endif // CEREAL_OLDER_GCC
84 iar(i_timePoint3);
85 iar(i_duration1);
86 #ifndef CEREAL_OLDER_GCC
87 iar(i_duration2);
88 #endif // CEREAL_OLDER_GCC
89 iar(i_duration3);
90 }
91
92 CHECK_EQ( o_timePoint1, i_timePoint1 );
93 #ifndef CEREAL_OLDER_GCC
94 CHECK_EQ( o_timePoint2, i_timePoint2 );
95 #endif // CEREAL_OLDER_GCC
96 CHECK_EQ( o_timePoint3, i_timePoint3 );
97 CHECK_EQ( o_duration1, i_duration1 );
98 #ifndef CEREAL_OLDER_GCC
99 CHECK_EQ( o_duration2, i_duration2 );
100 #endif // CEREAL_OLDER_GCC
101 CHECK_EQ( o_duration3, i_duration3 );
102 }
103 }
104
105 #endif // CEREAL_TEST_CHRONO_H_
106