Alexander Afanasyev | a562532 | 2012-03-06 00:03:41 -0800 | [diff] [blame^] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn> |
| 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #include <boost/test/unit_test.hpp> |
| 24 | #include <boost/test/output_test_stream.hpp> |
| 25 | using boost::test_tools::output_test_stream; |
| 26 | |
| 27 | #include <boost/make_shared.hpp> |
| 28 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 29 | |
| 30 | #include "../model/sync-std-name-info.h" |
| 31 | #include "../model/sync-full-state.h" |
| 32 | #include "../model/sync-diff-state.h" |
| 33 | |
| 34 | using namespace Sync; |
| 35 | using namespace std; |
| 36 | using namespace boost; |
| 37 | |
| 38 | BOOST_AUTO_TEST_SUITE(StateTestSuite) |
| 39 | |
| 40 | BOOST_AUTO_TEST_CASE (FullStateTest) |
| 41 | { |
| 42 | BOOST_CHECK_NO_THROW (FullState ()); |
| 43 | FullState state; |
| 44 | BOOST_CHECK_EQUAL (state.getLeaves ().size (), 0); |
| 45 | |
| 46 | output_test_stream output; |
| 47 | output << state.getTimeFromLastUpdate (); |
| 48 | BOOST_CHECK (output.is_equal ("not-a-date-time", true)); |
| 49 | |
| 50 | NameInfoConstPtr name = StdNameInfo::FindOrCreate ("/test/name"); |
| 51 | BOOST_CHECK_NO_THROW (state.update (name, SeqNo (12))); |
| 52 | BOOST_CHECK_NO_THROW (state.update (name, SeqNo (12))); |
| 53 | BOOST_CHECK_NO_THROW (state.update (name, SeqNo (12))); |
| 54 | BOOST_CHECK_EQUAL (state.getLeaves ().size (), 1); |
| 55 | BOOST_CHECK_EQUAL ((*state.getLeaves ().begin ())->getSeq ().getSeq (), 12); |
| 56 | |
| 57 | BOOST_CHECK_NO_THROW (state.update (name, SeqNo (13))); |
| 58 | BOOST_CHECK_EQUAL ((*state.getLeaves ().begin ())->getSeq ().getSeq (), 13); |
| 59 | |
| 60 | BOOST_CHECK_NO_THROW (state.remove (name)); |
| 61 | BOOST_CHECK_EQUAL (state.getLeaves ().size (), 0); |
| 62 | |
| 63 | BOOST_CHECK_EQUAL (state.getTimeFromLastUpdate ().total_milliseconds (), 0); |
| 64 | } |
| 65 | |
| 66 | BOOST_AUTO_TEST_CASE (DiffStateTest) |
| 67 | { |
| 68 | BOOST_CHECK_NO_THROW (DiffState ()); |
| 69 | DiffState state; |
| 70 | BOOST_CHECK_EQUAL (state.getLeaves ().size (), 0); |
| 71 | |
| 72 | NameInfoConstPtr name = StdNameInfo::FindOrCreate ("/test/name"); |
| 73 | BOOST_CHECK_NO_THROW (state.update (name, SeqNo (12))); |
| 74 | BOOST_CHECK_NO_THROW (state.update (name, SeqNo (12))); |
| 75 | BOOST_CHECK_NO_THROW (state.update (name, SeqNo (12))); |
| 76 | BOOST_CHECK_EQUAL (state.getLeaves ().size (), 1); |
| 77 | BOOST_CHECK_EQUAL ((*state.getLeaves ().begin ())->getSeq ().getSeq (), 12); |
| 78 | |
| 79 | BOOST_CHECK_NO_THROW (state.update (name, SeqNo (13))); |
| 80 | BOOST_CHECK_EQUAL ((*state.getLeaves ().begin ())->getSeq ().getSeq (), 13); |
| 81 | |
| 82 | BOOST_CHECK_NO_THROW (state.remove (name)); |
| 83 | BOOST_CHECK_EQUAL (state.getLeaves ().size (), 1); |
| 84 | BOOST_CHECK_EQUAL ((*state.getLeaves ().begin ())->getSeq ().getSeq (), 0); |
| 85 | } |
| 86 | |
| 87 | BOOST_AUTO_TEST_SUITE_END() |