42 {
43 boost::filesystem::path temp = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
44 try {
45 std::cerr << temp << " \n";
46
49 BOOST_CHECK_THROW( db2.add_index<
book_index >(), std::runtime_error );
50
52 BOOST_CHECK_THROW( db.add_index<
book_index>(), std::logic_error );
53
54
56
57
58 BOOST_TEST_MESSAGE( "Creating book" );
59 const auto& new_book = db.create<
book>( [](
book& b ) {
60 b.a = 3;
61 b.b = 4;
62 } );
64 BOOST_REQUIRE( &new_book != ©_new_book );
65
66 BOOST_REQUIRE_EQUAL( new_book.a, copy_new_book.
a );
67 BOOST_REQUIRE_EQUAL( new_book.b, copy_new_book.
b );
68
69 db.modify( new_book, [&](
book& b ) {
72 });
73 BOOST_REQUIRE_EQUAL( new_book.a, 5 );
74 BOOST_REQUIRE_EQUAL( new_book.b, 6 );
75
76 BOOST_REQUIRE_EQUAL( new_book.a, copy_new_book.
a );
77 BOOST_REQUIRE_EQUAL( new_book.b, copy_new_book.
b );
78
79 {
80 auto session = db.start_undo_session(
true);
81 db.modify( new_book, [&](
book& b ) {
84 });
85
86 BOOST_REQUIRE_EQUAL( new_book.a, 7 );
87 BOOST_REQUIRE_EQUAL( new_book.b, 8 );
88 }
89 BOOST_REQUIRE_EQUAL( new_book.a, 5 );
90 BOOST_REQUIRE_EQUAL( new_book.b, 6 );
91
92 {
93 auto session = db.start_undo_session(
true);
94 const auto& book2 = db.create<
book>( [&](
book& b ) {
97 });
98
99 BOOST_REQUIRE_EQUAL( new_book.a, 5 );
100 BOOST_REQUIRE_EQUAL( new_book.b, 6 );
101 BOOST_REQUIRE_EQUAL( book2.a, 9 );
102 BOOST_REQUIRE_EQUAL( book2.b, 10 );
103 }
104 BOOST_CHECK_THROW( db2.get(
book::id_type(1) ), std::out_of_range );
105 BOOST_REQUIRE_EQUAL( new_book.a, 5 );
106 BOOST_REQUIRE_EQUAL( new_book.b, 6 );
107
108
109 {
110 auto session = db.start_undo_session(
true);
111 db.modify( new_book, [&](
book& b ) {
114 });
115
116 BOOST_REQUIRE_EQUAL( new_book.a, 7 );
117 BOOST_REQUIRE_EQUAL( new_book.b, 8 );
119 }
120 BOOST_REQUIRE_EQUAL( new_book.a, 7 );
121 BOOST_REQUIRE_EQUAL( new_book.b, 8 );
122 db.undo();
123 BOOST_REQUIRE_EQUAL( new_book.a, 5 );
124 BOOST_REQUIRE_EQUAL( new_book.b, 6 );
125
126 BOOST_REQUIRE_EQUAL( new_book.a, copy_new_book.
a );
127 BOOST_REQUIRE_EQUAL( new_book.b, copy_new_book.
b );
128 } catch ( ... ) {
129 bfs::remove_all( temp );
130 throw;
131 }
132 bfs::remove_all( temp );
133}
CK_SESSION_HANDLE session
multi_index_container< book, indexed_by< ordered_unique< member< book, book::id_type,&book::id > >, ordered_unique< BOOST_MULTI_INDEX_MEMBER(book, int, a) >, ordered_unique< BOOST_MULTI_INDEX_MEMBER(book, int, b) > >, chainbase::node_allocator< book > > book_index