blob: a4fe0d68800bc3d0e91216021a458118616d9719 [file] [log] [blame]
Alexander Afanasyevee7e6132013-01-03 20:03:14 -08001/* -*- 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 */
21
22#include <boost/test/unit_test.hpp>
23#include <boost/lexical_cast.hpp>
24
25#include <unistd.h>
26#include "action-log.h"
27#include <iostream>
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080028#include <ccnx-name.h>
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080029
30using namespace std;
31using namespace boost;
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080032using namespace Ccnx;
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080033
34BOOST_AUTO_TEST_SUITE(DatabaseTest)
35
36
37BOOST_AUTO_TEST_CASE (BasicDatabaseTest)
38{
39 char dir_tmpl [] = "/tmp/tmp-chornoshare-XXXXXXXXXXX";
40 string tmp_dir = mkdtemp (dir_tmpl);
41 SyncLog db (tmp_dir, "/alex");
42
43 HashPtr hash = db.RememberStateInStateLog ();
44 // should be empty
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080045 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "7a6f2c1eefd539560d2dc3e5542868a79810d0867db15d9b87e41ec105899405");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080046
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080047 db.UpdateDeviceSeqno (Name ("Alex"), 1);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080048 hash = db.RememberStateInStateLog ();
49
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080050 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "bf19308cb2c2ddab7bcce66e9074cd0eed74893be0813ca67a95e97c55d65896");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080051
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080052 db.UpdateDeviceSeqno (Name ("Alex"), 2);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080053 hash = db.RememberStateInStateLog ();
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080054 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080055
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080056 db.UpdateDeviceSeqno (Name ("Alex"), 2);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080057 hash = db.RememberStateInStateLog ();
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080058 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080059
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080060 db.UpdateDeviceSeqno (Name ("Alex"), 1);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080061 hash = db.RememberStateInStateLog ();
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080062 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080063
64
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080065 // db.FindStateDifferences ("00", "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
66 // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0", "00");
67 // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
68 // "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
69 // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0",
70 // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080071
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080072 // db.UpdateDeviceSeqno (Name ("Bob"), 1);
73 // hash = db.RememberStateInStateLog ();
74 // BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080075
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080076 // db.FindStateDifferences ("00", "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
77 // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0",
78 // "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080079
80}
81
82BOOST_AUTO_TEST_SUITE_END()