blob: 7432fd028c29a11392ee3775a0dccfee8103eee8 [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>
28
29using namespace std;
30using namespace boost;
31
32BOOST_AUTO_TEST_SUITE(DatabaseTest)
33
34
35BOOST_AUTO_TEST_CASE (BasicDatabaseTest)
36{
37 char dir_tmpl [] = "/tmp/tmp-chornoshare-XXXXXXXXXXX";
38 string tmp_dir = mkdtemp (dir_tmpl);
39 SyncLog db (tmp_dir, "/alex");
40
41 HashPtr hash = db.RememberStateInStateLog ();
42 // should be empty
43 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "461f0ed1300b7f947fbe8e38a04186b74938febe7e43fe4ed571551fa3bd6ab9");
44
45 db.UpdateDeviceSeqno ("Alex", 1);
46 hash = db.RememberStateInStateLog ();
47
48 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "80463c859f23367e1cbabfa80d6de78af334589ec88dc9c56c854c1f7e196c34");
49
50 db.UpdateDeviceSeqno ("Alex", 2);
51 hash = db.RememberStateInStateLog ();
52 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
53
54 db.UpdateDeviceSeqno ("Alex", 2);
55 hash = db.RememberStateInStateLog ();
56 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
57
58 db.UpdateDeviceSeqno ("Alex", 1);
59 hash = db.RememberStateInStateLog ();
60 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
61
62
63 db.FindStateDifferences ("00", "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
64 db.FindStateDifferences ("95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833", "00");
65 db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
66 "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
67 db.FindStateDifferences ("95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833",
68 "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
69
70 db.UpdateDeviceSeqno ("Bob", 1);
71 hash = db.RememberStateInStateLog ();
72 BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
73
74 db.FindStateDifferences ("00", "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
75 db.FindStateDifferences ("95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833",
76 "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
77
78}
79
80BOOST_AUTO_TEST_SUITE_END()