akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [diff] [blame] | 1 | /* -*- 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: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * Chaoyi Bian <bcy@pku.edu.cn> |
| 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | #include <boost/test/unit_test.hpp> |
| 25 | #include <boost/test/output_test_stream.hpp> |
| 26 | #include <map> |
| 27 | using boost::test_tools::output_test_stream; |
| 28 | |
| 29 | #include <boost/make_shared.hpp> |
| 30 | |
| 31 | #include "sync-ccnx-wrapper.h" |
| 32 | #include "sync-app-data-fetch.h" |
| 33 | #include "sync-app-data-publish.h" |
| 34 | |
| 35 | using namespace Sync; |
| 36 | using namespace std; |
| 37 | using namespace boost; |
| 38 | |
| 39 | class TestStructApp { |
| 40 | public: |
| 41 | map<string, string> data; |
| 42 | void set(string str1, string str2) { |
| 43 | data.insert(make_pair(str1, str2)); |
| 44 | } |
| 45 | |
| 46 | void erase(string str1, string str2) { |
| 47 | data.erase(str1); |
| 48 | } |
| 49 | |
| 50 | string toString(){ |
| 51 | map<string, string>::iterator it = data.begin(); |
| 52 | string str = ""; |
| 53 | for (; it != data.end(); ++it){ |
| 54 | str += "<"; |
| 55 | str += it->first; |
| 56 | str += "|"; |
| 57 | str += it->second; |
| 58 | str += ">"; |
| 59 | } |
| 60 | return str; |
| 61 | } |
| 62 | |
| 63 | }; |
| 64 | |
| 65 | BOOST_AUTO_TEST_CASE (AppDataPublishAndFetchTest) |
| 66 | { |
| 67 | TestStructApp foo; |
| 68 | TestStructApp bar; |
| 69 | |
| 70 | string interest = "/april/fool"; |
| 71 | string seq[5] = {"0", "1", "2", "3", "4" }; |
| 72 | string str[5] = {"panda", "express", "tastes", "so", "good"}; |
| 73 | |
| 74 | for (int i = 0; i < 5; i++) { |
| 75 | foo.set(interest + "/" + "0/" + seq[i], str[i]); |
| 76 | } |
| 77 | |
| 78 | boost::function<void (string, string)> setFunc = |
| 79 | bind(&TestStructApp::set, &bar, _1, _2); |
| 80 | |
| 81 | shared_ptr<CcnxWrapper> handle(new CcnxWrapper()); |
| 82 | |
| 83 | AppDataFetch fetcher(handle, setFunc); |
| 84 | AppDataPublish publisher(handle); |
| 85 | |
| 86 | for (int i = 1; i <= 5; i++) { |
| 87 | publisher.publishData(interest, 0, str[i - 1], 5); |
| 88 | } |
| 89 | |
| 90 | BOOST_CHECK_EQUAL(publisher.getNextSeq(interest, 0), 5); |
| 91 | BOOST_CHECK_EQUAL(publisher.getRecentData(interest, 0), str[4]); |
| 92 | |
| 93 | fetcher.onUpdate (interest, SeqNo (0,4), SeqNo (0,-1)); |
| 94 | // give time for ccnd to react |
| 95 | sleep(1); |
| 96 | BOOST_CHECK_EQUAL(foo.toString(), bar.toString()); |
| 97 | |
| 98 | |
| 99 | boost::function<void (string, string)> eraseFunc = |
| 100 | bind(&TestStructApp::erase, &bar, _1, _2); |
| 101 | fetcher.setDataCallback(eraseFunc); |
| 102 | |
| 103 | fetcher.onUpdate (interest, SeqNo (0,4), SeqNo (0,-1)); |
| 104 | // give time for ccnd to react |
| 105 | sleep(1); |
| 106 | TestStructApp poo; |
| 107 | |
| 108 | BOOST_CHECK_EQUAL(poo.toString(), bar.toString()); |
| 109 | |
| 110 | } |
| 111 | */ |