]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added example/test program
authorArvin Schnell <aschnell@suse.de>
Wed, 16 Oct 2013 15:36:09 +0000 (17:36 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 16 Oct 2013 15:36:09 +0000 (17:36 +0200)
examples/c++-lib/.gitignore
examples/c++-lib/CreateNumber.cc [new file with mode: 0644]
examples/c++-lib/CreateTimeline.cc
examples/c++-lib/Makefile.am

index e5fb4c563bdbdabb2624d2ab3987ddf907967ad2..7e7ae7dbe984f4ca74788fb6ad02af5d6f4fa83a 100644 (file)
@@ -6,6 +6,8 @@ Create.o
 Create
 CmpDirs.o
 CmpDirs
+CreateNumber.o
+CreateNumber
 CreateTimeline.o
 CreateTimeline
 SnapTest.o
diff --git a/examples/c++-lib/CreateNumber.cc b/examples/c++-lib/CreateNumber.cc
new file mode 100644 (file)
index 0000000..1719a01
--- /dev/null
@@ -0,0 +1,52 @@
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <vector>
+#include <iostream>
+
+#include <snapper/Snapper.h>
+
+using namespace snapper;
+using namespace std;
+
+
+void
+deleteAll()
+{
+    Snapper* sh = new Snapper("testsuite");
+
+    Snapshots snapshots = sh->getSnapshots();
+
+    vector<Snapshots::iterator> tmp;
+    for (Snapshots::iterator it = snapshots.begin(); it != snapshots.end(); ++it)
+       if (!it->isCurrent())
+           tmp.push_back(it);
+
+    for (vector<Snapshots::iterator>::iterator it = tmp.begin(); it != tmp.end(); ++it)
+       sh->deleteSnapshot(*it);
+
+    delete sh;
+}
+
+
+int
+main()
+{
+    deleteAll();
+
+    Snapper* sh = new Snapper("testsuite");
+
+    for (size_t i = 0; i < 100; ++i)
+    {
+       map<string, string> userdata;
+       if (i % 5 == 0)
+           userdata["important"] = "yes";
+
+       sh->createSingleSnapshot(getuid(), "testsuite", "number", userdata);
+    }
+
+    delete sh;
+
+    exit(EXIT_SUCCESS);
+}
index d811710f2783ecc7cc7886b923d9d4523ce7127e..2ca03a5422c1e3cde8620081d904c2ebad1198d6 100644 (file)
@@ -1,5 +1,7 @@
 
 #include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
 #include <vector>
 #include <iostream>
 
@@ -38,9 +40,9 @@ main()
     time_t t = time(NULL) - 100 * 24*60*60;
     while (t < time(NULL))
     {
-       Snapshots::iterator snap = sh->createSingleSnapshot("testsuite");
+       Snapshots::iterator snap = sh->createSingleSnapshot(getuid(), "testsuite", "timeline",
+                                                           map<string, string>());
        // snap->setDate(t);
-       snap->setCleanup("timeline");
 
        t += 60*60;
     }
index a33cd11f27401198d44430ab24b9bc5d7fb6f699..03d1b33045a7a27f8902ee5ecaaf7fbdbb1d1ac0 100644 (file)
@@ -6,7 +6,7 @@ INCLUDES = -I$(top_srcdir)
 
 LDADD = ../../snapper/libsnapper.la
 
-noinst_PROGRAMS = List ListAll Create CmpDirs CreateTimeline SnapTest
+noinst_PROGRAMS = List ListAll Create CmpDirs CreateNumber CreateTimeline SnapTest
 
 List_SOURCES = List.cc
 
@@ -16,6 +16,8 @@ Create_SOURCES = Create.cc
 
 CmpDirs_SOURCES = CmpDirs.cc
 
+CreateNumber_SOURCES = CreateNumber.cc
+
 CreateTimeline_SOURCES = CreateTimeline.cc
 
 SnapTest_SOURCES = SnapTest.cc