Skip to content

Commit 25ace1e

Browse files
OznOgnikias
authored andcommitted
Add C++ interface test
1 parent 12c45a2 commit 25ace1e

8 files changed

+203
-0
lines changed

test/Makefile.am

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ AM_LDFLAGS =
88
noinst_PROGRAMS = \
99
plist_cmp \
1010
plist_test \
11+
plist_test++ \
1112
integer_set_test \
1213
plist_btest \
1314
plist_jtest \
@@ -18,6 +19,9 @@ plist_cmp_LDADD = \
1819
$(top_builddir)/src/libplist-2.0.la \
1920
$(top_builddir)/libcnary/libcnary.la
2021

22+
plist_test___SOURCES = plist_test++.cpp
23+
plist_test___LDADD = $(top_builddir)/src/libplist++-2.0.la
24+
2125
plist_test_SOURCES = plist_test.c
2226
plist_test_LDADD = $(top_builddir)/src/libplist-2.0.la
2327

@@ -40,6 +44,12 @@ TESTS = \
4044
large.test \
4145
huge.test \
4246
bigarray.test \
47+
empty++.test \
48+
small++.test \
49+
medium++.test \
50+
large++.test \
51+
huge++.test \
52+
bigarray++.test \
4353
dates.test \
4454
timezone1.test \
4555
timezone2.test \

test/bigarray++.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## -*- sh -*-
2+
3+
DATASRC=$top_srcdir/test/data
4+
DATAOUT=$top_builddir/test/data
5+
TESTFILE=6.plist
6+
7+
if ! test -d "$DATAOUT"; then
8+
mkdir -p $DATAOUT
9+
fi
10+
11+
echo "Converting"
12+
$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13+
14+
echo "Comparing"
15+
$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out

test/empty++.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## -*- sh -*-
2+
3+
DATASRC=$top_srcdir/test/data
4+
DATAOUT=$top_builddir/test/data
5+
TESTFILE=1.plist
6+
7+
if ! test -d "$DATAOUT"; then
8+
mkdir -p $DATAOUT
9+
fi
10+
11+
echo "Converting"
12+
$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13+
14+
echo "Comparing"
15+
$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out

test/huge++.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## -*- sh -*-
2+
3+
DATASRC=$top_srcdir/test/data
4+
DATAOUT=$top_builddir/test/data
5+
TESTFILE=5.plist
6+
7+
if ! test -d "$DATAOUT"; then
8+
mkdir -p $DATAOUT
9+
fi
10+
11+
echo "Converting"
12+
$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13+
14+
echo "Comparing"
15+
$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out

test/large++.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## -*- sh -*-
2+
3+
DATASRC=$top_srcdir/test/data
4+
DATAOUT=$top_builddir/test/data
5+
TESTFILE=4.plist
6+
7+
if ! test -d "$DATAOUT"; then
8+
mkdir -p $DATAOUT
9+
fi
10+
11+
echo "Converting"
12+
$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13+
14+
echo "Comparing"
15+
$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out

test/medium++.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## -*- sh -*-
2+
3+
DATASRC=$top_srcdir/test/data
4+
DATAOUT=$top_builddir/test/data
5+
TESTFILE=3.plist
6+
7+
if ! test -d "$DATAOUT"; then
8+
mkdir -p $DATAOUT
9+
fi
10+
11+
echo "Converting"
12+
$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13+
14+
echo "Comparing"
15+
$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out

test/plist_test++.cpp

+103
Original file line numberDiff line numberDiff line change
@@ -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+
27+
int 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+

test/small++.test

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## -*- sh -*-
2+
3+
DATASRC=$top_srcdir/test/data
4+
DATAOUT=$top_builddir/test/data
5+
TESTFILE=2.plist
6+
7+
if ! test -d "$DATAOUT"; then
8+
mkdir -p $DATAOUT
9+
fi
10+
11+
echo "Converting"
12+
$top_builddir/test/plist_test++ $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out
13+
14+
echo "Comparing"
15+
$top_builddir/test/plist_cmp $DATASRC/$TESTFILE $DATAOUT/$TESTFILE.out

0 commit comments

Comments
 (0)