]> git.meshlink.io Git - meshlink/commitdiff
Add a C++ version of the basic test.
authorGuus Sliepen <guus@meshlink.io>
Sat, 26 Jul 2014 12:18:03 +0000 (14:18 +0200)
committerGuus Sliepen <guus@meshlink.io>
Sat, 26 Jul 2014 12:18:03 +0000 (14:18 +0200)
test/Makefile.am
test/basicpp.cpp [new file with mode: 0644]
test/basicpp.test [new file with mode: 0755]

index ece9350b91b65b9dac592f30023b734fd1eddec6..67893aa23794eacb0b9c579c28707c830ede3268 100644 (file)
@@ -1,5 +1,6 @@
 TESTS = \
        basic.test \
+       basicpp.test \
        import-export.test \
        invite-join.test \
        sign-verify.test
@@ -8,11 +9,14 @@ dist_check_SCRIPTS = $(TESTS)
 
 AM_CPPFLAGS = -I../src
 
-check_PROGRAMS = basic import-export invite-join sign-verify
+check_PROGRAMS = basic basicpp import-export invite-join sign-verify
 
 basic_SOURCES = basic.c
 basic_LDADD = ../src/libmeshlink.la
 
+basicpp_SOURCES = basicpp.cpp
+basicpp_LDADD = ../src/libmeshlink.la
+
 import_export_SOURCES = import-export.c
 import_export_LDADD = ../src/libmeshlink.la
 
diff --git a/test/basicpp.cpp b/test/basicpp.cpp
new file mode 100644 (file)
index 0000000..d82610e
--- /dev/null
@@ -0,0 +1,85 @@
+#include <cstring>
+#include <iostream>
+
+#include "meshlink++.h"
+
+using namespace std;
+
+int main(int argc, char *argv[]) {
+       // Open a new meshlink instance.
+
+       meshlink::mesh *mesh = meshlink::open("basicpp_conf", "foo");
+       if(!mesh) {
+               cerr << "Could not initialize configuration for foo\n";
+               return 1;
+       }
+
+       // Check that our own node exists.
+
+       meshlink::node *self = mesh->get_node("foo");
+       if(!self) {
+               cerr << "Foo does not know about itself\n";
+               return 1;
+       }
+       if(strcmp(self->name, "foo")) {
+               cerr << "Foo thinks its name is " << self->name << "\n";
+               return 1;
+       }
+
+       // Start and stop the mesh.
+
+       if(!mesh->start()) {
+               cerr << "Foo could not start\n";
+               return 1;
+       }
+       mesh->stop();
+
+       // Make sure we can start and stop the mesh again.
+
+       if(!mesh->start()) {
+               cerr << "Foo could not start twice\n";
+               return 1;
+       }
+       mesh->stop();
+
+       // Close the mesh and open it again, now with a different name parameter.
+
+       meshlink::close(mesh);
+
+       // Check that the name is ignored now, and that we still are "foo".
+
+       mesh = meshlink::open("basic_conf", "bar");
+       if(!mesh) {
+               cerr << "Could not open configuration for foo a second time\n";
+               return 1;
+       }
+
+       if(mesh->get_node("bar")) {
+               cerr << "Foo knows about bar, it shouldn't\n";
+               return 1;
+       }
+
+       self = mesh->get_node("foo");
+       if(!self) {
+               cerr << "Foo doesn't know about itself the second time\n";
+               return 1;
+       }
+       if(strcmp(self->name, "foo")) {
+               cerr << "Foo thinks its name is " << self->name << " the second time\n";
+               return 1;
+       }
+
+       // Start and stop the mesh.
+
+       if(!mesh->start()) {
+               cerr << "Foo could not start a third time\n";
+               return 1;
+       }
+       mesh->stop();
+
+       // That's it.
+
+       meshlink::close(mesh);
+
+       return 0;
+}
diff --git a/test/basicpp.test b/test/basicpp.test
new file mode 100755 (executable)
index 0000000..13d6d0e
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+rm -Rf basicpp_conf
+./basicpp