Add test sample

This commit is contained in:
Grégory Soutadé 2021-09-09 20:57:10 +02:00
parent 89e9fdc55e
commit 7f2a84c10c
2 changed files with 29 additions and 2 deletions

View File

@ -46,8 +46,8 @@ libupdfparser.a: $(OBJECTS)
libupdfparser.so: $(OBJECTS)
$(CXX) obj/*.o $(LDFLAGS) -o $@ -shared
test: test.c libupdfparser.a
test: tests/test.cpp libupdfparser.a
g++ -ggdb -O0 $^ -o $@ -Iinclude libupdfparser.a
clean:
rm -rf libupdfparser.so libupdfparser.a obj
rm -rf libupdfparser.so libupdfparser.a obj test

27
tests/test.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <iostream>
#include <uPDFParser.h>
#include <uPDFParser_common.h>
int main(int argc, char** argv)
{
uPDFParser::Parser parser;
if (argc != 2 || std::string(argv[1]) == "-h" || std::string(argv[1]) == "--help")
{
std::cout << "Usage : " << argv[0] << " <file>" << std::endl;
return 0;
}
std::cout << "Parse " << argv[1] << std::endl;
try
{
parser.parse(argv[1]);
}
catch(uPDFParser::Exception e)
{
std::cout << e.what() << std::endl;
return -1;
}
return 0;
}