blob: 016d7849f997f638ec3314a160f77eca76cc677e [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 Afanasyev68f2a952013-01-08 14:34:16 -080029#include <boost/filesystem.hpp>
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080030
31using namespace std;
32using namespace boost;
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080033using namespace Ccnx;
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080034namespace fs = boost::filesystem;
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080035
36BOOST_AUTO_TEST_SUITE(DatabaseTest)
37
38
39BOOST_AUTO_TEST_CASE (BasicDatabaseTest)
40{
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080041 fs::path tmpdir = fs::unique_path (fs::temp_directory_path () / "%%%%-%%%%-%%%%-%%%%");
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080042 SyncLog db (tmpdir, "/alex");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080043
44 HashPtr hash = db.RememberStateInStateLog ();
45 // should be empty
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080046 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "7a6f2c1eefd539560d2dc3e5542868a79810d0867db15d9b87e41ec105899405");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080047
Zhenkai Zhue851b952013-01-13 22:29:57 -080048 db.UpdateDeviceSeqNo (Name ("Alex"), 1);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080049 hash = db.RememberStateInStateLog ();
50
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080051 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "bf19308cb2c2ddab7bcce66e9074cd0eed74893be0813ca67a95e97c55d65896");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080052
Zhenkai Zhue851b952013-01-13 22:29:57 -080053 db.UpdateDeviceSeqNo (Name ("Alex"), 2);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080054 hash = db.RememberStateInStateLog ();
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080055 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080056
Zhenkai Zhue851b952013-01-13 22:29:57 -080057 db.UpdateDeviceSeqNo (Name ("Alex"), 2);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080058 hash = db.RememberStateInStateLog ();
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080059 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080060
Zhenkai Zhue851b952013-01-13 22:29:57 -080061 db.UpdateDeviceSeqNo (Name ("Alex"), 1);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080062 hash = db.RememberStateInStateLog ();
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080063 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080064
Zhenkai Zhu6e7d4d22013-01-15 18:18:18 -080065 db.UpdateLocator(Name ("Alex"), Name("Hawaii"));
66
67 BOOST_CHECK_EQUAL(db.LookupLocator(Name ("Alex")), Name ("Hawaii"));
68
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080069
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080070 // db.FindStateDifferences ("00", "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
71 // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0", "00");
72 // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
73 // "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
74 // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0",
75 // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080076
Zhenkai Zhue851b952013-01-13 22:29:57 -080077 // db.UpdateDeviceSeqNo (Name ("Bob"), 1);
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080078 // hash = db.RememberStateInStateLog ();
79 // BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080080
Alexander Afanasyevd09871f2013-01-04 22:36:37 -080081 // db.FindStateDifferences ("00", "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
82 // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0",
83 // "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080084
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080085 remove_all (tmpdir);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080086}
87
88BOOST_AUTO_TEST_SUITE_END()