Added test-get-async
diff --git a/tests/test-encode-decode-Interest.cpp b/tests/test-encode-decode-Interest.cpp
index bba7596..d715c85 100644
--- a/tests/test-encode-decode-Interest.cpp
+++ b/tests/test-encode-decode-Interest.cpp
@@ -7,7 +7,6 @@
#include <sstream>
#include <iostream>
#include <ndn-cpp/Interest.hpp>
-#include <ndn-cpp/c/network/TcpTransport.h>
using namespace std;
using namespace ndn;
@@ -38,36 +37,17 @@
{
try {
Interest interest;
-#if 0
interest.decode(Interest1, sizeof(Interest1));
cout << "Interest name " << interest.getName().to_uri() << endl;
cout << "Interest minSuffixComponents " << interest.getMinSuffixComponents() << endl;
cout << "Interest publisherPublicKeyDigest length " << interest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() << endl;
cout << "Interest excludeEntryCount " << interest.getExclude().getEntryCount() << endl;
cout << "InterestLifetimeMilliseconds " << interest.getInterestLifetimeMilliseconds() << endl;
-#endif
vector<unsigned char> encoding;
interest.encode(encoding);
cout << "Interest encoding length " << encoding.size() << " vs. sizeof(Interest1) " << sizeof(Interest1) << endl;
- struct ndn_TcpTransport transport;
- ndn_TcpTransport_init(&transport);
- ndn_Error error;
- if (error = ndn_TcpTransport_connect(&transport, (char *)"E.hub.ndn.ucla.edu", 9695))
- return error;
- if (error = ndn_TcpTransport_send(&transport, &encoding[0], encoding.size()))
- return error;
-
- unsigned char buffer[1000];
- unsigned int nBytes;
- if (error = ndn_TcpTransport_receive(&transport, buffer, sizeof(buffer), &nBytes))
- return error;
-
- for (int i = 0; i < nBytes; ++i)
- printf("%02X ", (unsigned int)buffer[i]);
-
-#if 0
Interest reDecodedInterest;
reDecodedInterest.decode(encoding);
cout << "Re-decoded Interest name " << reDecodedInterest.getName().to_uri() << endl;
@@ -75,7 +55,6 @@
cout << "Re-decoded Interest publisherPublicKeyDigest length " << reDecodedInterest.getPublisherPublicKeyDigest().getPublisherPublicKeyDigest().size() << endl;
cout << "Re-decoded Interest excludeEntryCount " << reDecodedInterest.getExclude().getEntryCount() << endl;
cout << "Re-decoded InterestLifetimeMilliseconds " << reDecodedInterest.getInterestLifetimeMilliseconds() << endl;
-#endif
} catch (exception &e) {
cout << "exception: " << e.what() << endl;
}
diff --git a/tests/test-get-async.cpp b/tests/test-get-async.cpp
new file mode 100644
index 0000000..a185386
--- /dev/null
+++ b/tests/test-get-async.cpp
@@ -0,0 +1,49 @@
+/**
+ * @author: Jeff Thompson
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <cstdlib>
+#include <sstream>
+#include <iostream>
+#include <ndn-cpp/Interest.hpp>
+#include <ndn-cpp/ContentObject.hpp>
+#include <ndn-cpp/c/network/TcpTransport.h>
+
+using namespace std;
+using namespace ndn;
+int main(int argc, char** argv)
+{
+ try {
+ Interest interest;
+ interest.getName() = Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E");
+ vector<unsigned char> encoding;
+ interest.encode(encoding);
+
+ struct ndn_TcpTransport transport;
+ ndn_TcpTransport_init(&transport);
+ ndn_Error error;
+ if (error = ndn_TcpTransport_connect(&transport, (char *)"E.hub.ndn.ucla.edu", 9695))
+ return error;
+ if (error = ndn_TcpTransport_send(&transport, &encoding[0], encoding.size()))
+ return error;
+
+ unsigned char buffer[8000];
+ unsigned int nBytes;
+ while (1) {
+ if (error = ndn_TcpTransport_receive(&transport, buffer, sizeof(buffer), &nBytes))
+ return error;
+ if (buffer[0] == 0x04)
+ break;
+ }
+
+ for (int i = 0; i < nBytes; ++i)
+ printf("%02X ", (unsigned int)buffer[i]);
+
+ ContentObject contentObject;
+ contentObject.decode(buffer, nBytes);
+ } catch (exception &e) {
+ cout << "exception: " << e.what() << endl;
+ }
+ return 0;
+}