blob: 588b57883554627e8247b3630fa534460ba86983 [file] [log] [blame]
Zhenkai Zhu1bdc7032012-03-07 20:47:52 -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: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#include <boost/test/unit_test.hpp>
24#include <boost/test/output_test_stream.hpp>
25using boost::test_tools::output_test_stream;
26
27#include <boost/make_shared.hpp>
28
29#include "../model/sync-ccnx-wrapper.h"
30
31using namespace Sync;
32using namespace std;
33using namespace boost;
34
35string echoStr = "";
36
37void echo(string str) {
38 echoStr = str;
39}
40
41struct TestStruct {
42 string s_str;
43 void set(string str) {
44 s_str = str;
45 }
46};
47
48BOOST_AUTO_TEST_CASE (CcnxWrapperTest)
49{
50
51 CcnxWrapper ha;
52 CcnxWrapper hb;
53
54 TestStruct foo;
55
56 boost::function<void (string)> globalFunc = echo;
57 boost::function<void (string)> memberFunc =
58 bind1st(mem_fun(&TestStruct::set), &foo);
59
60 string prefix = "/ucla.edu";
61 ha.setInterestFilter(prefix, globalFunc);
62
63 string interest = "/ucla.edu/0";
64 hb.sendInterest(interest, memberFunc);
65
Zhenkai Zhu3a4758f2012-03-07 20:56:54 -080066 // give time for ccnd to react
67 sleep(5);
68
Zhenkai Zhu1bdc7032012-03-07 20:47:52 -080069 BOOST_CHECK_EQUAL(echoStr, interest);
70
Zhenkai Zhu1bdc7032012-03-07 20:47:52 -080071
72 string name = "/ucla.edu/0";
73 string data = "random bits: !#$!@#$!";
74 ha.publishData(name, data, 15);
75
76 hb.sendInterest(interest, memberFunc);
77
Zhenkai Zhu3a4758f2012-03-07 20:56:54 -080078 // give time for ccnd to react
79 sleep(5);
Zhenkai Zhu1bdc7032012-03-07 20:47:52 -080080 BOOST_CHECK_EQUAL(foo.s_str, data);
81
82}
83
84