diff options
author | Jay Berkenbilt <ejb@ql.org> | 2019-08-18 00:54:24 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2019-08-18 05:02:41 +0200 |
commit | e83f3308fbccd34959d325b830118eafe441fe48 (patch) | |
tree | b3ac08e39da91a00b67e147bd05f5379789fcbe3 /libtests | |
parent | 04419d7c3269aa29ff669c8b5f3a7999edb44bea (diff) | |
download | qpdf-e83f3308fbccd34959d325b830118eafe441fe48.tar.zst |
SparseOHArray
Diffstat (limited to 'libtests')
-rw-r--r-- | libtests/build.mk | 3 | ||||
-rw-r--r-- | libtests/qtest/sparse_array.test | 16 | ||||
-rw-r--r-- | libtests/sparse_array.cc | 82 |
3 files changed, 100 insertions, 1 deletions
diff --git a/libtests/build.mk b/libtests/build.mk index 4313b630..c8cc4d83 100644 --- a/libtests/build.mk +++ b/libtests/build.mk @@ -22,7 +22,8 @@ BINS_libtests = \ random \ rc4 \ runlength \ - sha2 + sha2 \ + sparse_array TARGETS_libtests = $(foreach B,$(BINS_libtests),libtests/$(OUTPUT_DIR)/$(call binname,$(B))) diff --git a/libtests/qtest/sparse_array.test b/libtests/qtest/sparse_array.test new file mode 100644 index 00000000..c3535d85 --- /dev/null +++ b/libtests/qtest/sparse_array.test @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +require TestDriver; + +my $td = new TestDriver('sparse array'); + +$td->runtest("sparse_array", + {$td->COMMAND => "sparse_array"}, + {$td->STRING => "sparse array tests done\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->report(1); diff --git a/libtests/sparse_array.cc b/libtests/sparse_array.cc new file mode 100644 index 00000000..9c3e00b4 --- /dev/null +++ b/libtests/sparse_array.cc @@ -0,0 +1,82 @@ +#include <qpdf/SparseOHArray.hh> +#include <assert.h> +#include <iostream> + +int main() +{ + SparseOHArray a; + assert(a.size() == 0); + + a.append(QPDFObjectHandle::parse("1")); + a.append(QPDFObjectHandle::parse("(potato)")); + a.append(QPDFObjectHandle::parse("null")); + a.append(QPDFObjectHandle::parse("null")); + a.append(QPDFObjectHandle::parse("/Quack")); + assert(a.size() == 5); + assert(a.at(0).isInteger() && (a.at(0).getIntValue() == 1)); + assert(a.at(1).isString() && (a.at(1).getStringValue() == "potato")); + assert(a.at(2).isNull()); + assert(a.at(3).isNull()); + assert(a.at(4).isName() && (a.at(4).getName() == "/Quack")); + + a.insert(4, QPDFObjectHandle::parse("/BeforeQuack")); + assert(a.size() == 6); + assert(a.at(0).isInteger() && (a.at(0).getIntValue() == 1)); + assert(a.at(4).isName() && (a.at(4).getName() == "/BeforeQuack")); + assert(a.at(5).isName() && (a.at(5).getName() == "/Quack")); + + a.insert(2, QPDFObjectHandle::parse("/Third")); + assert(a.size() == 7); + assert(a.at(1).isString() && (a.at(1).getStringValue() == "potato")); + assert(a.at(2).isName() && (a.at(2).getName() == "/Third")); + assert(a.at(3).isNull()); + assert(a.at(6).isName() && (a.at(6).getName() == "/Quack")); + + a.insert(0, QPDFObjectHandle::parse("/First")); + assert(a.size() == 8); + assert(a.at(0).isName() && (a.at(0).getName() == "/First")); + assert(a.at(1).isInteger() && (a.at(1).getIntValue() == 1)); + assert(a.at(7).isName() && (a.at(7).getName() == "/Quack")); + + a.erase(6); + assert(a.size() == 7); + assert(a.at(0).isName() && (a.at(0).getName() == "/First")); + assert(a.at(1).isInteger() && (a.at(1).getIntValue() == 1)); + assert(a.at(5).isNull()); + assert(a.at(6).isName() && (a.at(6).getName() == "/Quack")); + + a.erase(6); + assert(a.size() == 6); + assert(a.at(0).isName() && (a.at(0).getName() == "/First")); + assert(a.at(1).isInteger() && (a.at(1).getIntValue() == 1)); + assert(a.at(3).isName() && (a.at(3).getName() == "/Third")); + assert(a.at(4).isNull()); + assert(a.at(5).isNull()); + + a.setAt(4, QPDFObjectHandle::parse("12")); + assert(a.at(4).isInteger() && (a.at(4).getIntValue() == 12)); + a.setAt(4, QPDFObjectHandle::newNull()); + assert(a.at(4).isNull()); + + a.remove_last(); + assert(a.size() == 5); + assert(a.at(0).isName() && (a.at(0).getName() == "/First")); + assert(a.at(1).isInteger() && (a.at(1).getIntValue() == 1)); + assert(a.at(3).isName() && (a.at(3).getName() == "/Third")); + assert(a.at(4).isNull()); + + a.remove_last(); + assert(a.size() == 4); + assert(a.at(0).isName() && (a.at(0).getName() == "/First")); + assert(a.at(1).isInteger() && (a.at(1).getIntValue() == 1)); + assert(a.at(3).isName() && (a.at(3).getName() == "/Third")); + + a.remove_last(); + assert(a.size() == 3); + assert(a.at(0).isName() && (a.at(0).getName() == "/First")); + assert(a.at(1).isInteger() && (a.at(1).getIntValue() == 1)); + assert(a.at(2).isString() && (a.at(2).getStringValue() == "potato")); + + std::cout << "sparse array tests done" << std::endl; + return 0; +} |