Web Wispers 1.2.2 C++ Unit Test Coverage
Current view: top level - tests/wispers/group_session - GroupSessionDatabaseTest.cc (source / functions) Hit Total Coverage
Test: Web Wispers 1.2.2 C++ Unit Tests Lines: 275 275 100.0 %
Date: 2012-04-09 Functions: 75 76 98.7 %
Branches: 1070 2132 50.2 %

           Branch data     Line data    Source code
       1                 :            : /* Copyright 2006-2009 Savarese Software Research Corporation
       2                 :            :  *
       3                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
       4                 :            :  * you may not use this file except in compliance with the License.
       5                 :            :  * You may obtain a copy of the License at
       6                 :            :  *
       7                 :            :  *     https://www.savarese.com/software/ApacheLicense-2.0
       8                 :            :  *
       9                 :            :  * Unless required by applicable law or agreed to in writing, software
      10                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      11                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12                 :            :  * See the License for the specific language governing permissions and
      13                 :            :  * limitations under the License.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include <ssrc/wispers/group_session/GroupSessionDatabase.h>
      17                 :            : #include <ssrc/wispers/group_session/protocol.h>
      18                 :            : #include <ssrc/wispers/lua/Properties.h>
      19                 :            : #include <ssrc/wispers/database/InitializeLibrary.h>
      20                 :            : 
      21                 :            : #include <boost/scoped_ptr.hpp>
      22                 :            : 
      23                 :            : #define BOOST_TEST_MODULE GroupSessionDatabaseTest
      24                 :            : #include <boost/test/unit_test.hpp>
      25                 :            : 
      26                 :            : using namespace NS_SSRC_WSPR_GROUP_SESSION;
      27                 :            : using namespace NS_SSRC_WSPR;
      28                 :            : using NS_SSRC_WSPR_LUA::load_properties;
      29                 :            : 
      30                 :            : __BEGIN_NS_SSRC_WSPR_GROUP_SESSION
      31                 :         18 : bool operator<(const GroupSession & gs1, const GroupSession & gs2) {
      32                 :         18 :   return (gs1.gsid < gs2.gsid);
      33                 :            : }
      34                 :            : __END_NS_SSRC_WSPR_GROUP_SESSION
      35                 :            : 
      36                 :            : typedef uid_container::iterator uid_iterator;
      37                 :            : 
      38                 :            : typedef bool (GroupSessionDatabase::* add_fun)(const uid_type,
      39                 :            :                                                const gsid_type);
      40                 :            : typedef unsigned int (GroupSessionDatabase::* remove_fun)(const uid_type);
      41                 :            : typedef
      42                 :            : unsigned int (GroupSessionDatabase::* get_fun)(uid_container &,
      43                 :            :                                                const gsid_type) const;
      44                 :            : typedef
      45                 :            : unsigned int (GroupSessionDatabase::* addn_fun)(const uid_iterator &,
      46                 :            :                                                 const uid_iterator &,
      47                 :            :                                                 const gsid_type);
      48                 :            : typedef
      49                 :            : unsigned int (GroupSessionDatabase::* removen_fun)(const uid_iterator &,
      50                 :            :                                                    const uid_iterator &);
      51                 :            : 
      52         [ +  - ]:         16 : class GroupSessionDatabaseTestFixture {
      53                 :            : protected:
      54                 :            :   InitializeLibrary _init_lib;
      55                 :            :   boost::scoped_ptr<GroupSessionDatabase> db;
      56                 :            : 
      57                 :            : public:
      58                 :            : 
      59                 :            :   WISP_IMPORT(GroupSessionDatabase, MemberOperations);
      60                 :            : 
      61                 :         16 :   GroupSessionDatabaseTestFixture() {
      62         [ +  - ]:         16 :     std::system(INITDB_COMMAND);
      63   [ +  -  +  -  :         16 :     db.reset(new GroupSessionDatabase(DB_FILE, *load_properties(PROP_FILE)));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
      64                 :         16 :   }
      65                 :            : 
      66                 :          5 :   void _test_add_get_member_uids(MemberOperations & row_ops, get_fun get) {
      67                 :         10 :     uid_container results;
      68   [ +  -  +  -  :          5 :     BOOST_CHECK(row_ops.insert(MemberOperations::row_type(3, 31)));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      69   [ +  -  +  -  :          5 :     BOOST_CHECK(((*db).*get)(results, 3) == 1);
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  -  
                      + ]
      70                 :            : 
      71   [ +  -  +  -  :          5 :     BOOST_CHECK(results.size() == 1);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      72   [ +  -  +  -  :          5 :     BOOST_CHECK(results[0] == 31);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      73                 :            : 
      74   [ +  -  +  -  :          5 :     BOOST_CHECK(row_ops.insert(MemberOperations::row_type(3, 32)));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      75   [ +  -  +  -  :          5 :     BOOST_CHECK(row_ops.insert(MemberOperations::row_type(3, 33)));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      76                 :            : 
      77         [ +  - ]:          5 :     results.clear();
      78   [ +  -  +  -  :          5 :     BOOST_CHECK(((*db).*get)(results, 3) == 3);
          +  -  +  -  -  
          +  +  -  +  -  
          +  -  +  -  -  
                      + ]
      79                 :            : 
      80   [ +  -  +  -  :          5 :     BOOST_CHECK(results.size() == 3);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      81                 :            : 
      82   [ +  -  +  -  :          5 :     std::sort(results.begin(), results.end());
                   +  - ]
      83                 :            : 
      84   [ +  -  +  -  :          5 :     BOOST_CHECK(results[0] == 31);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      85   [ +  -  +  -  :          5 :     BOOST_CHECK(results[1] == 32);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      86   [ +  -  +  -  :          5 :     BOOST_CHECK(results[2] == 33);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      87                 :          5 :   }
      88                 :            : 
      89                 :          3 :   void _test_add_get_session() {
      90                 :          6 :     GroupSessionDatabase::GroupSessionOperations::find_result_type result;
      91                 :          3 :     sec_type created(TimeValue::now_seconds());
      92                 :          3 :     sec_type expires(created + 3600);
      93                 :            :     GroupSession session(5, created, expires,
      94   [ +  -  +  -  :          6 :                          "footype", "bargroup", "foo vs. bar", 0);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
      95                 :            : 
      96   [ +  -  +  -  :          3 :     BOOST_CHECK(db->group_session_ops.insert(session));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
      97   [ +  -  +  -  :          3 :     result = db->group_session_ops.find(4);
                   +  - ]
      98                 :            : 
      99   [ +  -  +  -  :          3 :     BOOST_CHECK(!result.first);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     100                 :            : 
     101   [ +  -  +  -  :          3 :     result = db->group_session_ops.find(5);
                   +  - ]
     102                 :            : 
     103   [ +  -  +  -  :          3 :     BOOST_CHECK(result.first);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     104   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.gsid == 5);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     105   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.get<0>() == 5);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     106   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.column_name<0>() == "gsid");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
     107   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.column_name(0) == "gsid");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
     108   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.table_name() == "GroupSession");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
     109   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.created > 0);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     110   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.expires == expires);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     111   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.type == "footype");
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     112   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.group == "bargroup");
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     113   [ +  -  +  -  :          3 :     BOOST_CHECK(result.second.name == "foo vs. bar");
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     114                 :          3 :   }
     115                 :            : 
     116                 :          3 :   void _test_add_get_participants() {
     117                 :          3 :     _test_add_get_member_uids(db->participant_ops,
     118                 :          6 :                              &GroupSessionDatabase::get_member_uids<uid_container>);
     119                 :          3 :   }
     120                 :            : 
     121                 :          1 :   void _test_add_get_observers() {
     122                 :          1 :     _test_add_get_member_uids(db->observer_ops,
     123                 :          2 :                               &GroupSessionDatabase::get_member_uids<uid_container>);
     124                 :          1 :   }
     125                 :            : 
     126                 :          3 :   void _test_find_expired_gsids() {
     127                 :          3 :     sec_type now(TimeValue::now_seconds());
     128   [ +  -  +  -  :          6 :     GroupSession session(1, now, now, "footype", "bargroup", "foo vs. bar", 0);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     129         [ +  - ]:          3 :     db->group_session_ops.save(session);
     130                 :          3 :     session.gsid = 2;
     131         [ +  - ]:          3 :     db->group_session_ops.save(session);
     132                 :          3 :     session.gsid = 3;
     133         [ +  - ]:          3 :     db->group_session_ops.save(session);
     134                 :            : 
     135                 :          3 :     now+=3600;
     136                 :          3 :     session.gsid = 4;
     137                 :          3 :     session.created = session.expires = now;
     138         [ +  - ]:          3 :     db->group_session_ops.save(session);
     139                 :            : 
     140   [ +  -  +  - ]:          6 :     gsid_container gsids;
     141                 :            : 
     142   [ +  -  +  -  :          3 :     BOOST_CHECK(3 == db->find_expired_gsids(gsids, now - 1));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     143   [ +  -  +  -  :          3 :     BOOST_CHECK(3 == gsids.size());
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     144                 :            : 
     145   [ +  -  +  -  :          3 :     std::sort(gsids.begin(), gsids.end());
                   +  - ]
     146                 :            : 
     147   [ +  -  +  -  :          3 :     BOOST_CHECK(gsids[0] == 1);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     148   [ +  -  +  -  :          3 :     BOOST_CHECK(gsids[1] == 2);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     149   [ +  -  +  -  :          3 :     BOOST_CHECK(gsids[2] == 3);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     150                 :          3 :   }
     151                 :            : 
     152                 :          2 :   void _test_add_get_reservation() {
     153                 :          4 :     GroupSessionDatabase::ReservationOperations::find_result_type result;
     154                 :          2 :     sec_type created(TimeValue::now_seconds());
     155                 :          2 :     sec_type expires = created + 3600;
     156                 :            : 
     157                 :          2 :     db->reservation_ops.insert(Reservation(5, created, expires,
     158                 :            :                                            "footype", "bargroup",
     159   [ +  -  +  -  :          4 :                                            "foo vs. bar", 9, 28, 808));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
     160   [ +  -  +  -  :          2 :     result = db->reservation_ops.find(4);
                   +  - ]
     161                 :            : 
     162   [ +  -  +  -  :          2 :     BOOST_CHECK(!result.first);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     163                 :            : 
     164   [ +  -  +  -  :          2 :     result = db->reservation_ops.find(5);
                   +  - ]
     165                 :            : 
     166   [ +  -  +  -  :          2 :     BOOST_CHECK(result.first);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     167   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.gsid == 5);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     168   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.created == created);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     169   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.expires == expires);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     170   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.type == "footype");
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     171   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.group == "bargroup");
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     172   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.name == "foo vs. bar");
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     173   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.max_observers == 9);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     174   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.creator_uid == 28);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     175   [ +  -  +  -  :          2 :     BOOST_CHECK(result.second.gs_lifetime == 808);
          +  -  +  -  +  
          -  +  -  +  -  
                   -  + ]
     176                 :          2 :   }
     177                 :            : };
     178                 :            : 
     179                 :          1 : BOOST_FIXTURE_TEST_SUITE(all, GroupSessionDatabaseTestFixture)
     180                 :            : 
     181   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_add_get_session) {
                   +  - ]
     182                 :          1 :   _test_add_get_session();
     183                 :          1 : }
     184                 :            : 
     185   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_add_get_participants) {
                   +  - ]
     186                 :          1 :   _test_add_get_participants();
     187                 :          1 : }
     188                 :            : 
     189   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_add_get_observers) {
                   +  - ]
     190                 :          1 :   _test_add_get_observers();
     191                 :          1 : }
     192                 :            : 
     193   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_get_member_uids) {
                   +  - ]
     194                 :          1 :   _test_add_get_participants();
     195                 :            :   //_test_add_get_observers();
     196                 :            : 
     197                 :          2 :   uid_container results;
     198         [ +  - ]:          1 :   db->get_member_uids(results, 3);
     199                 :            : 
     200   [ +  -  +  -  :          1 :   BOOST_CHECK(results.size() == 3);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     201                 :            : 
     202   [ +  -  +  -  :          1 :   std::sort(results.begin(), results.end());
                   +  - ]
     203                 :            : 
     204   [ +  -  +  -  :          1 :   BOOST_CHECK(results[0] == 31);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     205   [ +  -  +  -  :          1 :   BOOST_CHECK(results[1] == 32);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     206   [ +  -  +  -  :          1 :   BOOST_CHECK(results[2] == 33);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     207                 :            :   /*
     208                 :            :     uid_iterator it = results.begin();
     209                 :            :     ++it;
     210                 :            : 
     211                 :            :     BOOST_CHECK(db->participant_ops.insert(results.begin(), results.end()) == 2);
     212                 :            : 
     213                 :            :     it = results.begin();
     214                 :            :     ++it;
     215                 :            : 
     216                 :            :     BOOST_CHECK(db->observer_ops.insert(Member(results.begin(), it) == 1));
     217                 :            : 
     218                 :            :     results.clear();
     219                 :            :     db->get_member_uids(results, 3);
     220                 :            : 
     221                 :            :     BOOST_CHECK(results.size() == 3);
     222                 :            : 
     223                 :            :     std::sort(results.begin(), results.end());
     224                 :            : 
     225                 :            :     BOOST_CHECK(results[0] == 31);
     226                 :            :     BOOST_CHECK(results[1] == 32);
     227                 :            :     BOOST_CHECK(results[2] == 33);
     228                 :            :   */
     229                 :          1 : }
     230                 :            : 
     231   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_remove_session) {
                   +  - ]
     232                 :          1 :   _test_add_get_session();
     233                 :          1 :   _test_add_get_participants();
     234                 :            : 
     235   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(1u, db->group_session_ops.erase(5));
     236   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(0u, db->group_session_ops.erase(3));
     237   [ +  -  +  -  :          1 :   BOOST_CHECK(!db->group_session_ops.find(5).first);
          +  -  +  -  +  
                -  -  + ]
     238   [ +  -  +  -  :          1 :   BOOST_CHECK(!db->group_session_ops.find(3).first);
          +  -  +  -  +  
                -  -  + ]
     239                 :            : 
     240                 :          1 :   Member observers[3] = { Member(8, 81), Member(8, 82), Member(8, 83)};
     241                 :          1 :   Member participants[3] = { Member(8, 181), Member(8, 182), Member(8, 183)};
     242                 :            : 
     243                 :          1 :   sec_type created(TimeValue::now_seconds());
     244                 :          1 :   sec_type expires(created + 3600);
     245                 :            : 
     246                 :          1 :   db->group_session_ops.save(GroupSession(8, created, expires,
     247                 :            :                                           "footype", "bargroup",
     248   [ +  -  +  -  :          2 :                                           "foo vs. bar", 0));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
     249                 :          1 :   db->participant_ops.insert(&participants[0], &participants[3]);
     250                 :          1 :   db->observer_ops.insert(&observers[0], &observers[3]);
     251                 :            : 
     252                 :          2 :   uid_container results;
     253                 :            : 
     254         [ +  - ]:          1 :   results.clear();
     255   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(6u, db->get_member_uids(results, 8));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     256   [ +  -  +  -  :          1 :   BOOST_CHECK(6u == results.size());
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     257         [ +  - ]:          1 :   results.clear();
     258   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(1u, db->group_session_ops.erase(8));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     259   [ +  -  +  -  :          1 :   BOOST_CHECK(!db->group_session_ops.find(8).first);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
     260   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(0u, db->get_member_uids(results, 8));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     261   [ +  -  +  -  :          1 :   BOOST_CHECK(0u == results.size());
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     262                 :          1 : }
     263                 :            : 
     264   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_get_participant_sessions) {
                   +  - ]
     265                 :          1 :   sec_type created(TimeValue::now_seconds());
     266                 :          1 :   sec_type expires(created + 3600);
     267                 :            :   GroupSession session(0, created, expires,
     268   [ +  -  +  -  :          2 :                        "footype", "bargroup", "foo vs. bar", 0);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     269                 :            : 
     270         [ +  + ]:          5 :   for(unsigned int gsid = 22; gsid < 26; ++gsid) {
     271                 :          4 :     session.gsid = gsid;
     272         [ +  - ]:          4 :     db->group_session_ops.save(session);
     273                 :            :   }
     274                 :            : 
     275         [ +  - ]:          1 :   db->participant_ops.insert(Member(22, 84));
     276         [ +  - ]:          1 :   db->participant_ops.insert(Member(23, 84));
     277         [ +  - ]:          1 :   db->participant_ops.insert(Member(24, 84));
     278         [ +  - ]:          1 :   db->participant_ops.insert(Member(25, 84));
     279                 :            : 
     280   [ +  -  +  - ]:          2 :   group_session_container sessions;
     281                 :            : 
     282   [ +  -  +  -  :          1 :   BOOST_CHECK(0 == db->get_participant_sessions(sessions, 80));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     283   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions.size() == 0);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     284   [ +  -  +  -  :          1 :   BOOST_CHECK(4 == db->get_participant_sessions(sessions, 84));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     285   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions.size() == 4);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     286                 :            : 
     287   [ +  -  +  -  :          1 :   std::sort(sessions.begin(), sessions.end());
                   +  - ]
     288                 :            : 
     289   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].gsid == 22);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     290   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[1].gsid == 23);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     291   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[2].gsid == 24);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     292   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[3].gsid == 25);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     293                 :          1 : }
     294                 :            : 
     295   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_find_expired_gsids) {
                   +  - ]
     296                 :          1 :   _test_find_expired_gsids();
     297                 :          1 : }
     298                 :            : 
     299   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_get_sessions_by_type) {
                   +  - ]
     300                 :          1 :   sec_type now(TimeValue::now_seconds());
     301   [ +  -  +  -  :          2 :   GroupSession session(1, now, now, "footype", "bargroup", "foo vs. bar", 0);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     302                 :            : 
     303         [ +  + ]:          4 :   for(unsigned int gsid = 1; gsid < 4; ++gsid) {
     304                 :          3 :     session.gsid = gsid;
     305         [ +  - ]:          3 :     db->group_session_ops.save(session);
     306                 :            :   }
     307                 :            : 
     308         [ +  - ]:          1 :   session.type = "bartype";
     309                 :            : 
     310         [ +  + ]:          6 :   for(unsigned int gsid = 5; gsid < 10; ++gsid) {
     311                 :          5 :     session.gsid = gsid;
     312         [ +  - ]:          5 :     db->group_session_ops.save(session);
     313                 :            :   }
     314                 :            : 
     315   [ +  -  +  - ]:          2 :   group_session_container sessions;
     316                 :            : 
     317   [ +  -  +  -  :          1 :   BOOST_CHECK(3 == db->get_sessions_by_type(sessions, "footype"));
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
     318                 :            : 
     319   [ +  -  +  -  :          1 :   std::sort(sessions.begin(), sessions.end());
                   +  - ]
     320                 :            : 
     321   [ +  -  +  + ]:          4 :   for(unsigned int i = 0; i < sessions.size(); ++i) {
     322   [ +  -  +  -  :          3 :     BOOST_CHECK(sessions[i].gsid == (i + 1));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     323                 :            :   }
     324                 :            : 
     325         [ +  - ]:          1 :   sessions.clear();
     326   [ +  -  +  -  :          1 :   BOOST_CHECK(5 == db->get_sessions_by_type(sessions, "bartype"));
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  -  + ]
     327                 :            : 
     328   [ +  -  +  -  :          1 :   std::sort(sessions.begin(), sessions.end());
                   +  - ]
     329                 :            : 
     330   [ +  -  +  + ]:          6 :   for(unsigned int i = 0; i < sessions.size(); ++i) {
     331   [ +  -  +  -  :          5 :     BOOST_CHECK(sessions[i].gsid == (i + 5));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     332                 :            :   }
     333                 :          1 : }
     334                 :            : 
     335   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_remove_expired_sessions) {
                   +  - ]
     336                 :          1 :   _test_find_expired_gsids();
     337                 :            : 
     338                 :          1 :   sec_type now(TimeValue::now_seconds() + 3600);
     339                 :            : 
     340   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(4u, db->remove_expired_sessions(now));
     341                 :            : 
     342                 :          2 :   gsid_container gsids;
     343                 :            : 
     344   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(0u, db->find_expired_gsids(gsids, now));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     345                 :            : 
     346         [ +  - ]:          1 :   _test_find_expired_gsids();
     347                 :            : 
     348         [ +  - ]:          1 :   db->participant_ops.insert(Member(1,17));
     349         [ +  - ]:          1 :   db->participant_ops.insert(Member(2, 17));
     350         [ +  - ]:          1 :   db->participant_ops.insert(Member(4, 13));
     351         [ +  - ]:          1 :   db->observer_ops.insert(Member(1, 13));
     352         [ +  - ]:          1 :   db->observer_ops.insert(Member(2, 13));
     353         [ +  - ]:          1 :   db->observer_ops.insert(Member(4, 17));
     354                 :            : 
     355                 :          1 :   now = TimeValue::now_seconds();
     356                 :            : 
     357   [ +  -  +  - ]:          2 :   group_session_container sessions;
     358                 :            : 
     359   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(2u, db->get_participant_sessions(sessions, 17));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     360   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(1u, db->get_observer_sessions(sessions, 17));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     361   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(1u, db->get_participant_sessions(sessions, 13));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     362   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(2u, db->get_observer_sessions(sessions, 13));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     363   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(3u, db->remove_expired_sessions(now));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     364   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(0u, db->get_participant_sessions(sessions, 17));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     365   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(1u, db->get_observer_sessions(sessions, 17));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     366   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(1u, db->get_participant_sessions(sessions, 13));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     367   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(0u, db->get_observer_sessions(sessions, 13));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     368                 :            : 
     369   [ +  -  +  -  :          1 :   BOOST_CHECK(!db->group_session_ops.find(1).first);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
     370   [ +  -  +  -  :          1 :   BOOST_CHECK(!db->group_session_ops.find(2).first);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
     371   [ +  -  +  -  :          1 :   BOOST_CHECK(!db->group_session_ops.find(3).first);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
     372   [ +  -  +  -  :          1 :   BOOST_CHECK(db->group_session_ops.find(4).first);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
     373                 :          1 : }
     374                 :            : 
     375   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_add_get_reservation) {
                   +  - ]
     376                 :          1 :   _test_add_get_reservation();
     377                 :          1 : }
     378                 :            : 
     379   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_add_get_reservation_participants) {
                   +  - ]
     380                 :          1 :   _test_add_get_member_uids(db->reservation_participant_ops,
     381                 :          2 :                             &GroupSessionDatabase::get_reservation_participants<uid_container>);
     382                 :            : 
     383                 :          1 : }
     384                 :            : 
     385   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_find_sessions) {
                   +  - ]
     386                 :          1 :   sec_type created(TimeValue::now_seconds());
     387                 :          1 :   sec_type expires(created + 3600);
     388                 :            :   GroupSession session(5, created, expires,
     389   [ +  -  +  -  :          2 :                        "footype", "bargroup", "foo vs. bar", 2);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     390                 :            : 
     391   [ +  -  +  -  :          1 :   BOOST_CHECK(db->group_session_ops.insert(session));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     392                 :            : 
     393   [ +  -  +  - ]:          2 :   group_session_container sessions;
     394                 :            : 
     395         [ +  - ]:          1 :   db->find_sessions(sessions);
     396                 :            : 
     397   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions.size() == 1);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     398                 :            : 
     399   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].gsid == 5);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     400   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].get<0>() == 5);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     401   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].column_name<0>() == "gsid");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     402   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].column_name(0) == "gsid");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     403   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].table_name() == "GroupSession");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     404   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].created > 0);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     405   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].expires == expires);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     406   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].type == "footype");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
     407   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].group == "bargroup");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
     408   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].name == "foo vs. bar");
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
                      + ]
     409   [ +  -  +  -  :          1 :   BOOST_CHECK(sessions[0].max_observers == 2);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     410                 :          1 : }
     411                 :            : 
     412   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_is_member) {
                   +  - ]
     413                 :          1 :   const uid_type uid = 31;
     414                 :          1 :   const gsid_type gsid = 3;
     415                 :            : 
     416   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(false, db->is_member(uid, gsid));
     417   [ +  -  +  -  :          1 :   BOOST_CHECK(db->observer_ops.insert(Member(gsid, uid)));
          +  -  +  -  -  
                      + ]
     418   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(true, db->is_member(uid, gsid));
     419                 :          1 : }
     420                 :            : 
     421   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_find_members_for_uid) {
                   +  - ]
     422                 :          1 :   sec_type created(TimeValue::now_seconds());
     423                 :          1 :   sec_type expires(created + 3600);
     424                 :            : 
     425                 :          1 :   db->group_session_ops.save(GroupSession(8, created, expires,
     426                 :            :                                           "footype", "bargroup",
     427   [ +  -  +  -  :          2 :                                           "foo vs. bar", 0));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
     428                 :          1 :   db->group_session_ops.save(GroupSession(9, created, expires,
     429                 :            :                                           "footype", "bargroup",
     430   [ +  -  +  -  :          2 :                                           "foo vs. bar", 0));
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
     431                 :            : 
     432                 :          1 :   db->participant_ops.insert(Member(8, 22));
     433                 :          1 :   db->participant_ops.insert(Member(8, 24));
     434                 :          1 :   db->observer_ops.insert(Member(8, 23));
     435                 :          1 :   db->observer_ops.insert(Member(9, 22));
     436                 :          1 :   db->observer_ops.insert(Member(9, 23));
     437                 :            : 
     438                 :          2 :   uid_container results;
     439                 :            : 
     440   [ +  -  +  -  :          1 :   BOOST_CHECK_EQUAL(2u, db->find_members_for_uid(results, 22));
          +  -  +  -  +  
             -  +  -  -  
                      + ]
     441   [ +  -  +  -  :          1 :   BOOST_CHECK(2u == results.size());
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     442   [ +  -  +  -  :          1 :   BOOST_CHECK(results[0] == 23);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     443   [ +  -  +  -  :          1 :   BOOST_CHECK(results[1] == 24);
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  -  + ]
     444                 :          1 : }
     445                 :            : 
     446   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(test_count_sessions) {
                   +  - ]
     447   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(0u, db->count_sessions());
     448                 :          1 :   _test_add_get_session();
     449   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(1u, db->count_sessions());
     450                 :          1 : }
     451                 :            : 
     452   [ +  -  +  -  :          5 : BOOST_AUTO_TEST_CASE(Test_count_reservations) {
                   +  - ]
     453   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(0u, db->count_reservations());
     454                 :          1 :   _test_add_get_reservation();
     455   [ +  -  -  + ]:          1 :   BOOST_CHECK_EQUAL(1u, db->count_reservations());
     456                 :          1 : }
     457                 :            : 
     458   [ +  -  +  -  :          4 : BOOST_AUTO_TEST_SUITE_END()
             -  +  #  # ]