blob: ba1feccc0cd3bc2f771c38078f45704dfa0ea91e [file] [log] [blame]
Alexander Afanasyev71b43e72012-12-27 01:03:43 -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 *
Alexander Afanasyev8811b352013-01-02 12:51:15 -080018 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080020 */
21
Alexander Afanasyev242f8772013-01-01 23:26:31 -080022#include "db-helper.h"
Alexander Afanasyevae43c502012-12-29 17:26:37 -080023#include <iostream>
24
25using namespace std;
26using namespace boost;
27
28typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
29
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080030
31int
32main (int argc, char **argv)
33{
Alexander Afanasyevae43c502012-12-29 17:26:37 -080034 try
35 {
36 DbHelper db ("./");
37
38 HashPtr hash = db.RememberStateInStateLog ();
39 // should be empty
40 cout << "Hash: [" << *hash << "]" << endl;
41
42 //
43 db.UpdateDeviceSeqno ("Alex", 1);
44 hash = db.RememberStateInStateLog ();
45 cout << "Hash: [" << *hash << "]" << endl;
46
47 db.UpdateDeviceSeqno ("Alex", 2);
48 hash = db.RememberStateInStateLog ();
49 cout << "Hash: [" << *hash << "]" << endl;
50
51 db.UpdateDeviceSeqno ("Alex", 2);
52 hash = db.RememberStateInStateLog ();
53 cout << "Hash: [" << *hash << "]" << endl;
54
55 db.UpdateDeviceSeqno ("Alex", 1);
56 hash = db.RememberStateInStateLog ();
57 cout << "Hash: [" << *hash << "]" << endl;
58
59 db.FindStateDifferences ("00", "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
60 db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52", "00");
61 db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
62 "ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52");
63 db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
64 "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
65
66 db.UpdateDeviceSeqno ("Bob", 1);
67 hash = db.RememberStateInStateLog ();
68 cout << "Hash: [" << *hash << "]" << endl;
69
70 db.FindStateDifferences ("00", "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
71 db.FindStateDifferences ("ec0a9941fa726e1fb8f34ecdbd8e3faa75dc9dba22e6a2ea1d8482aae5fdfb52",
72 "48f4d95b503b9a79c2d5939fa67722b13fc01db861fc501d09efd0a38dbafab8");
73 }
74 catch (const boost::exception &e)
75 {
76 cout << "ERRORR: " << *get_error_info<errmsg_info_str> (e) << endl;
77 }
78
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080079 return 0;
80}