summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorGravatar Sébastien Gonzalve2023-04-21 12:40:18 +0200
committerGravatar Nikias Bassen2023-04-21 12:40:18 +0200
commit25ace1e8cb7f9a464c29dd2ce80cd68104d54f84 (patch)
treeb084e02e0021d78c62bae94ac2e2f214631a469d /test
parent12c45a21b4f223ca2a4ccba42ade2366f4dbde5c (diff)
downloadlibplist-25ace1e8cb7f9a464c29dd2ce80cd68104d54f84.tar.gz
libplist-25ace1e8cb7f9a464c29dd2ce80cd68104d54f84.tar.bz2
Add C++ interface test
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am10
-rwxr-xr-xtest/bigarray++.test15
-rwxr-xr-xtest/empty++.test15
-rwxr-xr-xtest/huge++.test15
-rwxr-xr-xtest/large++.test15
-rwxr-xr-xtest/medium++.test15
-rw-r--r--test/plist_test++.cpp103
-rwxr-xr-xtest/small++.test15
8 files changed, 203 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 5326317..5d31f5a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,6 +8,7 @@ AM_LDFLAGS =
8noinst_PROGRAMS = \ 8noinst_PROGRAMS = \
9 plist_cmp \ 9 plist_cmp \
10 plist_test \ 10 plist_test \
11 plist_test++ \
11 integer_set_test \ 12 integer_set_test \
12 plist_btest \ 13 plist_btest \
13 plist_jtest \ 14 plist_jtest \
@@ -18,6 +19,9 @@ plist_cmp_LDADD = \
18 $(top_builddir)/src/libplist-2.0.la \ 19 $(top_builddir)/src/libplist-2.0.la \
19 $(top_builddir)/libcnary/libcnary.la 20 $(top_builddir)/libcnary/libcnary.la
20 21
22plist_test___SOURCES = plist_test++.cpp
23plist_test___LDADD = $(top_builddir)/src/libplist++-2.0.la
24
21plist_test_SOURCES = plist_test.c 25plist_test_SOURCES = plist_test.c
22plist_test_LDADD = $(top_builddir)/src/libplist-2.0.la 26plist_test_LDADD = $(top_builddir)/src/libplist-2.0.la
23 27
@@ -40,6 +44,12 @@ TESTS = \
40 large.test \ 44 large.test \
41 huge.test \ 45 huge.test \
42 bigarray.test \ 46 bigarray.test \
47 empty++.test \
48 small++.test \
49 medium++.test \
50 large++.test \
51 huge++.test \
52 bigarray++.test \
43 dates.test \ 53 dates.test \
44 timezone1.test \ 54 timezone1.test \
45 timezone2.test \ 55 timezone2.test \
diff --git a/test/bigarray++.test b/test/bigarray++.test
new file mode 100755
index 0000000..da65387
--- /dev/null
+++ b/test/bigarray++.test
@@ -0,0 +1,15 @@
1## -*- sh -*-
2
3DATASRC=$top_srcdir/test/data
4DATAOUT=$top_builddir/test/data
5TESTFILE=6.plist
6
7if ! test -d "$DATAOUT"; then
8 mkdir -p $DATAOUT
9fi
10
11echo "Converting"
12$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13
14echo "Comparing"
15$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
diff --git a/test/empty++.test b/test/empty++.test
new file mode 100755
index 0000000..f29e95e
--- /dev/null
+++ b/test/empty++.test
@@ -0,0 +1,15 @@
1## -*- sh -*-
2
3DATASRC=$top_srcdir/test/data
4DATAOUT=$top_builddir/test/data
5TESTFILE=1.plist
6
7if ! test -d "$DATAOUT"; then
8 mkdir -p $DATAOUT
9fi
10
11echo "Converting"
12$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13
14echo "Comparing"
15$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
diff --git a/test/huge++.test b/test/huge++.test
new file mode 100755
index 0000000..3b6425e
--- /dev/null
+++ b/test/huge++.test
@@ -0,0 +1,15 @@
1## -*- sh -*-
2
3DATASRC=$top_srcdir/test/data
4DATAOUT=$top_builddir/test/data
5TESTFILE=5.plist
6
7if ! test -d "$DATAOUT"; then
8 mkdir -p $DATAOUT
9fi
10
11echo "Converting"
12$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13
14echo "Comparing"
15$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
diff --git a/test/large++.test b/test/large++.test
new file mode 100755
index 0000000..cdadd75
--- /dev/null
+++ b/test/large++.test
@@ -0,0 +1,15 @@
1## -*- sh -*-
2
3DATASRC=$top_srcdir/test/data
4DATAOUT=$top_builddir/test/data
5TESTFILE=4.plist
6
7if ! test -d "$DATAOUT"; then
8 mkdir -p $DATAOUT
9fi
10
11echo "Converting"
12$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13
14echo "Comparing"
15$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
diff --git a/test/medium++.test b/test/medium++.test
new file mode 100755
index 0000000..3488dfd
--- /dev/null
+++ b/test/medium++.test
@@ -0,0 +1,15 @@
1## -*- sh -*-
2
3DATASRC=$top_srcdir/test/data
4DATAOUT=$top_builddir/test/data
5TESTFILE=3.plist
6
7if ! test -d "$DATAOUT"; then
8 mkdir -p $DATAOUT
9fi
10
11echo "Converting"
12$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13
14echo "Comparing"
15$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
diff --git a/test/plist_test++.cpp b/test/plist_test++.cpp
new file mode 100644
index 0000000..33205c1
--- /dev/null
+++ b/test/plist_test++.cpp
@@ -0,0 +1,103 @@
1/*
2 * source libplist++ regression test
3 *
4 * Copyright (c) 2021 Sebastien Gonzalve All Rights Reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21
22#include "plist/plist++.h"
23#include <fstream>
24#include <sstream>
25#include <iostream>
26
27int main(int argc, char *argv[])
28{
29 if (argc != 3)
30 {
31 printf("Wrong input\n");
32 return 1;
33 }
34
35 const char* file_in = argv[1];
36 const char* file_out = argv[2];
37
38 //read input file
39 std::ifstream iplist;
40 iplist.open(file_in);
41
42 if (!iplist)
43 {
44 printf("File does not exists\n");
45 return 2;
46 }
47
48 std::cout << "File " << file_in << " is open\n";
49
50 std::string plist_xml;
51 {
52 std::stringstream buffer;
53 buffer << iplist.rdbuf();
54 plist_xml = buffer.str();
55 }
56
57 iplist.close();
58
59 //convert one format to another
60 PList::Structure* root_node1 = PList::Structure::FromXml(plist_xml);
61 if (!root_node1)
62 {
63 std::cout << "PList XML parsing failed\n";
64 return 3;
65 }
66
67 std::cout << "PList XML parsing succeeded\n";
68 std::vector<char> plist_bin = root_node1->ToBin();
69 // FIXME There is no way to test for success of ToBin for now.
70
71 std::cout << "PList BIN writing succeeded\n";
72 PList::Structure* root_node2 = PList::Structure::FromBin(plist_bin);
73 if (!root_node2)
74 {
75 std::cout << "PList BIN parsing failed\n";
76 return 5;
77 }
78
79 std::cout << "PList BIN parsing succeeded\n";
80 std::string plist_xml2 = root_node2->ToXml();
81 if (plist_xml2.empty())
82 {
83 std::cout << "PList XML writing failed\n";
84 return 8;
85 }
86
87 std::cout << "PList XML writing succeeded\n";
88 {
89 std::ofstream oplist;
90 oplist.open(file_out);
91 oplist << plist_xml2;
92 }
93
94 if (plist_xml.size() != plist_xml2.size())
95 {
96 std::cout << "Size of input and output is different\n"
97 << "Input size : " << plist_xml.size()
98 << "\nOutput size : " << plist_xml2.size() << '\n';
99 }
100
101 return 0;
102}
103
diff --git a/test/small++.test b/test/small++.test
new file mode 100755
index 0000000..28c7676
--- /dev/null
+++ b/test/small++.test
@@ -0,0 +1,15 @@
1## -*- sh -*-
2
3DATASRC=$top_srcdir/test/data
4DATAOUT=$top_builddir/test/data
5TESTFILE=2.plist
6
7if ! test -d "$DATAOUT"; then
8 mkdir -p $DATAOUT
9fi
10
11echo "Converting"
12$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13
14echo "Comparing"
15$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out