From eae75dbe448b0395aee7e49c2a9cca9f82680782 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 19 Jun 2022 08:56:36 -0400 Subject: Add Pl_Function -- a generic function pipeline --- libtests/CMakeLists.txt | 1 + libtests/pl_function.cc | 29 +++++++++++++++++++++++++++++ libtests/qtest/pl_function.test | 17 +++++++++++++++++ libtests/qtest/pl_function/exp | 2 ++ 4 files changed, 49 insertions(+) create mode 100644 libtests/pl_function.cc create mode 100644 libtests/qtest/pl_function.test create mode 100644 libtests/qtest/pl_function/exp (limited to 'libtests') diff --git a/libtests/CMakeLists.txt b/libtests/CMakeLists.txt index 62ba390e..ea4dc7cd 100644 --- a/libtests/CMakeLists.txt +++ b/libtests/CMakeLists.txt @@ -24,6 +24,7 @@ set(TEST_PROGRAMS nntree numrange pdf_version + pl_function pointer_holder predictors qintc diff --git a/libtests/pl_function.cc b/libtests/pl_function.cc new file mode 100644 index 00000000..960ad5cb --- /dev/null +++ b/libtests/pl_function.cc @@ -0,0 +1,29 @@ +#include + +#include +#include +#include +#include + +int +main(int argc, char* argv[]) +{ + Pl_Function p1( + "p1", nullptr, [](unsigned char const* data, size_t len) { + std::cout << "p1: " << len << ": " << data << std::endl; + }); + p1.write(reinterpret_cast("potato"), 6); + + std::string s; + Pl_String ps("string", nullptr, s); + Pl_Base64 b("base64", &ps, Pl_Base64::a_encode); + Pl_Function p2( + "p2", &b, [](unsigned char const* data, size_t len) { + std::cout << "p2: " << len << ": " << data << std::endl; + }); + p2.write(reinterpret_cast("salad"), 5); + p2.finish(); + assert(s == "c2FsYWQ="); + + return 0; +} diff --git a/libtests/qtest/pl_function.test b/libtests/qtest/pl_function.test new file mode 100644 index 00000000..847aa472 --- /dev/null +++ b/libtests/qtest/pl_function.test @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +chdir("pl_function") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +my $td = new TestDriver('pl_function'); + +$td->runtest("pl_function", + {$td->COMMAND => "pl_function"}, + {$td->FILE => "exp", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->report(1); diff --git a/libtests/qtest/pl_function/exp b/libtests/qtest/pl_function/exp new file mode 100644 index 00000000..fd2ea1bc --- /dev/null +++ b/libtests/qtest/pl_function/exp @@ -0,0 +1,2 @@ +p1: 6: potato +p2: 5: salad -- cgit v1.2.3-54-g00ecf