diff options
Diffstat (limited to 'qpdf')
-rw-r--r-- | qpdf/test_driver.cc | 144 |
1 files changed, 76 insertions, 68 deletions
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 2998e0a1..99c5cf53 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -1749,7 +1749,7 @@ void runtest(int n, char const* filename1, char const* arg2) // number-tree.pdf QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); QPDFNumberTreeObjectHelper ntoh(qtest, pdf); - for (auto iter: ntoh) + for (auto& iter: ntoh) { std::cout << iter.first << " " << iter.second.getStringValue() @@ -1785,32 +1785,36 @@ void runtest(int n, char const* filename1, char const* arg2) assert(iter1 == new1.end()); new1.insert(1, QPDFObjectHandle::newString("1")); ++iter1; - assert((*iter1).first == 1); + assert((*iter1).first == 1); // exercise operator* explicitly + auto& iter1_val = *iter1; --iter1; assert(iter1 == new1.end()); --iter1; - assert((*iter1).first == 1); + assert(iter1->first == 1); + assert(iter1_val.first == 1); new1.insert(2, QPDFObjectHandle::newString("2")); ++iter1; - assert((*iter1).first == 2); + assert(iter1->first == 2); + assert(iter1_val.first == 2); ++iter1; assert(iter1 == new1.end()); + assert(! iter1_val.second.isInitialized()); ++iter1; - assert((*iter1).first == 1); + assert(iter1->first == 1); --iter1; assert(iter1 == new1.end()); --iter1; - assert((*iter1).first == 2); + assert(iter1->first == 2); std::cout << "insertAfter" << std::endl; auto new2 = QPDFNumberTreeObjectHelper::newEmpty(pdf); auto iter2 = new2.begin(); assert(iter2 == new2.end()); iter2.insertAfter(3, QPDFObjectHandle::newString("3!")); - assert((*iter2).first == 3); + assert(iter2->first == 3); iter2.insertAfter(4, QPDFObjectHandle::newString("4!")); - assert((*iter2).first == 4); - for (auto i: new2) + assert(iter2->first == 4); + for (auto& i: new2) { std::cout << i.first << " " << i.second.unparse() << std::endl; } @@ -1830,7 +1834,7 @@ void runtest(int n, char const* filename1, char const* arg2) std::cout << "/Bad2" << std::endl; auto bad2 = QPDFNumberTreeObjectHelper( pdf.getTrailer().getKey("/Bad2"), pdf); - for (auto i: bad2) + for (auto& i: bad2) { std::cout << i.first << " " << i.second.unparse() << std::endl; } @@ -1844,21 +1848,21 @@ void runtest(int n, char const* filename1, char const* arg2) assert(empty.begin() == empty.end()); assert(empty.last() == empty.end()); auto i = empty.insert(5, QPDFObjectHandle::newString("5")); - assert((*i).first == 5); - assert((*i).second.getStringValue() == "5"); - assert((*empty.begin()).first == 5); - assert((*empty.last()).first == 5); - assert((*empty.begin()).second.getStringValue() == "5"); + assert(i->first == 5); + assert(i->second.getStringValue() == "5"); + assert(empty.begin()->first == 5); + assert(empty.last()->first == 5); + assert(empty.begin()->second.getStringValue() == "5"); i = empty.insert(5, QPDFObjectHandle::newString("5+")); - assert((*i).first == 5); - assert((*i).second.getStringValue() == "5+"); - assert((*empty.begin()).second.getStringValue() == "5+"); + assert(i->first == 5); + assert(i->second.getStringValue() == "5+"); + assert(empty.begin()->second.getStringValue() == "5+"); i = empty.insert(6, QPDFObjectHandle::newString("6")); - assert((*i).first == 6); - assert((*i).second.getStringValue() == "6"); - assert((*empty.begin()).second.getStringValue() == "5+"); - assert((*empty.last()).first == 6); - assert((*empty.last()).second.getStringValue() == "6"); + assert(i->first == 6); + assert(i->second.getStringValue() == "6"); + assert(empty.begin()->second.getStringValue() == "5+"); + assert(empty.last()->first == 6); + assert(empty.last()->second.getStringValue() == "6"); } std::cout << "Insert into invalid" << std::endl; auto invalid1 = QPDFNumberTreeObjectHelper( @@ -1875,7 +1879,7 @@ void runtest(int n, char const* filename1, char const* arg2) std::cout << "/Bad3, no repair" << std::endl; auto bad3_oh = pdf.getTrailer().getKey("/Bad3"); auto bad3 = QPDFNumberTreeObjectHelper(bad3_oh, pdf, false); - for (auto i: bad3) + for (auto& i: bad3) { std::cout << i.first << " " << i.second.unparse() << std::endl; } @@ -1883,7 +1887,7 @@ void runtest(int n, char const* filename1, char const* arg2) std::cout << "/Bad3, repair" << std::endl; bad3 = QPDFNumberTreeObjectHelper(bad3_oh, pdf, true); - for (auto i: bad3) + for (auto& i: bad3) { std::cout << i.first << " " << i.second.unparse() << std::endl; } @@ -1893,7 +1897,7 @@ void runtest(int n, char const* filename1, char const* arg2) auto bad4 = QPDFNumberTreeObjectHelper( pdf.getTrailer().getKey("/Bad4"), pdf); bad4.insert(5, QPDFObjectHandle::newString("5")); - for (auto i: bad4) + for (auto& i: bad4) { std::cout << i.first << " " << i.second.unparse() << std::endl; } @@ -1924,7 +1928,7 @@ void runtest(int n, char const* filename1, char const* arg2) // name-tree.pdf QPDFObjectHandle qtest = pdf.getTrailer().getKey("/QTest"); QPDFNameTreeObjectHelper ntoh(qtest, pdf); - for (auto iter: ntoh) + for (auto& iter: ntoh) { std::cout << iter.first << " -> " << iter.second.getStringValue() @@ -1945,8 +1949,8 @@ void runtest(int n, char const* filename1, char const* arg2) assert(ntoh.findObject("07 sev\xe2\x80\xa2n", oh)); assert("seven!" == oh.getStringValue()); auto last = ntoh.last(); - assert((*last).first == "29 twenty-nine"); - assert((*last).second.getUTF8Value() == "twenty-nine!"); + assert(last->first == "29 twenty-nine"); + assert(last->second.getUTF8Value() == "twenty-nine!"); auto new1 = QPDFNameTreeObjectHelper::newEmpty(pdf); auto iter1 = new1.begin(); @@ -1957,32 +1961,36 @@ void runtest(int n, char const* filename1, char const* arg2) assert(iter1 == new1.end()); new1.insert("1", QPDFObjectHandle::newString("1")); ++iter1; - assert((*iter1).first == "1"); + assert(iter1->first == "1"); + auto& iter1_val = *iter1; --iter1; assert(iter1 == new1.end()); --iter1; - assert((*iter1).first == "1"); + assert(iter1->first == "1"); + assert(iter1_val.first == "1"); new1.insert("2", QPDFObjectHandle::newString("2")); ++iter1; - assert((*iter1).first == "2"); + assert(iter1->first == "2"); + assert(iter1_val.first == "2"); ++iter1; assert(iter1 == new1.end()); + assert(! iter1_val.second.isInitialized()); ++iter1; - assert((*iter1).first == "1"); + assert(iter1->first == "1"); --iter1; assert(iter1 == new1.end()); --iter1; - assert((*iter1).first == "2"); + assert(iter1->first == "2"); std::cout << "insertAfter" << std::endl; auto new2 = QPDFNameTreeObjectHelper::newEmpty(pdf); auto iter2 = new2.begin(); assert(iter2 == new2.end()); iter2.insertAfter("3", QPDFObjectHandle::newString("3!")); - assert((*iter2).first == "3"); + assert(iter2->first == "3"); iter2.insertAfter("4", QPDFObjectHandle::newString("4!")); - assert((*iter2).first == "4"); - for (auto i: new2) + assert(iter2->first == "4"); + for (auto& i: new2) { std::cout << i.first << " " << i.second.unparse() << std::endl; } @@ -1996,21 +2004,21 @@ void runtest(int n, char const* filename1, char const* arg2) assert(empty.begin() == empty.end()); assert(empty.last() == empty.end()); auto i = empty.insert("five", QPDFObjectHandle::newString("5")); - assert((*i).first == "five"); - assert((*i).second.getStringValue() == "5"); - assert((*empty.begin()).first == "five"); - assert((*empty.last()).first == "five"); - assert((*empty.begin()).second.getStringValue() == "5"); + assert(i->first == "five"); + assert(i->second.getStringValue() == "5"); + assert(empty.begin()->first == "five"); + assert(empty.last()->first == "five"); + assert(empty.begin()->second.getStringValue() == "5"); i = empty.insert("five", QPDFObjectHandle::newString("5+")); - assert((*i).first == "five"); - assert((*i).second.getStringValue() == "5+"); - assert((*empty.begin()).second.getStringValue() == "5+"); + assert(i->first == "five"); + assert(i->second.getStringValue() == "5+"); + assert(empty.begin()->second.getStringValue() == "5+"); i = empty.insert("six", QPDFObjectHandle::newString("6")); - assert((*i).first == "six"); - assert((*i).second.getStringValue() == "6"); - assert((*empty.begin()).second.getStringValue() == "5+"); - assert((*empty.last()).first == "six"); - assert((*empty.last()).second.getStringValue() == "6"); + assert(i->first == "six"); + assert(i->second.getStringValue() == "6"); + assert(empty.begin()->second.getStringValue() == "5+"); + assert(empty.last()->first == "six"); + assert(empty.last()->second.getStringValue() == "6"); } // Exercise deprecated API until qpdf 11 @@ -2030,8 +2038,8 @@ void runtest(int n, char const* filename1, char const* arg2) std::cout << "/Bad1 -- wrong key type" << std::endl; bad1 = QPDFNameTreeObjectHelper( pdf.getTrailer().getKey("/Bad1"), pdf); - assert((*bad1.find("G", true)).first == "A"); - for (auto i: bad1) + assert(bad1.find("G", true)->first == "A"); + for (auto const& i: bad1) { std::cout << i.first << std::endl; } @@ -2039,8 +2047,8 @@ void runtest(int n, char const* filename1, char const* arg2) std::cout << "/Bad2 -- invalid kid" << std::endl; auto bad2 = QPDFNameTreeObjectHelper( pdf.getTrailer().getKey("/Bad2"), pdf); - assert((*bad2.find("G", true)).first == "B"); - for (auto i: bad2) + assert(bad2.find("G", true)->first == "B"); + for (auto const& i: bad2) { std::cout << i.first << std::endl; } @@ -2053,8 +2061,8 @@ void runtest(int n, char const* filename1, char const* arg2) std::cout << "/Bad4 -- invalid kid" << std::endl; auto bad4 = QPDFNameTreeObjectHelper( pdf.getTrailer().getKey("/Bad4"), pdf); - assert((*bad4.find("F", true)).first == "C"); - for (auto i: bad4) + assert(bad4.find("F", true)->first == "C"); + for (auto const& i: bad4) { std::cout << i.first << std::endl; } @@ -2062,12 +2070,12 @@ void runtest(int n, char const* filename1, char const* arg2) std::cout << "/Bad5 -- loop in find" << std::endl; auto bad5 = QPDFNameTreeObjectHelper( pdf.getTrailer().getKey("/Bad5"), pdf); - assert((*bad5.find("F", true)).first == "D"); + assert(bad5.find("F", true)->first == "D"); std::cout << "/Bad6 -- bad limits" << std::endl; auto bad6 = QPDFNameTreeObjectHelper( pdf.getTrailer().getKey("/Bad6"), pdf); - assert((*bad6.insert("H", QPDFObjectHandle::newNull())).first == "H"); + assert(bad6.insert("H", QPDFObjectHandle::newNull())->first == "H"); } else if (n == 49) { @@ -2574,12 +2582,12 @@ void runtest(int n, char const* filename1, char const* arg2) auto check_split1 = [&split1](int k) { auto i = split1.insert(k, QPDFObjectHandle::newString( QUtil::int_to_string(k))); - assert((*i).first == k); + assert(i->first == k); }; check_split1(15); check_split1(35); check_split1(125); - for (auto i: split1) + for (auto const& i: split1) { std::cout << i.first << std::endl; } @@ -2591,10 +2599,10 @@ void runtest(int n, char const* filename1, char const* arg2) auto check_split2 = [](QPDFNameTreeObjectHelper& noh, std::string const& k) { auto i = noh.insert(k, QPDFObjectHandle::newUnicodeString(k)); - assert((*i).first == k); + assert(i->first == k); }; check_split2(split2, "C"); - for (auto i: split2) + for (auto const& i: split2) { std::cout << i.first << std::endl; } @@ -2605,7 +2613,7 @@ void runtest(int n, char const* filename1, char const* arg2) split3.setSplitThreshold(4); check_split2(split3, "P"); check_split2(split3, "\xcf\x80"); - for (auto i: split3) + for (auto& i: split3) { std::cout << i.first << " " << i.second.unparse() << std::endl; } @@ -2626,11 +2634,11 @@ void runtest(int n, char const* filename1, char const* arg2) assert(value.getUTF8Value() == "c"); auto iter1 = erase1.find("1B"); iter1.remove(); - assert((*iter1).first == "1D"); + assert(iter1->first == "1D"); iter1.remove(); assert(iter1 == erase1.end()); --iter1; - assert((*iter1).first == "1A"); + assert(iter1->first == "1A"); iter1.remove(); assert(iter1 == erase1.end()); @@ -2640,14 +2648,14 @@ void runtest(int n, char const* filename1, char const* arg2) iter2.remove(); assert(iter2 == erase2.end()); --iter2; - assert((*iter2).first == 240); + assert(iter2->first == 240); auto k1 = erase2_oh.getKey("/Kids").getArrayItem(1); auto l1 = k1.getKey("/Limits"); assert(l1.getArrayItem(0).getIntValue() == 230); assert(l1.getArrayItem(1).getIntValue() == 240); iter2 = erase2.find(210); iter2.remove(); - assert((*iter2).first == 220); + assert(iter2->first == 220); k1 = erase2_oh.getKey("/Kids").getArrayItem(0); l1 = k1.getKey("/Limits"); assert(l1.getArrayItem(0).getIntValue() == 220); @@ -2667,7 +2675,7 @@ void runtest(int n, char const* filename1, char const* arg2) pdf.getTrailer().getKey("/Erase4"), pdf); iter2 = erase4.find(420); iter2.remove(); - assert((*iter2).first == 430); + assert(iter2->first == 430); QPDFWriter w(pdf, "a.pdf"); w.setStaticID(true); |