Updated and more functional database (sync-log) test
diff --git a/test/database-test.cc b/test/database-test.cc
index 016d784..3663a41 100644
--- a/test/database-test.cc
+++ b/test/database-test.cc
@@ -45,42 +45,62 @@
// should be empty
BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "7a6f2c1eefd539560d2dc3e5542868a79810d0867db15d9b87e41ec105899405");
- db.UpdateDeviceSeqNo (Name ("Alex"), 1);
+ db.UpdateDeviceSeqNo (Name ("/alex"), 1);
hash = db.RememberStateInStateLog ();
- BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "bf19308cb2c2ddab7bcce66e9074cd0eed74893be0813ca67a95e97c55d65896");
+ BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "3410477233f98d6c3f9a6f8da24494bf5a65e1a7c9f4f66b228128bd4e020558");
- db.UpdateDeviceSeqNo (Name ("Alex"), 2);
+ db.UpdateDeviceSeqNo (Name ("/alex"), 2);
hash = db.RememberStateInStateLog ();
- BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
+ BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "2ff304769cdb0125ac039e6fe7575f8576dceffc62618a431715aaf6eea2bf1c");
- db.UpdateDeviceSeqNo (Name ("Alex"), 2);
+ db.UpdateDeviceSeqNo (Name ("/alex"), 2);
hash = db.RememberStateInStateLog ();
- BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
+ BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "2ff304769cdb0125ac039e6fe7575f8576dceffc62618a431715aaf6eea2bf1c");
- db.UpdateDeviceSeqNo (Name ("Alex"), 1);
+ db.UpdateDeviceSeqNo (Name ("/alex"), 1);
hash = db.RememberStateInStateLog ();
- BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
+ BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "2ff304769cdb0125ac039e6fe7575f8576dceffc62618a431715aaf6eea2bf1c");
- db.UpdateLocator(Name ("Alex"), Name("Hawaii"));
+ db.UpdateLocator(Name ("/alex"), Name("/hawaii"));
- BOOST_CHECK_EQUAL(db.LookupLocator(Name ("Alex")), Name ("Hawaii"));
+ BOOST_CHECK_EQUAL(db.LookupLocator(Name ("/alex")), Name ("/hawaii"));
+ SyncStateMsgPtr msg = db.FindStateDifferences ("00", "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
+ BOOST_CHECK_EQUAL (msg->state_size(), 0);
+
+ msg = db.FindStateDifferences ("00", "2ff304769cdb0125ac039e6fe7575f8576dceffc62618a431715aaf6eea2bf1c");
+ BOOST_CHECK_EQUAL (msg->state_size(), 1);
+ BOOST_CHECK_EQUAL (msg->state (0).type (), SyncState::UPDATE);
+ BOOST_CHECK_EQUAL (msg->state (0).seq (), 2);
- // db.FindStateDifferences ("00", "95284d3132a7a88b85c5141ca63efa68b7a7daf37315def69e296a0c24692833");
- // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0", "00");
- // db.FindStateDifferences ("869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce",
- // "86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0");
- // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0",
- // "869c38c6dffe8911ced320aecc6d9244904d13d3e8cd21081311f2129b4557ce");
+ msg = db.FindStateDifferences ("2ff304769cdb0125ac039e6fe7575f8576dceffc62618a431715aaf6eea2bf1c", "00");
+ BOOST_CHECK_EQUAL (msg->state_size(), 1);
+ BOOST_CHECK_EQUAL (msg->state (0).type (), SyncState::DELETE);
- // db.UpdateDeviceSeqNo (Name ("Bob"), 1);
- // hash = db.RememberStateInStateLog ();
- // BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
+ msg = db.FindStateDifferences ("7a6f2c1eefd539560d2dc3e5542868a79810d0867db15d9b87e41ec105899405",
+ "2ff304769cdb0125ac039e6fe7575f8576dceffc62618a431715aaf6eea2bf1c");
+ BOOST_CHECK_EQUAL (msg->state_size(), 1);
+ BOOST_CHECK_EQUAL (msg->state (0).type (), SyncState::UPDATE);
+ BOOST_CHECK_EQUAL (msg->state (0).seq (), 2);
- // db.FindStateDifferences ("00", "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
- // db.FindStateDifferences ("86b51f1f98662583b295b61385ae4450ff8fac955981f1ca4381144ab1d7a4e0",
- // "d001d4680fd9adcb48e34a795e3cc3d5d36f209fbab34fd57f70f362c2085310");
+ msg = db.FindStateDifferences ("2ff304769cdb0125ac039e6fe7575f8576dceffc62618a431715aaf6eea2bf1c",
+ "7a6f2c1eefd539560d2dc3e5542868a79810d0867db15d9b87e41ec105899405");
+ BOOST_CHECK_EQUAL (msg->state_size(), 1);
+ BOOST_CHECK_EQUAL (msg->state (0).type (), SyncState::UPDATE);
+ BOOST_CHECK_EQUAL (msg->state (0).seq (), 0);
+
+ db.UpdateDeviceSeqNo (Name ("/bob"), 1);
+ hash = db.RememberStateInStateLog ();
+ BOOST_CHECK_EQUAL (lexical_cast<string> (*hash), "5df5affc07120335089525e82ec9fda60c6dccd7addb667106fb79de80610519");
+
+ msg = db.FindStateDifferences ("00", "5df5affc07120335089525e82ec9fda60c6dccd7addb667106fb79de80610519");
+ BOOST_CHECK_EQUAL (msg->state_size(), 2);
+ BOOST_CHECK_EQUAL (msg->state (0).type (), SyncState::UPDATE);
+ BOOST_CHECK_EQUAL (msg->state (0).seq (), 2);
+
+ BOOST_CHECK_EQUAL (msg->state (1).type (), SyncState::UPDATE);
+ BOOST_CHECK_EQUAL (msg->state (1).seq (), 1);
remove_all (tmpdir);
}