summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Figuière <hub@figuiere.net>2017-01-22 18:00:03 -0500
committerHubert Figuière <hub@figuiere.net>2017-01-23 00:00:37 -0500
commit0df4c68671940eb7c504d59dd7613f79b97b92b0 (patch)
tree11995853a69f14c3663b8978581895f96c6db64e
parent49bac10e1b823b50da29860944b8fae30bf05711 (diff)
2.4.x: Bug 99480 - Add test for iterators.
This would catch similar changes that broke test elsewhere. Rename test3 to testiterator.
-rw-r--r--exempi/tests/Makefile.am10
-rw-r--r--exempi/tests/test-iterator.cpp (renamed from exempi/tests/test3.cpp)81
2 files changed, 74 insertions, 17 deletions
diff --git a/exempi/tests/Makefile.am b/exempi/tests/Makefile.am
index 9016674..86cbe35 100644
--- a/exempi/tests/Makefile.am
+++ b/exempi/tests/Makefile.am
@@ -42,12 +42,12 @@ TEST_EXTENSIONS = .sh
if WITH_UNIT_TEST
check_PROGRAMS = testexempicore testserialise testwritenewprop \
testtiffleak testxmpfiles testxmpfileswrite \
- testparse test3 testinit testfdo18635 testfdo83313 testcpp testwebp \
+ testparse testiterator testinit testfdo18635 testfdo83313 testcpp testwebp \
testadobesdk \
$(NULL)
TESTS = testcore.sh testinit testexempicore testserialise testwritenewprop \
testtiffleak testxmpfiles testxmpfileswrite \
- testparse test3 testfdo18635 testfdo83313 testcpp testwebp \
+ testparse testiterator testfdo18635 testfdo83313 testcpp testwebp \
testadobesdk \
$(NULL)
TESTS_ENVIRONMENT = TEST_DIR=$(srcdir) BOOST_TEST_CATCH_SYSTEM_ERRORS=no VALGRIND="$(VALGRIND)"
@@ -98,9 +98,9 @@ testparse_SOURCES = testparse.cpp utils.cpp
testparse_LDADD = ../libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIBS@
testparse_LDFLAGS = -static @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@
-test3_SOURCES = test3.cpp utils.cpp
-test3_LDADD = ../libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIBS@
-test3_LDFLAGS = -static @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@
+testiterator_SOURCES = test-iterator.cpp utils.cpp
+testiterator_LDADD = ../libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIBS@
+testiterator_LDFLAGS = -static @BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS@
testfdo18635_SOURCES = test-bgo.cpp utils.cpp
testfdo18635_LDADD = ../libexempi.la @BOOST_UNIT_TEST_FRAMEWORK_LIBS@
diff --git a/exempi/tests/test3.cpp b/exempi/tests/test-iterator.cpp
index 90f84a3..f78910e 100644
--- a/exempi/tests/test3.cpp
+++ b/exempi/tests/test-iterator.cpp
@@ -1,7 +1,7 @@
/*
* exempi - test3.cpp
*
- * Copyright (C) 2007-2008 Hubert Figuiere
+ * Copyright (C) 2007-2017 Hubert Figuiere
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -81,28 +81,85 @@ int test_main(int argc, char *argv[])
BOOST_CHECK(xmp != NULL);
- XmpIteratorPtr iter =
- xmp_iterator_new(xmp, NULL, NULL, XMP_ITER_JUSTLEAFNODES);
-
XmpStringPtr the_schema = xmp_string_new();
XmpStringPtr the_path = xmp_string_new();
XmpStringPtr the_prop = xmp_string_new();
uint32_t options;
- while (xmp_iterator_next(iter, the_schema, the_path, the_prop, &options)) {
- std::cout << xmp_string_cstr(the_schema) << " / "
- << xmp_string_cstr(the_path) << " = "
- << xmp_string_cstr(the_prop);
- if (options) {
- std::cout << boost::format(" options = 0x%1$x") % options;
+ typedef std::array<std::string, 3> tuple3;
+
+ {
+ // leafnodes iteration
+ XmpIteratorPtr iter =
+ xmp_iterator_new(xmp, NS_DC, NULL, XMP_ITER_JUSTLEAFNODES);
+
+ BOOST_CHECK(iter);
+ std::vector<tuple3> props;
+
+ while (xmp_iterator_next(iter, the_schema, the_path, the_prop, &options)) {
+ props.push_back(tuple3 {
+ xmp_string_cstr(the_schema),
+ xmp_string_cstr(the_path),
+ xmp_string_cstr(the_prop)
+ });
+ }
+
+ BOOST_CHECK(props.size() == 7);
+ for (auto prop_tuple : props) {
+ BOOST_CHECK(prop_tuple[0] == NS_DC);
}
- std::cout << std::endl;
+ BOOST_CHECK(props[0][2] == "unknown");
+ BOOST_CHECK(props[3][1] == "dc:subject[1]");
+
+ BOOST_CHECK(xmp_iterator_free(iter));
+ }
+
+ {
+ // leafname iteration
+ XmpIteratorPtr iter =
+ xmp_iterator_new(xmp, NS_DC, "rights", XMP_ITER_JUSTLEAFNAME);
+
+ BOOST_CHECK(iter);
+ std::vector<tuple3> props;
+
+ while (xmp_iterator_next(iter, the_schema, the_path, the_prop, &options)) {
+ props.push_back(tuple3 {
+ xmp_string_cstr(the_schema),
+ xmp_string_cstr(the_path),
+ xmp_string_cstr(the_prop)
+ });
+ }
+
+ BOOST_CHECK(props.size() == 3);
+
+ BOOST_CHECK(props[0] == tuple3({ NS_DC, "dc:rights", "" }));
+ BOOST_CHECK(props[1] == tuple3({ "", "[1]", "2006, Hubert Figuiere" }));
+ BOOST_CHECK(props[2] == tuple3({ "http://www.w3.org/XML/1998/namespace", "xml:lang", "x-default" }));
+
+ BOOST_CHECK(xmp_iterator_free(iter));
+ }
+
+ {
+ // Iterator with property but no NS is invalid.
+ XmpIteratorPtr iter =
+ xmp_iterator_new(xmp, NULL, "rights", XMP_ITER_JUSTLEAFNODES);
+
+ // Invalid iterator
+ BOOST_CHECK(!iter);
+ }
+
+ {
+ // Iterating namespaces is invalid.
+ XmpIteratorPtr iter =
+ xmp_iterator_new(xmp, NULL, NULL, XMP_ITER_NAMESPACES);
+
+ // Invalid iterator
+ BOOST_CHECK(!iter);
}
xmp_string_free(the_prop);
xmp_string_free(the_path);
xmp_string_free(the_schema);
- BOOST_CHECK(xmp_iterator_free(iter));
BOOST_CHECK(xmp_free(xmp));
free(buffer);